Skip to content

Instantly share code, notes, and snippets.

@aaaddress1
Last active February 26, 2021 08:05
Show Gist options
  • Save aaaddress1/55d88fa73e78c95f169448b634cf0004 to your computer and use it in GitHub Desktop.
Save aaaddress1/55d88fa73e78c95f169448b634cf0004 to your computer and use it in GitHub Desktop.
dynPatchSelf.cc
// dynamic patch self function by [email protected]
#include <windows.h>
#include <algorithm>
#include <iterator>
using namespace std;
void hello()
{
puts("Are You Helloing?");
}
int main(void)
{
BYTE pattern[] = "\xCD\x03\xCD\x03\xCD\x03\xCD\x03";
PBYTE pFound = search((PBYTE)main, &((PBYTE)main)[0x200], pattern, &pattern[sizeof(pattern) - 1]);
VirtualProtect(pFound, 5, PAGE_EXECUTE_READWRITE, (PDWORD)&pattern);
pFound[0] = '\xE8';
*(PDWORD)&pFound[1] = (DWORD)hello - (DWORD)pFound - 5;
asm __volatile__(".byte 0xCD;.byte 0x03;.byte 0xCD;.byte 0x03;.byte 0xCD;.byte 0x03;.byte 0xCD;.byte 0x03;");
return 0;
}
@aaaddress1
Copy link
Author

截圖 2021-02-26 16 04 19

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment