我的HTC Sensation XL有一个Android LKM,如下所示,它将在调用sys_open之前打印一条调试消息。我的操作系统是Ubuntu 11.10 64bit。 Android内核是从http://www.htcdev.com/devcenter/downloads下载的runnymede-crc-2.6.35。
/ *
* mydebug.c
*系统调用sys_open dubugging
* /
#include <linux/kernel.h>
#include <linux/module.h>
#include <asm/unistd.h>
asmlinkage ssize_t (*orig_open)(const char *pathname, int flags);
asmlinkage ssize_t hooked_open(const char *pathname, int flags)
{
printk(KERN_INFO "SYS_OPEN: %s\n", pathname);
return orig_open(pathname, flags);
}
static int __init root_start(void)
{
unsigned long sys_addr = 0xc003b104; /* System.map */
unsigned long *sys_call_table= (unsigned long *)sys_addr;
orig_open = sys_call_table[__NR_open];
sys_call_table[__NR_open] = hooked_open;
return 0;
}
static void __exit root_stop(void)
{
unsigned long sys_addr = 0xc003b104;
unsigned long *sys_call_table= (unsigned long *)sys_addr;
sys_call_table[__NR_open] = &orig_open;
}
module_init(root_start);
module_exit(root_stop);
但它在编译期间显示错误,
make -C /home/scott/runnymede-crc-2.6.35/ M=$(PWD) ARCH=arm CROSS_COMPILE=~/android-ndk-r7b/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi- modules
make[1]: Entering directory '/home/scott/runnymede-crc-2.6.35'
CC [M] /home/scott/workspace/debugkit/mydebug.o
cc1: warnings being treated as errors
/home/scott/workspace/debugkit/mydebug.c: In function 'root_start':
/home/scott/workspace/debugkit/mydebug.c:23: error: assignment makes pointer from integer without a cast
/home/scott/workspace/debugkit/mydebug.c:24: error: assignment makes integer from pointer without a cast
/home/scott/workspace/debugkit/mydebug.c: In function 'root_stop':
/home/scott/workspace/debugkit/mydebug.c:34: error: assignment makes integer from pointer without a cast
make[2]: [/home/scott/workspace/debugkit/mydebug.o] Error 1
make[1]: [_module_/home/scott/workspace/debugkit] Error 2
make[1]: Leaving directory '/home/scott/runnymede-crc-2.6.35'
make: [default] Error 2
任何人都可以帮助我?
答案 0 :(得分:1)
您将sys_call_table
定义为指向unsigned long的指针,然后执行sys_call_table[1234]
。
结果类型是unsigned long。您尝试为此指定一个指针。
这正是编译器告诉你的。重新定义sys_call_table
的类型或转换作业。
请注意,替换系统调用是非常不受欢迎的,特别是来自内核模块。事实上,你必须做一些愚蠢的事情,比如使用system.map中的硬编码地址,这一事实应该被视为你不应该首先这样做的提示。