- 论坛徽章:
- 0
|
- /**
- * Return the first appearence of NEEDLE in HAYSTACK.
- * */
- static void *memmem(const void *haystack, size_t haystack_len,
- const void *needle, size_t needle_len)
- {
- const char *begin;
- const char *const last_possible
- = (const char *) haystack + haystack_len - needle_len;
- if (needle_len == 0)
- /* The first occurrence of the empty string is deemed to occur at
- the beginning of the string. */
- return (void *) haystack;
- /* Sanity check, otherwise the loop might search through the whole
- memory. */
- if (__builtin_expect(haystack_len < needle_len, 0))
- return NULL;
- for (begin = (const char *) haystack; begin <= last_possible;
- ++begin)
- if (begin[0] == ((const char *) needle)[0]
- && !memcmp((const void *) &begin[1],
- (const void *) ((const char *) needle + 1),
- needle_len - 1))
- return (void *) begin;
- return NULL;
- }
- /**
- * Find the location of sys_call_table
- */
- static unsigned long get_sys_call_table(void)
- {
- /* we'll read first 100 bytes of int $0x80 */
- #define OFFSET_SYSCALL 100
- struct idtr idtr;
- struct idt idt;
- unsigned sys_call_off;
- unsigned retval;
- char sc_asm[OFFSET_SYSCALL], *p;
- /* well, let's read IDTR */
- asm("sidt %0":"=m"(idtr)
- :
- :"memory" );
- dbgprint("idtr base at 0x%X\n", (unsigned int)idtr.base);
- /* Read in IDT for vector 0x80 (syscall) */
- memcpy(&idt, (char *) idtr.base + 8 * 0x80, sizeof(idt));
- sys_call_off = (idt.off2 << 16) | idt.off1;
- dbgprint("idt80: flags=%X sel=%X off=%X\n",
- (unsigned) idt.flags, (unsigned) idt.sel, sys_call_off);
- /* we have syscall routine address now, look for syscall table
- dispatch (indirect call) */
- memcpy(sc_asm, (void *)sys_call_off, OFFSET_SYSCALL);
- /**
- * Search opcode of `call sys_call_table(,eax,4)'
- */
- p = (char *) memmem(sc_asm, OFFSET_SYSCALL, "\xff\x14\x85", 3);
- if (p == NULL)
- return 0;
- retval = *(unsigned *) (p + 3);
- if (p) {
- dbgprint("sys_call_table at 0x%x, call dispatch at 0x%x\n",
- retval, (unsigned int) p);
- }
- return retval;
- #undef OFFSET_SYSCALL
- }
复制代码 这个是我以前做的项目里的一部分,应该是抄的albcamus的某个帖子,在as5下没有问题。
查找前先处理cr0的第17位(还是第20位?)
[ 本帖最后由 caravsapm70 于 2009-9-24 13:06 编辑 ] |
|