Skip to content

Commit ac98426

Browse files
committed
Added a variable holding the missing DLL in case of missing dependency
1 parent 5f83e41 commit ac98426

File tree

2 files changed

+49
-37
lines changed

2 files changed

+49
-37
lines changed

MemoryModule.c

Lines changed: 8 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -62,43 +62,6 @@
6262

6363
#include "MemoryModule.h"
6464

65-
struct ExportNameEntry {
66-
LPCSTR name;
67-
WORD idx;
68-
};
69-
70-
typedef BOOL (WINAPI *DllEntryProc)(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved);
71-
typedef int (WINAPI *ExeEntryProc)(void);
72-
73-
#ifdef _WIN64
74-
typedef struct POINTER_LIST {
75-
struct POINTER_LIST *next;
76-
void *address;
77-
} POINTER_LIST;
78-
#endif
79-
80-
typedef struct {
81-
PIMAGE_NT_HEADERS headers;
82-
unsigned char *codeBase;
83-
HCUSTOMMODULE *modules;
84-
int numModules;
85-
BOOL initialized;
86-
BOOL isDLL;
87-
BOOL isRelocated;
88-
CustomAllocFunc alloc;
89-
CustomFreeFunc free;
90-
CustomLoadLibraryFunc loadLibrary;
91-
CustomGetProcAddressFunc getProcAddress;
92-
CustomFreeLibraryFunc freeLibrary;
93-
struct ExportNameEntry *nameExportsTable;
94-
void *userdata;
95-
ExeEntryProc exeEntry;
96-
DWORD pageSize;
97-
#ifdef _WIN64
98-
POINTER_LIST *blockedMemory;
99-
#endif
100-
} MEMORYMODULE, *PMEMORYMODULE;
101-
10265
typedef struct {
10366
LPVOID address;
10467
LPVOID alignedAddress;
@@ -435,6 +398,13 @@ PerformBaseRelocation(PMEMORYMODULE module, ptrdiff_t delta)
435398
return TRUE;
436399
}
437400

401+
static char memoryModuleMissingDependency[256];
402+
403+
const char *MemoryModuleMissingDependency()
404+
{
405+
return memoryModuleMissingDependency;
406+
}
407+
438408
static BOOL
439409
BuildImportTable(PMEMORYMODULE module)
440410
{
@@ -456,6 +426,7 @@ BuildImportTable(PMEMORYMODULE module)
456426
if (handle == NULL) {
457427
SetLastError(ERROR_MOD_NOT_FOUND);
458428
result = FALSE;
429+
strncpy(memoryModuleMissingDependency, (LPCSTR) (codeBase + importDesc->Name), sizeof(memoryModuleMissingDependency));
459430
break;
460431
}
461432

MemoryModule.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ typedef void *HMEMORYRSRC;
3535

3636
typedef void *HCUSTOMMODULE;
3737

38+
3839
#ifdef __cplusplus
3940
extern "C" {
4041
#endif
@@ -45,6 +46,44 @@ typedef HCUSTOMMODULE (*CustomLoadLibraryFunc)(LPCSTR, void *);
4546
typedef FARPROC (*CustomGetProcAddressFunc)(HCUSTOMMODULE, LPCSTR, void *);
4647
typedef void (*CustomFreeLibraryFunc)(HCUSTOMMODULE, void *);
4748

49+
struct ExportNameEntry {
50+
LPCSTR name;
51+
WORD idx;
52+
};
53+
54+
typedef BOOL (WINAPI *DllEntryProc)(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved);
55+
typedef int (WINAPI *ExeEntryProc)(void);
56+
57+
#ifdef _WIN64
58+
typedef struct POINTER_LIST {
59+
struct POINTER_LIST *next;
60+
void *address;
61+
} POINTER_LIST;
62+
#endif
63+
64+
65+
typedef struct {
66+
PIMAGE_NT_HEADERS headers;
67+
unsigned char *codeBase;
68+
HCUSTOMMODULE *modules;
69+
int numModules;
70+
BOOL initialized;
71+
BOOL isDLL;
72+
BOOL isRelocated;
73+
CustomAllocFunc alloc;
74+
CustomFreeFunc free;
75+
CustomLoadLibraryFunc loadLibrary;
76+
CustomGetProcAddressFunc getProcAddress;
77+
CustomFreeLibraryFunc freeLibrary;
78+
struct ExportNameEntry *nameExportsTable;
79+
void *userdata;
80+
ExeEntryProc exeEntry;
81+
DWORD pageSize;
82+
#ifdef _WIN64
83+
POINTER_LIST *blockedMemory;
84+
#endif
85+
} MEMORYMODULE, *PMEMORYMODULE;
86+
4887
/**
4988
* Load EXE/DLL from memory location with the given size.
5089
*
@@ -161,6 +200,8 @@ FARPROC MemoryDefaultGetProcAddress(HCUSTOMMODULE, LPCSTR, void *);
161200
*/
162201
void MemoryDefaultFreeLibrary(HCUSTOMMODULE, void *);
163202

203+
const char *MemoryModuleMissingDependency();
204+
164205
#ifdef __cplusplus
165206
}
166207
#endif

0 commit comments

Comments
 (0)