Пример #1
0
DR_EXPORT void
dr_client_main(client_id_t id, int argc, const char *argv[])
{
    /* We need 2 reg slots beyond drreg's eflags slots => 3 slots */
    drreg_options_t ops = { sizeof(ops), 3, false };
    dr_set_client_name("DynamoRIO Sample Client 'memtrace'",
                       "http://dynamorio.org/issues");
    if (!drmgr_init() || drreg_init(&ops) != DRREG_SUCCESS || !drutil_init())
        DR_ASSERT(false);

    /* register events */
    dr_register_exit_event(event_exit);
    if (!drmgr_register_thread_init_event(event_thread_init) ||
        !drmgr_register_thread_exit_event(event_thread_exit) ||
        !drmgr_register_bb_app2app_event(event_bb_app2app, NULL) ||
        !drmgr_register_bb_instrumentation_event(NULL /*analysis_func*/,
                                                 event_app_instruction, NULL))
        DR_ASSERT(false);

    client_id = id;
    mutex = dr_mutex_create();

    tls_idx = drmgr_register_tls_field();
    DR_ASSERT(tls_idx != -1);
    /* The TLS field provided by DR cannot be directly accessed from the code cache.
     * For better performance, we allocate raw TLS so that we can directly
     * access and update it with a single instruction.
     */
    if (!dr_raw_tls_calloc(&tls_seg, &tls_offs, MEMTRACE_TLS_COUNT, 0))
        DR_ASSERT(false);

    /* make it easy to tell, by looking at log file, which client executed */
    dr_log(NULL, DR_LOG_ALL, 1, "Client 'memtrace' initializing\n");
}
Пример #2
0
DR_EXPORT void
dr_init(client_id_t id)
{
    drmgr_priority_t priority = {sizeof(priority), "drmgr-test", NULL, NULL, 0};
    drmgr_priority_t priority4 = {sizeof(priority), "drmgr-test4", NULL, NULL, 0};
    drmgr_priority_t sys_pri_A = {sizeof(priority), "drmgr-test-A",
                                  NULL, NULL, 10};
    drmgr_priority_t sys_pri_B = {sizeof(priority), "drmgr-test-B",
                                  "drmgr-test-A", NULL, 5};
    bool ok;

    drmgr_init();
    dr_register_exit_event(event_exit);
    drmgr_register_thread_init_event(event_thread_init);
    drmgr_register_thread_exit_event(event_thread_exit);

    ok = drmgr_register_bb_instrumentation_event(event_bb_analysis,
                                                 event_bb_insert,
                                                 &priority);
    CHECK(ok, "drmgr register bb failed");

    /* check register/unregister instrumentation_ex */
    ok = drmgr_register_bb_instrumentation_ex_event(event_bb4_app2app,
                                                    event_bb4_analysis,
                                                    event_bb4_insert2,
                                                    event_bb4_instru2instru,
                                                    NULL);
    CHECK(ok, "drmgr_register_bb_instrumentation_ex_event failed");
    ok = drmgr_unregister_bb_instrumentation_ex_event(event_bb4_app2app,
                                                      event_bb4_analysis,
                                                      event_bb4_insert2,
                                                      event_bb4_instru2instru);
    CHECK(ok, "drmgr_unregister_bb_instrumentation_ex_event failed");

    /* test data passing among all 4 phases */
    ok = drmgr_register_bb_instrumentation_ex_event(event_bb4_app2app,
                                                    event_bb4_analysis,
                                                    event_bb4_insert,
                                                    event_bb4_instru2instru,
                                                    &priority4);

    tls_idx = drmgr_register_tls_field();
    CHECK(tls_idx != -1, "drmgr_register_tls_field failed");
    cls_idx = drmgr_register_cls_field(event_thread_context_init,
                                       event_thread_context_exit);
    CHECK(cls_idx != -1, "drmgr_register_tls_field failed");

    dr_register_filter_syscall_event(event_filter_syscall);
    ok = drmgr_register_pre_syscall_event_ex(event_pre_sys_A, &sys_pri_A) &&
        drmgr_register_pre_syscall_event_ex(event_pre_sys_B, &sys_pri_B);
    CHECK(ok, "drmgr register sys failed");
    ok = drmgr_register_post_syscall_event_ex(event_post_sys_A, &sys_pri_A) &&
        drmgr_register_post_syscall_event_ex(event_post_sys_B, &sys_pri_B);
    CHECK(ok, "drmgr register sys failed");

    syslock = dr_mutex_create();

    ok = drmgr_register_bb_app2app_event(one_time_bb_event, NULL);
    CHECK(ok, "drmgr app2app registration failed");
}
Пример #3
0
DR_EXPORT void
dr_client_main(client_id_t id, int argc, const char *argv[])
{
    dr_set_client_name("DynamoRIO Sample Client 'inline'",
                       "http://dynamorio.org/issues");
    if (!drmgr_init())
        DR_ASSERT(false);

    hashtable_init_ex(&head_table, HASH_BITS, HASH_INTPTR, false/*!strdup*/,
                      false/*synchronization is external*/,
                      free_trace_head_entry, NULL, NULL);

    dr_register_exit_event(event_exit);
    if (!drmgr_register_bb_instrumentation_event(event_analyze_bb, NULL, NULL))
        DR_ASSERT(false);
    dr_register_delete_event(event_fragment_deleted);
    dr_register_end_trace_event(query_end_trace);

    /* Make it easy to tell from the log file which client executed. */
    dr_log(NULL, DR_LOG_ALL, 1, "Client 'inline' initializing\n");
#ifdef SHOW_RESULTS
    /* also give notification to stderr */
    if (dr_is_notify_on()) {
# ifdef WINDOWS
        /* Ask for best-effort printing to cmd window.  Must be called at init. */
        dr_enable_console_printing();
# endif
        dr_fprintf(STDERR, "Client inline is running\n");
    }
#endif
}
Пример #4
0
DR_EXPORT void
dr_init(client_id_t id)
{
    if (!drmgr_init())
        CHECK(false, "init failed");

    /* init buffer routines */
    drx_init();
    circular_fast = drx_buf_create_circular_buffer(DRX_BUF_FAST_CIRCULAR_BUFSZ);
    circular_slow = drx_buf_create_circular_buffer(CIRCULAR_SLOW_SZ);
    trace         = drx_buf_create_trace_buffer(TRACE_SZ, verify_trace_buffer);
    CHECK(circular_fast != NULL, "circular fast failed");
    CHECK(circular_slow != NULL, "circular slow failed");
    CHECK(trace != NULL, "trace failed");

    CHECK(drmgr_register_thread_init_event(event_thread_init),
          "event thread init failed");

    /* register events */
    dr_register_exit_event(event_exit);
    if (!drmgr_register_bb_instrumentation_event(event_app_analysis,
                                                 event_app_instruction,
                                                 NULL))
        CHECK(false, "init failed");
}
Пример #5
0
DR_EXPORT void
dr_client_main(client_id_t id, int argc, const char *argv[])
{
    uint i;

    dr_set_client_name("DynamoRIO Sample Client 'stats'", "http://dynamorio.org/issues");
    my_id = id;
    /* Make it easy to tell by looking at the log which client executed. */
    dr_log(NULL, LOG_ALL, 1, "Client 'stats' initializing\n");

    if (!drmgr_init())
        DR_ASSERT(false);
    drx_init();

    stats = shared_memory_init();
    memset(stats, 0, sizeof(stats));
    stats->num_stats = NUM_STATS;
    stats->pid = dr_get_process_id();
    for (i=0; i<NUM_STATS; i++) {
        strncpy(stats->names[i], stat_names[i], CLIENTSTAT_NAME_MAX_LEN);
        stats->names[i][CLIENTSTAT_NAME_MAX_LEN-1] = '\0';
    }
    dr_register_exit_event(event_exit);
    if (!drmgr_register_bb_instrumentation_event(event_analyze_bb,
                                                 event_insert_instrumentation, NULL))
        DR_ASSERT(false);
}
Пример #6
0
DR_EXPORT
void dr_init(client_id_t id)
{
    client_id = id;
    dr_fprintf(STDERR, "thank you for testing the client interface\n");
    drmgr_init();
    cls_idx = drmgr_register_cls_field(event_thread_context_init,
                                       event_thread_context_exit);
    ASSERT(cls_idx != -1);
    dr_register_nudge_event(event_nudge, id);
    dr_register_filter_syscall_event(event_filter_syscall);
    drmgr_register_pre_syscall_event(event_pre_syscall);
    drmgr_register_post_syscall_event(event_post_syscall);
    dr_register_exit_event(event_exit);

#ifdef WINDOWS
    sysnum_CreateProcess = get_sysnum("NtCreateProcess");
    ASSERT(sysnum_CreateProcess != -1);
    /* not asserting on these since added later */
    sysnum_CreateProcessEx = get_sysnum("NtCreateProcessEx");
    sysnum_CreateUserProcess = get_sysnum("NtCreateUserProcess");
    sysnum_ResumeThread = get_sysnum("NtResumeThread");
    ASSERT(sysnum_ResumeThread != -1);
#endif
}
Пример #7
0
/* callbacks for the entire process */
void funcwrap_init(client_id_t id, const char * name, const char * arguments)
{

	file_t in_file;
	char logfilename[MAX_STRING_LENGTH];

	drmgr_init();
	drwrap_init();
	tls_index = drmgr_register_tls_field();

	DR_ASSERT(parse_commandline_args(arguments) == true);
	head = md_initialize();
	if (!dr_file_exists(client_arg->filter_filename)){
		file_registered = false;
	}
	/* we expect the filter file to be of the form for function filtering */
	else{
		file_registered = true;
		in_file = dr_open_file(client_arg->filter_filename, DR_FILE_READ);
		DR_ASSERT(in_file != INVALID_FILE);
		md_read_from_file(head, in_file, false);
		dr_close_file(in_file);
	}

	if (log_mode){
		populate_conv_filename(logfilename, logdir, name, NULL);
		logfile = dr_open_file(logfilename, DR_FILE_WRITE_OVERWRITE);
	}
	strncpy(ins_pass_name, name, MAX_STRING_LENGTH);
	

}
Пример #8
0
DR_EXPORT void
dr_client_main(client_id_t id, int argc, const char *argv[])
{
    drreg_options_t ops = {sizeof(ops), 1 /*max slots needed: aflags*/, false};
    dr_set_client_name("DynamoRIO Sample Client 'bbcount'",
                       "http://dynamorio.org/issues");
    if (!drmgr_init() || drreg_init(&ops) != DRREG_SUCCESS)
        DR_ASSERT(false);

    /* register events */
    dr_register_exit_event(event_exit);
    if (!drmgr_register_bb_instrumentation_event(NULL, event_app_instruction, NULL))
        DR_ASSERT(false);

    /* make it easy to tell, by looking at log file, which client executed */
    dr_log(NULL, LOG_ALL, 1, "Client 'bbcount' initializing\n");
#ifdef SHOW_RESULTS
    /* also give notification to stderr */
    if (dr_is_notify_on()) {
# ifdef WINDOWS
        /* ask for best-effort printing to cmd window.  must be called at init. */
        dr_enable_console_printing();
# endif
        dr_fprintf(STDERR, "Client bbcount is running\n");
    }
#endif
}
Пример #9
0
/* callbacks for the entire process */
void memdump_init(client_id_t id, const char * name, const char * arguments)
{

	char logfilename[MAX_STRING_LENGTH];
	file_t in_file;

	drmgr_init();
	drutil_init();
	drwrap_init();
	tls_index = drmgr_register_tls_field();
	DR_ASSERT(parse_commandline_args(arguments) == true);

	filter_head = md_initialize();
	done_head = md_initialize();
	app_pc_head = md_initialize();
	
	in_file = dr_open_file(client_arg->filter_filename, DR_FILE_READ);
	md_read_from_file(filter_head, in_file, false);
	dr_close_file(in_file);
	
	in_file = dr_open_file(client_arg->app_pc_filename, DR_FILE_READ);
	md_read_from_file(app_pc_head, in_file, false);
	dr_close_file(in_file);


	if (log_mode){
		populate_conv_filename(logfilename, logdir, name, NULL);
		logfile = dr_open_file(logfilename, DR_FILE_WRITE_OVERWRITE);
	}
	strncpy(ins_pass_name, name, MAX_STRING_LENGTH);
	mutex = dr_mutex_create();

}
Пример #10
0
DR_EXPORT void
dr_client_main(client_id_t id, int argc, const char *argv[])
{
    drreg_options_t ops = { sizeof(ops), 4 /*max slots needed*/, false };

    dr_set_client_name("DynamoRIO Sample Client 'memval'", "http://dynamorio.org/issues");
    if (!drmgr_init() || !drutil_init() || !drx_init())
        DR_ASSERT(false);
    if (drreg_init(&ops) != DRREG_SUCCESS)
        DR_ASSERT(false);

    /* register events */
    dr_register_exit_event(event_exit);
    if (!drmgr_register_thread_init_event(event_thread_init) ||
        !drmgr_register_thread_exit_event(event_thread_exit) ||
        !drmgr_register_bb_app2app_event(event_bb_app2app, NULL) ||
        !drmgr_register_bb_instrumentation_event(event_app_analysis,
                                                 event_app_instruction, NULL))
        DR_ASSERT(false);
    client_id = id;

    tls_idx = drmgr_register_tls_field();
    trace_buffer = drx_buf_create_trace_buffer(MEM_BUF_SIZE, trace_fault);
    /* We could make this a trace buffer and specially handle faults, but it is not yet
     * worth the effort.
     */
    write_buffer = drx_buf_create_circular_buffer(WRT_BUF_SIZE);
    DR_ASSERT(tls_idx != -1 && trace_buffer != NULL && write_buffer != NULL);

    /* make it easy to tell, by looking at log file, which client executed */
    dr_log(NULL, DR_LOG_ALL, 1, "Client 'memval' initializing\n");
}
Пример #11
0
DR_EXPORT
void dr_init(client_id_t id)
{
    drsys_options_t ops = { sizeof(ops), 0, };
    drmgr_init();
    if (drsys_init(id, &ops) != DRMF_SUCCESS)
        ASSERT(false, "drsys failed to init");
    dr_register_exit_event(exit_event);

    dr_register_filter_syscall_event(event_filter_syscall);
    drmgr_register_pre_syscall_event(event_pre_syscall);
    drmgr_register_post_syscall_event(event_post_syscall);
    if (drsys_filter_all_syscalls() != DRMF_SUCCESS)
        ASSERT(false, "drsys_filter_all_syscalls should never fail");

    test_static_queries();

    test_static_iterator();

    /* XXX: it would be nice to do deeper tests:
     * + drsys_filter_syscall() and have an app that makes both filtered
     *   and unfiltered syscalls
     * + have app make specific syscall w/ specific args and ensure
     *   they match up
     */
}
Пример #12
0
void inscount_init(client_id_t id, const char * name,  const char * arguments)
{

	file_t in_file;
	char logfilename[MAX_STRING_LENGTH];

	drmgr_init();

	global_count = 0;

	DR_ASSERT(parse_commandline_args(arguments) == true);
	head = md_initialize();


	if(client_arg->filter_mode != FILTER_NONE){
		in_file = dr_open_file(client_arg->filter_filename,DR_FILE_READ);
		DR_ASSERT(in_file != INVALID_FILE);
		md_read_from_file(head,in_file,false);
		dr_close_file(in_file);
	}

	if (log_mode){
		populate_conv_filename(logfilename, logdir, name, NULL);
		logfile = dr_open_file(logfilename, DR_FILE_WRITE_OVERWRITE);
	}
	strncpy(ins_pass_name, name, MAX_STRING_LENGTH);



}
Пример #13
0
DR_EXPORT void 
dr_init(client_id_t id)
{
    drmgr_priority_t priority = {sizeof(priority), "drmgr-test", NULL, NULL, 0};
    drmgr_priority_t priority4 = {sizeof(priority), "drmgr-test4", NULL, NULL, 0};
    bool ok;

    drmgr_init();
    dr_register_exit_event(event_exit);
    drmgr_register_thread_init_event(event_thread_init);
    drmgr_register_thread_exit_event(event_thread_exit);

    ok = drmgr_register_bb_instrumentation_event(event_bb_analysis,
                                                 event_bb_insert,
                                                 &priority);
    CHECK(ok, "drmgr register bb failed");

    /* test data passing among all 4 phases */
    ok = drmgr_register_bb_instrumentation_ex_event(event_bb4_app2app,
                                                    event_bb4_analysis,
                                                    event_bb4_insert,
                                                    event_bb4_instru2instru,
                                                    &priority4);

    tls_idx = drmgr_register_tls_field();
    CHECK(tls_idx != 1, "drmgr_register_tls_field failed");
    cls_idx = drmgr_register_cls_field(event_thread_context_init,
                                       event_thread_context_exit);
    CHECK(cls_idx != 1, "drmgr_register_tls_field failed");
}
Пример #14
0
DR_EXPORT void
dr_client_main(client_id_t id, int argc, const char *argv[])
{
    module_data_t *appmod;
    dr_set_client_name("DynamoRIO Sample Client 'modxfer_app2lib'",
                       "http://dynamorio.org/issues");
    appmod = dr_get_main_module();
    DR_ASSERT(appmod != NULL);
    app_base = appmod->start;
    app_end = appmod->end;
    dr_free_module_data(appmod);

    if (!drmgr_init())
        DR_ASSERT(false);

    /* register events */
    dr_register_exit_event(event_exit);
    if (!drmgr_register_bb_instrumentation_event(event_analyze_bb,
                                                 event_insert_instrumentation, NULL))
        DR_ASSERT(false);

    /* make it easy to tell, by looking at log file, which client executed */
    dr_log(NULL, DR_LOG_ALL, 1, "Client 'modxfer_app2lib' initializing\n");
#ifdef SHOW_RESULTS
    /* also give notification to stderr */
    if (dr_is_notify_on()) {
#    ifdef WINDOWS
        /* ask for best-effort printing to cmd window.  must be called at init. */
        dr_enable_console_printing();
#    endif
        dr_fprintf(STDERR, "Client modxfer_app2lib is running\n");
    }
#endif
}
Пример #15
0
DR_EXPORT void
dr_client_main(client_id_t id, int argc, const char *argv[])
{
    dr_set_client_name("DynamoRIO Sample Client 'div'", "http://dynamorio.org/issues");
    if (!drmgr_init())
        DR_ASSERT(false);
    dr_register_exit_event(exit_event);
    if (!drmgr_register_bb_instrumentation_event(NULL, event_app_instruction, NULL))
        DR_ASSERT(false);
    count_mutex = dr_mutex_create();
}
Пример #16
0
DR_EXPORT void
dr_init(client_id_t id)
{
    drmgr_init();
    drwrap_init();
    dr_register_exit_event(event_exit);
    drmgr_register_module_load_event(module_load_event);
    drmgr_register_module_unload_event(module_unload_event);
    tls_idx = drmgr_register_tls_field();
    CHECK(tls_idx > -1, "unable to reserve TLS field");
}
Пример #17
0
DR_EXPORT void
dr_client_main(client_id_t id, int argc, const char *argv[])
{
    drreg_options_t ops = { sizeof(ops), 1 /*max slots needed*/, false };
    if (!drmgr_init())
        CHECK(false, "drmgr init failed");
    if (drreg_init(&ops) != DRREG_SUCCESS)
        CHECK(false, "drreg_init failed");
    dr_register_exit_event(event_exit);
    if (!drmgr_register_bb_instrumentation_event(NULL, event_app_instruction, NULL))
        CHECK(false, "bb reg failed");
}
Пример #18
0
drcovlib_status_t
drcovlib_init(drcovlib_options_t *ops)
{
    int count = dr_atomic_add32_return_sum(&drcovlib_init_count, 1);
    if (count > 1)
        return DRCOVLIB_SUCCESS;

    if (ops->struct_size != sizeof(options))
        return DRCOVLIB_ERROR_INVALID_PARAMETER;
    if ((ops->flags & (~(DRCOVLIB_DUMP_AS_TEXT|DRCOVLIB_THREAD_PRIVATE))) != 0)
        return DRCOVLIB_ERROR_INVALID_PARAMETER;
    if (TEST(DRCOVLIB_THREAD_PRIVATE, ops->flags)) {
        if (!dr_using_all_private_caches())
            return DRCOVLIB_ERROR_INVALID_SETUP;
        drcov_per_thread = true;
    }
    options = *ops;
    if (options.logdir != NULL)
        dr_snprintf(logdir, BUFFER_SIZE_ELEMENTS(logdir), "%s", ops->logdir);
    else /* default */
        dr_snprintf(logdir, BUFFER_SIZE_ELEMENTS(logdir), ".");
    NULL_TERMINATE_BUFFER(logdir);
    options.logdir = logdir;
    if (options.native_until_thread > 0)
        go_native = true;

    drmgr_init();
    drx_init();

    /* We follow a simple model of the caller requesting the coverage dump,
     * either via calling the exit routine, using its own soft_kills nudge, or
     * an explicit dump call for unusual cases.  This means that drx's
     * soft_kills remains inside the outer later, i.e., the drcov client.  This
     * is the easiest approach for coordinating soft_kills among many libraries.
     * Thus, we do *not* register for an exit event here.
     */

    drmgr_register_thread_init_event(event_thread_init);
    drmgr_register_thread_exit_event(event_thread_exit);
    drmgr_register_bb_instrumentation_event(event_basic_block_analysis, NULL, NULL);
    dr_register_filter_syscall_event(event_filter_syscall);
    drmgr_register_pre_syscall_event(event_pre_syscall);
#ifdef UNIX
    dr_register_fork_init_event(event_fork);
#endif

    tls_idx = drmgr_register_tls_field();
    if (tls_idx == -1)
        return DRCOVLIB_ERROR;

    return event_init();
}
Пример #19
0
DR_EXPORT
bool
drx_init(void)
{
    int count = dr_atomic_add32_return_sum(&drx_init_count, 1);
    if (count > 1)
        return true;

    drmgr_init();
    note_base = drmgr_reserve_note_range(DRX_NOTE_COUNT);
    ASSERT(note_base != DRMGR_NOTE_NONE, "failed to reserve note range");

    return true;
}
Пример #20
0
DR_EXPORT
void dr_init(client_id_t id)
{
    drsys_options_t ops = { sizeof(ops), 0, };
    drmgr_init();
    if (drsys_init(id, &ops) != DRMF_SUCCESS)
        ASSERT(false, "drsys failed to init");
    dr_register_exit_event(exit_event);

    dr_register_filter_syscall_event(event_filter_syscall);
    drmgr_register_pre_syscall_event(event_pre_syscall);
    drmgr_register_post_syscall_event(event_post_syscall);
    if (drsys_filter_all_syscalls() != DRMF_SUCCESS)
        ASSERT(false, "drsys_filter_all_syscalls should never fail");
}
Пример #21
0
DR_EXPORT void
dr_init(client_id_t id)
{
    drreg_options_t ops = { sizeof(ops), 2 /*max slots needed*/, false };
    drreg_status_t res;
    bool ok = drmgr_init();
    CHECK(ok, "drmgr_init failed");
    ok = drx_init();
    CHECK(ok, "drx_init failed");
    res = drreg_init(&ops);
    CHECK(res == DRREG_SUCCESS, "drreg_init failed");
    dr_register_exit_event(event_exit);
    if (!drmgr_register_bb_instrumentation_event(NULL, event_app_instruction, NULL))
        DR_ASSERT(false);
}
Пример #22
0
DR_EXPORT void
dr_init(client_id_t id)
{
    dr_set_client_name("DynamoRIO client 'ssljack'", "http://dynamorio.org/issues");
    /* make it easy to tell, by looking at log file, which client executed */
    dr_log(NULL, DR_LOG_ALL, 1, "Client ssljack initializing\n");
#ifdef SHOW_RESULTS
    if (dr_is_notify_on()) {
        dr_fprintf(STDERR, "Client ssljack running! See trace-* files for SSL logs!\n");
    }
#endif

    drmgr_init();
    drwrap_init();
    dr_register_exit_event(event_exit);
    drmgr_register_module_load_event(module_load_event);
}
Пример #23
0
DR_EXPORT void
dr_client_main(client_id_t id, int argc, const char *argv[])
{
    /* We need 2 reg slots beyond drreg's eflags slots => 3 slots */
    drreg_options_t ops = {sizeof(ops), 3, false};
    /* Specify priority relative to other instrumentation operations: */
    drmgr_priority_t priority = {
        sizeof(priority), /* size of struct */
        "memtrace",       /* name of our operation */
        NULL,             /* optional name of operation we should precede */
        NULL,             /* optional name of operation we should follow */
        0};               /* numeric priority */
    dr_set_client_name("DynamoRIO Sample Client 'memtrace'",
                       "http://dynamorio.org/issues");
    page_size = dr_page_size();
    drmgr_init();
    drutil_init();
    client_id = id;
    mutex = dr_mutex_create();
    dr_register_exit_event(event_exit);
    if (!drmgr_register_thread_init_event(event_thread_init) ||
        !drmgr_register_thread_exit_event(event_thread_exit) ||
        !drmgr_register_bb_app2app_event(event_bb_app2app, &priority) ||
        !drmgr_register_bb_instrumentation_event(NULL, event_bb_insert, &priority) ||
        drreg_init(&ops) != DRREG_SUCCESS) {
        /* something is wrong: can't continue */
        DR_ASSERT(false);
        return;
    }
    tls_index = drmgr_register_tls_field();
    DR_ASSERT(tls_index != -1);

    code_cache_init();
    /* make it easy to tell, by looking at log file, which client executed */
    dr_log(NULL, DR_LOG_ALL, 1, "Client 'memtrace' initializing\n");
#ifdef SHOW_RESULTS
    if (dr_is_notify_on()) {
# ifdef WINDOWS
        /* ask for best-effort printing to cmd window.  must be called at init. */
        dr_enable_console_printing();
# endif
        dr_fprintf(STDERR, "Client memtrace is running\n");
    }
#endif
}
Пример #24
0
DR_EXPORT void
dr_client_main(client_id_t id, int argc, const char *argv[])
{
    /* We need no drreg slots ourselves, but we initialize drreg as we call
     * drreg_restore_app_values(), required since drx_insert_counter_update()
     * uses drreg when drmgr is used.
     */
    drreg_options_t ops = {sizeof(ops)};
    dr_set_client_name("DynamoRIO Sample Client 'modxfer'",
                       "http://dynamorio.org/issues");
    if (!drmgr_init() || drreg_init(&ops) != DRREG_SUCCESS)
        DR_ASSERT(false);
    drx_init();
    /* register events */
    dr_register_exit_event(event_exit);
    if (!drmgr_register_bb_instrumentation_event(event_analyze_bb,
                                                 event_insert_instrumentation, NULL))
        DR_ASSERT(false);
    drmgr_register_module_load_event(event_module_load);
    drmgr_register_module_unload_event(event_module_unload);

    mod_lock = dr_mutex_create();

    logfile = log_file_open(id, NULL /* drcontext */,
                            NULL/* path */, "modxfer",
#ifndef WINDOWS
                            DR_FILE_CLOSE_ON_FORK |
#endif
                            DR_FILE_ALLOW_LARGE);

    DR_ASSERT(logfile != INVALID_FILE);
    /* make it easy to tell, by looking at log file, which client executed */
    dr_log(NULL, LOG_ALL, 1, "Client 'modxfer' initializing\n");
#ifdef SHOW_RESULTS
    /* also give notification to stderr */
    if (dr_is_notify_on()) {
# ifdef WINDOWS
        /* ask for best-effort printing to cmd window.  must be called at init. */
        dr_enable_console_printing();
# endif
        dr_fprintf(STDERR, "Client modxfer is running\n");
    }
#endif
}
Пример #25
0
DR_EXPORT void
dr_client_main(client_id_t id, int argc, const char *argv[])
{
    umbra_map_options_t umbra_map_ops;

    drmgr_init();

    memset(&umbra_map_ops, 0, sizeof(umbra_map_ops));
    umbra_map_ops.scale              = UMBRA_MAP_SCALE_DOWN_4X;
    umbra_map_ops.flags              = UMBRA_MAP_CREATE_SHADOW_ON_TOUCH;
    umbra_map_ops.default_value      = 0;
    umbra_map_ops.default_value_size = 1;

    if (umbra_init(id) != DRMF_SUCCESS)
        DR_ASSERT_MSG(false, "fail to init umbra");
    if (umbra_create_mapping(&umbra_map_ops, &umbra_map) != DRMF_SUCCESS)
        DR_ASSERT_MSG(false, "fail to create shadow memory mapping");
    dr_register_exit_event(exit_event);
}
Пример #26
0
DR_EXPORT void
dr_client_main(client_id_t id, int argc, const char *argv[])
{
    drreg_options_t ops = {sizeof(ops), 2 /*max slots needed*/, false};
    dr_set_client_name("DynamoRIO Sample Client 'bbbuf'",
                       "http://dynamorio.org/issues");
    if (!drmgr_init() || !drx_init() ||
        drreg_init(&ops) != DRREG_SUCCESS)
        DR_ASSERT(false);

    buf = drx_buf_create_circular_buffer(DRX_BUF_FAST_CIRCULAR_BUFSZ);
    DR_ASSERT(buf);

    /* register events */
    dr_register_exit_event(event_exit);
    if (!drmgr_register_thread_init_event(event_thread_init) ||
        !drmgr_register_bb_instrumentation_event(NULL, event_app_instruction, NULL))
        DR_ASSERT(false);
}
Пример #27
0
void instrace_init(client_id_t id, const char * name, const char * arguments)
{

	file_t in_file;
	file_t out_file;
	int i;
	char logfilename[MAX_STRING_LENGTH];

    drmgr_init();
    drutil_init();
    client_id = id;

	DR_ASSERT(parse_commandline_args(arguments)==true);

	head = md_initialize();
	instrace_head = md_initialize();

	if(client_arg->filter_mode != FILTER_NONE){
		in_file = dr_open_file(client_arg->filter_filename,DR_FILE_READ);
		DR_ASSERT(in_file != INVALID_FILE);
		md_read_from_file(head,in_file,false);
		dr_close_file(in_file);
	}

	mutex = dr_mutex_create();
    tls_index = drmgr_register_tls_field();
    DR_ASSERT(tls_index != -1);
    code_cache_init();

	if (log_mode){
		populate_conv_filename(logfilename, logdir, name, NULL);
		logfile = dr_open_file(logfilename, DR_FILE_WRITE_OVERWRITE);
	}
	strncpy(ins_pass_name, name, MAX_STRING_LENGTH);

	for(i=OP_FIRST;i<=OP_LAST; i++){
		opcodes_visited[i] = false;
	}

	
	

}
Пример #28
0
/*
 * Main entry point that sets up all the facilities we need.
 */
DR_EXPORT void dr_client_main(client_id_t id, int argc, const char **argv)
{
    dr_set_client_name(
        "Time-sensitive activity logger for PuTTY crypto testing",
        "https://www.chiark.greenend.org.uk/~sgtatham/putty/");

    outfile = INVALID_FILE;

    bool ok = drmgr_init();
    DR_ASSERT(ok);

    /*
     * Run our main instrumentation pass with lower priority than
     * drwrap, so that we don't start logging the inside of a function
     * whose drwrap pre-wrapper would have wanted to disable logging.
     */
    drmgr_priority_t pri = {sizeof(pri), "sclog", NULL, NULL,
                            DRMGR_PRIORITY_INSERT_DRWRAP+1};
    ok = drmgr_register_bb_instrumentation_event(
        NULL, instrument_instr, &pri);
    DR_ASSERT(ok);

    ok = drutil_init();
    DR_ASSERT(ok);

    ok = drwrap_init();
    DR_ASSERT(ok);

    drsym_error_t symstatus = drsym_init(0);
    DR_ASSERT(symstatus == DRSYM_SUCCESS);

    dr_register_exit_event(exit_event);

    drreg_options_t ops = { sizeof(ops), 3, false };
    drreg_status_t regstatus = drreg_init(&ops);
    DR_ASSERT(regstatus == DRREG_SUCCESS);

    drmgr_register_module_load_event(load_module);

    ok = drmgr_register_bb_app2app_event(expand_rep_movsb, NULL);
    DR_ASSERT(ok);
}
Пример #29
0
DR_EXPORT
void dr_init(client_id_t id)
{
    uint i = 0;
    uint const_arrays_num;
    drsys_options_t ops = { sizeof(ops), 0, };

    dr_set_client_name("Dr. STrace", "http://drmemory.org/issues");

#ifdef WINDOWS
    dr_enable_console_printing();
#endif

    options_init(id);
    drsym_init(0);
    drmgr_init();
    drx_init();

    if (drsys_init(id, &ops) != DRMF_SUCCESS)
        ASSERT(false, "drsys failed to init");
    dr_register_exit_event(exit_event);

    dr_register_filter_syscall_event(event_filter_syscall);
    drmgr_register_pre_syscall_event(event_pre_syscall);
    drmgr_register_post_syscall_event(event_post_syscall);
    if (drsys_filter_all_syscalls() != DRMF_SUCCESS)
        ASSERT(false, "drsys_filter_all_syscalls should never fail");
    open_log_file();

    const_arrays_num = get_const_arrays_num();
    hashtable_init(&nconsts_table, HASHTABLE_BITSIZE, HASH_STRING, false);
    while (i < const_arrays_num) {
        const_values_t *named_consts = const_struct_array[i];
        bool res = hashtable_add(&nconsts_table,
                                 (void *) named_consts[0].const_name,
                                 (void *) named_consts);
        if (!res)
            ASSERT(false, "drstrace failed to add to hashtable");
        i++;
    }

}
Пример #30
0
DR_EXPORT drmf_status_t
drfuzz_init(client_id_t client_id)
{
    drmf_status_t res;
    int count = dr_atomic_add32_return_sum(&drfuzz_init_count, 1);
    if (count > 1)
        return DRMF_SUCCESS;

    res = drmf_check_version(client_id);
    if (res != DRMF_SUCCESS)
        return res;

    callbacks = global_alloc(sizeof(drfuzz_callbacks_t), HEAPSTAT_MISC);
    memset(callbacks, 0, sizeof(drfuzz_callbacks_t));

    drmgr_init();
    drwrap_init();

#ifdef UNIX
    drmgr_register_signal_event(fault_handler);
#else /* WINDOWS */
    drmgr_register_exception_event(fault_handler);
#endif
    drmgr_register_thread_init_event(thread_init);
    drmgr_register_thread_exit_event(thread_exit);
    drmgr_register_bb_app2app_event(bb_event, NULL);

    tls_idx_fuzzer = drmgr_register_tls_field();
    if (tls_idx_fuzzer < 0) {
        DRFUZZ_ERROR("drfuzz failed to reserve TLS slot--initialization failed\n");
        return DRMF_ERROR;
    }

    /* Synchronized to allow addition and removal of fuzz targets during execution
     * of the target program, e.g. to explore control flow paths.
     */
    hashtable_init_ex(&fuzz_target_htable, 3, HASH_INTPTR, false/*no strdup*/,
                      true/*synchronized*/, free_fuzz_target, NULL/*no custom hash*/,
                      NULL/*no custom comparator*/);

    return DRMF_SUCCESS;
}