2 k345bu k345bu 于 2015.07.24 14:11 提问

HOOK WebBrowser获取打开的网址 request response header等.

以下代码使用了EsayHook

想先获取到打开的网址. 无奈断点断不到..是否HOOK的函数错了?

 using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using EasyHook;


namespace TestHookAPI
{
    public partial class Form1 : Form
    {
        LocalHook hookt = null;
        [DllImport("WININET.dll", SetLastError = true, CharSet = CharSet.Unicode)]
        public static extern IntPtr InternetOpenUrlW(
                                IntPtr hInternet,
                                string lpszUrl,
                                string lpszHeaders,
                                Int32 dwHeadersLength,
                                Int32 dwFlags,
                                System.UIntPtr dwContext
                                );

        [UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = true)]
        public delegate IntPtr d_InternetOpenUrl(
                                        IntPtr hInternet,
                                        string lpszUrl,
                                        string lpszHeaders,
                                        Int32 dwHeadersLength,
                                        Int32 dwFlags,
                                        System.UIntPtr dwContext
                                        );
        public static IntPtr h_InternetOpenUrl(
                                        IntPtr hInternet,
                                        string lpszUrl,
                                        string lpszHeaders,
                                        Int32 dwHeadersLength,
                                        Int32 dwFlags,
                                        System.UIntPtr dwContext
                                        )
        {
            IntPtr pret = InternetOpenUrlW(hInternet, lpszUrl, lpszHeaders, dwHeadersLength, dwFlags, dwContext);
            return pret;
        }

        public Form1()
        {
            InitializeComponent();

        }
        private void Form1_Load(object sender, EventArgs e)
        {
            hookt = LocalHook.Create(LocalHook.GetProcAddress("WININET.dll", "InternetOpenUrlW"), new d_InternetOpenUrl(h_InternetOpenUrl), this);
            hookt.ThreadACL.SetExclusiveACL(new Int32[0]);
            webBrowser1.Navigate("http://www.baidu.com/");
        }

        private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {

        }
    }
}

Csdn user default icon
上传中...
上传图片
插入图片