1
0
Fork 0

DBG: added GetFileNameFromProcessHandle as fallback if CreateProcessInfo->hFile is NULL

This commit is contained in:
mrexodia 2016-06-06 13:51:48 +02:00
parent 749d526257
commit 424c69bc54
No known key found for this signature in database
GPG Key ID: D72F9A4FAA0073B4
3 changed files with 17 additions and 3 deletions

View File

@ -223,6 +223,19 @@ bool GetFileNameFromHandle(HANDLE hFile, char* szFileName)
return true;
}
bool GetFileNameFromProcessHandle(HANDLE hProcess, char* szFileName)
{
wchar_t wszDosFileName[MAX_PATH] = L"";
if(!GetProcessImageFileNameW(hProcess, wszDosFileName, sizeof(wszDosFileName)))
return false;
wchar_t wszFileName[MAX_PATH] = L"";
if(!DevicePathToPathW(wszDosFileName, wszFileName, MAX_PATH * sizeof(wchar_t)))
return false;
strcpy_s(szFileName, MAX_PATH, StringUtils::Utf16ToUtf8(wszFileName).c_str());
return true;
}
/**
\brief Get a boolean setting from the configuration file.
\param section The section of the setting (UTF-8).

View File

@ -75,6 +75,7 @@ void formatdec(char* string);
bool FileExists(const char* file);
bool DirExists(const char* dir);
bool GetFileNameFromHandle(HANDLE hFile, char* szFileName);
bool GetFileNameFromProcessHandle(HANDLE hProcess, char* szFileName);
bool settingboolget(const char* section, const char* name);
arch GetFileArchitecture(const char* szFileName);
bool IsWow64();

View File

@ -779,8 +779,8 @@ static void cbCreateProcess(CREATE_PROCESS_DEBUG_INFO* CreateProcessInfo)
void* base = CreateProcessInfo->lpBaseOfImage;
char DebugFileName[deflen] = "";
if(!GetFileNameFromHandle(CreateProcessInfo->hFile, DebugFileName))
strcpy_s(DebugFileName, "??? (GetFileNameFromHandle failed!)");
if(!GetFileNameFromHandle(CreateProcessInfo->hFile, DebugFileName) && !GetFileNameFromProcessHandle(CreateProcessInfo->hProcess, DebugFileName))
strcpy_s(DebugFileName, "??? (GetFileNameFromHandle failed)");
dprintf("Process Started: " fhex " %s\n", base, DebugFileName);
//update memory map
@ -1015,7 +1015,7 @@ static void cbLoadDll(LOAD_DLL_DEBUG_INFO* LoadDll)
char DLLDebugFileName[deflen] = "";
if(!GetFileNameFromHandle(LoadDll->hFile, DLLDebugFileName))
strcpy_s(DLLDebugFileName, "??? (GetFileNameFromHandle failed!)");
strcpy_s(DLLDebugFileName, "??? (GetFileNameFromHandle failed)");
SafeSymLoadModuleExW(fdProcessInfo->hProcess, LoadDll->hFile, StringUtils::Utf8ToUtf16(DLLDebugFileName).c_str(), 0, (DWORD64)base, 0, 0, 0);
IMAGEHLP_MODULEW64 modInfo;