我正在尝试从另一个程序中检索文本。我使用Ollydbg来查找需要挂钩以获取信息的函数的地址。我使用EasyHook注入下面的代码。
钩子工作正常,直到我调用原始函数。每次我这样做时它都会崩溃。我认为这可能与函数的返回类型有关。由于我不熟悉倒车,因此无法确定正确的返回类型。我尝试了几种不同的返回类型,从 void 到 int。函数返回后,EAX
指向一个 unicode 字符串,但未使用该值。从我读到的,EAX
是返回的变量将被存储的地方。
更新:
我现在看到这个异常正在发生。
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at ServerDLL.Injector.DoSomeThingDelegate.Invoke(Int32 argument1, Int32 argument2)
at ServerDLL.Injector.DoSomeThing(Int32 argument1, Int32 argument2)
调用函数:
Address Hex dump Command Comments
00425373 |. 894424 04 MOV DWORD PTR SS:[ESP+4],EAX ; /Arg2
00425377 |. 8B45 A8 MOV EAX,DWORD PTR SS:[EBP-58] ; |
0042537A |. 890424 MOV DWORD PTR SS:[ESP],EAX ; |Arg1
0042537D |. E8 8EC3FFFF CALL DoSomething;
00425382 |. 8B4D 8C MOV ECX,DWORD PTR SS:[EBP-74]
00425385 |. 8B45 A8 MOV EAX,DWORD PTR SS:[EBP-58]
static string DoSomeThing(int argument1, int argument2)
{
Log.WriteLine(argument1);
Log.WriteLine(argument2);
DoSomeThingDelegate del = Marshal.GetDelegateForFunctionPointer(new IntPtr(0x421810), typeof(DoSomeThingDelegate)) as DoSomeThingDelegate;
if (del == null) return "";
return del(seatnumber, stack);
}
[UnmanagedFunctionPointer(CallingConvention.Cdecl, SetLastError = true, CharSet = CharSet.Auto)]
delegate string DoSomeThingDelegate(int argument1, int argument2);
public void Run(RemoteHooking.IContext InContext, String InArg1)
{
CreateRecvHook = LocalHook.Create(new IntPtr(0x421810), new DoSomeThingDelegate(DoSomeThing), this);
CreateRecvHook.ThreadACL.SetExclusiveACL(new Int32[] { 0 });
}