开发 Internet Explorer、浏览器辅助对象扩展?

2024-01-19

1)我正在尝试用 C# 创建一个简单的 BHO,就像这里已经回答的那样:https://stackoverflow.com/a/5740004/285594 https://stackoverflow.com/a/5740004/285594

2)但不幸的是,他们都尝试了少于IE11的尝试,有些成功了,有些也失败了

3)按照该答案中提到的所有内容后,我还购买了官方代码签名,但它根本无法在 IE11 Windows 7 64 位中工作。

您可以下载我准备好的 Visual studio 2013 版本:其中包括 IE11 的所有源代码和详细信息:

https://www.dropbox.com/s/60kg212vkjb7yud/ClassLibrary2.rar https://www.dropbox.com/s/60kg212vkjb7yud/ClassLibrary2.rar

问:任何人都可以请建议/建议/帮助我怎样才能使这个 BHO 成为一个 hello world?

我也尝试过 codeproject 中的其他示例,但我仍然无法完成工作,自 4 周以来一直在尝试,我迷失了,请告知我的 ClassLibrary2.rar 中有什么问题,它没有突出显示文本“浏览器” ?

我完全迷失了,请指教。

EDIT:

IEAddon.cs

using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using Microsoft.Win32;
using mshtml;
using SHDocVw;

namespace InternetExplorerExtension
{
  [ComVisible(true)]
  [ClassInterface(ClassInterfaceType.None)]
  [Guid("D40C654D-7C51-4EB3-95B2-1E23905C2A2D")]
  [ProgId("MyBHO.WordHighlighter")]
  public class WordHighlighterBHO : IObjectWithSite, IOleCommandTarget
  {
    const string DefaultTextToHighlight = "browser";

    IWebBrowser2 browser;
    private object site;

    #region Highlight Text
    void OnDocumentComplete(object pDisp, ref object URL)
    {
      try
      {

        // This will prevent this method being executed more than once.
        if (pDisp != this.site)
          return;

        var document2 = browser.Document as IHTMLDocument2;
        var document3 = browser.Document as IHTMLDocument3;

        var window = document2.parentWindow;
        window.execScript(@"function FncAddedByAddon() { alert('Message added by addon.'); }");

        Queue<IHTMLDOMNode> queue = new Queue<IHTMLDOMNode>();
        foreach (IHTMLDOMNode eachChild in document3.childNodes)
          queue.Enqueue(eachChild);

        while (queue.Count > 0)
        {
          // replacing desired text with a highlighted version of it
          var domNode = queue.Dequeue();

          var textNode = domNode as IHTMLDOMTextNode;
          if (textNode != null)
          {
            if (textNode.data.Contains(TextToHighlight))
            {
              var newText = textNode.data.Replace(TextToHighlight, "<span style='background-color: yellow; cursor: hand;' onclick='javascript:FncAddedByAddon()' title='Click to open script based alert window.'>" + TextToHighlight + "</span>");
              var newNode = document2.createElement("span");
              newNode.innerHTML = newText;
              domNode.replaceNode((IHTMLDOMNode)newNode);
            }
          }
          else
          {
            // adding children to collection
            var x = (IHTMLDOMChildrenCollection)(domNode.childNodes);
            foreach (IHTMLDOMNode eachChild in x)
            {
              if (eachChild is mshtml.IHTMLScriptElement)
                continue;
              if (eachChild is mshtml.IHTMLStyleElement)
                continue;

              queue.Enqueue(eachChild);
            }
          }
        }
      }
      catch (Exception ex)
      {
        MessageBox.Show(ex.Message);
      }
    }
    #endregion
    #region Load and Save Data
    static string TextToHighlight = DefaultTextToHighlight;
    public static string RegData = "Software\\MyIEExtension";

    [DllImport("ieframe.dll")]
    public static extern int IEGetWriteableHKCU(ref IntPtr phKey);

    private static void SaveOptions()
    {
      // In IE 7,8,9,(desktop)10 tabs run in Protected Mode
      // which prohibits writes to HKLM, HKCU.
      // Must ask IE for "Writable" registry section pointer
      // which will be something like HKU/S-1-7***/Software/AppDataLow/
      // In "metro" IE 10 mode, tabs run in "Enhanced Protected Mode"
      // where BHOs are not allowed to run, except in edge cases.
      // see http://blogs.msdn.com/b/ieinternals/archive/2012/03/23/understanding-ie10-enhanced-protected-mode-network-security-addons-cookies-metro-desktop.aspx
      IntPtr phKey = new IntPtr();
      var answer = IEGetWriteableHKCU(ref phKey);
      RegistryKey writeable_registry = RegistryKey.FromHandle(
          new Microsoft.Win32.SafeHandles.SafeRegistryHandle(phKey, true)
      );
      RegistryKey registryKey = writeable_registry.OpenSubKey(RegData, true);

      if (registryKey == null)
        registryKey = writeable_registry.CreateSubKey(RegData);
      registryKey.SetValue("Data", TextToHighlight);

      writeable_registry.Close();
    }
    private static void LoadOptions()
    {
      // In IE 7,8,9,(desktop)10 tabs run in Protected Mode
      // which prohibits writes to HKLM, HKCU.
      // Must ask IE for "Writable" registry section pointer
      // which will be something like HKU/S-1-7***/Software/AppDataLow/
      // In "metro" IE 10 mode, tabs run in "Enhanced Protected Mode"
      // where BHOs are not allowed to run, except in edge cases.
      // see http://blogs.msdn.com/b/ieinternals/archive/2012/03/23/understanding-ie10-enhanced-protected-mode-network-security-addons-cookies-metro-desktop.aspx
      IntPtr phKey = new IntPtr();
      var answer = IEGetWriteableHKCU(ref phKey);
      RegistryKey writeable_registry = RegistryKey.FromHandle(
          new Microsoft.Win32.SafeHandles.SafeRegistryHandle(phKey, true)
      );
      RegistryKey registryKey = writeable_registry.OpenSubKey(RegData, true);

      if (registryKey == null)
        registryKey = writeable_registry.CreateSubKey(RegData);
      registryKey.SetValue("Data", TextToHighlight);

      if (registryKey == null)
      {
        TextToHighlight = DefaultTextToHighlight;
      }
      else
      {
        TextToHighlight = (string)registryKey.GetValue("Data");
      }
      writeable_registry.Close();
    }
    #endregion

    [Guid("6D5140C1-7436-11CE-8034-00AA006009FA")]
    [InterfaceType(1)]
    public interface IServiceProvider
    {
      int QueryService(ref Guid guidService, ref Guid riid, out IntPtr ppvObject);
    }

    #region Implementation of IObjectWithSite
    int IObjectWithSite.SetSite(object site)
    {
      this.site = site;

      if (site != null)
      {
        LoadOptions();

        var serviceProv = (IServiceProvider)this.site;
        var guidIWebBrowserApp = Marshal.GenerateGuidForType(typeof(IWebBrowserApp)); // new Guid("0002DF05-0000-0000-C000-000000000046");
        var guidIWebBrowser2 = Marshal.GenerateGuidForType(typeof(IWebBrowser2)); // new Guid("D30C1661-CDAF-11D0-8A3E-00C04FC9E26E");
        IntPtr intPtr;
        serviceProv.QueryService(ref guidIWebBrowserApp, ref guidIWebBrowser2, out intPtr);

        browser = (IWebBrowser2)Marshal.GetObjectForIUnknown(intPtr);

        ((DWebBrowserEvents2_Event)browser).DocumentComplete +=
            new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete);
      }
      else
      {
        ((DWebBrowserEvents2_Event)browser).DocumentComplete -=
            new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete);
        browser = null;
      }
      return 0;
    }
    int IObjectWithSite.GetSite(ref Guid guid, out IntPtr ppvSite)
    {
      IntPtr punk = Marshal.GetIUnknownForObject(browser);
      int hr = Marshal.QueryInterface(punk, ref guid, out ppvSite);
      Marshal.Release(punk);
      return hr;
    }
    #endregion
    #region Implementation of IOleCommandTarget
    int IOleCommandTarget.QueryStatus(IntPtr pguidCmdGroup, uint cCmds, ref OLECMD prgCmds, IntPtr pCmdText)
    {
      return 0;
    }
    int IOleCommandTarget.Exec(IntPtr pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
    {
      try
      {
        // Accessing the document from the command-bar.
        var document = browser.Document as IHTMLDocument2;
        var window = document.parentWindow;
        var result = window.execScript(@"alert('You will now be allowed to configure the text to highlight...');");

        var form = new HighlighterOptionsForm();
        form.InputText = TextToHighlight;
        if (form.ShowDialog() != DialogResult.Cancel)
        {
          TextToHighlight = form.InputText;
          SaveOptions();
        }
      }
      catch (Exception ex)
      {
        MessageBox.Show(ex.Message);
      }

      return 0;
    }
    #endregion

    #region Registering with regasm
    public static string RegBHO = "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Browser Helper Objects";
    public static string RegCmd = "Software\\Microsoft\\Internet Explorer\\Extensions";

    [ComRegisterFunction]
    public static void RegisterBHO(Type type)
    {
      string guid = type.GUID.ToString("B");

      // BHO
      {
        RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(RegBHO, true);
        if (registryKey == null)
          registryKey = Registry.LocalMachine.CreateSubKey(RegBHO);
        RegistryKey key = registryKey.OpenSubKey(guid);
        if (key == null)
          key = registryKey.CreateSubKey(guid);
        key.SetValue("Alright", 1);
        registryKey.Close();
        key.Close();
      }

      // Command
      {
        RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(RegCmd, true);
        if (registryKey == null)
          registryKey = Registry.LocalMachine.CreateSubKey(RegCmd);
        RegistryKey key = registryKey.OpenSubKey(guid);
        if (key == null)
          key = registryKey.CreateSubKey(guid);
        key.SetValue("ButtonText", "Highlighter options");
        key.SetValue("CLSID", "{1FBA04EE-3024-11d2-8F1F-0000F87ABD16}");
        key.SetValue("ClsidExtension", guid);
        key.SetValue("Icon", "");
        key.SetValue("HotIcon", "");
        key.SetValue("Default Visible", "Yes");
        key.SetValue("MenuText", "&Highlighter options");
        key.SetValue("ToolTip", "Highlighter options");
        //key.SetValue("KeyPath", "no");
        registryKey.Close();
        key.Close();
      }
    }

    [ComUnregisterFunction]
    public static void UnregisterBHO(Type type)
    {
      string guid = type.GUID.ToString("B");
      // BHO
      {
        RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(RegBHO, true);
        if (registryKey != null)
          registryKey.DeleteSubKey(guid, false);
      }
      // Command
      {
        RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(RegCmd, true);
        if (registryKey != null)
          registryKey.DeleteSubKey(guid, false);
      }
    }
    #endregion
  }
}

我正在尝试做同样的事情 - 我刚刚注意到构建日志中有一个错误

将程序集添加到缓存失败:尝试安装程序集 没有响亮的名字

所以我添加了 *.snk 并突出显示有效(使用 ie11、x64),但“突出显示选项”菜单项不起作用

IE扩展示例 https://www.dropbox.com/s/artu9pvbep8jkz2/IEExtension.7z

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

开发 Internet Explorer、浏览器辅助对象扩展? 的相关文章

  • 无法使用c#更改视频捕获分辨率

    我正在尝试使用 C 中的 DirectShowNet 更改默认网络摄像头分辨率 据我所知 我需要通过调用 windows win32 api dll 中内置的 VideoInfoHeader 类来更改它以进行 avi 捕获 我有来自 Dir
  • 如何在 ASP.NET MVC 中将 XML 文件发送到客户端

    在 ASP NET MVC 中 我有一个数据库表 我想在某个视图页面上有一个按钮 如果某个用户单击该按钮 我的应用程序将生成包含数据库中所有行的 XML 文件 然后 应将包含 XML 的文件发送到客户端 以便用户看到下载弹出窗口 同样 我希
  • 采用 std::vector 或 std::array 的模板函数

    我有一个函数 当前接受 2 个向量 其中可以包含任何普通的旧数据 template
  • 信号与信号2

    我的应用程序可能会受益于使用 boost 的信号库之一而不是本土解决方案 该应用程序是多线程的 但执行信号处理的部分是单线程的 如果多线程不是问题 是否有任何理由更喜欢 Boost Signals2 而不是 Boost Signal Boo
  • Winform DatagridView 数字列排序

    我只使用一个简单的 DataGridView 来保存一堆数据 有趣的是 我在特定列中有小数 但是当按小数列排序时 它的排序是错误的 例如 起始顺序可能是 0 56 3 45 500 89 20078 90 1 56 100 29 2 39
  • FluentAssertions ShouldNotThrow 无法识别异步方法/Func

    我正在尝试检查异步方法是否抛出具体异常 为此 我使用 MSTEST 和 FluentAssertions 2 0 1 我已经检查过这个关于 Codeplex 的讨论 http fluentassertions codeplex com wo
  • 如何调试.NET Windows Service OnStart方法?

    我用 NET 编写的代码仅在作为 Windows 服务安装时才会失败 该故障甚至不允许服务启动 我不知道如何进入 OnStart 方法 如何 调试 Windows 服务应用程序 http msdn microsoft com en us l
  • 检测反射 DLL 注入

    在过去的几年中 恶意软件 以及一些渗透测试工具 如 Metasploit 的 meterpreter 负载 已经开始使用反射 DLL 注入 PDF http www harmonysecurity com files HS P005 Ref
  • asp.net core http 如果没有内容类型标头,则删除 `FromBody` 忽略

    我在 http 中使用 bodyDELETE要求 我知道目前删除主体是非标准的 但是允许的 使用时出现问题HttpClient它不允许删除请求的正文 我知道我可以使用SendAsync 但我宁愿让我的 API 更加灵活 我希望这个机构是可选
  • 如何在 C++ 运行时更改 QML 对象的属性?

    我想在运行时更改 QML 对象的文本 我尝试如下 但文本仍然为空 这是后端类 class BackEnd public QObject Q OBJECT Q PROPERTY QString userFieldText READ userF
  • 本地时间的内存需要释放吗?

    void log time t current time 0 tm ptm localtime current stuf 只是想确定 我是否需要在方法结束时释放 tm 指针分配的内存 不 你不应该释放它 该结构是静态分配的 检查文档 htt
  • 从 C# 调用时无法识别 Powershell 命令

    这是这个的延续Question https stackoverflow com questions 66280000 powershell object returns null 66280138 noredirect 1 comment1
  • 意外的 const 引用行为

    include
  • 实体框架读取列但阻止其更新

    给定一个数据库表 其中有一列包含历史数据但不再填充 实体框架中是否有一种方法可以读取该列 但在使用相同的模型对象时防止它被更新 例如我有一个对象 public class MyObject public string CurrentData
  • 如何重用具有稍微不同的 ProcessStartInfo 实例的 Process 实例?

    我有以下开始的代码robocopy https technet microsoft com en us library cc733145 aspx as a Process 我还需要进行数据库查询以确定每次需要复制哪些目录robocopy被
  • 如何在控制台程序中获取鼠标位置?

    如何在 Windows 控制台程序中用 C 获取鼠标单击位置 点击时返回鼠标位置的变量 我想用简单的文本命令绘制一个菜单 这样当有人点击时 游戏就会注册它并知道位置 我知道如何做我需要做的一切 除了单击时获取鼠标位置 您需要使用 Conso
  • 使用C标准数学库精确计算标准正态分布的CDF

    标准 C 数学库不提供计算标准正态分布 CDF 的函数 normcdf 然而 它确实提供了密切相关的函数 误差函数 erf 和互补误差函数 erfc 计算 CDF 的最快方法通常是通过误差函数 使用预定义常量 M SQRT1 2 来表示 d
  • 强制函数调用的顺序?

    假设我有一个抽象基类 并且我想要一个必须由派生类实现的纯虚方法 但我想确保派生方法以特定顺序调用函数 我可以做什么来强制执行它 I E base class virtual void doABC 0 virtual void A 0 vir
  • 在 LP2844Z(Zebra 打印机)上的收据中包含 PNG [重复]

    这个问题在这里已经有答案了 我正在致力于创建一个基于 HTML5 画布的签名 绘图框 目前我们在服务器上将画布保存为PNG 但可以轻松地将base64字符串保存在数据库中 现在的问题是我们如何在打印的收据上添加签名 目前我们使用 GF 字段
  • 创建进程默认浏览器

    我目前正在使用 ShellExecute 打开 在用户浏览器中打开 URL 但在 Win7 和 Vista 中遇到了一些麻烦 因为该程序作为服务运行提升 我想获取线程 id 因此 ShellExecute 无法获取线程 id 因此我开始使用

随机推荐

  • 如何将加载的图像读取到 blob 中? [复制]

    这个问题在这里已经有答案了 可能的重复 如何将图像对象转换为二进制 blob https stackoverflow com questions 13375333 how to convert an image object to a bi
  • Scala 中的理解评估很奇怪(?)

    现在 我花了a while找出为什么我的递归会以某种方式设法破坏堆栈 这是导致此问题的部分 scala gt for i lt List 1 2 3 j println why am I evaluated 10 if false yiel
  • Google App Engine 数据存储区和其他 NoSQL 数据库的无架构设计指南

    我相信许多其他人都有关系数据库背景 因此我正在寻找一些可靠的指南来在 Google App Engine 上设置 设计我的数据存储区 人们对于设置此类无模式数据存储有什么好的经验法则吗 我了解一些基础知识 例如非规范化 因为您无法进行连接
  • 静态库调试符号

    在 VS2010 中 有一个选项可以为 exe dll 生成调试信息linker但下没有这样的选项图书管理员对于库 调试信息是否嵌入静态库中 里面有一个选项C C 属性为程序数据库文件名对于库 exe 和 dll 默认情况下 它进入我的中间
  • 使用flutter打印包,如何从URL打印PDF?

    我在flutter中使用打印包 https pub dev packages printing https pub dev packages printing 该文档展示了如何从头开始创建 PDF 我已经在 URL 上有一个 PDF 有没有
  • os.environ 对 C 扩展模块的可见性

    如果我使用更改环境变量os environ 我之后导入的模块会看到这种变化吗 具体来说 sqlite3 requires https stackoverflow com a 23251896 336527使用环境变量来确定其临时文件位置 但
  • 当 URL 不正确时,curl_easy_perform 崩溃

    我在尝试使用下载文件时遇到问题libcurl 该程序使用多个线程 每个需要下载文件的线程都会创建一个libcurl处理来工作 当 URL 正确时 一切正常 但如果 URL 错误 程序就会崩溃 在调试模式下 如果 URL 不正确curl ea
  • 如何将弹出框 MATERIAL-UI 功能组件转换为基于类的组件?

    我正在尝试将此功能组件转换为基于类的组件 我已经尝试了几个小时但找不到放置这些的位置const组件中的变量 如果有人可以将其写在基于类的组件中 我们将不胜感激 const useStyles makeStyles theme gt typo
  • MIPS 汇编:从整数转换为十六进制

    我发现这个代码片段我认为可以将整数转换为十六进制 然而 我根本不遵循它 我添加了一些评论 说明了我认为正在发生的事情 但我不知道为什么要这样做 那么 假设我正确地注意到每行正在做什么 有人可以向我解释为什么要这样做吗 至于它如何以任何方式帮
  • 更新到 macos mavericks 后 gem install autotest-fsevent 失败

    更新到 Maveriks 后安装 gem 时遇到问题autotest fsevent 这是我得到的错误 Mellon public lasdolphin sudo gem install autotest fsevent Building
  • 是否有跨平台方法可以将资源嵌入到用 C++ 编写的二进制应用程序中? [复制]

    这个问题在这里已经有答案了 我试图将一些资源 图像 音乐和数据文件 捆绑到我的二进制应用程序 用 C 编写 中 我希望将所有内容都包含在一个可执行文件中 这样我就可以发送 大 可执行文件并且它可以工作 不能删除任何资产 我看到 Visual
  • .animate 回调函数之后的 .done

    我想在 animate 回调函数之后调用一个函数 我正在使用 done 方法来实现此目的 但它不起作用 fiddle http jsfiddle net dWAP4 function button click function div an
  • 向特定用户授予文件访问权限[关闭]

    Closed 这个问题是无关 help closed questions 目前不接受答案 在Linux中 如何向特定人员授予文件 文件夹的访问权限 换句话说 假设我只想允许只有用户 fred 能够读取文件 那么我该怎么做呢 请注意 我了解
  • 密码验证C++

    嗨 这是我第一次使用课程 所以对我糟糕的解释表示歉意 基本上我正在为电梯程序制作密码功能 LogIn 是我的类的名称 其中包含字符串 john 它是密码 除了错误密码尝试的循环之外 一切似乎都工作正常 如果第一次密码尝试正确 则代码可以正常
  • 成员函数特征

    我正在编写一个模板类 它包装成员函数以减少一些调用 如果某些条件为真 则不需要调用成员函数 签名看起来像这样 template
  • heroku 上的数据库名称以及用户、密码和主机

    我想在heroku 上安装一个带有数据库的php 脚本 如何获取我安装的数据库的数据库名称 密码 用户和主机信息 Heroku 上有多种不同的数据库 您可以查看选项并将它们添加到您的应用程序中 addons heroku com https
  • 如何调试 grails 命令

    当我运行 dbm generate changelog 时 抛出异常 我想调试这个脚本 但我不知道该怎么做 我尝试在脚本文件中放置断点 DatabaseMigrationCommon groovy然后在 eclipse 中创建新的 debu
  • AngularJS - 多次 ng-click - 事件冒泡

    在以下示例中 li h3 item title h3 li
  • Android 上的生物识别提示副标题文本被截断

    我已经实现了生物识别身份验证 其中我的副标题 验证用户名的生物识别信息以登录到我的App Name 有点长 最后会被截断 这主要发生在三星设备上 任何字符长度限制或 OEM 问题都无法解决 他们必须为此提出一个解决方案 因为我们无法控制它
  • 开发 Internet Explorer、浏览器辅助对象扩展?

    1 我正在尝试用 C 创建一个简单的 BHO 就像这里已经回答的那样 https stackoverflow com a 5740004 285594 https stackoverflow com a 5740004 285594 2 但