将程序输出从 /dev/*char_device* 重定向到文本文件

逆向工程 固件 linux 司机
2021-06-13 16:23:58

我目前正在尝试反转运行我拥有 root 的 2.6 Linux 内核的 IoT 机器。在这台机器上,软件写入 /dev/ some_device来控制我认为是串行总线的 GPIO 引脚。为了控制这些 GPIO 引脚,我一直在尝试反转板载软件以掌握驱动程序如何寻找输入,但反编译很混乱/缺少部分。

因此,我的问题是: 我是否能够将用于 /dev/ some_device 的程序输出重定向到文本文件进行分析?

例如当前的映射:

程序->(字符序列)-> /dev/*char_device*

我正在寻找一种方法将程序输出从设备重定向到文本文件,或者更好的是,将设备的任何写入重定向到文本文件。例子:

程序->(字符序列)--\ /dev/*char_device*
                              \
                               \-----> *my_text_file*

同样,我这样做的动机是分析驾驶员如何期望输入。我已经知道串行总线上的逻辑输入/输出/返回通信,我只需要能够确定设备驱动程序的细节。任何帮助表示赞赏。如果需要更多信息,请告诉我。

-Update- 这是我在源代码反编译中找到的一个方法。虽然我无法验证这是否是我所针对的设备的确切处理程序,但它被具有相似名称的设备使用。

// 地址范围:0x1000c470 - 0x1000c6f7
int32_t function_1000c470(int32_t * a1, int32_t a2, int32_t a3, char * path) {
    int32_t v1 = (int32_t)a1;
    int32_t v2; // bp-144
    int32_t v3 = &v2; // 0x1000c470_0
    v2 = v3;
    g602 = v3;
    int32_t fd = 打开(路径,O_RDWR);
    int32_t * fd2 = (int32_t *)(v1 + 4); // 0x1000c4a8_0
    * fd2 = fd;
    如果(* fd2 0x1000c6d8
    } 别的 {
        // 0x1000c500
        fprintf(g94, "用 fd %d\n 打开串行设备 %s", path, *fd2);
        int32_t termios_p;
        tcgetattr(*fd2, (struct termios *)&termios_p);
        cfmakeraw((struct termios *)&termios_p);
        cfsetospeed((struct termios *)&termios_p, 9);
        cfsetispeed((struct termios *)&termios_p, 9);
        tcsetattr(*fd2, TCSANOW, (struct termios *)&termios_p);
        ioctl(*fd2, 0x5415);
        g1 &= -0x2000001;
        ioctl(*fd2, 0x5418);
        *(int32_t *)(v1 + 16) = 0;
        *(int32_t *)(v1 + 20) = 0;
        int32_t * v4 = (int32_t *)(4 * *fd2 / 32 + v1 + 1668); // 0x1000c630_0
        *v4 = 1 0x1000c674
        }
        // 0x1000c674
        *(int32_t *)(v1 + 8) = v7 + 1;
        *(int32_t *)(v1 + 1624) = 0;
        *(int32_t *)(v1 + 1620) = 0;
        *(int32_t *)(v1 + 1628) = 0;
        memset((char *)(v1 + 120), 0, 1500);
        function_1000c6f8(*fd2, 0);
        // 分支 -> 0x1000c6d8
    }
    int32_t v8 = v2; // 0x1000c6dc
    g602 = *(int32_t *)(v8 - 4);
    返回 *(int32_t *)(v8 + 4);
}
1个回答

/dev/ptmx为此目的使用过:

说我想拦截写入的数据 /dev/somedevice

  • 首先我打开主人:/dev/ptmx.
  • 然后我通过调用分配一个奴隶ptsname
  • 现在重命名/dev/somedevice/dev/somedevice.orig
  • 符号链接/dev/somedevice到 pts 从站。
  • 打开原始设备 /dev/somedevice.orig

  • 开始在主设备和原始设备之间复制数据。将数据记录到日志文件中。

确保拦截器在原始程序打开设备之前启动。

另外,我认为您可能会遇到ioctl以这种方式处理s 的问题