MCPcopy Create free account
hub / github.com/1401199262/MemoryVirtualization / VehExceptionHandler

Function VehExceptionHandler

HideMemory.cpp:18–66  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16}
17
18LONG NTAPI VehExceptionHandler(EXCEPTION_POINTERS* ExceptionInfo)
19{
20 DWORD OldProtect = 0;
21 if (ExceptionInfo->ExceptionRecord->ExceptionCode == EXCEPTION_ACCESS_VIOLATION)
22 {
23 for (auto it = PagesOfNoAccessOfData.begin(); it != PagesOfNoAccessOfData.end(); it++)
24 {
25 if (ExceptionInfo->ExceptionRecord->ExceptionInformation[1] <= (*it).lpAddress + (*it).dwSize &&
26 ExceptionInfo->ExceptionRecord->ExceptionInformation[1] >= (*it).lpAddress)
27 {
28 m.lock();
29 //Restore Page Protection and Decrypt
30 (*it).Protected = FALSE;//Not Protected
31 VirtualProtect((LPVOID)(*it).lpAddress, (*it).dwSize, PAGE_EXECUTE_READWRITE, &OldProtect);
32
33 if ((*it).Decrypt)
34 (*it).Decrypt((*it).lpAddress, (*it).dwSize);
35 else
36 EncryptData((*it).lpAddress, (*it).dwSize);//Decrypt
37
38 ExceptionInfo->ContextRecord->EFlags |= 0x100;//Do a single step
39 return EXCEPTION_CONTINUE_EXECUTION;
40
41 }
42 }
43
44 }
45
46 if (ExceptionInfo->ExceptionRecord->ExceptionCode == STATUS_SINGLE_STEP)
47 {
48 for (auto it = PagesOfNoAccessOfData.begin(); it != PagesOfNoAccessOfData.end(); it++)
49 {
50 if ((*it).Protected == FALSE)
51 {
52 if ((*it).Encrypt)
53 (*it).Encrypt((*it).lpAddress, (*it).dwSize);
54 else
55 EncryptData((*it).lpAddress, (*it).dwSize);//加密
56
57 VirtualProtect((LPVOID)(*it).lpAddress, (*it).dwSize, PAGE_NOACCESS, &OldProtect);
58 m.unlock();
59 return EXCEPTION_CONTINUE_EXECUTION;
60 }
61 }
62 }
63
64 return EXCEPTION_CONTINUE_SEARCH;
65
66}
67
68BOOL Init()
69{

Callers

nothing calls this directly

Calls 1

EncryptDataFunction · 0.85

Tested by

no test coverage detected