type<br> TCode5=packed record<br> siJmp:Byte;<br> dwAddr
WORD;<br> end;<br><br> TThunkCode=packed record<br> codeBak:TCode5;<br> codeThunk:TCode5;<br> addr_Sys
ointer;<br> addr_Thunk
ointer;<br> end;<br><br>type<br> TMessageBoxA=function(hWnd: HWND; lpText, lpCaption: PAnsiChar; uType: UINT): Integer; stdcall;<br><br>var<br> ThunkCode:TThunkCode;<br> hProcess:THandle;<br><br>function MyMessageBoxA(hWnd: HWND; lpText, lpCaption: PAnsiChar; uType: UINT): Integer; stdcall;<br>var<br> dwByetsWrite
WORD;<br>begin<br> ShowMessage('testing...');<br> WriteProcessMemory(hProcess,<br> ThunkCode.addr_Sys,<br> @ThunkCode.codeBak,<br> 5,<br> dwByetsWrite);<br> TMessageBoxA(ThunkCode.addr_Sys)(hwnd,lpText,lpCaption,uType);<br> WriteProcessMemory(hProcess,<br> ThunkCode.addr_Sys,<br> @ThunkCode.codeThunk,<br> 5,<br> dwByetsWrite);<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>const<br> szDllName='user32.dll';<br> szProcName='MessageBoxA';<br>var<br> hMod:HMODULE;<br> P:TMessageBoxA;<br> dwBytesRead
WORD;<br>begin<br> hMod:=GetModuleHandle(szDllName);<br> ThunkCode.addr_Sys:=Pointer(GetProcAddress(hMod,szProcName));<br> ThunkCode.addr_Thunk:=@MyMessageBoxA;<br> ThunkCode.codeThunk.siJmp:=Byte($E9);<br> ThunkCode.codeThunk.dwAddr:=DWORD(ThunkCode.addr_Thunk)-DWORD(ThunkCode.addr_Sys)-5;<br> ThunkCode.codeBak.siJmp:=PByte(ThunkCode.addr_Sys)^;<br> ThunkCode.codeBak.dwAddr:=PDWORD(DWORD(ThunkCode.addr_Sys)+1)^;<br> hProcess:=GetCurrentProcess;<br> WriteProcessMemory(hProcess,<br> ThunkCode.addr_Sys,<br> @ThunkCode.codeThunk,<br> 5,<br> dwBytesRead);<br>end;<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br> MyMessageBoxA(0,nil,nil,0);<br>end;