全部博文(346)
分类: C/C++
2008-08-27 22:15:58
Header | Leading guard(0xFC) | User data(0xEB) | Tailing guard(0xFC) |
空闲内存(0xDD) |
Before if (m_hsession) gblHandles->ReleaseUserHandle( m_hsession ); if (m_dberr) delete m_dberr; After if (m_hsession) { _Insight_stack_call(0); gblHandles->ReleaseUserHandle(m_hsession); _Insight_after_call(); } _Insight_ptra_check(1994, (void **) &m_dberr, (void *) m_dberr); if (m_dberr) { _Insight_deletea(1994, (void **) &m_dberr, (void *) m_dberr, 0); delete m_dberr; } |
void *__bound_ptr_add(void *p, intoffset) { unsignedlongaddr = (unsignedlong)p; BoundEntry *e; #if defined(BOUND_DEBUG) printf("add: 0x%x %d\n", (int)p, offset); #endif e = __bound_t1[addr >> (BOUND_T2_BITS + BOUND_T3_BITS)]; e = (BoundEntry *)((char *)e + ((addr >> (BOUND_T3_BITS - BOUND_E_BITS)) & ((BOUND_T2_SIZE - 1) << BOUND_E_BITS))); addr -= e->start; if (addr > e->size) { e = __bound_find_region(e, p); addr = (unsignedlong)p - e->start; } addr += offset; if (addr > e->size) returnINVALID_POINTER; /* return an invalid pointer */ returnp + offset; } staticvoid__bound_check(constvoid *p, size_tsize) { if (size == 0) return; p = __bound_ptr_add((void *)p, size); if (p == INVALID_POINTER) bound_error("invalid pointer"); } |
void *__bound_malloc(size_tsize, constvoid *caller) { void *ptr; /* we allocate one more byte to ensure the regions will be separated by at least one byte. With the glibc malloc, it may be in fact not necessary */ ptr = libc_malloc(size + 1); if (!ptr) returnNULL; __bound_new_region(ptr, size); returnptr; } void__bound_free(void *ptr, constvoid *caller) { if (ptr == NULL) return; if (__bound_delete_region(ptr) != 0) bound_error("freeing invalid region"); libc_free(ptr); } |
void *__bound_memcpy(void *dst, constvoid *src, size_tsize) { __bound_check(dst, size); __bound_check(src, size); /* check also region overlap */ if (src >= dst && src < dst + size) bound_error("overlapping regions in memcpy()"); returnmemcpy(dst, src, size); } |
voidmain ( void ) { CreateProcess ( ..., DEBUG_ONLY_THIS_PROCESS ,... ) ; while ( 1 == WaitForDebugEvent ( ... ) ) { if ( EXIT_PROCESS ) { break ; } ContinueDebugEvent ( ... ) ; } } |
#include #include #include #include #include etc. */ intmain(intargc, char *argv[]) { pid_t traced_process; struct user_regs_struct regs; longins; if(argc != 2) { printf("Usage: %s argv[0], argv[1]); exit(1); } traced_process = atoi(argv[1]); ptrace(PTRACE_ATTACH, traced_process, NULL, NULL); wait(NULL); ptrace(PTRACE_GETREGS, traced_process, NULL, ®s); ins = ptrace(PTRACE_PEEKTEXT, traced_process, regs.eip, NULL); printf("EIP: %lx Instruction executed: %lx\n", regs.eip, ins); ptrace(PTRACE_DETACH, traced_process, NULL, NULL); return 0; } |