int main(int argc, char *argv[]) { pid_t child = 0; siginfo_t sig; if (argc != 3) { errx(EXIT_FAILURE, "usage: %s pid tracer_buff_address\n", argv[0]); } dump_prefix = getenv("CERE_WORKING_PATH"); if(!dump_prefix) { debug_print("%s\n", "CERE_WORKING_PATH not defined, using defaut cere dir.\n"); dump_prefix = ".cere"; } char * ft = getenv("CERE_FIRSTTOUCH"); if (ft && strcmp("TRUE", ft) == 0) { firsttouch_active = true; debug_print("%s\n", "First touch capture is active"); } child = atoi(argv[1]); sscanf(argv[2], "%p", &tracer_buff); tracer_init(child); /* Wait for lock_mem trap */ pid_t tid = handle_events_until_dump_trap(-1); register_t ret = get_arg_from_regs(tid); assert(ret == TRAP_LOCK_MEM); stop_all_except(tid); tracer_lock_mem(tid); debug_print("%s\n", "******* TRACER_LOCKED"); tracer_state = TRACER_LOCKED; continue_all(); /* Dump arguments */ tracer_dump(tid); debug_print("%s\n", "******* TRACER_DUMPING"); tracer_state = TRACER_DUMPING; ptrace_syscall(tid); while (1) { handle_events_until_dump_trap(-1); } }
static void tracer_init(pid_t pid) { PAGESIZE = sysconf(_SC_PAGESIZE); event_t e = wait_event(pid); assert(e.signo == SIGSTOP); follow_threads(pid); create_dump_dir(); debug_print("%s\n", "Tracer initialized"); if (firsttouch_active) { htable_init(&firsttouch, rehash, NULL); stop_all_except(pid); tracer_lock_mem(pid); debug_print("%s\n", "******* TRACER_FIRSTTOUCH"); tracer_state = TRACER_FIRSTTOUCH; } else { debug_print("%s\n", "******* TRACER_UNLOCKED"); tracer_state = TRACER_UNLOCKED; } continue_all(); }
static void stop_application() { continue_all(screen); g_main_loop_unref(loop); exit(0); }