int symbol(const uint8_t *addr, char *sym, uint32_t length) { int len; *sym = 0; const uint8_t *mod = module_from_address(addr); if(mod == NULL) { return -1; } const wchar_t *module_name = get_module_file_name((HMODULE) mod); symbol_t s; s.address = (uintptr_t) addr; s.lower_address = s.higher_address = 0; s.lower_funcname = s.higher_funcname = NULL; symbol_enumerate_module((HMODULE) mod, &_symbol_callback, &s); if(s.lower_address != 0) { len = our_snprintf(sym, length, "%s+%p", s.lower_funcname, (uintptr_t) addr - s.lower_address); sym += len, length -= len; } if(s.higher_address != 0) { if(s.lower_address != 0) { *sym++ = ' ', length--; } len = our_snprintf(sym, length, "%s-%p", s.higher_funcname, s.higher_address - (uintptr_t) addr); sym += len, length -= len; } if(module_name != NULL) { if(s.lower_address != 0 || s.higher_address != 0) { *sym++ = ' ', length--; } while (length-- > 20 && *module_name != 0 && *module_name != '.') { *sym++ = tolower(*module_name++); } our_snprintf(sym, length, "+%p", addr - mod); } return 0; }
std::basic_string< CharT > get_current_module_name() { static HMODULE hSelfModule = 0; BOOST_LOG_ONCE_BLOCK() { init_self_module_handle(hSelfModule); } // Get the module file name CharT buf[MAX_PATH]; DWORD size = get_module_file_name(hSelfModule, buf, sizeof(buf) / sizeof(*buf)); if (size == 0) BOOST_LOG_THROW_DESCR(system_error, "Could not get module file name"); return std::basic_string< CharT >(buf, buf + size); }
static int open_exe_cfg(const char* module) { if (cfg) // if the configure is be opne,the return ; return 0; char exe_name[256]; // 获得当前运行的程序名 if (!get_module_file_name(exe_name, 128)) return -1; strcat(exe_name, ".cfg"); // 打开配置文件 cfg = fopen(exe_name, module); if (!cfg) return -1; return 0; }