C# System.DllNotFoundException在Visual Studio 2010中使用EasyHook
我有以下代码:C# System.DllNotFoundException在Visual Studio 2010中使用EasyHook,c#,hook,easyhook,C#,Hook,Easyhook,我有以下代码: try { Debug.WriteLine("Hook Start"); RecvHook = LocalHook.Create( LocalHook.GetProcAddress("ws2_32.dll", "recv"), new Drecv(recv_Hooked), this);
try
{
Debug.WriteLine("Hook Start");
RecvHook = LocalHook.Create(
LocalHook.GetProcAddress("ws2_32.dll", "recv"),
new Drecv(recv_Hooked),
this);
RecvHook.ThreadACL.SetExclusiveACL(new Int32[] { 0 });
}
catch (Exception ExtInfo)
{
Debug.WriteLine("Error creating Hook");
}
...
[DllImport("ws2_32.dll")]
static extern int recv(
IntPtr socketHandle,
IntPtr buf,
int count,
int socketFlags
);
[UnmanagedFunctionPointer(CallingConvention.StdCall,
CharSet = CharSet.Unicode,
SetLastError = true)]
delegate int Drecv(
IntPtr socketHandle,
IntPtr buf,
int count,
int socketFlags
);
static int recv_Hooked(
IntPtr socketHandle,
IntPtr buf,
int count,
int socketFlags)
{
byte[] test = new byte[count];
Marshal.Copy(buf, test, 0, count);
IntPtr ptr = IntPtr.Zero;
ptr = Marshal.AllocHGlobal(count);
Marshal.Copy(test, 0, ptr, count);
string s = System.Text.UnicodeEncoding.Unicode.GetString(test);
Debug.WriteLine(s);
System.IO.StreamWriter file = new System.IO.StreamWriter("log.txt");
file.WriteLine(s);
file.Close();
return recv(socketHandle, buf, count, socketFlags);
}
当我运行项目时,出现以下错误:
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in System.Windows.Forms.dll
Inizio Hook
A first chance exception of type 'System.DllNotFoundException' occurred in EasyHook.dll
A first chance exception of type 'System.DllNotFoundException' occurred in EasyHook.dll
Error creating Hook
关于可能导致该错误的原因有何建议?我添加了对所需的所有dll的引用…最有可能的是::尝试以管理员身份运行VS 2010。实际上,我创建了VS开始菜单快捷方式“以管理员身份运行”,所以我不必记住 或者:Inject方法的EasyHook文档提到:“如果您将库注入任何目标进程,请记住您的工作目录将被切换。EasyHook将自动添加注入应用程序的目录作为目标PATH环境变量的第一个目录。因此,请确保所有必需的依赖项都位于注入应用程序的目录、系统目录或PATH变量中默认包含的任何目录中“ 万不得已的最后手段:有些错误至少是半良性的,因此您可以进入VS菜单“调试-->异常…”并取消选中有问题的错误,除非它不会在那里中断。我曾经有过一两个案例,在我告诉VS不要在该错误上中断时,代码实际上运行良好
顺便说一句:您包括了哪些二进制文件,您的系统架构和操作系统是什么?我不能给您确切的解决方案,但您可能会遇到这些问题
- 是否要在project/bin文件夹中添加dll?如果是,请将该文件夹复制到System32,然后再次添加为对该文件夹的引用
- 或者尝试此操作,打开Visual studio命令提示符并运行此命令regsvr32 yourdllocation 然后现在将其添加为参考