static void options_init(client_id_t id) { const char *opstr = dr_get_options(id); const char *s; char token[OPTION_MAX_LENGTH]; /* default values */ dr_snprintf(options.logdir, BUFFER_SIZE_ELEMENTS(options.logdir), "."); for (s = dr_get_token(opstr, token, BUFFER_SIZE_ELEMENTS(token)); s != NULL; s = dr_get_token(s, token, BUFFER_SIZE_ELEMENTS(token))) { if (strcmp(token, "-logdir") == 0) { s = dr_get_token(s, options.logdir, BUFFER_SIZE_ELEMENTS(options.logdir)); USAGE_CHECK(s != NULL, "missing logdir path"); } else if (strcmp(token, "-verbose") == 0) { s = dr_get_token(s, token, BUFFER_SIZE_ELEMENTS(token)); USAGE_CHECK(s != NULL, "missing -verbose number"); if (s != NULL) { int res = dr_sscanf(token, "%u", &verbose); USAGE_CHECK(res == 1, "invalid -verbose number"); } } else if (strcmp(token, "-symcache_path") == 0) { s = dr_get_token(s, options.sympath, BUFFER_SIZE_ELEMENTS(options.sympath)); USAGE_CHECK(s != NULL, "missing symcache dir path"); ALERT(2, "<drstrace symbol source is %s>\n", options.sympath); } else { ALERT(0, "UNRECOGNIZED OPTION: \"%s\"\n", token); USAGE_CHECK(false, "invalid option"); } } }
static void doCommandLineArgProcessing(client_id_t id){ const char * args = dr_get_options(id); int i = 0; int string_index = 0; int index = -1; int name_collect_state = 0; int arguments_collect_state = 0; while(args[i] != '\0'){ if(args[i] == '-'){ name_collect_state = 1; arguments_collect_state = 0; if(index>=0){ arguments[index].arguments[string_index - 1] = '\0'; } index++; string_index = 0; i++; continue; } if(args[i] == ' ' && name_collect_state){ arguments[index].name[string_index++] = '\0'; name_collect_state = 0; arguments_collect_state = 1; string_index = 0; i++; continue; } if(name_collect_state){ arguments[index].name[string_index++] = args[i]; } if(arguments_collect_state){ arguments[index].arguments[string_index++] = args[i]; } i++; } //epilog arguments[index].arguments[string_index++] = '\0'; argument_length = index + 1; process_global_arguments(); }
DR_EXPORT void dr_init(client_id_t id) { const char *options = dr_get_options(id); if (strlen(options) == 0) { bb_truncation_length = DEFAULT_BB_TRUNCATION_LENGTH; } else { ASSERT(strlen(options) == 1); /* supports bb truncation at 1-9 instrs */ bb_truncation_length = (options[0] - '0'); ASSERT(bb_truncation_length < 10 && bb_truncation_length > 0); } dr_fprintf(STDERR, "thank you for testing the client interface\n"); dr_register_bb_event(bb_event); }
DR_EXPORT void dr_init(client_id_t id) { const char *options = dr_get_options(id); dr_fprintf(STDERR, "options = %s\n", options); if (options != NULL && strstr(options, "use_unlink") != NULL) { use_unlink = true; } #ifdef WINDOWS dr_register_module_load_event(module_load_event); #endif dr_register_exit_event(exit_event); dr_register_trace_event(trace_event); dr_register_delete_event(deleted_event); dr_register_bb_event(bb_event); dr_register_kernel_xfer_event(kernel_xfer_event); }
DR_EXPORT void dr_init(client_id_t id) { dr_set_client_name("DynamoRIO Sample Client 'MF_moduledb'", "http://dynamorio.org/issues"); VDISPLAY_FUNC(NAME" initializing."); /* register the events we wish to handle */ dr_register_security_event(event_security_violation); dr_register_nudge_event(event_nudge, id); dr_register_exit_event(event_exit); /* read the client options */ table_def_file_name = dr_get_options(id); if (table_def_file_name == NULL || table_def_file_name[0] == '\0') { DISPLAY_FUNC(NAME" requires the table name as parameter\n"); dr_abort(); } /* initialize structures */ table_lock = dr_mutex_create(); read_table(); }
DR_EXPORT void dr_init(client_id_t id) { const char *option; option = dr_get_options(id); fi_printf("the passed option to this client: %s\n", option); sid = atoi(option); fi_printf("sid: %d\n", sid); init_log_file(); dr_register_filter_syscall_event(pre_syscall_filter); drmgr_init(); tls_idx = drmgr_register_tls_field(); drmgr_register_pre_syscall_event(pre_syscall); drmgr_register_post_syscall_event(post_syscall); drmgr_register_thread_init_event(thread_init_event); drmgr_register_thread_exit_event(thread_exit_event); jfile_fds[0] = -1; jfile_fds[1] = -1; }
DR_EXPORT void dr_init(client_id_t client_id) { const char *opts = dr_get_options(client_id); dr_fprintf(STDERR, "client opts: %s\n", opts); }
DR_EXPORT void dr_init(client_id_t id) { char buf[MAXIMUM_PATH]; int64 pos; int i; uint prot; byte *base_pc; size_t size; size_t bytes_read, bytes_written; byte *edge, *mbuf; bool ok; byte *f_map; /* The Makefile will pass a full absolute path (for Windows and Linux) as the client * option to a dummy file in the which we use to exercise the file api routines. * TODO - these tests should be a lot more thorough, but the basic functionality * is there (should add write tests, file_exists, directory etc. tests). */ file = dr_open_file(dr_get_options(id), DR_FILE_READ); if (file == INVALID_FILE) dr_fprintf(STDERR, "Error opening file\n"); memset(buf, 0, sizeof(buf)); dr_read_file(file, buf, 10); pos = dr_file_tell(file); if (pos < 0) dr_fprintf(STDERR, "tell error\n"); dr_fprintf(STDERR, "%s\n", buf); if (!dr_file_seek(file, 0, DR_SEEK_SET)) dr_fprintf(STDERR, "seek error\n"); memset(buf, 0, sizeof(buf)); dr_read_file(file, buf, 5); dr_fprintf(STDERR, "%s\n", buf); for (i = 0; i < 100; i++) buf[i] = 0; if (!dr_file_seek(file, pos - 5, DR_SEEK_CUR)) dr_fprintf(STDERR, "seek error\n"); memset(buf, 0, sizeof(buf)); dr_read_file(file, buf, 7); dr_fprintf(STDERR, "%s\n", buf); if (!dr_file_seek(file, -6, DR_SEEK_END)) dr_fprintf(STDERR, "seek error\n"); memset(buf, 0, sizeof(buf)); /* read "x\nEOF\n" from the data file */ dr_read_file(file, buf, 6); /* check for DOS line ending */ if (buf[4] == '\r') { /* Account for two line endings: the snippet is "x\r\nEOF\r\n". * No conversion required--ctest will discard the '\r' when comparing results. */ if (!dr_file_seek(file, -8, DR_SEEK_END)) dr_fprintf(STDERR, "seek error\n"); memset(buf, 0, sizeof(buf)); dr_read_file(file, buf, 8); } dr_fprintf(STDERR, "%s\n", buf); #define EXTRA_SIZE 0x60 size = PAGE_SIZE + EXTRA_SIZE; f_map = dr_map_file(file, &size, 0, NULL, DR_MEMPROT_READ, DR_MAP_PRIVATE); if (f_map == NULL || size < (PAGE_SIZE + EXTRA_SIZE)) dr_fprintf(STDERR, "map error\n"); /* test unaligned unmap */ if (!dr_unmap_file(f_map + PAGE_SIZE, EXTRA_SIZE)) dr_fprintf(STDERR, "unmap error\n"); /* leave file open and check in exit event that it's still open after * app tries to close it */ dr_register_exit_event(event_exit); /* Test dr_rename_file. */ test_dr_rename_delete(); /* Test the memory query routines */ dummy_func(); if (!dr_memory_is_readable((byte *)dummy_func, 1) || !dr_memory_is_readable(read_only_buf+1000, 4000) || !dr_memory_is_readable(writable_buf+1000, 4000)) { dr_fprintf(STDERR, "ERROR : dr_memory_is_readable() incorrect results\n"); } if (!dr_query_memory((byte *)dummy_func, &base_pc, &size, &prot)) dr_fprintf(STDERR, "ERROR : can't find dummy_func mem region\n"); dr_fprintf(STDERR, "dummy_func is %s%s%s\n", TEST(DR_MEMPROT_READ, prot) ? "r" : "", TEST(DR_MEMPROT_WRITE, prot) ? "w" : "", TEST(DR_MEMPROT_EXEC, prot) ? "x" : ""); if (base_pc > (byte *)dummy_func || base_pc + size < (byte *)dummy_func) dr_fprintf(STDERR, "dummy_func region mismatch"); memset(writable_buf, 0, sizeof(writable_buf)); /* strip off write copy */ if (!dr_query_memory(writable_buf+100, &base_pc, &size, &prot)) dr_fprintf(STDERR, "ERROR : can't find dummy_func mem region\n"); dr_fprintf(STDERR, "writable_buf is %s%s%s\n", TEST(DR_MEMPROT_READ, prot) ? "r" : "", TEST(DR_MEMPROT_WRITE, prot) ? "w" : "", #ifdef UNIX /* Linux sometimes (probably depends on version and hardware NX * support) lists all readable regions as also exectuable in the * maps file. We just skip checking here for Linux to make * matching the template file easier. */ "" #else TEST(DR_MEMPROT_EXEC, prot) ? "x" : "" #endif ); if (base_pc > writable_buf || base_pc + size < writable_buf) dr_fprintf(STDERR, "writable_buf region mismatch\n"); if (base_pc + size < writable_buf + sizeof(writable_buf)) dr_fprintf(STDERR, "writable_buf size mismatch "PFX" "PFX" "PFX" "PFX"\n", base_pc, size, writable_buf, sizeof(writable_buf)); if (!dr_query_memory(read_only_buf+100, &base_pc, &size, &prot)) dr_fprintf(STDERR, "ERROR : can't find dummy_func mem region\n"); dr_fprintf(STDERR, "read_only_buf is %s%s\n", TEST(DR_MEMPROT_READ, prot) ? "r" : "", TEST(DR_MEMPROT_WRITE, prot) ? "w" : ""); if (base_pc > read_only_buf || base_pc + size < read_only_buf) dr_fprintf(STDERR, "read_only_buf region mismatch"); if (base_pc + size < read_only_buf + sizeof(read_only_buf)) dr_fprintf(STDERR, "read_only_buf size mismatch"); /* test the safe_read functions */ /* TODO - extend test to cover racy writes and reads (won't work on Linux yet). */ memset(safe_buf, 0xcd, sizeof(safe_buf)); if (!dr_safe_read(read_only_buf + 4000, 1000, safe_buf, &bytes_read) || bytes_read != 1000 || !memchk(safe_buf, 0, 1000) || *(safe_buf+1000) != 0xcd) { dr_fprintf(STDERR, "ERROR in plain dr_safe_read()\n"); } memset(safe_buf, 0xcd, sizeof(safe_buf)); /* read_only_buf will be in .rodata on Linux, and can be followed by string * constants with the same page protections. In order to be sure that we're * copying zeroes, we map our own memory. */ mbuf = dr_nonheap_alloc(PAGE_SIZE*3, DR_MEMPROT_READ|DR_MEMPROT_WRITE); memset(mbuf, 0, PAGE_SIZE*3); dr_memory_protect(mbuf + PAGE_SIZE*2, PAGE_SIZE, DR_MEMPROT_NONE); edge = find_prot_edge(mbuf, DR_MEMPROT_READ); bytes_read = 0xcdcdcdcd; if (dr_safe_read(edge - (PAGE_SIZE + 10), PAGE_SIZE+20, safe_buf, &bytes_read) || bytes_read == 0xcdcdcdcd || bytes_read > PAGE_SIZE+10 || !memchk(safe_buf, 0, bytes_read)) { dr_fprintf(STDERR, "ERROR in overlap dr_safe_read()\n"); } dr_nonheap_free(mbuf, PAGE_SIZE*3); dr_fprintf(STDERR, "dr_safe_read() check\n"); /* test DR_TRY_EXCEPT */ DR_TRY_EXCEPT(dr_get_current_drcontext(), { ok = false; *((int *)4) = 37; }, { /* EXCEPT */