static file_t open_sigil2_fifo(const char *path, int flags) { /* Wait for Sigil2 to create pipes * Timeout is empirical */ uint max_tests = 10; for(uint i=0; i<max_tests+1; ++i) { if(dr_file_exists(path)) break; if(i == max_tests) { dr_printf("%s\n", path); DR_ASSERT_MSG(false, "DrSigil timed out waiting for sigil2 fifos"); } struct timespec ts; ts.tv_sec = 0; ts.tv_nsec = 200000000L; nanosleep(&ts, NULL); } file_t f = dr_open_file(path, flags); if(f == INVALID_FILE) DR_ABORT_MSG("error opening empty fifo"); return f; }
/* 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); }
int main(int argc, char *argv[]) { char *dll = NULL; int i; /* module + address per line */ char line[MAXIMUM_PATH*2]; size_t modoffs; /* options that can be local vars */ bool addr2sym = false; bool addr2sym_multi = false; bool sym2addr = false; bool enumerate = false; bool enumerate_all = false; bool search = false; bool searchall = false; for (i = 1; i < argc; i++) { if (_stricmp(argv[i], "-e") == 0) { if (i+1 >= argc) { PRINT_USAGE(argv[0]); return 1; } i++; dll = argv[i]; if ( #ifdef WINDOWS _access(dll, 4/*read*/) == -1 #else !dr_file_exists(dll) #endif ) { printf("ERROR: invalid path %s\n", dll); return 1; } } else if (_stricmp(argv[i], "-f") == 0) { show_func = true; } else if (_stricmp(argv[i], "-v") == 0) { verbose = true; } else if (_stricmp(argv[i], "-a") == 0 || _stricmp(argv[i], "-s") == 0) { if (i+1 >= argc) { PRINT_USAGE(argv[0]); return 1; } if (_stricmp(argv[i], "-a") == 0) addr2sym = true; else sym2addr = true; i++; /* rest of args read below */ break; } else if (_stricmp(argv[i], "-q") == 0) { addr2sym_multi = true; } else if (_stricmp(argv[i], "--enum") == 0) { enumerate = true; } else if (_stricmp(argv[i], "--list") == 0) { enumerate_all = true; } else if (_stricmp(argv[i], "--search") == 0) { search = true; } else if (_stricmp(argv[i], "--searchall") == 0) { search = true; searchall = true; } else { PRINT_USAGE(argv[0]); return 1; } } if (((sym2addr || addr2sym) && dll == NULL) || (addr2sym_multi && dll != NULL) || (!sym2addr && !addr2sym && !addr2sym_multi && !enumerate_all)) { PRINT_USAGE(argv[0]); return 1; } dr_standalone_init(); if (drsym_init(IF_WINDOWS_ELSE(NULL, 0)) != DRSYM_SUCCESS) { printf("ERROR: unable to initialize symbol library\n"); return 1; } if (!addr2sym_multi) { if (enumerate_all) enumerate_symbols(dll, NULL, search, searchall); else { /* kind of a hack: assumes i hasn't changed and that -s/-a is last option */ for (; i < argc; i++) { if (addr2sym) { if (sscanf(argv[i], "%x", (uint *)&modoffs) == 1) lookup_address(dll, modoffs); else printf("ERROR: unknown input %s\n", argv[i]); } else if (enumerate || search) enumerate_symbols(dll, argv[i], search, searchall); else lookup_symbol(dll, argv[i]); } } } else { while (!feof(stdin)) { char modpath[MAXIMUM_PATH]; if (fgets(line, sizeof(line), stdin) == NULL || /* when postprocess.pl closes the pipe, fgets is not * returning, so using an alternative eof code */ strcmp(line, ";exit\n") == 0) break; /* Ensure we support spaces in paths by using ; to split. * Since ; separates PATH, no Windows dll will have ; in its name. */ if (sscanf(line, "%"MAX_PATH_STR"[^;];%x", (char *)&modpath, (uint *)&modoffs) == 2) { lookup_address(modpath, modoffs); fflush(stdout); /* ensure flush in case piped */ } else if (verbose) printf("Error: unknown input %s\n", line); } } if (drsym_exit() != DRSYM_SUCCESS) printf("WARNING: error cleaning up symbol library\n"); return 0; }