免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1141 | 回复: 0
打印 上一主题 下一主题

another way to get sys_call_table for kernel 2.6 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-02-15 09:47 |只看该作者 |倒序浏览
sys_call_table in Linux kernel 2.6 is not exported. here is a way to find it out.

#include linux/kernel.h>
#include linux/module.h>
#include linux/init.h>
#include linux/config.h>
#include linux/thread_info.h>
#include linux/ptrace.h>
MODULE_LICENSE("Dual BSD/GPL");
struct    dummyidt {
    unsigned short    idtdata[4];
};
static    void *arch_get_syscall_entry(void)
{
    struct dummyidt *idt;
    char    idtrbuf[8];
    void    *addr;
    __asm__ volatile ("sidt %0;"
            :"=m"(idtrbuf[0]));
    idt = (void*)(*(unsigned long*)(idtrbuf + 2));
    printk("idt@:%p\n", idt);
    addr = (void*)(((unsigned int )idt[0x80].idtdata[0]) |
        (((unsigned int)idt[0x80].idtdata[3])  16));
    printk("syscall entry@: %p\n", addr);
    return    addr;
}
static    int addr_seems_ok(void *addr)
{
    static    void    *addrbegin = NULL;
    if (addrbegin == NULL){
        addrbegin = arch_get_syscall_entry();
    }
    if ((addr > addrbegin) && (addr  addrbegin + 2000))
        return    1;
    return    0;
}
static    void* get_tbl_addr(unsigned long stacksz)
{
    char    callinstr[] = {0xff, 0x14, 0x85, 0};
    void    *stacktop;
    void    *syscalltable = NULL;
    char    *mem;
    stacktop = (void*)current_thread_info() + stacksz;
    stacktop -= sizeof(struct pt_regs) + sizeof(void*);
    mem = *(char**)stacktop;
    if (!addr_seems_ok(mem))
        return    syscalltable;
    mem -= 7;
    /*
     * @mem points to the address of
     * `call sys_call_table(, %eax, 4)`, now.
     */
    if (strcmp(mem, callinstr) == 0){
        mem += 3;
        syscalltable = (void*)*(unsigned long *)mem;
    }
    return    syscalltable;
}
static    int getsyscall_init(void)
{
    void *tbl;
    unsigned long stacksz;
    for (stacksz = 1  PAGE_SHIFT; stacksz  (1  14); stacksz = 1){
        tbl = get_tbl_addr(stacksz);
        if (tbl != NULL){
            goto    findtbl;
        }
    }
    printk("syscall table not found\n");
    return    0;
findtbl:
    printk("syscall table @ %p, stacksize=%lu\n",
            tbl, stacksz);
    return    0;
}
static    void getsyscall_exit(void)
{
}
module_init(getsyscall_init);
module_exit(getsyscall_exit);

I was laughing at the Windows Vxers' brute force search for PE header, when I was a college student, and what I am searching for now is even not a string...


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/10543/showart_247586.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP