Javascript 浏览器本机注入

Javascript 浏览器本机注入,javascript,c++,google-chrome,google-chrome-extension,firefox-addon,Javascript,C++,Google Chrome,Google Chrome Extension,Firefox Addon,遵循以下脚本:,这是一种注入代码以获取在参数中传递的值的方法 或者更清楚(可以是任何JavaScript函数): 但是,在在线游戏中,我不应该使用该方法,而是希望将其注入JavaScript引擎(Native code)。不完全是我想知道如何发展,如果不是,我该怎么办?。如果我必须使用另一种编程语言或某种方法来做这件事?这很容易做到。下面所有的代码都是模板代码,这意味着所有插件的通用复制粘贴,只需稍加调整。下面是一个关于如何编写firefox引导插件的小教程。这基本上和这里一样,但对你的工作是个

遵循以下脚本:,这是一种注入代码以获取在参数中传递的值的方法

或者更清楚(可以是任何JavaScript函数):


但是,在在线游戏中,我不应该使用该方法,而是希望将其注入JavaScript引擎(
Native code
)。不完全是我想知道如何发展,如果不是,我该怎么办?。如果我必须使用另一种编程语言或某种方法来做这件事?

这很容易做到。下面所有的代码都是模板代码,这意味着所有插件的通用复制粘贴,只需稍加调整。下面是一个关于如何编写firefox引导插件的小教程。这基本上和这里一样,但对你的工作是个性化的:(我没有包括图标和本地化等细节)

  • 在计算机上创建一个空文件夹
  • 在其中创建这些空白的新文件:bootstrap.js和install.rdf以及chrome.manifest和inject.js
  • 将此模板粘贴到install.rdf中:

    <?xml version="1.0" encoding="utf-8"?>
        <!-- This Source Code Form is subject to the terms of the Mozilla Public
       - License, v. 2.0. If a copy of the MPL was not distributed with this
       - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
        <RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:em="http://www.mozilla.org/2004/em-rdf#">
          <Description about="urn:mozilla:install-manifest">
            <em:id>Bootstrap-Skeleton@jetpack</em:id>
            <em:version>initial</em:version>
            <em:type>2</em:type>
            <em:bootstrap>true</em:bootstrap>
            <em:unpack>false</em:unpack>
    
            <!-- Firefox -->
            <em:targetApplication>
              <Description>
                <em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
                <em:minVersion>7.0</em:minVersion>
                <em:maxVersion>27.0</em:maxVersion>
              </Description>
            </em:targetApplication>
    
            <!-- Front End MetaData -->
            <em:name>Bootstrap Skeleton</em:name>
            <em:description>How all bootstrap addons start.</em:description>
            <em:creator>Noitidart</em:creator>
            <em:contributor>Pat for Icon</em:contributor>
            <em:optionsType>2</em:optionsType>
          </Description>
        </RDF>
    
    function startup(aData, aReason) {}
    
    function shutdown(aData, aReason) {
        if (aReason == APP_SHUTDOWN) return;
    }
    
    function install() {}
    
    function uninstall() {}
    
  • 现在使用以下内容更新其内容:

    const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
    Cu.import('resource://gre/modules/Services.jsm');
    var browserWinAddedTo;
    function startup(aData, aReason) {
        var recentBrowserWindow = Services.wm.getMostRecentWindow('navigator:browser');
        browserWinAddedTo = recentBrowserWindow;
        if (recentBrowserWindow.document.readyState == 'complete') { //on startup `aDOMWindow.document.readyState` is `uninitialized`
            recentBrowserWindow.messageManager.loadFrameScript('chrome://dragonboundcheater@wzvang/content/inject.js');
        } else {
            recentBrowserWindow.addEventListener('load', function () {
                recentBrowserWindow.removeEventListener('load', arguments.callee, false);
                recentBrowserWindow.messageManager.loadFrameScript('chrome://dragonboundcheater@wzvang/content/inject.js');
            }, false);
        }
    }
    
    function shutdown(aData, aReason) {
        if (aReason == APP_SHUTDOWN) return;
        browserWinAddedTo.messageManager.removeDelayedFrameScript('chrome://dragonboundcheater@wzvang/content/inject.js');
    }
    
    function install() {}
    
    function uninstall() {}
    
  • 在chrome.manifest中添加以下内容:
    content-dragongboundcheater./

  • 在inject.js中,现在我们可以做js想要做的任何事情,但首先要确保主机匹配,还可以看到,这告诉我们窗口对象是由全局变量
    content
    引用的,因此无论我们想访问哪里,我们都使用
    content
    ,如果您想访问js环境,我们可以通过
    content.wrappedJSObject
    来访问。让我们将inject.js设为:

    (function() {
        var window = content;
        var js = window.wrappedJSObject;
    
    
        if (window.location.host.indexOf('dragonbound.net') == -1) {
           return;
        }
    
        var parse = js.JSON.parse;
        js.JSON.parse = function(){
            console.log('Getting params: ', arguments);
            return parse.apply(js.JSON, arguments)
        };
        js.JSON.parse.toString = function(){ return 'function parse() { [native code] }' };
    
        var wss = js.WebSocket.prototype.send;
        js.WebSocket.prototype.send = function(){
            console.log('Getting params', arguments);
            return wss.apply(this, arguments)
        }
        js.WebSocket.prototype.send.toString = function(){ return 'function send() { [native code] }' }
    })();
    
  • 然后将文件夹中的所有内容压缩,将其从.zip重命名为.xpi,并拖动到firefox中,瞧:)


  • 注意,我有一个错误:在新打开的选项卡上,它没有运行脚本,我必须研究一下,这将在一段时间内完成安装成功。但我得到了这个控制台的一句话:
    没有注册chrome软件包chrome://wzvang/content/inject.js
    谢谢,我已经理解了,但是我必须阅读文档,了解每件事的工作原理。我希望页面不以任何方式检测JavaScript的处理。你有什么建议吗?@wZVanG我不明白你的问题,你说不检测js处理是什么意思?我的意思是,如果页面,在本例中是
    dragonsbound.net
    可能有一些方法检测或知道我的注射?。这是我不想发生的事。
    (function() {
        var window = content;
        var js = window.wrappedJSObject;
    
    
        if (window.location.host.indexOf('dragonbound.net') == -1) {
           return;
        }
    
        var parse = js.JSON.parse;
        js.JSON.parse = function(){
            console.log('Getting params: ', arguments);
            return parse.apply(js.JSON, arguments)
        };
        js.JSON.parse.toString = function(){ return 'function parse() { [native code] }' };
    
        var wss = js.WebSocket.prototype.send;
        js.WebSocket.prototype.send = function(){
            console.log('Getting params', arguments);
            return wss.apply(this, arguments)
        }
        js.WebSocket.prototype.send.toString = function(){ return 'function send() { [native code] }' }
    })();