1
0
Fork 0

DBG: moved some functions to different files

This commit is contained in:
Mr. eXoDia 2014-12-14 01:58:17 +01:00
parent b29695b8ab
commit e8f4cd2ddf
5 changed files with 68 additions and 66 deletions

View File

@ -92,23 +92,6 @@ static bool _patchrestore(duint addr)
return patchdel(addr, true);
}
static int _modpathfromaddr(duint addr, char* path, int size)
{
Memory<wchar_t*> wszModPath(size * sizeof(wchar_t), "_modpathfromaddr:wszModPath");
if(!GetModuleFileNameExW(fdProcessInfo->hProcess, (HMODULE)modbasefromaddr(addr), wszModPath, size))
{
*path = '\0';
return 0;
}
strcpy_s(path, size, StringUtils::Utf16ToUtf8(wszModPath()).c_str());
return (int)strlen(path);
}
static int _modpathfromname(const char* modname, char* path, int size)
{
return _modpathfromaddr(modbasefromname(modname), path, size);
}
static void _getcallstack(DBGCALLSTACK* callstack)
{
stackgetcallstack(GetContextDataEx(hActiveThread, UE_CSP), (CALLSTACK*)callstack);
@ -181,46 +164,6 @@ static void _memupdatemap()
memupdatemap(fdProcessInfo->hProcess);
}
static duint _fileoffsettova(const char* modname, duint offset)
{
char modpath[MAX_PATH] = "";
if(DbgFunctions()->ModPathFromName(modname, modpath, MAX_PATH))
{
HANDLE FileHandle;
DWORD LoadedSize;
HANDLE FileMap;
ULONG_PTR FileMapVA;
if(StaticFileLoadW(StringUtils::Utf8ToUtf16(modpath).c_str(), UE_ACCESS_READ, false, &FileHandle, &LoadedSize, &FileMap, &FileMapVA))
{
ULONGLONG rva = ConvertFileOffsetToVA(FileMapVA, //FileMapVA
FileMapVA + (ULONG_PTR)offset, //Offset inside FileMapVA
false); //Return without ImageBase
StaticFileUnloadW(StringUtils::Utf8ToUtf16(modpath).c_str(), true, FileHandle, LoadedSize, FileMap, FileMapVA);
return offset < LoadedSize ? (duint)rva + modbasefromname(modname) : 0;
}
}
return 0;
}
static duint _vatofileoffset(duint va)
{
char modpath[MAX_PATH] = "";
if(DbgFunctions()->ModPathFromAddr(va, modpath, MAX_PATH))
{
HANDLE FileHandle;
DWORD LoadedSize;
HANDLE FileMap;
ULONG_PTR FileMapVA;
if(StaticFileLoadW(StringUtils::Utf8ToUtf16(modpath).c_str(), UE_ACCESS_READ, false, &FileHandle, &LoadedSize, &FileMap, &FileMapVA))
{
ULONGLONG offset = ConvertVAtoFileOffsetEx(FileMapVA, LoadedSize, 0, va - modbasefromaddr(va), true, false);
StaticFileUnloadW(StringUtils::Utf8ToUtf16(modpath).c_str(), true, FileHandle, LoadedSize, FileMap, FileMapVA);
return (duint)offset;
}
}
return 0;
}
void dbgfunctionsinit()
{
_dbgfunctions.AssembleAtEx = _assembleatex;
@ -237,8 +180,8 @@ void dbgfunctionsinit()
_dbgfunctions.PatchEnum = (PATCHENUM)patchenum;
_dbgfunctions.PatchRestore = _patchrestore;
_dbgfunctions.PatchFile = (PATCHFILE)patchfile;
_dbgfunctions.ModPathFromAddr = _modpathfromaddr;
_dbgfunctions.ModPathFromName = _modpathfromname;
_dbgfunctions.ModPathFromAddr = modpathfromaddr;
_dbgfunctions.ModPathFromName = modpathfromname;
_dbgfunctions.DisasmFast = disasmfast;
_dbgfunctions.MemUpdateMap = _memupdatemap;
_dbgfunctions.GetCallStack = _getcallstack;
@ -253,6 +196,6 @@ void dbgfunctionsinit()
_dbgfunctions.IsProcessElevated = IsProcessElevated;
_dbgfunctions.GetCmdline = _getcmdline;
_dbgfunctions.SetCmdline = _setcmdline;
_dbgfunctions.FileOffsetToVa = _fileoffsettova;
_dbgfunctions.VaToFileOffset = _vatofileoffset;
_dbgfunctions.FileOffsetToVa = valfileoffsettova;
_dbgfunctions.VaToFileOffset = valvatofileoffset;
}

View File

@ -323,6 +323,23 @@ uint modentryfromaddr(uint addr)
return found->second.entry;
}
int modpathfromaddr(duint addr, char* path, int size)
{
Memory<wchar_t*> wszModPath(size * sizeof(wchar_t), "modpathfromaddr:wszModPath");
if(!GetModuleFileNameExW(fdProcessInfo->hProcess, (HMODULE)modbasefromaddr(addr), wszModPath, size))
{
*path = '\0';
return 0;
}
strcpy_s(path, size, StringUtils::Utf16ToUtf8(wszModPath()).c_str());
return (int)strlen(path);
}
int modpathfromname(const char* modname, char* path, int size)
{
return modpathfromaddr(modbasefromname(modname), path, size);
}
///api functions
bool apienumexports(uint base, EXPORTENUMCALLBACK cbEnum)
{

View File

@ -136,6 +136,8 @@ uint modbasefromname(const char* modname);
uint modsizefromaddr(uint addr);
bool modsectionsfromaddr(uint addr, std::vector<MODSECTIONINFO>* sections);
uint modentryfromaddr(uint addr);
int modpathfromaddr(duint addr, char* path, int size);
int modpathfromname(const char* modname, char* path, int size);
bool apienumexports(uint base, EXPORTENUMCALLBACK cbEnum);

View File

@ -1535,7 +1535,7 @@ bool valfromstring(const char* string, uint* value, bool silent, bool baseonly,
return false; //nothing was OK
}
bool longEnough(const char* str, size_t min_length)
static bool longEnough(const char* str, size_t min_length)
{
size_t length = 0;
while(str[length] && length < min_length)
@ -1545,7 +1545,7 @@ bool longEnough(const char* str, size_t min_length)
return false;
}
bool startsWith(const char* pre, const char* str)
static bool startsWith(const char* pre, const char* str)
{
size_t lenpre = strlen(pre);
return longEnough(str, lenpre) ? StrNCmpI(str, pre, (int) lenpre) == 0 : false;
@ -1561,8 +1561,7 @@ bool startsWith(const char* pre, const char* str)
#define x8780BITFPU_PRE_FIELD_STRING "x87r"
#define STRLEN_USING_SIZEOF(string) (sizeof(string) - 1)
void fpustuff(const char* string, uint value)
static void fpustuff(const char* string, uint value)
{
uint xorval = 0;
uint flags = 0;
@ -2053,3 +2052,43 @@ bool valtostring(const char* string, uint* value, bool silent)
}
return varset(string, *value, false); //variable
}
uint valfileoffsettova(const char* modname, uint offset)
{
char modpath[MAX_PATH] = "";
if(modpathfromname(modname, modpath, MAX_PATH))
{
HANDLE FileHandle;
DWORD LoadedSize;
HANDLE FileMap;
ULONG_PTR FileMapVA;
if(StaticFileLoadW(StringUtils::Utf8ToUtf16(modpath).c_str(), UE_ACCESS_READ, false, &FileHandle, &LoadedSize, &FileMap, &FileMapVA))
{
ULONGLONG rva = ConvertFileOffsetToVA(FileMapVA, //FileMapVA
FileMapVA + (ULONG_PTR)offset, //Offset inside FileMapVA
false); //Return without ImageBase
StaticFileUnloadW(StringUtils::Utf8ToUtf16(modpath).c_str(), true, FileHandle, LoadedSize, FileMap, FileMapVA);
return offset < LoadedSize ? (duint)rva + modbasefromname(modname) : 0;
}
}
return 0;
}
uint valvatofileoffset(uint va)
{
char modpath[MAX_PATH] = "";
if(modpathfromaddr(va, modpath, MAX_PATH))
{
HANDLE FileHandle;
DWORD LoadedSize;
HANDLE FileMap;
ULONG_PTR FileMapVA;
if(StaticFileLoadW(StringUtils::Utf8ToUtf16(modpath).c_str(), UE_ACCESS_READ, false, &FileHandle, &LoadedSize, &FileMap, &FileMapVA))
{
ULONGLONG offset = ConvertVAtoFileOffsetEx(FileMapVA, LoadedSize, 0, va - modbasefromaddr(va), true, false);
StaticFileUnloadW(StringUtils::Utf8ToUtf16(modpath).c_str(), true, FileHandle, LoadedSize, FileMap, FileMapVA);
return (duint)offset;
}
}
return 0;
}

View File

@ -16,6 +16,7 @@ bool valx87controlwordflagfromstring(uint controlword, const char* string);
unsigned short valmxcsrfieldfromstring(uint mxcsrflags, const char* string);
unsigned short valx87statuswordfieldfromstring(uint statusword, const char* string);
unsigned short valx87controlwordfieldfromstring(uint controlword, const char* string);
void fpustuff(const char* string, uint value);
uint valfileoffsettova(const char* modname, uint offset);
uint valvatofileoffset(uint va);
#endif // _VALUE_H