android内核系统调用钩子可以';t跨越我的钩子函数

android内核系统调用钩子可以';t跨越我的钩子函数,android,linux,Android,Linux,最近,我学习了如何钩住android金鱼内核2.6,我编写了如下钩子.c: #include <linux/kernel.h> #include <linux/module.h> #include <linux/moduleparam.h> #include <linux/unistd.h> #include <linux/semaphore.h> #include <asm/cacheflush.h> #include &

最近,我学习了如何钩住android金鱼内核2.6,我编写了如下钩子.c:

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/unistd.h>
#include <linux/semaphore.h>
#include <asm/cacheflush.h>
#include <linux/string.h>

void **sys_call_table;

asmlinkage int (*original_call_open) (const char*, int, int);

asmlinkage int (*original_call_read) (unsigned int, char*, int);

asmlinkage int our_sys_read(unsigned int fd, char * buf, int count){

if(fd == 0 && count == 1){
    printk("有文件正在被读取intercept 0x%02X", buf[0]);
}

return original_call_read(fd, buf, count);
}

asmlinkage int our_sys_open(const char* file, int flags, int mode)
{
    //联系人 /data/data/com.android.providers.contacts/databases/contacts2.db
    //通话记录       /data/data/com.android.providers.telephony/databases/telephony.db
    //短信记录  /data/data/com.android.providers.telephony/databases/mmssms.db
    char * contact = "/data/data/com.android.providers.contacts/databases/contacts2.db";
    char * telephony = "/data/data/com.android.providers.telephony/databases/telephony.db";
    char * sms = "/data/data/com.android.providers.telephony/databases/mmssms.db";
    if (strcmp(file, contact) == 0){
       printk("应用程序正在读取手机的联系人记录!!!\n");
    }
   if (strcmp(file, telephony) == 0){
    printk("应用程序正在读取手机的通话记录!!!\n");
   }
   if (strcmp(file, sms) == 0){
    printk("应用程序正在读取手机的短信记录!!!\n");
   }


// printk("A file was opened\n%s\n%d\n%d\n",file,flags,mode);
   return original_call_open(file, flags, mode);
 }

int init_module()
{

sys_call_table = (void*)0xc0022f24;
original_call_open = sys_call_table[__NR_open];
original_call_read = sys_call_table[__NR_read];

sys_call_table[__NR_open] = our_sys_open;
sys_call_table[__NR_read] = our_sys_read;
return 0;
}

void cleanup_module()
{
// Restore the original call
sys_call_table[__NR_open] = original_call_open;
sys_call_table[__NR_read] = original_call_read;
}
}


我的应用程序访问联系人,但当我使用cat/proc/kmsg时,它不会显示我的内核信息。有人能帮我吗?多谢各位

经过几天的学习,我得到了正确的答案,哦……这是一个可怕的过程。现在,让我们来回答这个问题~~

if (strcmp(file, contact) == 0){
   printk("应用程序正在读取手机的联系人记录!!!\n");
}
上层程序是解决这个问题的关键,我们知道APK文件将使用api来读取联系人,但在我的程序中,我使用strcmp()来比较字符串。API将不会使用“/data/data/com.android.providers.contacts/databases/contacts2.db”,单击此字符串。也许它会使用“/data/data/com.android.providers.contacts/databases/contacts2.db/data…” 所以我们应该使用strstr()来比较这些。 最后是正确的程序:

if (strcmp(file, contact)) == 0 || strstr(file, contact) != NULL){
     printk("应用程序正在读取手机的联系人记录!!!");
}

不大可能发生的您实际的问题很可能是在开始测试之前文件已经打开了。请记住,读取联系人数据库的不是您的应用程序,而是另一个程序,它通常在引导后不久启动,并在授权应用程序通过IPC请求时执行操作。当然,无论如何,你不应该在内核模块中硬编码路径。这很酷,你是对的~~但是我想知道挂接内核调用的更好方法,因为你说硬编码路径并不更好!谢谢你的评论,希望你能回复我@克丽斯特拉顿
if (strcmp(file, contact)) == 0 || strstr(file, contact) != NULL){
     printk("应用程序正在读取手机的联系人记录!!!");
}