ULONG systemGetVarName(const string &userLib){ if(ofs.is_open()) { ofs.close(); } ofs.open("d:\\log\\symbolTable.txt", ios::out); if(!ofs.is_open()) { printf"pp.txt file open err\n"); return 1; } ofs<<"address "<<"name"<<std::endl; DWORD64 address = 0; HANDLE hProcess = GetCurrentProcess(); // HANDLE hThread = GetCurrentThread(); BOOL bret = SymInitialize(hProcess,NULL,FALSE); if(!bret){ ATE_LOG(ERR,"SymInitialize fail\n"); return 2; } TCHAR szImageName[MAX_PATH]; #ifdef UNICODE _snprintf_s(szImageName, userLib.length(), "%S", userLib.c_str()); #else _snprintf_s(szImageName, userLib.length(), "%s", userLib.c_str()); #endif //DWORD64 dwBaseAddr = 0; address = SymLoadModuleEx(hProcess, // target process NULL, // handle to image - not used szImageName, // name of image file NULL, // name of module - not required (DWORD64)m_hUserLibHandle, // base address - not required 0, // size of image - not required NULL, // MODLOAD_DATA used for special cases 0); if (!address) // flags - not required { // SymLoadModuleEx failed DWORD error = GetLastError(); ATE_LOG(ERR,"SymLoadModuleEx returned error : %d\n", error); return PROJECT_LOAD_DLL_FAILED; } bret = SymEnumSymbols(hProcess,address,"*",EnumSymCallBack,NULL); if(!bret) { SymCleanup(hProcess); ATE_LOG(ERR,"SymEnumSymbols fail\n"); return PROJECT_LOAD_DLL_FAILED; } if(isObjectNameDuplicate) { isObjectNameDuplicate = false; SymCleanup(hProcess); return PROJECT_LOAD_DLL_FAILED; } SymCleanup(hProcess); return E_OK; }
BOOL EnumSymCallBack(PSYMBOL_INFO pSymInfo, ULONG SymbolSize, PVOID UserContext) { ofs<<hex<<pSymInfo->Address<<" "<<pSymInfo->Name<<std::endl; try { std::string temp = pSymInfo->Name; if(temp.size() && temp[0] != '_') { temp = "_"+temp; } int status; char *demangled = abi::__cxa_demangle(temp.c_str(), NULL, NULL, &status); if(demangled) { // 可以被解析的函数 ofs<< temp << " -> " << demangled << " " << status << std::endl; free(demangled); }else { // 全局变量和c函数不会被解析 ofs<<"func: " << pSymInfo->Name << " -> " << (uint64_t)pSymInfo->Address << std::endl; } }catch(...) { std::cout << "catch:" << std::endl; } return TRUE; }
标签:txt,temp,dll,ofs,mingw,解析,open From: https://www.cnblogs.com/a9999/p/18304785