SPI 设备嗅探/镜像功能

逆向工程 尖峰
2021-07-08 17:04:06

我有一个嵌入式 Linux ARM 板,其中一个应用程序打开/dev/spidev1.0设备并不断与另一个 MCU 对话。现在,如果我尝试查看哪些交换(这是我需要的),执行 hexdump/dev/spidev1.0会在开始时显示一些内容,但会导致应用程序崩溃。该应用程序非常敏感,我认为它会崩溃,因为该应用程序使用并且不能同时用于查看。

如果我编写一些额外的代码/驱动程序,有没有办法创建别名,或者像这个设备的镜像之类的东西?或者我没有机会像那样嗅探流量(在软件中)?

改写:

int ioctl(int fd, unsigned long request, struct spi_ioc_transfer *xfer)

但是,gcc输出以下错误:

myioctl.c:6:5: error: conflicting types for ‘ioctl’ In file included from myioctl.c:1:0: /usr/lib/gcc-cross/arm-linux-gnueabi/4.7/../../../../arm-linux-gnueabi/include/s‌​ys/ioctl.h:41:12: note: previous declaration of ‘ioctl’ was here

任何帮助如何原始定义:

/* Perform the I/O control operation specified by REQUEST on FD.
   One argument may follow; its presence and type depend on REQUEST.
   Return value depends on REQUEST.  Usually -1 indicates error.  */

extern int ioctl (int __fd, unsigned long int __request, ...) __THROW;

可以被覆盖。

1个回答

如果此 Linux 发行版确实支持 LD_PRELOAD,您可以轻松地使用此功能来覆盖此特定设备的打开/关闭/读取/写入/ioctl-ing 功能。在这里查看非常基本的教程:http : //www.catonmat.net/blog/simple-ld-preload-tutorial/

这不需要编写驱动程序和非常有用的方法。此外,您可以尝试使用strace实用程序来跟踪所有 IO 系统调用,这显然包括对您设备的访问。