S
sy0116
Unregistered / Unconfirmed
GUEST, unregistred user!
我用以下代码HOOK CreateProcessA函数,但是发现HOOK过后我也不能用CreateProcess了,请问如何才能正确恢复原函数的入口<br><br>unit APIhook;<br><br>interface<br>uses<br> Windows;<br><br>type<br> MyCreateProcessA=function(lpApplicationName: PChar; lpCommandLine: PChar;<br> lpProcessAttributes, lpThreadAttributes: PSecurityAttributes;<br> bInheritHandles: BOOL; dwCreationFlags: DWORD; lpEnvironment: Pointer;<br> lpCurrentDirectory: PChar; const lpStartupInfo: TStartupInfo;<br> var lpProcessInformation: TProcessInformation): BOOL; stdcall;<br><br> TJump=packed record<br> MovEAX:Byte;<br> Addr:MyCreateProcessA;<br> JmpEAX:Word;<br> resvered:Byte;<br> end;<br><br>var<br> OldJmp:TJump;<br> hDll:THandle;<br> pOldCreateProcessointer;<br> OriCreateProcess:MyCreateProcessA;<br> crd:Cardinal;<br>procedure HookCreateProcess;<br><br>implementation<br><br>function SyCreateProcessA(lpApplicationName: PChar; lpCommandLine: PChar;<br> lpProcessAttributes, lpThreadAttributes: PSecurityAttributes;<br> bInheritHandles: BOOL; dwCreationFlags: DWORD; lpEnvironment: Pointer;<br> lpCurrentDirectory: PChar; const lpStartupInfo: TStartupInfo;<br> var lpProcessInformation: TProcessInformation): BOOL; stdcall;<br>begin<br> SetWindowText(FindWindow('tform1','form1'),lpCommandLine);<br> WriteProcessMemory(GetCurrentProcess,pOldCreateProcess,@OldJmp,8,crd);//回复原函数前八个字节,但没成功<br> Result:=CreateProcess(lpApplicationName,lpCommandLine,lpProcessAttributes,lpThreadAttributes,<br> bInheritHandles,dwCreationFlags,lpEnvironment,lpCurrentDirectory,<br> lpStartupInfo,lpProcessInformation);<br>end;<br>procedure HookCreateProcess;<br>var<br> DrComJmp:TJump;<br>begin<br> DrComJmp.MovEAX:=$B8;<br> DrComJmp.JmpEAX:=$E0FF;<br> DrComJmp.Addr:=@SyCreateProcessA;<br> hDll:=GetModuleHandle(kernel32);<br> pOldCreateProcess:=GetProcAddress(hDll,'CreateProcessA');<br> @OriCreateProcess:=pOldCreateProcess;<br> ReadProcessMemory(GetCurrentProcess,pOldCreateProcess,@OldJmp,8,crd);//在此处记下原函数的入口前八个字节<br> WriteProcessMemory(GetCurrentProcess,pOldCreateProcess,@DrComJmp,8,crd);<br>end;<br>end.