program hook;<br><br>uses<br> windows;<br><br>var<br>oldbytes : array [1..8] of byte;<br>newbytes : array [1..8] of byte;<br>process : cardinal;<br><br>function messageboxWhookproc(hWnd: HWND; lpText, lpCaption: PWideChar; uType: UINT): Integer; stdcall;<br>var<br>process: Cardinal;<br>nAUx: Cardinal;<br>begin<br>process := OpenProcess( PROCESS_ALL_ACCESS, True, GetCurrentProcessId );<br>lpText := 'Hahahaha Got hooked!!!';<br>WriteProcessMemory(process, GetProcAddress( GetModuleHandle( 'user32.dll' ), 'MessageBoxW' ) , @oldBytes, 8, nAux );<br>Result := MessageBoxW( hWnd, lpText, lpCaption, uType );<br>WriteProcessMemory(process, GetProcAddress( GetModuleHandle( 'user32.dll' ), 'MessageBoxW' ) , @newbytes, 8, nAux );<br>closehandle(process);<br>end;<br><br>procedure hookit;<br>type<br>TJumpCode = packed record<br>jmp: Byte; // mov eax,<br>addresse: cardinal; // address<br>jmp2, jmp3: byte; // call eax<br>end;<br>var<br>process:Cardinal;<br>location:Cardinal;<br>JmpCode:TJumpCode;<br>nAux
Word;<br>begin<br>process:=OpenProcess( PROCESS_ALL_ACCESS,True, GetCurrentProcessId);<br>location:=Cardinal(GetProcAddress(GetModuleHandle('user32.dll'),'MessageBoxW'));<br>ReadProcessMemory( process, Pointer( location ), @oldbytes, 8, nAux );<br>JmpCode.jmp := $B8; // MOV EAX,<br>JmpCode.addresse := Cardinal( @messageboxWhookproc);<br>JmpCode.jmp2 := $FF;<br>JmpCode.jmp3 := $e0;<br>WriteProcessMemory(process, Pointer( location ), @jmpcode, SizeOf( TJumpCode ), nAux );<br>closehandle(process);<br>end;<br><br><br><br>procedure unhookit;<br>var<br>process: Cardinal;<br>nAux: Cardinal;<br>begin<br>process := OpenProcess( PROCESS_ALL_ACCESS, True, GetCurrentProcessId );<br>WriteProcessMemory(process, GetProcAddress( GetModuleHandle( 'user32.dll' ), 'MessageBoxW' ) , @oldbytes, 8, nAux );<br>closehandle(process);<br>end;<br><br>begin<br>process:=OpenProcess( PROCESS_ALL_ACCESS, True, GetCurrentProcessId );<br>MessageBoxW(0,'i will be hooked very soonner','hook',mb_ok);<br>hookit;<br>MessageBoxW(0,'i will be faked','lol',mb_ok);<br>unhookit;<br>closehandle(process);<br>end.