| 69 | } |
| 70 | |
| 71 | void 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) |
| 100 | struct JmpImmediate { |
no outgoing calls
no test coverage detected