File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -239,7 +239,7 @@ NTSTATUS MemoryLoadLibrary(
239239 LPVOID (old_header->OptionalHeader .ImageBase ),
240240 old_header->OptionalHeader .SizeOfImage ,
241241 MEM_RESERVE,
242- PAGE_READWRITE
242+ PAGE_EXECUTE_READWRITE
243243 );
244244 if (!base) {
245245 if (old_header->OptionalHeader .DllCharacteristics & IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE) {
Original file line number Diff line number Diff line change @@ -347,7 +347,11 @@ VOID NTAPI HookLdrShutdownThread(VOID) {
347347 entry = entry->Flink ;
348348 }
349349
350- --MmpGlobalDataPtr->MmpTls ->MmpActiveThreadCount ;
350+ if (record) {
351+ --MmpGlobalDataPtr->MmpTls ->MmpActiveThreadCount ;
352+ }
353+
354+ assert (0 < (int )MmpGlobalDataPtr->MmpTls ->MmpActiveThreadCount );
351355
352356 LeaveCriticalSection (&MmpGlobalDataPtr->MmpTls ->MmpTlspLock );
353357
@@ -371,7 +375,7 @@ VOID NTAPI HookLdrShutdownThread(VOID) {
371375 }
372376 else {
373377 if (MmpGlobalDataPtr->MmpTls ->MmpTlsList .Flink != &MmpGlobalDataPtr->MmpTls ->MmpTlsList ) {
374- assert (false );
378+ assert (NtCurrentTeb ()-> ThreadLocalStoragePointer == nullptr );
375379 }
376380 }
377381
Original file line number Diff line number Diff line change @@ -146,3 +146,45 @@ int thread() {
146146 return -1 ;
147147}
148148
149+ DWORD Value;
150+ volatile LPDWORD lpAddr;
151+
152+ LONG WINAPI Filter (_In_ struct _EXCEPTION_POINTERS * ExceptionInfo) {
153+
154+ if (ExceptionInfo->ExceptionRecord ->ExceptionCode == STATUS_ACCESS_VIOLATION) {
155+
156+ lpAddr = &Value;
157+
158+ // +++++++
159+ // begin compiler specific
160+ // +++++++
161+
162+ // ExceptionInfo->ContextRecord->Rip -= 7;
163+ ExceptionInfo->ContextRecord ->Rax = (ULONG_PTR)lpAddr;
164+
165+ // +++++++
166+ // end compiler specific
167+ // +++++++
168+
169+ return EXCEPTION_CONTINUE_EXECUTION;
170+ }
171+
172+ return EXCEPTION_CONTINUE_SEARCH;
173+ }
174+
175+ int unhandled_exception () {
176+ auto filter = SetUnhandledExceptionFilter (Filter);
177+ auto ff = SetUnhandledExceptionFilter (filter);
178+
179+ if (ff != Filter) {
180+ printf (" %p\t %p\t %p\n failed\n " , filter, ff, Filter);
181+ return 0 ;
182+ }
183+
184+ filter = SetUnhandledExceptionFilter (Filter);
185+ lpAddr = nullptr ;
186+ *lpAddr = 1 ;
187+ SetUnhandledExceptionFilter (filter);
188+
189+ return 1234 ;
190+ }
Original file line number Diff line number Diff line change @@ -4,4 +4,5 @@ test = __test__
44thread
55Socket = ws2_32.WSASocketW
66VerifyTruse = wintrust.WinVerifyTrust
7- test_user32
7+ test_user32
8+ unhandled_exception
Original file line number Diff line number Diff line change 11#include " ../MemoryModule/stdafx.h"
2+ #include " ../MemoryModule/LoadDllMemoryApi.h"
23#include < cstdio>
34
45static PVOID ReadDllFile (LPCSTR FileName) {
@@ -115,10 +116,22 @@ int test() {
115116 return 0 ;
116117}
117118
118- int main () {
119- DisplayStatus ();
119+ void test_uef () {
120+ auto buffer = ReadDllFile (" a.dll" );
121+
122+ HMODULE hm = LoadLibraryMemory (buffer);
123+ auto pfn = GetProcAddress (hm, " unhandled_exception" );
124+
125+ auto result = pfn ();
126+ if (result == 1234 ) {
127+ printf (" mmpp success\n " );
128+ }
120129
121- test ();
130+ return ;
131+ }
132+
133+ int main () {
134+ test_uef ();
122135
123136 return 0 ;
124137}
You can’t perform that action at this time.
0 commit comments