当动态加载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
*/
1 回答
我们写它来读取(通过
popen()
等)shell命令的输出,或者将其转换为C.