MCPcopy Create free account
hub / github.com/BeneficialCode/WinArk / MapLockedCopyMemory

Function MapLockedCopyMemory

KernelLibrary/detours.cpp:71–97  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

69}
70
71void MapLockedCopyMemory(PUCHAR pDst, PVOID pSrc, ULONG length) {
72 UCHAR code[4] = { 0 };
73
74 PHYSICAL_ADDRESS physicalAddress = { 0 };
75 PVOID virtualAddress = nullptr;
76
77 if (length > sizeof(ULONG)) {
78 RtlCopyMemory(code, pSrc, sizeof(ULONG));
79 }
80 else {
81 RtlCopyMemory(code, pSrc, length);
82 RtlCopyMemory(code + length, pDst + length, sizeof(ULONG) - length);
83 }
84
85 physicalAddress = MmGetPhysicalAddress(pDst);
86 virtualAddress = MmMapIoSpace(physicalAddress, length, MmNonCached);
87 if (virtualAddress != nullptr) {
88 if (length > sizeof(ULONG)) {
89 InterlockedExchange(reinterpret_cast<LONG*>(virtualAddress), 0xfeebUI32);
90 RtlCopyMemory(reinterpret_cast<PCHAR>(virtualAddress) + sizeof(ULONG),
91 reinterpret_cast<PCHAR>(pSrc) + sizeof(ULONG),
92 length - sizeof(ULONG));
93 }
94 InterlockedExchange(reinterpret_cast<LONG*>(virtualAddress), *reinterpret_cast<PLONG>(code));
95 MmUnmapIoSpace(virtualAddress, length);
96 }
97}
98
99#pragma pack(push,1)
100struct JmpImmediate {

Callers 5

DetourGenJmpImmediateFunction · 0.85
DetourGenJmpIndirectFunction · 0.85
DetourGenBrkFunction · 0.85
DetourGenJmpAddressFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected