diff --git a/MemoryModule.c b/MemoryModule.c index 9f95a70..327a7ba 100644 --- a/MemoryModule.c +++ b/MemoryModule.c @@ -62,43 +62,6 @@ #include "MemoryModule.h" -struct ExportNameEntry { - LPCSTR name; - WORD idx; -}; - -typedef BOOL (WINAPI *DllEntryProc)(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved); -typedef int (WINAPI *ExeEntryProc)(void); - -#ifdef _WIN64 -typedef struct POINTER_LIST { - struct POINTER_LIST *next; - void *address; -} POINTER_LIST; -#endif - -typedef struct { - PIMAGE_NT_HEADERS headers; - unsigned char *codeBase; - HCUSTOMMODULE *modules; - int numModules; - BOOL initialized; - BOOL isDLL; - BOOL isRelocated; - CustomAllocFunc alloc; - CustomFreeFunc free; - CustomLoadLibraryFunc loadLibrary; - CustomGetProcAddressFunc getProcAddress; - CustomFreeLibraryFunc freeLibrary; - struct ExportNameEntry *nameExportsTable; - void *userdata; - ExeEntryProc exeEntry; - DWORD pageSize; -#ifdef _WIN64 - POINTER_LIST *blockedMemory; -#endif -} MEMORYMODULE, *PMEMORYMODULE; - typedef struct { LPVOID address; LPVOID alignedAddress; @@ -435,6 +398,13 @@ PerformBaseRelocation(PMEMORYMODULE module, ptrdiff_t delta) return TRUE; } +static char memoryModuleMissingDependency[256]; + +const char *MemoryModuleMissingDependency() +{ + return memoryModuleMissingDependency; +} + static BOOL BuildImportTable(PMEMORYMODULE module) { @@ -456,6 +426,7 @@ BuildImportTable(PMEMORYMODULE module) if (handle == NULL) { SetLastError(ERROR_MOD_NOT_FOUND); result = FALSE; + strncpy(memoryModuleMissingDependency, (LPCSTR) (codeBase + importDesc->Name), sizeof(memoryModuleMissingDependency)); break; } diff --git a/MemoryModule.h b/MemoryModule.h index a728f6b..8be150c 100644 --- a/MemoryModule.h +++ b/MemoryModule.h @@ -35,6 +35,7 @@ typedef void *HMEMORYRSRC; typedef void *HCUSTOMMODULE; + #ifdef __cplusplus extern "C" { #endif @@ -45,6 +46,44 @@ typedef HCUSTOMMODULE (*CustomLoadLibraryFunc)(LPCSTR, void *); typedef FARPROC (*CustomGetProcAddressFunc)(HCUSTOMMODULE, LPCSTR, void *); typedef void (*CustomFreeLibraryFunc)(HCUSTOMMODULE, void *); +struct ExportNameEntry { + LPCSTR name; + WORD idx; +}; + +typedef BOOL (WINAPI *DllEntryProc)(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved); +typedef int (WINAPI *ExeEntryProc)(void); + +#ifdef _WIN64 +typedef struct POINTER_LIST { + struct POINTER_LIST *next; + void *address; +} POINTER_LIST; +#endif + + +typedef struct { + PIMAGE_NT_HEADERS headers; + unsigned char *codeBase; + HCUSTOMMODULE *modules; + int numModules; + BOOL initialized; + BOOL isDLL; + BOOL isRelocated; + CustomAllocFunc alloc; + CustomFreeFunc free; + CustomLoadLibraryFunc loadLibrary; + CustomGetProcAddressFunc getProcAddress; + CustomFreeLibraryFunc freeLibrary; + struct ExportNameEntry *nameExportsTable; + void *userdata; + ExeEntryProc exeEntry; + DWORD pageSize; +#ifdef _WIN64 + POINTER_LIST *blockedMemory; +#endif +} MEMORYMODULE, *PMEMORYMODULE; + /** * Load EXE/DLL from memory location with the given size. * @@ -161,6 +200,8 @@ FARPROC MemoryDefaultGetProcAddress(HCUSTOMMODULE, LPCSTR, void *); */ void MemoryDefaultFreeLibrary(HCUSTOMMODULE, void *); +const char *MemoryModuleMissingDependency(); + #ifdef __cplusplus } #endif