C # Cross-origin browser (unrestricted). ie,
How can I operate ie browsers across domains? Http: // blog already exists in my previous post
.Csdn.net/u012395622/article/details/46426043 but it is not very good
Because you cannot operate programs that are not Internet Explorer but are based on the IE Kernel
You can clearly see a simple hypertext browser box written in "easy language"
The software is running, but it jumps to my blog.
You know, you are going to browse Baidu's home page.
You will see the code jump to my
Blog, you can understand it as browser hijacking.
First, you need to prepare a "window Spy ++" tool. You can use the built-in "Visual Studio" tool.
Spy ++ tool, you first need to find a "IE kernel-based" browser software, get
But remember that the class name in the window must be "Internet assumer_server ".
And then provide its window handle to the GetHtmlDocumentByHandle function.
Reference this post: http://blog.csdn.net/u012395622/article/details/46503661
After obtaining webDomDoc, call CorssDomain. GetWebBrowserByHtml
The Document function obtains the browser operation pointer (IWebBrowser2) and then
You can think about how to have fun and how to have fun.
The event interface is used to listen to browser POST requests or directly interfere with users' browser jumps.
Sample Code 1:
object webDomDoc = GetHtmlDocumentByHandle((IntPtr)4784608); CorssDomain.IWebBrowser2 webObject = CorssDomain.GetWebBrowserByHtmlDocument(webDomDoc); webObject.Silent = true; object unknown = null; webObject.Navigate("http://blog.csdn.net/u012395622", ref unknown, ref unknown, ref unknown, ref unknown);
Sample Code 2:
CorssDomain.IWebBrowser2 webObject = CorssDomain.GetWebBrowserByHtmlDocument(webBrowser1.Document.DomDocument); webObject.Silent = true; object unknown = null; webObject.Navigate("http://blog.csdn.net/u012395622", ref unknown, ref unknown, ref unknown, ref unknown);
CorssDomain:
using System;using System.Reflection;using System.Runtime.InteropServices;namespace CorssDomain{ public partial class CorssDomain { [ComImport, Guid("6D5140C1-7436-11CE-8034-00AA006009FA"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] public interface IServiceProvider { [return: MarshalAs(UnmanagedType.I4)] [PreserveSig] int QueryService(ref Guid guidService, ref Guid riid, [MarshalAs(UnmanagedType.Interface)] out object ppvObject); } [ComImport, Guid("D30C1661-CDAF-11d0-8A3E-00C04FC9E26E"), TypeLibType(TypeLibTypeFlags.FOleAutomation | TypeLibTypeFlags.FDual | TypeLibTypeFlags.FHidden)] public interface IWebBrowser2 { [DispId(100)] void GoBack(); [DispId(0x65)] void GoForward(); [DispId(0x66)] void GoHome(); [DispId(0x67)] void GoSearch(); [DispId(0x68)] void Navigate([In] string Url, [In] ref object flags, [In] ref object targetFrameName, [In] ref object postData, [In] ref object headers); [DispId(-550)] void Refresh(); [DispId(0x69)] void Refresh2([In] ref object level); [DispId(0x6a)] void Stop(); [DispId(200)] object Application {[return: MarshalAs(UnmanagedType.IDispatch)] get; } [DispId(0xc9)] object Parent {[return: MarshalAs(UnmanagedType.IDispatch)] get; } [DispId(0xca)] object Container {[return: MarshalAs(UnmanagedType.IDispatch)] get; } [DispId(0xcb)] object Document {[return: MarshalAs(UnmanagedType.IDispatch)] get; } [DispId(0xcc)] bool TopLevelContainer { get; } [DispId(0xcd)] string Type { get; } [DispId(0xce)] int Left { get; set; } [DispId(0xcf)] int Top { get; set; } [DispId(0xd0)] int Width { get; set; } [DispId(0xd1)] int Height { get; set; } [DispId(210)] string LocationName { get; } [DispId(0xd3)] string LocationURL { get; } [DispId(0xd4)] bool Busy { get; } [DispId(300)] void Quit(); [DispId(0x12d)] void ClientToWindow(out int pcx, out int pcy); [DispId(0x12e)] void PutProperty([In] string property, [In] object vtValue); [DispId(0x12f)] object GetProperty([In] string property); [DispId(0)] string Name { get; } [DispId(-515)] int HWND { get; } [DispId(400)] string FullName { get; } [DispId(0x191)] string Path { get; } [DispId(0x192)] bool Visible { get; set; } [DispId(0x193)] bool StatusBar { get; set; } [DispId(0x194)] string StatusText { get; set; } [DispId(0x195)] int ToolBar { get; set; } [DispId(0x196)] bool MenuBar { get; set; } [DispId(0x197)] bool FullScreen { get; set; } [DispId(500)] void Navigate2([In] ref object URL, [In] ref object flags, [In] ref object targetFrameName, [In] ref object postData, [In] ref object headers); [DispId(0x1f5)] OLECMDF QueryStatusWB([In] OLECMDID cmdID); [DispId(0x1f6)] void ExecWB([In] OLECMDID cmdID, [In] OLECMDEXECOPT cmdexecopt, ref object pvaIn, IntPtr pvaOut); [DispId(0x1f7)] void ShowBrowserBar([In] ref object pvaClsid, [In] ref object pvarShow, [In] ref object pvarSize); [DispId(-525)] int ReadyState { get; } [DispId(550)] bool Offline { get; set; } [DispId(0x227)] bool Silent { get; set; } [DispId(0x228)] bool RegisterAsBrowser { get; set; } [DispId(0x229)] bool RegisterAsDropTarget { get; set; } [DispId(0x22a)] bool TheaterMode { get; set; } [DispId(0x22b)] bool AddressBar { get; set; } [DispId(0x22c)] bool Resizable { get; set; } } public enum OLECMDF { OLECMDF_DEFHIDEONCTXTMENU = 0x20, OLECMDF_ENABLED = 2, OLECMDF_INVISIBLE = 0x10, OLECMDF_LATCHED = 4, OLECMDF_NINCHED = 8, OLECMDF_SUPPORTED = 1 } public enum OLECMDID { OLECMDID_PAGESETUP = 8, OLECMDID_PRINT = 6, OLECMDID_PRINTPREVIEW = 7, OLECMDID_PROPERTIES = 10, OLECMDID_SAVEAS = 4 } public enum OLECMDEXECOPT { OLECMDEXECOPT_DODEFAULT, OLECMDEXECOPT_PROMPTUSER, OLECMDEXECOPT_DONTPROMPTUSER, OLECMDEXECOPT_SHOWHELP } public static Guid IID_IWebBrowser2 = new Guid("D30C1661-CDAF-11D0-8A3E-00C04FC9E26E"); public static Guid IID_IWebBrowserApp = new Guid("0002DF05-0000-0000-C000-000000000046"); public const int S_OK = 0; public static IWebBrowser2 GetWebBrowserByHtmlDocument(object ppvObject) { object webObject = null; if (ppvObject != null && Marshal.IsComObject(ppvObject)) { IServiceProvider sp; //ppvObject = ppvObject.GetType(). // InvokeMember("parentWindow", BindingFlags.GetProperty, null, ppvObject, null); if ((sp = ppvObject as IServiceProvider) != null) { if (sp.QueryService(ref IID_IWebBrowserApp, ref IID_IWebBrowser2, out webObject) != S_OK) throw new ArgumentException(); } } return webObject as IWebBrowser2; } }}
[DllImport("user32.dll", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool GetClassName( [In]IntPtr hWnd, [MarshalAs(UnmanagedType.VBByRefStr)]ref string IpClassName, [In]int nMaxCount ); [DllImport("oleacc.dll", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool ObjectFromLresult( [In]int lResult, [In]ref Guid riid, [In]int wParam, [Out, MarshalAs(UnmanagedType.IUnknown)]out object ppvObject ); [DllImport("user32.dll", SetLastError = true)] [return: MarshalAs(UnmanagedType.I4)] public static extern int RegisterWindowMessage( [In]string lpString ); [DllImport("user32.dll", EntryPoint = "SendMessageTimeoutA", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool SendMessageTimeout( [In]IntPtr MSG, [In]int hWnd, [In]int wParam, [In]int lParam, [In]int fuFlags, [In]int uTimeout, [In, Out]ref int lpdwResult ); public static object GetComObjectByHandle(int Msg, Guid riid, IntPtr hWnd) { object _ComObject; int lpdwResult = 0; if (!SendMessageTimeout(hWnd, Msg, 0, 0, SMTO_ABORTIFHUNG, 1000, ref lpdwResult)) return null; if (ObjectFromLresult(lpdwResult, ref riid, 0, out _ComObject)) return null; return _ComObject; } public object GetHtmlDocumentByHandle(IntPtr hWnd) { string buffer = new string('\0', 24); GetClassName(hWnd, ref buffer, 25); if (buffer != "Internet Explorer_Server") return null; return GetComObjectByHandle(WM_HTML_GETOBJECT, IID_IHTMLDocument, hWnd); } public const int SMTO_ABORTIFHUNG = 2; public readonly static int WM_HTML_GETOBJECT = RegisterWindowMessage("WM_HTML_GETOBJECT"); public readonly static Guid IID_IHTMLDocument = new Guid("626fc520-a41e-11cf-a731-00a0c9082637");