c# - EasyHook recv 不是 "hook"所有数据包

标签 c# easyhook

我设法编写了一个 Hook recv 函数的半工作 EasyHook 示例。我编写了一个表单,添加了一个 WebBrowser 组件,然后启动了应用程序。问题是,我得到了 HTTP 数据包,但如果有套接字,似乎 recv 停止“ Hook ”。 问题是,使用外部应用程序 Spystudio,我可以让它们挂接 recv。那么,我错过了什么?

using System;
using System.Collections.Generic;
using System.Data;
using System.Runtime.InteropServices;
using System.Threading;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels.Ipc;
using EasyHook;

namespace flashing
{
    public partial class Form1 : Form,EasyHook.IEntryPoint
    {
        public LocalHook CreateRecvHook;

        public Form1()
        {
            InitializeComponent();
        }

        [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)
        {
            int bytesCount = recv(socketHandle, buf, count, socketFlags);
            if (bytesCount > 0)
            {
                byte[] newBuffer = new byte[bytesCount];
                Marshal.Copy(buf, newBuffer, 0, bytesCount);
                string s = System.Text.ASCIIEncoding.ASCII.GetString(newBuffer);
                TextWriter tw = new StreamWriter("log.txt");
                tw.Write(s);
                tw.Close();
                Debug.WriteLine("Hooked:>" + s);
            }
            return bytesCount;
        }


        private void bottonHook_Click(object sender, EventArgs e)
        {
            try
            {
                CreateRecvHook = LocalHook.Create(
                    LocalHook.GetProcAddress("Ws2_32.dll", "recv"),
                    new Drecv(recv_Hooked),
                    this);

                CreateRecvHook.ThreadACL.SetExclusiveACL(new Int32[] { 0 });
            }
            catch (Exception ExtInfo)
            {
                Debug.WriteLine("Error creating the Hook");
                return;
            }
            RemoteHooking.WakeUpProcess();
        }

        private void buttonLoader_Click(object sender, EventArgs e)
        {
            axShockwaveFlash1.LoadMovie(0, "test.swf");
        }
    }    
}

编辑:我对 recv 毫无疑问,这是 apimonitor 告诉我的:

# TID Module API Return Error
5 2696 Flash10l.ocx recv ( 1992, 0x07080000, 65536, 0 ) 1

那么,有人可以帮助我吗?

最佳答案

问题已解决。造成麻烦的线路是

CreateRecvHook.ThreadACL.SetExclusiveACL(new Int32[] { 0 });

我改成了

CreateRecvHook.ThreadACL.SetInclusiveACL(new Int32[] { 0 });

现在一切正常。 谢谢大家:)

关于c# - EasyHook recv 不是 "hook"所有数据包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4589328/

相关文章:

c# - 在这种情况下,LINQ是最好的解决方案吗? LINQ到数据集

c# - Ajax 请求在 Safari 和 Ipad 上不会调用 Controller ,在 Iphone 上正常

c++ - 如何使用非托管 EasyHook 从进程中的任何线程 Hook 方法?

c# - EasyHook 给定的 32 位库不存在,用户库没有导出正确的运行

c# - C# 的 EasyHook 替代品

c# - 此 C# 的等效 XAML 行

c# - System.IO.Directory.Exists() 与 Windows 和 Linux 一起使用

c# - 使用 array.sort 对数组进行排序

c - EasyHook:在 native C 应用程序中从 32 位应用程序注入(inject) 64 位 dll?

c++ - 使用 C++ 和 EasyHook 注入(inject) x64 进程 Hook x86-DLL 的 x64-DLL 失败