当动态加载linux内核驱动程序时,我们如何编写一个C函数来报告驱动程序模块所在的位置(内存地址)?
这是更多的Windows,但是,如果我们适应类似的驱动程序Linux工作?
long sizeOfExe = 0; FILE *fp; fp = fopen("./Mini.ko", "rb"); // reading itself fseek(fp, 0L, SEEK_END); sizeOfExe = ftell(fp); printf("The size of this driver module is: %ld bytes\n", sizeOfExe); int* addressStartOfFile = &fp; printf("Location of this driver module starts at: 0x%x\n", addressStartOfFile); printf("Location of this driver module ends at: 0x%x\n", (addressStartOfFile+sizeOfExe)); /* The size of this driver module is: 18727 bytes Location of this driver module starts at: 0x28ff30 Location of this driver module ends at: 0x2a23cc */
当动态加载linux内核驱动程序时,我们如何编写一个C函数来报告驱动程序模块所在的位置(内存地址)?
我们编写它来读取(通过popen()
等)shell命令的输出或转换为C
grep '\[modulename]' /proc/k*syms | sort