1
0
Fork 0

DBG: simplify the PatchFile function

This commit is contained in:
mrexodia 2015-11-26 02:57:14 +01:00
parent 1b7c38d985
commit 9674967f73
1 changed files with 5 additions and 6 deletions

View File

@ -212,19 +212,18 @@ int PatchFile(const PATCHINFO* List, int Count, const char* FileName, char* Erro
return -1;
}
// Get the unicode version of the module's path
wchar_t originalName[MAX_PATH];
if(!GetModuleFileNameExW(fdProcessInfo->hProcess, (HMODULE)moduleBase, originalName, ARRAYSIZE(originalName)))
//get the origin module path
char modPath[MAX_PATH] = "";
if(!ModPathFromAddr(moduleBase, modPath, MAX_PATH))
{
if(Error)
if (Error)
sprintf_s(Error, MAX_ERROR_SIZE, "Failed to get module path of module %s", moduleName);
return -1;
}
// Create a temporary backup file
if(!CopyFileW(originalName, StringUtils::Utf8ToUtf16(FileName).c_str(), false))
if (!CopyFileW(StringUtils::Utf8ToUtf16(modPath).c_str(), StringUtils::Utf8ToUtf16(FileName).c_str(), false))
{
if(Error)
strcpy_s(Error, MAX_ERROR_SIZE, "Failed to make a copy of the original file (patch target is in use?)");