diff --git a/x64_dbg_dbg/_exports.cpp b/x64_dbg_dbg/_exports.cpp index 2b428584..ce829e84 100644 --- a/x64_dbg_dbg/_exports.cpp +++ b/x64_dbg_dbg/_exports.cpp @@ -103,36 +103,34 @@ extern "C" DLL_EXPORT bool _dbg_addrinfoget(duint addr, SEGMENTREG segment, ADDR { if(labelget(addr, addrinfo->label)) retval=true; - else + if(!retval) //no user labels { //TODO: auto-labels - /*const char* apiname=(const char*)ImporterGetAPINameFromDebugee(fdProcessInfo->hProcess, addr); - if(apiname) + DWORD64 displacement=0; + char buffer[sizeof(SYMBOL_INFO) + MAX_LABEL_SIZE * sizeof(char)]; + PSYMBOL_INFO pSymbol = (PSYMBOL_INFO)buffer; + pSymbol->SizeOfStruct = sizeof(SYMBOL_INFO); + pSymbol->MaxNameLen = MAX_LABEL_SIZE; + if(SymFromAddr(fdProcessInfo->hProcess, (DWORD64)addr, &displacement, pSymbol) and !displacement) { - strcpy(addrinfo->label, apiname); + strcpy(addrinfo->label, pSymbol->Name); retval=true; } - uint addr_dw=0; - if(memread(fdProcessInfo->hProcess, (const void*)addr, &addr_dw, sizeof(uint), 0)) - { - const char* apiname=(const char*)ImporterGetAPINameFromDebugee(fdProcessInfo->hProcess, addr_dw); - if(apiname) - { - strcpy(addrinfo->label, apiname); - retval=true; - } - }*/ if(!retval) { - DWORD64 displacement=0; - char buffer[sizeof(SYMBOL_INFO) + MAX_LABEL_SIZE * sizeof(char)]; - PSYMBOL_INFO pSymbol = (PSYMBOL_INFO)buffer; - pSymbol->SizeOfStruct = sizeof(SYMBOL_INFO); - pSymbol->MaxNameLen = MAX_LABEL_SIZE; - if(SymFromAddr(fdProcessInfo->hProcess, (DWORD64)addr, &displacement, pSymbol) and !displacement) + uint addr_=0; + if(memread(fdProcessInfo->hProcess, (const void*)addr, &addr_, sizeof(uint), 0)) { - strcpy(addrinfo->label, pSymbol->Name); - retval=true; + DWORD64 displacement=0; + char buffer[sizeof(SYMBOL_INFO) + MAX_LABEL_SIZE * sizeof(char)]; + PSYMBOL_INFO pSymbol = (PSYMBOL_INFO)buffer; + pSymbol->SizeOfStruct = sizeof(SYMBOL_INFO); + pSymbol->MaxNameLen = MAX_LABEL_SIZE; + if(SymFromAddr(fdProcessInfo->hProcess, (DWORD64)addr_, &displacement, pSymbol) and !displacement) + { + strcpy(addrinfo->label, pSymbol->Name); + retval=true; + } } } } @@ -142,18 +140,22 @@ extern "C" DLL_EXPORT bool _dbg_addrinfoget(duint addr, SEGMENTREG segment, ADDR if(commentget(addr, addrinfo->comment)) retval=true; //TODO: auto-comments - else + if(!retval) { - if(!retval) + DWORD dwDisplacement; + IMAGEHLP_LINE64 line; + line.SizeOfStruct = sizeof(IMAGEHLP_LINE64); + if(SymGetLineFromAddr64(fdProcessInfo->hProcess, (DWORD64)addr, &dwDisplacement, &line) and !dwDisplacement) { - DWORD dwDisplacement; - IMAGEHLP_LINE64 line; - line.SizeOfStruct = sizeof(IMAGEHLP_LINE64); - if(SymGetLineFromAddr64(fdProcessInfo->hProcess, (DWORD64)addr, &dwDisplacement, &line) and !dwDisplacement) - { - sprintf(addrinfo->comment, "line: %u", line.LineNumber); - retval=true; - } + char filename[deflen]=""; + strcpy(filename, line.FileName); + int len=strlen(filename); + while(filename[len]!='\\' and len!=0) + len--; + if(len) + len++; + sprintf(addrinfo->comment, "%s:%u", filename+len, line.LineNumber); + retval=true; } } } diff --git a/x64_dbg_dbg/addrinfo.cpp b/x64_dbg_dbg/addrinfo.cpp index 6a5c2596..62e40912 100644 --- a/x64_dbg_dbg/addrinfo.cpp +++ b/x64_dbg_dbg/addrinfo.cpp @@ -4,7 +4,6 @@ #include "memory.h" static sqlite3* db; -static sqlite3* internaldb; ///basic database functions void dbinit() @@ -30,18 +29,6 @@ void dbinit() dprintf("SQL Error: %s\n", errorText); sqlite3_free(errorText); } - //initialize internal database - if(sqlite3_open(":memory:", &internaldb)) - { - dputs("failed to open database!"); - return; - } - strcpy(sql, "CREATE TABLE IF NOT EXISTS exports (id INTEGER PRIMARY KEY AUTOINCREMENT, base INT64 NOT NULL, mod TEXT, name TEXT NOT NULL, addr INT64 NOT NULL)"); - if(sqlite3_exec(internaldb, sql, 0, 0, &errorText)!=SQLITE_OK) //error - { - dprintf("SQL Error: %s\n", errorText); - sqlite3_free(errorText); - } } static int loadOrSaveDb(sqlite3* memory, const char* file, bool save) @@ -78,9 +65,6 @@ bool dbload() bool dbsave() { - DeleteFileA("internal.db"); - loadOrSaveDb(internaldb, "internal.db", true); - CreateDirectoryA(sqlitedb_basedir, 0); //create database directory if(loadOrSaveDb(db, dbpath, true)!=SQLITE_OK) return false; @@ -92,86 +76,29 @@ void dbclose() dbsave(); sqlite3_db_release_memory(db); sqlite3_close(db); //close program database - sqlite3_db_release_memory(internaldb); - sqlite3_close(internaldb); //close internal database } ///module functions - -static std::vector modinfo; - bool modnamefromaddr(uint addr, char* modname) { - int total=modinfo.size(); - for(int i=0; i=modinfo.at(i).start and addrhProcess, (DWORD64)addr, &modInfo)) + return false; + _strlwr(modInfo.ModuleName); + strcpy(modname, modInfo.ModuleName); + return true; } uint modbasefromaddr(uint addr) { - int total=modinfo.size(); - for(int i=0; i=modinfo.at(i).start and addr=31) + IMAGEHLP_MODULE64 modInfo; + memset(&modInfo, 0, sizeof(modInfo)); + modInfo.SizeOfStruct=sizeof(IMAGEHLP_MODULE64); + if(!SymGetModuleInfo64(fdProcessInfo->hProcess, (DWORD64)addr, &modInfo)) return false; - MODINFO info; - info.start=base; - info.end=base+size; - strcpy(info.name, name); - _strlwr(info.name); - modinfo.push_back(info); - apienumexports(base, cbExport); - return true; -} - -bool modunload(uint base) -{ - if(!base) - return false; - int total=modinfo.size(); - for(int i=0; ihProcess, LoadDll->hFile, DLLDebugFileName, 0, (DWORD64)base, 0, 0, 0); - IMAGEHLP_MODULE64 modInfo; - memset(&modInfo, 0, sizeof(modInfo)); - modInfo.SizeOfStruct=sizeof(IMAGEHLP_MODULE64); - if(SymGetModuleInfo64(fdProcessInfo->hProcess, (DWORD64)base, &modInfo)) - modload(modInfo.BaseOfImage, modInfo.ImageSize, modInfo.ModuleName); } static void cbUnloadDll(UNLOAD_DLL_DEBUG_INFO* UnloadDll) @@ -282,7 +277,6 @@ static void cbUnloadDll(UNLOAD_DLL_DEBUG_INFO* UnloadDll) DevicePathToPath(DLLDebugFileName, DLLDebugFileName, deflen); dprintf("DLL Unloaded: "fhex" %s\n", base, DLLDebugFileName); SymUnloadModule64(fdProcessInfo->hProcess, (DWORD64)base); - modunload((uint)base); } static void cbCreateProcess(CREATE_PROCESS_DEBUG_INFO* CreateProcessInfo) @@ -315,12 +309,6 @@ static void cbCreateProcess(CREATE_PROCESS_DEBUG_INFO* CreateProcessInfo) SymInitialize(fdProcessInfo->hProcess, 0, false); //initialize symbols //SymRegisterCallback64(fdProcessInfo->hProcess, SymRegisterCallbackProc64, 0); SymLoadModuleEx(fdProcessInfo->hProcess, CreateProcessInfo->hFile, DebugFileName, 0, (DWORD64)base, 0, 0, 0); - - IMAGEHLP_MODULE64 modInfo; - memset(&modInfo, 0, sizeof(modInfo)); - modInfo.SizeOfStruct=sizeof(IMAGEHLP_MODULE64); - if(SymGetModuleInfo64(fdProcessInfo->hProcess, (DWORD64)base, &modInfo)) - modload(modInfo.BaseOfImage, modInfo.ImageSize, modInfo.ModuleName); } static void cbSystemBreakpoint(void* ExceptionData) @@ -337,25 +325,6 @@ static void cbSystemBreakpoint(void* ExceptionData) //lock lock(WAITID_RUN); wait(WAITID_RUN); - - /*//my code - - //list memorymap(cbListPage) - ReadMemory(va) - setBP(va, type, callback) - - //gui - GuiChangeCIP(va, base, size) - - - //gui - cbClearMap - cbAddPage(MEMORY_BASIC_INFO, modulename) - cbEndMap - - //dbg - MemoryMap(cbClear, cbAddPage, cbEndMap) - */ } static void cbStep()