rendered paste body#include <cstdlib>#include <iostream>#include <windows.h>using namespace std;int NOPMem (void* aNOP,int szNOP){ if(aNOP==0||szNOP==0)return -1; char* p=(char*)aNOP; int i=szNOP; while (i>0){ *p=0x90; p = p+1; i--; } return 0;}int CopyMem (void* aSource,void* aDestination,int szMem){ if (aSource==0||aDestination==0||szMem==0)return -1; int i=szMem; char* p1=(char*)aSource; char* p2=(char*)aDestination; while (i>0){ *p2=*p1; i--; p2=p2+1; p1=p1+1; } return 0;}int SetJMP(void* aJMP,void* aTo){ if(aJMP==0||aTo==0)return -1; char* pcharf=(char*)aJMP; *pcharf=0xE9; unsigned long nextinstruction=(unsigned long)pcharf+5; unsigned long offset = (unsigned long)aTo-nextinstruction; unsigned long* poffset=(unsigned long*)aJMP+1; *poffset=offset; return 0;}int SetCALL(void* aCALL,void* aTo){ if(aCALL==0||aTo==0)return -1; char* pcharf=(char*)aCALL; *pcharf=0xE8; unsigned long nextinstruction=(unsigned long)pcharf+5; unsigned long offset = (unsigned long)aTo-nextinstruction; unsigned long* poffset=(unsigned long*)aCALL+1; *poffset=offset; return 0;}int HookFuncJMP(void* aFunc,void* aNewFunc,void* pOldBytes,int szOldBytes){ if(aFunc==0||aNewFunc==0||pOldBytes==0||szOldBytes<5)return -1; if(CopyMem(aFunc,pOldBytes,szOldBytes)==-1)return -1; if(SetJMP(aFunc,aNewFunc)==-1)return -1; int excess=szOldBytes-5;unsigned long taFunc=(unsigned long)aFunc+5; if (excess>0)if(NOPMem((void*)taFunc,excess)==-1)return -1; return 0; }int HookFuncCALL(void* aFunc,void* aNewFunc,void* pOldBytes,int szOldBytes){ if(aFunc==0||aNewFunc==0||pOldBytes==0||szOldBytes<5)return -1; if(CopyMem(aFunc,pOldBytes,szOldBytes)==-1)return -1; if(SetCALL(aFunc,aNewFunc)==-1)return -1; int excess=szOldBytes-5;unsigned long taFunc=(unsigned long)aFunc+5; if (excess>0)if(NOPMem((void*)taFunc,excess)==-1)return -1; return 0; }int main(int argc, char *argv[]){ char lolt[5]; DWORD oldp; HMODULE lol1 = GetModuleHandle("kernel32.dll"); FARPROC lol2= GetProcAddress(lol1,"WriteProcessMemory"); BOOL lol = VirtualProtect((PVOID)lol2,5,PAGE_EXECUTE_READWRITE,&oldp); int cook = HookFuncJMP((void*)lol2,(void*)&HookFuncCALL,&lolt,5); system("PAUSE"); return EXIT_SUCCESS;}