11# MemoryModule
22A tool to parse and load module in memory, as well as attach a DLL in EXE.
3-
43Most of the functions are inline, so that it can also be used in shellcode.
54
65## compile
@@ -33,7 +32,7 @@ winpe_memFreeLibrary(memdll);
3332
3433// memory loadlibrary at specific address
3534size_t targetaddr = sizeof(size_t) > 4 ? 0x140030000: 0x90000;
36- memdll = winpe_memLoadLibraryEx(memdll , targetaddr,
35+ memdll = winpe_memLoadLibraryEx(mempe , targetaddr,
3736 WINPE_LDFLAG_MEMALLOC, (PFN_LoadLibraryA)winpe_findloadlibrarya(),
3837 (PFN_GetProcAddress)winpe_memGetProcAddress);
3938winpe_memFreeLibrary(memdll);
@@ -58,7 +57,6 @@ These functions are essential to load memory module in windows.
5857 will load the mempe in a valid imagebase
5958 return hmodule base
6059*/
61- WINPEDEF WINPE_EXPORT
6260inline void * STDCALL winpe_memLoadLibrary (void * mempe);
6361
6462/*
@@ -69,7 +67,6 @@ inline void* STDCALL winpe_memLoadLibrary(void *mempe);
6967 must combined with WINPE_LDFLAG_MEMALLOC
7068 return hmodule base
7169* /
72- WINPEDEF WINPE_EXPORT
7370inline void* STDCALL winpe_memLoadLibraryEx(void * mempe,
7471 size_t imagebase, DWORD flag,
7572 PFN_LoadLibraryA pfnLoadLibraryA,
@@ -79,14 +76,12 @@ inline void* STDCALL winpe_memLoadLibraryEx(void *mempe,
7976 similar to FreeLibrary, will call dllentry
8077 return true or false
8178* /
82- WINPEDEF WINPE_EXPORT
8379inline BOOL STDCALL winpe_memFreeLibrary(void * mempe);
8480
8581/*
8682 FreeLibraryEx with VirtualFree custom function
8783 return true or false
8884* /
89- WINPEDEF WINPE_EXPORT
9085inline BOOL STDCALL winpe_memFreeLibraryEx(void * mempe,
9186 PFN_LoadLibraryA pfnLoadLibraryA,
9287 PFN_GetProcAddress pfnGetProcAddress);
@@ -95,7 +90,6 @@ inline BOOL STDCALL winpe_memFreeLibraryEx(void *mempe,
9590 similar to GetProcAddress
9691 return function va
9792* /
98- WINPEDEF WINPE_EXPORT
9993inline PROC STDCALL winpe_memGetProcAddress(
10094 void * mempe, const char * funcname);
10195
@@ -104,21 +98,21 @@ inline PROC STDCALL winpe_memGetProcAddress(
10498 load the origin rawpe in memory buffer by mem align
10599 return memsize
106100* /
107- size_t winpe_memload(const void * rawpe, size_t rawsize,
101+ inline size_t winpe_memload(const void * rawpe, size_t rawsize,
108102 void * mempe, size_t memsize, bool_t same_align);
109103
110104
111105/*
112106 realoc the addrs for the mempe addr as image base
113107 return realoc count
114108* /
115- size_t winpe_memreloc(void * mempe, size_t newimagebase);
109+ inline size_t winpe_memreloc(void * mempe, size_t newimagebase);
116110
117111/*
118112 load the iat for the mempe
119113 return iat count
120114* /
121- size_t winpe_membindiat(void * mempe,
115+ inline size_t winpe_membindiat(void * mempe,
122116 PFN_LoadLibraryA pfnLoadLibraryA,
123117 PFN_GetProcAddress pfnGetProcAddress);
124118```
@@ -127,6 +121,6 @@ See `winpe.h` for parsing and loading PE structure in detail.
127121
128122## known issues
129123
130- * attach x64 DLL to exe crash on calling some windows API
131-
132- (load x64 DLL in memory after main function doesn't have this problem)
124+ * ~~ attach x64 DLL to exe crash on calling some windows API~~
125+ problem occured by `movaps xmm0, xmmword ptr ss:[rsp]`
126+ fixed by stack memory align with 0x10
0 commit comments