1
0
Fork 0

DBG: properly fix the GetProcAddress crash

This commit is contained in:
mrexodia 2017-03-14 11:18:47 +01:00
parent 281ccdfb4c
commit 6d1db38613
No known key found for this signature in database
GPG Key ID: FC89E0AAA0C1AAD8
3 changed files with 10 additions and 8 deletions

View File

@ -8,6 +8,7 @@
#include "debugger.h"
#include "memory.h"
#include "module.h"
#include "value.h"
///api functions
bool apienumexports(duint base, const EXPORTENUMCALLBACK & cbEnum)
@ -64,7 +65,7 @@ bool apienumexports(duint base, const EXPORTENUMCALLBACK & cbEnum)
HINSTANCE hTempDll = LoadLibraryExA(forwarded_api, 0, DONT_RESOLVE_DLL_REFERENCES | LOAD_LIBRARY_AS_DATAFILE);
if(hTempDll)
{
duint local_addr = (duint)GetProcAddress(hTempDll, forwarded_api + j + 1);
duint local_addr = SafeGetProcAddress(hTempDll, forwarded_api + j + 1);
if(local_addr)
{
duint remote_addr = ImporterGetRemoteAPIAddress(fdProcessInfo->hProcess, local_addr);

View File

@ -1280,15 +1280,15 @@ bool setregister(const char* string, duint value)
return false;
}
static FARPROC SafeGetProcAddress(HMODULE hModule, const char* lpProcName)
duint SafeGetProcAddress(HMODULE hModule, const char* lpProcName)
{
__try
{
return GetProcAddress(hModule, lpProcName);
return duint(GetProcAddress(hModule, lpProcName));
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
return nullptr;
return 0;
}
}
@ -1354,7 +1354,7 @@ bool valapifromstring(const char* name, duint* value, int* value_size, bool prin
}
else
{
duint addr = noexports ? 0 : (duint)GetProcAddress(mod, apiname);
duint addr = noexports ? 0 : SafeGetProcAddress(mod, apiname);
if(addr) //found exported function
addr = modbase + (addr - (duint)mod); //correct for loaded base
else //not found
@ -1379,7 +1379,7 @@ bool valapifromstring(const char* name, duint* value, int* value_size, bool prin
{
if(noexports) //get the exported functions with the '?' delimiter
{
addr = (duint)GetProcAddress(mod, apiname);
addr = SafeGetProcAddress(mod, apiname);
if(addr) //found exported function
addr = modbase + (addr - (duint)mod); //correct for loaded base
}
@ -1391,7 +1391,7 @@ bool valapifromstring(const char* name, duint* value, int* value_size, bool prin
radix = 10, apiname++;
if(convertNumber(apiname, ordinal, radix) && ordinal <= 0xFFFF)
{
addr = duint(GetProcAddress(mod, LPCSTR(ordinal)));
addr = SafeGetProcAddress(mod, LPCSTR(ordinal));
if(addr) //found exported function
addr = modbase + (addr - (duint)mod); //correct for loaded base
else if(!ordinal) //support for getting the image base using <modname>:0
@ -1436,7 +1436,7 @@ bool valapifromstring(const char* name, duint* value, int* value_size, bool prin
HMODULE hModule = LoadLibraryExW(szModuleName, 0, DONT_RESOLVE_DLL_REFERENCES);
if(hModule)
{
ULONG_PTR funcAddress = (ULONG_PTR)SafeGetProcAddress(hModule, name);
duint funcAddress = SafeGetProcAddress(hModule, name);
if(funcAddress)
{
if(!_wcsicmp(szBaseName, L"kernel32.dll"))

View File

@ -6,6 +6,7 @@
//functions
bool valuesignedcalc();
void valuesetsignedcalc(bool a);
duint SafeGetProcAddress(HMODULE hModule, const char* lpProcName);
bool valapifromstring(const char* name, duint* value, int* value_size, bool printall, bool silent, bool* hexonly);
bool convertNumber(const char* str, duint & result, int radix);
bool convertLongLongNumber(const char* str, unsigned long long & result, int radix);