DBG: safe dbghelp functions
This commit is contained in:
parent
0fb5f7590b
commit
20fa55cc2b
|
@ -107,10 +107,10 @@ extern "C" DLL_EXPORT bool _dbg_addrinfoget(duint addr, SEGMENTREG segment, ADDR
|
||||||
PSYMBOL_INFO pSymbol = (PSYMBOL_INFO)buffer;
|
PSYMBOL_INFO pSymbol = (PSYMBOL_INFO)buffer;
|
||||||
pSymbol->SizeOfStruct = sizeof(SYMBOL_INFO);
|
pSymbol->SizeOfStruct = sizeof(SYMBOL_INFO);
|
||||||
pSymbol->MaxNameLen = MAX_LABEL_SIZE;
|
pSymbol->MaxNameLen = MAX_LABEL_SIZE;
|
||||||
if(SymFromAddr(fdProcessInfo->hProcess, (DWORD64)addr, &displacement, pSymbol) and !displacement)
|
if(SafeSymFromAddr(fdProcessInfo->hProcess, (DWORD64)addr, &displacement, pSymbol) and !displacement)
|
||||||
{
|
{
|
||||||
pSymbol->Name[pSymbol->MaxNameLen - 1] = '\0';
|
pSymbol->Name[pSymbol->MaxNameLen - 1] = '\0';
|
||||||
if(!bUndecorateSymbolNames or !UnDecorateSymbolName(pSymbol->Name, addrinfo->label, MAX_LABEL_SIZE, UNDNAME_COMPLETE))
|
if(!bUndecorateSymbolNames or !SafeUnDecorateSymbolName(pSymbol->Name, addrinfo->label, MAX_LABEL_SIZE, UNDNAME_COMPLETE))
|
||||||
strcpy_s(addrinfo->label, pSymbol->Name);
|
strcpy_s(addrinfo->label, pSymbol->Name);
|
||||||
retval = true;
|
retval = true;
|
||||||
}
|
}
|
||||||
|
@ -123,10 +123,10 @@ extern "C" DLL_EXPORT bool _dbg_addrinfoget(duint addr, SEGMENTREG segment, ADDR
|
||||||
uint val = 0;
|
uint val = 0;
|
||||||
if(memread(fdProcessInfo->hProcess, (const void*)basicinfo.memory.value, &val, sizeof(val), 0))
|
if(memread(fdProcessInfo->hProcess, (const void*)basicinfo.memory.value, &val, sizeof(val), 0))
|
||||||
{
|
{
|
||||||
if(SymFromAddr(fdProcessInfo->hProcess, (DWORD64)val, &displacement, pSymbol) and !displacement)
|
if(SafeSymFromAddr(fdProcessInfo->hProcess, (DWORD64)val, &displacement, pSymbol) and !displacement)
|
||||||
{
|
{
|
||||||
pSymbol->Name[pSymbol->MaxNameLen - 1] = '\0';
|
pSymbol->Name[pSymbol->MaxNameLen - 1] = '\0';
|
||||||
if(!bUndecorateSymbolNames or !UnDecorateSymbolName(pSymbol->Name, addrinfo->label, MAX_LABEL_SIZE, UNDNAME_COMPLETE))
|
if(!bUndecorateSymbolNames or !SafeUnDecorateSymbolName(pSymbol->Name, addrinfo->label, MAX_LABEL_SIZE, UNDNAME_COMPLETE))
|
||||||
sprintf_s(addrinfo->label, "JMP.&%s", pSymbol->Name);
|
sprintf_s(addrinfo->label, "JMP.&%s", pSymbol->Name);
|
||||||
retval = true;
|
retval = true;
|
||||||
}
|
}
|
||||||
|
@ -160,7 +160,7 @@ extern "C" DLL_EXPORT bool _dbg_addrinfoget(duint addr, SEGMENTREG segment, ADDR
|
||||||
DWORD dwDisplacement;
|
DWORD dwDisplacement;
|
||||||
IMAGEHLP_LINE64 line;
|
IMAGEHLP_LINE64 line;
|
||||||
line.SizeOfStruct = sizeof(IMAGEHLP_LINE64);
|
line.SizeOfStruct = sizeof(IMAGEHLP_LINE64);
|
||||||
if(SymGetLineFromAddr64(fdProcessInfo->hProcess, (DWORD64)addr, &dwDisplacement, &line) and !dwDisplacement)
|
if(SafeSymGetLineFromAddr64(fdProcessInfo->hProcess, (DWORD64)addr, &dwDisplacement, &line) and !dwDisplacement)
|
||||||
{
|
{
|
||||||
char filename[deflen] = "";
|
char filename[deflen] = "";
|
||||||
strcpy_s(filename, line.FileName);
|
strcpy_s(filename, line.FileName);
|
||||||
|
|
|
@ -22,12 +22,7 @@
|
||||||
#include "DeviceNameResolver\DeviceNameResolver.h"
|
#include "DeviceNameResolver\DeviceNameResolver.h"
|
||||||
#include "handle.h"
|
#include "handle.h"
|
||||||
#include "stringutils.h"
|
#include "stringutils.h"
|
||||||
|
#include "dbghelp_safe.h"
|
||||||
#ifdef __GNUC__
|
|
||||||
#include "dbghelp\dbghelp.h"
|
|
||||||
#else
|
|
||||||
#include <dbghelp.h>
|
|
||||||
#endif //__GNUC__
|
|
||||||
|
|
||||||
#ifndef __GNUC__
|
#ifndef __GNUC__
|
||||||
#define and &&
|
#define and &&
|
||||||
|
|
|
@ -0,0 +1,158 @@
|
||||||
|
#include "_global.h"
|
||||||
|
#include "dbghelp_safe.h"
|
||||||
|
#include "threading.h"
|
||||||
|
|
||||||
|
DWORD
|
||||||
|
SafeUnDecorateSymbolName(
|
||||||
|
__in PCSTR name,
|
||||||
|
__out_ecount(maxStringLength) PSTR outputString,
|
||||||
|
__in DWORD maxStringLength,
|
||||||
|
__in DWORD flags
|
||||||
|
)
|
||||||
|
{
|
||||||
|
CriticalSectionLocker locker(LockSym);
|
||||||
|
return UnDecorateSymbolName(name, outputString, maxStringLength, flags);
|
||||||
|
}
|
||||||
|
BOOL
|
||||||
|
SafeSymUnloadModule64(
|
||||||
|
__in HANDLE hProcess,
|
||||||
|
__in DWORD64 BaseOfDll
|
||||||
|
)
|
||||||
|
{
|
||||||
|
CriticalSectionLocker locker(LockSym);
|
||||||
|
return SymUnloadModule64(hProcess, BaseOfDll);
|
||||||
|
}
|
||||||
|
BOOL
|
||||||
|
SafeSymSetSearchPath(
|
||||||
|
__in HANDLE hProcess,
|
||||||
|
__in_opt PCSTR SearchPath
|
||||||
|
)
|
||||||
|
{
|
||||||
|
CriticalSectionLocker locker(LockSym);
|
||||||
|
return SymSetSearchPath(hProcess, SearchPath);
|
||||||
|
}
|
||||||
|
DWORD
|
||||||
|
SafeSymSetOptions(
|
||||||
|
__in DWORD SymOptions
|
||||||
|
)
|
||||||
|
{
|
||||||
|
CriticalSectionLocker locker(LockSym);
|
||||||
|
return SymSetOptions(SymOptions);
|
||||||
|
}
|
||||||
|
BOOL
|
||||||
|
SafeSymInitialize(
|
||||||
|
__in HANDLE hProcess,
|
||||||
|
__in_opt PCSTR UserSearchPath,
|
||||||
|
__in BOOL fInvadeProcess
|
||||||
|
)
|
||||||
|
{
|
||||||
|
CriticalSectionLocker locker(LockSym);
|
||||||
|
return SymInitialize(hProcess, UserSearchPath, fInvadeProcess);
|
||||||
|
}
|
||||||
|
BOOL
|
||||||
|
SafeSymRegisterCallback64(
|
||||||
|
__in HANDLE hProcess,
|
||||||
|
__in PSYMBOL_REGISTERED_CALLBACK64 CallbackFunction,
|
||||||
|
__in ULONG64 UserContext
|
||||||
|
)
|
||||||
|
{
|
||||||
|
CriticalSectionLocker locker(LockSym);
|
||||||
|
return SymRegisterCallback64(hProcess, CallbackFunction, UserContext);
|
||||||
|
}
|
||||||
|
DWORD64
|
||||||
|
SafeSymLoadModuleEx(
|
||||||
|
__in HANDLE hProcess,
|
||||||
|
__in_opt HANDLE hFile,
|
||||||
|
__in_opt PCSTR ImageName,
|
||||||
|
__in_opt PCSTR ModuleName,
|
||||||
|
__in DWORD64 BaseOfDll,
|
||||||
|
__in DWORD DllSize,
|
||||||
|
__in_opt PMODLOAD_DATA Data,
|
||||||
|
__in_opt DWORD Flags
|
||||||
|
)
|
||||||
|
{
|
||||||
|
CriticalSectionLocker locker(LockSym);
|
||||||
|
return SymLoadModuleEx(hProcess, hFile, ImageName, ModuleName, BaseOfDll, DllSize, Data, Flags);
|
||||||
|
}
|
||||||
|
BOOL
|
||||||
|
SafeSymGetModuleInfo64(
|
||||||
|
__in HANDLE hProcess,
|
||||||
|
__in DWORD64 qwAddr,
|
||||||
|
__out PIMAGEHLP_MODULE64 ModuleInfo
|
||||||
|
)
|
||||||
|
{
|
||||||
|
CriticalSectionLocker locker(LockSym);
|
||||||
|
return SymGetModuleInfo64(hProcess, qwAddr, ModuleInfo);
|
||||||
|
}
|
||||||
|
BOOL
|
||||||
|
SafeSymGetSearchPath(
|
||||||
|
__in HANDLE hProcess,
|
||||||
|
__out_ecount(SearchPathLength) PSTR SearchPath,
|
||||||
|
__in DWORD SearchPathLength
|
||||||
|
)
|
||||||
|
{
|
||||||
|
CriticalSectionLocker locker(LockSym);
|
||||||
|
return SymGetSearchPath(hProcess, SearchPath, SearchPathLength);
|
||||||
|
}
|
||||||
|
BOOL
|
||||||
|
SafeSymEnumSymbols(
|
||||||
|
__in HANDLE hProcess,
|
||||||
|
__in ULONG64 BaseOfDll,
|
||||||
|
__in_opt PCSTR Mask,
|
||||||
|
__in PSYM_ENUMERATESYMBOLS_CALLBACK EnumSymbolsCallback,
|
||||||
|
__in_opt PVOID UserContext
|
||||||
|
)
|
||||||
|
{
|
||||||
|
CriticalSectionLocker locker(LockSym);
|
||||||
|
return SymEnumSymbols(hProcess, BaseOfDll, Mask, EnumSymbolsCallback, UserContext);
|
||||||
|
}
|
||||||
|
BOOL
|
||||||
|
SafeSymEnumerateModules(
|
||||||
|
__in HANDLE hProcess,
|
||||||
|
__in PSYM_ENUMMODULES_CALLBACK EnumModulesCallback,
|
||||||
|
__in_opt PVOID UserContext
|
||||||
|
)
|
||||||
|
{
|
||||||
|
CriticalSectionLocker locker(LockSym);
|
||||||
|
return SymEnumerateModules(hProcess, EnumModulesCallback, UserContext);
|
||||||
|
}
|
||||||
|
BOOL
|
||||||
|
SafeSymGetLineFromAddr64(
|
||||||
|
__in HANDLE hProcess,
|
||||||
|
__in DWORD64 qwAddr,
|
||||||
|
__out PDWORD pdwDisplacement,
|
||||||
|
__out PIMAGEHLP_LINE64 Line64
|
||||||
|
)
|
||||||
|
{
|
||||||
|
CriticalSectionLocker locker(LockSym);
|
||||||
|
return SymGetLineFromAddr64(hProcess, qwAddr, pdwDisplacement, Line64);
|
||||||
|
}
|
||||||
|
BOOL
|
||||||
|
SafeSymFromName(
|
||||||
|
__in HANDLE hProcess,
|
||||||
|
__in PCSTR Name,
|
||||||
|
__inout PSYMBOL_INFO Symbol
|
||||||
|
)
|
||||||
|
{
|
||||||
|
CriticalSectionLocker locker(LockSym);
|
||||||
|
return SymFromName(hProcess, Name, Symbol);
|
||||||
|
}
|
||||||
|
BOOL
|
||||||
|
SafeSymFromAddr(
|
||||||
|
__in HANDLE hProcess,
|
||||||
|
__in DWORD64 Address,
|
||||||
|
__out_opt PDWORD64 Displacement,
|
||||||
|
__inout PSYMBOL_INFO Symbol
|
||||||
|
)
|
||||||
|
{
|
||||||
|
CriticalSectionLocker locker(LockSym);
|
||||||
|
return SymFromAddr(hProcess, Address, Displacement, Symbol);
|
||||||
|
}
|
||||||
|
BOOL
|
||||||
|
SafeSymCleanup(
|
||||||
|
__in HANDLE hProcess
|
||||||
|
)
|
||||||
|
{
|
||||||
|
CriticalSectionLocker locker(LockSym);
|
||||||
|
return SymCleanup(hProcess);
|
||||||
|
}
|
|
@ -0,0 +1,105 @@
|
||||||
|
#ifndef _DBGHELP_SAFE_H
|
||||||
|
#define _DBGHELP_SAFE_H
|
||||||
|
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#include "dbghelp\dbghelp.h"
|
||||||
|
#else
|
||||||
|
#include <dbghelp.h>
|
||||||
|
#endif //__GNUC__
|
||||||
|
|
||||||
|
DWORD
|
||||||
|
SafeUnDecorateSymbolName(
|
||||||
|
__in PCSTR name,
|
||||||
|
__out_ecount(maxStringLength) PSTR outputString,
|
||||||
|
__in DWORD maxStringLength,
|
||||||
|
__in DWORD flags
|
||||||
|
);
|
||||||
|
BOOL
|
||||||
|
SafeSymUnloadModule64(
|
||||||
|
__in HANDLE hProcess,
|
||||||
|
__in DWORD64 BaseOfDll
|
||||||
|
);
|
||||||
|
BOOL
|
||||||
|
SafeSymSetSearchPath(
|
||||||
|
__in HANDLE hProcess,
|
||||||
|
__in_opt PCSTR SearchPath
|
||||||
|
);
|
||||||
|
DWORD
|
||||||
|
SafeSymSetOptions(
|
||||||
|
__in DWORD SymOptions
|
||||||
|
);
|
||||||
|
BOOL
|
||||||
|
SafeSymInitialize(
|
||||||
|
__in HANDLE hProcess,
|
||||||
|
__in_opt PCSTR UserSearchPath,
|
||||||
|
__in BOOL fInvadeProcess
|
||||||
|
);
|
||||||
|
BOOL
|
||||||
|
SafeSymRegisterCallback64(
|
||||||
|
__in HANDLE hProcess,
|
||||||
|
__in PSYMBOL_REGISTERED_CALLBACK64 CallbackFunction,
|
||||||
|
__in ULONG64 UserContext
|
||||||
|
);
|
||||||
|
DWORD64
|
||||||
|
SafeSymLoadModuleEx(
|
||||||
|
__in HANDLE hProcess,
|
||||||
|
__in_opt HANDLE hFile,
|
||||||
|
__in_opt PCSTR ImageName,
|
||||||
|
__in_opt PCSTR ModuleName,
|
||||||
|
__in DWORD64 BaseOfDll,
|
||||||
|
__in DWORD DllSize,
|
||||||
|
__in_opt PMODLOAD_DATA Data,
|
||||||
|
__in_opt DWORD Flags
|
||||||
|
);
|
||||||
|
BOOL
|
||||||
|
SafeSymGetModuleInfo64(
|
||||||
|
__in HANDLE hProcess,
|
||||||
|
__in DWORD64 qwAddr,
|
||||||
|
__out PIMAGEHLP_MODULE64 ModuleInfo
|
||||||
|
);
|
||||||
|
BOOL
|
||||||
|
SafeSymGetSearchPath(
|
||||||
|
__in HANDLE hProcess,
|
||||||
|
__out_ecount(SearchPathLength) PSTR SearchPath,
|
||||||
|
__in DWORD SearchPathLength
|
||||||
|
);
|
||||||
|
BOOL
|
||||||
|
SafeSymEnumSymbols(
|
||||||
|
__in HANDLE hProcess,
|
||||||
|
__in ULONG64 BaseOfDll,
|
||||||
|
__in_opt PCSTR Mask,
|
||||||
|
__in PSYM_ENUMERATESYMBOLS_CALLBACK EnumSymbolsCallback,
|
||||||
|
__in_opt PVOID UserContext
|
||||||
|
);
|
||||||
|
BOOL
|
||||||
|
SafeSymEnumerateModules(
|
||||||
|
__in HANDLE hProcess,
|
||||||
|
__in PSYM_ENUMMODULES_CALLBACK EnumModulesCallback,
|
||||||
|
__in_opt PVOID UserContext
|
||||||
|
);
|
||||||
|
BOOL
|
||||||
|
SafeSymGetLineFromAddr64(
|
||||||
|
__in HANDLE hProcess,
|
||||||
|
__in DWORD64 qwAddr,
|
||||||
|
__out PDWORD pdwDisplacement,
|
||||||
|
__out PIMAGEHLP_LINE64 Line64
|
||||||
|
);
|
||||||
|
BOOL
|
||||||
|
SafeSymFromName(
|
||||||
|
__in HANDLE hProcess,
|
||||||
|
__in PCSTR Name,
|
||||||
|
__inout PSYMBOL_INFO Symbol
|
||||||
|
);
|
||||||
|
BOOL
|
||||||
|
SafeSymFromAddr(
|
||||||
|
__in HANDLE hProcess,
|
||||||
|
__in DWORD64 Address,
|
||||||
|
__out_opt PDWORD64 Displacement,
|
||||||
|
__inout PSYMBOL_INFO Symbol
|
||||||
|
);
|
||||||
|
BOOL
|
||||||
|
SafeSymCleanup(
|
||||||
|
__in HANDLE hProcess
|
||||||
|
);
|
||||||
|
|
||||||
|
#endif //_DBGHELP_SAFE_H
|
|
@ -622,17 +622,17 @@ static void cbCreateProcess(CREATE_PROCESS_DEBUG_INFO* CreateProcessInfo)
|
||||||
sprintf(dbpath, "%s\\%s", dbbasepath, sqlitedb);
|
sprintf(dbpath, "%s\\%s", dbbasepath, sqlitedb);
|
||||||
dprintf("Database file: %s\n", dbpath);
|
dprintf("Database file: %s\n", dbpath);
|
||||||
dbload();
|
dbload();
|
||||||
SymSetOptions(SYMOPT_DEBUG | SYMOPT_LOAD_LINES | SYMOPT_ALLOW_ABSOLUTE_SYMBOLS | SYMOPT_FAVOR_COMPRESSED | SYMOPT_IGNORE_NT_SYMPATH);
|
SafeSymSetOptions(SYMOPT_DEBUG | SYMOPT_LOAD_LINES | SYMOPT_ALLOW_ABSOLUTE_SYMBOLS | SYMOPT_FAVOR_COMPRESSED | SYMOPT_IGNORE_NT_SYMPATH);
|
||||||
GuiSymbolLogClear();
|
GuiSymbolLogClear();
|
||||||
char szServerSearchPath[MAX_PATH * 2] = "";
|
char szServerSearchPath[MAX_PATH * 2] = "";
|
||||||
sprintf_s(szServerSearchPath, "SRV*%s", szSymbolCachePath);
|
sprintf_s(szServerSearchPath, "SRV*%s", szSymbolCachePath);
|
||||||
SymInitialize(fdProcessInfo->hProcess, szServerSearchPath, false); //initialize symbols
|
SafeSymInitialize(fdProcessInfo->hProcess, szServerSearchPath, false); //initialize symbols
|
||||||
SymRegisterCallback64(fdProcessInfo->hProcess, SymRegisterCallbackProc64, 0);
|
SafeSymRegisterCallback64(fdProcessInfo->hProcess, SymRegisterCallbackProc64, 0);
|
||||||
SymLoadModuleEx(fdProcessInfo->hProcess, CreateProcessInfo->hFile, DebugFileName, 0, (DWORD64)base, 0, 0, 0);
|
SafeSymLoadModuleEx(fdProcessInfo->hProcess, CreateProcessInfo->hFile, DebugFileName, 0, (DWORD64)base, 0, 0, 0);
|
||||||
IMAGEHLP_MODULE64 modInfo;
|
IMAGEHLP_MODULE64 modInfo;
|
||||||
memset(&modInfo, 0, sizeof(modInfo));
|
memset(&modInfo, 0, sizeof(modInfo));
|
||||||
modInfo.SizeOfStruct = sizeof(modInfo);
|
modInfo.SizeOfStruct = sizeof(modInfo);
|
||||||
if(SymGetModuleInfo64(fdProcessInfo->hProcess, (DWORD64)base, &modInfo))
|
if(SafeSymGetModuleInfo64(fdProcessInfo->hProcess, (DWORD64)base, &modInfo))
|
||||||
modload((uint)base, modInfo.ImageSize, modInfo.ImageName);
|
modload((uint)base, modInfo.ImageSize, modInfo.ImageName);
|
||||||
dbggetprivateusage(fdProcessInfo->hProcess, true);
|
dbggetprivateusage(fdProcessInfo->hProcess, true);
|
||||||
memupdatemap(fdProcessInfo->hProcess); //update memory map
|
memupdatemap(fdProcessInfo->hProcess); //update memory map
|
||||||
|
@ -697,7 +697,7 @@ static void cbExitProcess(EXIT_PROCESS_DEBUG_INFO* ExitProcess)
|
||||||
callbackInfo.ExitProcess = ExitProcess;
|
callbackInfo.ExitProcess = ExitProcess;
|
||||||
plugincbcall(CB_EXITPROCESS, &callbackInfo);
|
plugincbcall(CB_EXITPROCESS, &callbackInfo);
|
||||||
//Cleanup
|
//Cleanup
|
||||||
SymCleanup(fdProcessInfo->hProcess);
|
SafeSymCleanup(fdProcessInfo->hProcess);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cbCreateThread(CREATE_THREAD_DEBUG_INFO* CreateThread)
|
static void cbCreateThread(CREATE_THREAD_DEBUG_INFO* CreateThread)
|
||||||
|
@ -808,11 +808,11 @@ static void cbLoadDll(LOAD_DLL_DEBUG_INFO* LoadDll)
|
||||||
else
|
else
|
||||||
strcpy_s(DLLDebugFileName, MAX_PATH, StringUtils::Utf16ToUtf8(wszFileName).c_str());
|
strcpy_s(DLLDebugFileName, MAX_PATH, StringUtils::Utf16ToUtf8(wszFileName).c_str());
|
||||||
}
|
}
|
||||||
SymLoadModuleEx(fdProcessInfo->hProcess, LoadDll->hFile, DLLDebugFileName, 0, (DWORD64)base, 0, 0, 0);
|
SafeSymLoadModuleEx(fdProcessInfo->hProcess, LoadDll->hFile, DLLDebugFileName, 0, (DWORD64)base, 0, 0, 0);
|
||||||
IMAGEHLP_MODULE64 modInfo;
|
IMAGEHLP_MODULE64 modInfo;
|
||||||
memset(&modInfo, 0, sizeof(modInfo));
|
memset(&modInfo, 0, sizeof(modInfo));
|
||||||
modInfo.SizeOfStruct = sizeof(IMAGEHLP_MODULE64);
|
modInfo.SizeOfStruct = sizeof(IMAGEHLP_MODULE64);
|
||||||
if(SymGetModuleInfo64(fdProcessInfo->hProcess, (DWORD64)base, &modInfo))
|
if(SafeSymGetModuleInfo64(fdProcessInfo->hProcess, (DWORD64)base, &modInfo))
|
||||||
modload((uint)base, modInfo.ImageSize, modInfo.ImageName);
|
modload((uint)base, modInfo.ImageSize, modInfo.ImageName);
|
||||||
dbggetprivateusage(fdProcessInfo->hProcess, true);
|
dbggetprivateusage(fdProcessInfo->hProcess, true);
|
||||||
memupdatemap(fdProcessInfo->hProcess); //update memory map
|
memupdatemap(fdProcessInfo->hProcess); //update memory map
|
||||||
|
@ -910,7 +910,7 @@ static void cbUnloadDll(UNLOAD_DLL_DEBUG_INFO* UnloadDll)
|
||||||
if(modnamefromaddr((uint)base, modname, true))
|
if(modnamefromaddr((uint)base, modname, true))
|
||||||
bpenumall(cbRemoveModuleBreakpoints, modname);
|
bpenumall(cbRemoveModuleBreakpoints, modname);
|
||||||
GuiUpdateBreakpointsView();
|
GuiUpdateBreakpointsView();
|
||||||
SymUnloadModule64(fdProcessInfo->hProcess, (DWORD64)base);
|
SafeSymUnloadModule64(fdProcessInfo->hProcess, (DWORD64)base);
|
||||||
dprintf("DLL Unloaded: "fhex" %s\n", base, modname);
|
dprintf("DLL Unloaded: "fhex" %s\n", base, modname);
|
||||||
|
|
||||||
if(bBreakOnNextDll || settingboolget("Events", "DllUnload"))
|
if(bBreakOnNextDll || settingboolget("Events", "DllUnload"))
|
||||||
|
|
|
@ -1405,7 +1405,7 @@ CMDRESULT cbDebugDownloadSymbol(int argc, char* argv[])
|
||||||
char szModulePath[MAX_PATH] = "";
|
char szModulePath[MAX_PATH] = "";
|
||||||
strcpy_s(szModulePath, StringUtils::Utf16ToUtf8(wszModulePath).c_str());
|
strcpy_s(szModulePath, StringUtils::Utf16ToUtf8(wszModulePath).c_str());
|
||||||
char szOldSearchPath[MAX_PATH] = "";
|
char szOldSearchPath[MAX_PATH] = "";
|
||||||
if(!SymGetSearchPath(fdProcessInfo->hProcess, szOldSearchPath, MAX_PATH)) //backup current search path
|
if(!SafeSymGetSearchPath(fdProcessInfo->hProcess, szOldSearchPath, MAX_PATH)) //backup current search path
|
||||||
{
|
{
|
||||||
dputs("SymGetSearchPath failed!");
|
dputs("SymGetSearchPath failed!");
|
||||||
return STATUS_ERROR;
|
return STATUS_ERROR;
|
||||||
|
@ -1414,24 +1414,24 @@ CMDRESULT cbDebugDownloadSymbol(int argc, char* argv[])
|
||||||
if(argc > 2)
|
if(argc > 2)
|
||||||
szSymbolStore = argv[2];
|
szSymbolStore = argv[2];
|
||||||
sprintf_s(szServerSearchPath, "SRV*%s*%s", szSymbolCachePath, szSymbolStore);
|
sprintf_s(szServerSearchPath, "SRV*%s*%s", szSymbolCachePath, szSymbolStore);
|
||||||
if(!SymSetSearchPath(fdProcessInfo->hProcess, szServerSearchPath)) //set new search path
|
if(!SafeSymSetSearchPath(fdProcessInfo->hProcess, szServerSearchPath)) //set new search path
|
||||||
{
|
{
|
||||||
dputs("SymSetSearchPath (1) failed!");
|
dputs("SymSetSearchPath (1) failed!");
|
||||||
return STATUS_ERROR;
|
return STATUS_ERROR;
|
||||||
}
|
}
|
||||||
if(!SymUnloadModule64(fdProcessInfo->hProcess, (DWORD64)modbase)) //unload module
|
if(!SafeSymUnloadModule64(fdProcessInfo->hProcess, (DWORD64)modbase)) //unload module
|
||||||
{
|
{
|
||||||
SymSetSearchPath(fdProcessInfo->hProcess, szOldSearchPath);
|
SafeSymSetSearchPath(fdProcessInfo->hProcess, szOldSearchPath);
|
||||||
dputs("SymUnloadModule64 failed!");
|
dputs("SymUnloadModule64 failed!");
|
||||||
return STATUS_ERROR;
|
return STATUS_ERROR;
|
||||||
}
|
}
|
||||||
if(!SymLoadModuleEx(fdProcessInfo->hProcess, 0, szModulePath, 0, (DWORD64)modbase, 0, 0, 0)) //load module
|
if(!SafeSymLoadModuleEx(fdProcessInfo->hProcess, 0, szModulePath, 0, (DWORD64)modbase, 0, 0, 0)) //load module
|
||||||
{
|
{
|
||||||
dputs("SymLoadModuleEx failed!");
|
dputs("SymLoadModuleEx failed!");
|
||||||
SymSetSearchPath(fdProcessInfo->hProcess, szOldSearchPath);
|
SafeSymSetSearchPath(fdProcessInfo->hProcess, szOldSearchPath);
|
||||||
return STATUS_ERROR;
|
return STATUS_ERROR;
|
||||||
}
|
}
|
||||||
if(!SymSetSearchPath(fdProcessInfo->hProcess, szOldSearchPath))
|
if(!SafeSymSetSearchPath(fdProcessInfo->hProcess, szOldSearchPath))
|
||||||
{
|
{
|
||||||
dputs("SymSetSearchPath (2) failed!");
|
dputs("SymSetSearchPath (2) failed!");
|
||||||
return STATUS_ERROR;
|
return STATUS_ERROR;
|
||||||
|
|
|
@ -26,7 +26,7 @@ static BOOL CALLBACK EnumSymbols(PSYMBOL_INFO pSymInfo, ULONG SymbolSize, PVOID
|
||||||
if(pSymInfo->Address == pSymInfo->ModBase)
|
if(pSymInfo->Address == pSymInfo->ModBase)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
if(!UnDecorateSymbolName(pSymInfo->Name, curSymbol.undecoratedSymbol, MAX_SYM_NAME, UNDNAME_COMPLETE))
|
if(!SafeUnDecorateSymbolName(pSymInfo->Name, curSymbol.undecoratedSymbol, MAX_SYM_NAME, UNDNAME_COMPLETE))
|
||||||
{
|
{
|
||||||
BridgeFree(curSymbol.undecoratedSymbol);
|
BridgeFree(curSymbol.undecoratedSymbol);
|
||||||
curSymbol.undecoratedSymbol = 0;
|
curSymbol.undecoratedSymbol = 0;
|
||||||
|
@ -47,7 +47,7 @@ void symenum(uint base, CBSYMBOLENUM cbSymbolEnum, void* user)
|
||||||
symbolCbData.cbSymbolEnum = cbSymbolEnum;
|
symbolCbData.cbSymbolEnum = cbSymbolEnum;
|
||||||
symbolCbData.user = user;
|
symbolCbData.user = user;
|
||||||
char mask[] = "*";
|
char mask[] = "*";
|
||||||
SymEnumSymbols(fdProcessInfo->hProcess, base, mask, EnumSymbols, &symbolCbData);
|
SafeSymEnumSymbols(fdProcessInfo->hProcess, base, mask, EnumSymbols, &symbolCbData);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _WIN64
|
#ifdef _WIN64
|
||||||
|
@ -68,7 +68,7 @@ void symupdatemodulelist()
|
||||||
{
|
{
|
||||||
std::vector<SYMBOLMODULEINFO> modList;
|
std::vector<SYMBOLMODULEINFO> modList;
|
||||||
modList.clear();
|
modList.clear();
|
||||||
SymEnumerateModules(fdProcessInfo->hProcess, EnumModules, &modList);
|
SafeSymEnumerateModules(fdProcessInfo->hProcess, EnumModules, &modList);
|
||||||
int modcount = (int)modList.size();
|
int modcount = (int)modList.size();
|
||||||
SYMBOLMODULEINFO* modListBridge = (SYMBOLMODULEINFO*)BridgeAlloc(sizeof(SYMBOLMODULEINFO) * modcount);
|
SYMBOLMODULEINFO* modListBridge = (SYMBOLMODULEINFO*)BridgeAlloc(sizeof(SYMBOLMODULEINFO) * modcount);
|
||||||
for(int i = 0; i < modcount; i++)
|
for(int i = 0; i < modcount; i++)
|
||||||
|
@ -82,19 +82,19 @@ void symdownloadallsymbols(const char* szSymbolStore)
|
||||||
szSymbolStore = "http://msdl.microsoft.com/download/symbols";
|
szSymbolStore = "http://msdl.microsoft.com/download/symbols";
|
||||||
std::vector<SYMBOLMODULEINFO> modList;
|
std::vector<SYMBOLMODULEINFO> modList;
|
||||||
modList.clear();
|
modList.clear();
|
||||||
SymEnumerateModules(fdProcessInfo->hProcess, EnumModules, &modList);
|
SafeSymEnumerateModules(fdProcessInfo->hProcess, EnumModules, &modList);
|
||||||
int modcount = (int)modList.size();
|
int modcount = (int)modList.size();
|
||||||
if(!modcount)
|
if(!modcount)
|
||||||
return;
|
return;
|
||||||
char szOldSearchPath[MAX_PATH] = "";
|
char szOldSearchPath[MAX_PATH] = "";
|
||||||
if(!SymGetSearchPath(fdProcessInfo->hProcess, szOldSearchPath, MAX_PATH)) //backup current path
|
if(!SafeSymGetSearchPath(fdProcessInfo->hProcess, szOldSearchPath, MAX_PATH)) //backup current path
|
||||||
{
|
{
|
||||||
dputs("SymGetSearchPath failed!");
|
dputs("SymGetSearchPath failed!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
char szServerSearchPath[MAX_PATH * 2] = "";
|
char szServerSearchPath[MAX_PATH * 2] = "";
|
||||||
sprintf_s(szServerSearchPath, "SRV*%s*%s", szSymbolCachePath, szSymbolStore);
|
sprintf_s(szServerSearchPath, "SRV*%s*%s", szSymbolCachePath, szSymbolStore);
|
||||||
if(!SymSetSearchPath(fdProcessInfo->hProcess, szServerSearchPath)) //update search path
|
if(!SafeSymSetSearchPath(fdProcessInfo->hProcess, szServerSearchPath)) //update search path
|
||||||
{
|
{
|
||||||
dputs("SymSetSearchPath (1) failed!");
|
dputs("SymSetSearchPath (1) failed!");
|
||||||
return;
|
return;
|
||||||
|
@ -109,18 +109,18 @@ void symdownloadallsymbols(const char* szSymbolStore)
|
||||||
dprintf("GetModuleFileNameExW("fhex") failed!\n", modbase);
|
dprintf("GetModuleFileNameExW("fhex") failed!\n", modbase);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(!SymUnloadModule64(fdProcessInfo->hProcess, (DWORD64)modbase))
|
if(!SafeSymUnloadModule64(fdProcessInfo->hProcess, (DWORD64)modbase))
|
||||||
{
|
{
|
||||||
dprintf("SymUnloadModule64("fhex") failed!\n", modbase);
|
dprintf("SymUnloadModule64("fhex") failed!\n", modbase);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(!SymLoadModuleEx(fdProcessInfo->hProcess, 0, StringUtils::Utf16ToUtf8(szModulePath).c_str(), 0, (DWORD64)modbase, 0, 0, 0))
|
if(!SafeSymLoadModuleEx(fdProcessInfo->hProcess, 0, StringUtils::Utf16ToUtf8(szModulePath).c_str(), 0, (DWORD64)modbase, 0, 0, 0))
|
||||||
{
|
{
|
||||||
dprintf("SymLoadModuleEx("fhex") failed!\n", modbase);
|
dprintf("SymLoadModuleEx("fhex") failed!\n", modbase);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!SymSetSearchPath(fdProcessInfo->hProcess, szOldSearchPath)) //restore search path
|
if(!SafeSymSetSearchPath(fdProcessInfo->hProcess, szOldSearchPath)) //restore search path
|
||||||
{
|
{
|
||||||
dputs("SymSetSearchPath (2) failed!");
|
dputs("SymSetSearchPath (2) failed!");
|
||||||
}
|
}
|
||||||
|
@ -134,7 +134,7 @@ bool symfromname(const char* name, uint* addr)
|
||||||
PSYMBOL_INFO pSymbol = (PSYMBOL_INFO)buffer;
|
PSYMBOL_INFO pSymbol = (PSYMBOL_INFO)buffer;
|
||||||
pSymbol->SizeOfStruct = sizeof(SYMBOL_INFO);
|
pSymbol->SizeOfStruct = sizeof(SYMBOL_INFO);
|
||||||
pSymbol->MaxNameLen = MAX_LABEL_SIZE;
|
pSymbol->MaxNameLen = MAX_LABEL_SIZE;
|
||||||
if(!SymFromName(fdProcessInfo->hProcess, name, pSymbol))
|
if(!SafeSymFromName(fdProcessInfo->hProcess, name, pSymbol))
|
||||||
return false;
|
return false;
|
||||||
*addr = (uint)pSymbol->Address;
|
*addr = (uint)pSymbol->Address;
|
||||||
return true;
|
return true;
|
||||||
|
@ -155,10 +155,10 @@ const char* symgetsymbolicname(uint addr)
|
||||||
PSYMBOL_INFO pSymbol = (PSYMBOL_INFO)buffer;
|
PSYMBOL_INFO pSymbol = (PSYMBOL_INFO)buffer;
|
||||||
pSymbol->SizeOfStruct = sizeof(SYMBOL_INFO);
|
pSymbol->SizeOfStruct = sizeof(SYMBOL_INFO);
|
||||||
pSymbol->MaxNameLen = MAX_LABEL_SIZE;
|
pSymbol->MaxNameLen = MAX_LABEL_SIZE;
|
||||||
if(SymFromAddr(fdProcessInfo->hProcess, (DWORD64)addr, &displacement, pSymbol) and !displacement)
|
if(SafeSymFromAddr(fdProcessInfo->hProcess, (DWORD64)addr, &displacement, pSymbol) and !displacement)
|
||||||
{
|
{
|
||||||
pSymbol->Name[pSymbol->MaxNameLen - 1] = '\0';
|
pSymbol->Name[pSymbol->MaxNameLen - 1] = '\0';
|
||||||
if(!bUndecorateSymbolNames or !UnDecorateSymbolName(pSymbol->Name, label, MAX_SYM_NAME, UNDNAME_COMPLETE))
|
if(!bUndecorateSymbolNames or !SafeUnDecorateSymbolName(pSymbol->Name, label, MAX_SYM_NAME, UNDNAME_COMPLETE))
|
||||||
strcpy_s(label, pSymbol->Name);
|
strcpy_s(label, pSymbol->Name);
|
||||||
retval = true;
|
retval = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ enum CriticalSectionLock
|
||||||
LockPatches,
|
LockPatches,
|
||||||
LockThreads,
|
LockThreads,
|
||||||
LockDprintf,
|
LockDprintf,
|
||||||
|
LockSym,
|
||||||
LockLast
|
LockLast
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
<ClCompile Include="command.cpp" />
|
<ClCompile Include="command.cpp" />
|
||||||
<ClCompile Include="comment.cpp" />
|
<ClCompile Include="comment.cpp" />
|
||||||
<ClCompile Include="console.cpp" />
|
<ClCompile Include="console.cpp" />
|
||||||
|
<ClCompile Include="dbghelp_safe.cpp" />
|
||||||
<ClCompile Include="debugger.cpp" />
|
<ClCompile Include="debugger.cpp" />
|
||||||
<ClCompile Include="debugger_commands.cpp" />
|
<ClCompile Include="debugger_commands.cpp" />
|
||||||
<ClCompile Include="disasm_fast.cpp" />
|
<ClCompile Include="disasm_fast.cpp" />
|
||||||
|
@ -68,6 +69,7 @@
|
||||||
<ClInclude Include="comment.h" />
|
<ClInclude Include="comment.h" />
|
||||||
<ClInclude Include="console.h" />
|
<ClInclude Include="console.h" />
|
||||||
<ClInclude Include="dbghelp\dbghelp.h" />
|
<ClInclude Include="dbghelp\dbghelp.h" />
|
||||||
|
<ClInclude Include="dbghelp_safe.h" />
|
||||||
<ClInclude Include="debugger.h" />
|
<ClInclude Include="debugger.h" />
|
||||||
<ClInclude Include="debugger_commands.h" />
|
<ClInclude Include="debugger_commands.h" />
|
||||||
<ClInclude Include="DeviceNameResolver\DeviceNameResolver.h" />
|
<ClInclude Include="DeviceNameResolver\DeviceNameResolver.h" />
|
||||||
|
|
|
@ -195,6 +195,9 @@
|
||||||
<ClCompile Include="patternfind.cpp">
|
<ClCompile Include="patternfind.cpp">
|
||||||
<Filter>Source Files\Utilities</Filter>
|
<Filter>Source Files\Utilities</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="dbghelp_safe.cpp">
|
||||||
|
<Filter>Source Files\Utilities</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="x64_dbg.h">
|
<ClInclude Include="x64_dbg.h">
|
||||||
|
@ -371,5 +374,8 @@
|
||||||
<ClInclude Include="patternfind.h">
|
<ClInclude Include="patternfind.h">
|
||||||
<Filter>Header Files\Utilities</Filter>
|
<Filter>Header Files\Utilities</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="dbghelp_safe.h">
|
||||||
|
<Filter>Header Files\Utilities</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
Loading…
Reference in New Issue