1

下面這個腳本:#content_script.js,這是爲獲得其在參數傳遞的值注入代碼的方式。原生瀏覽器注射

或者更明確(它可以是任何JavaScript的功能):

(function() { 
    var parse = JSON.parse; 
    JSON.parse = function(){ 
     console.log('Getting params: ', arguments); 
     return parse.apply(JSON, arguments) 
    }; 
    JSON.parse.toString = function(){ return 'function parse() { [native code] }' }; 

    var wss = WebSocket.prototype.send; 
    WebSocket.prototype.send = function(){ 
     console.log('Getting params', arguments); 
     return wss.apply(this, arguments) 
    } 
    WebSocket.prototype.send.toString = function(){ return 'function send() { [native code] }' } 
})(); 

但是,在線遊戲我的情況是我不應該使用這種方法,而不是我想將它注入JavaScript引擎(Native Code)。不完全我想知道如何發展,如果不是,我該怎麼做?如果我必須使用另一種編程語言或某種方法來做到這一點?

回答

1

這是很容易做到。下面的所有代碼都是模板代碼,這意味着所有插件的通用複製粘貼,並稍作調整。這裏是一個關於如何編寫firefox bootstrap插件的小教程。它基本上是因爲在這裏,但個性化你的工作同樣的事情:https://gist.github.com/Noitidart/9025999(我沒有包括像圖標和本地化的細節雖然)

  1. 計算機
  2. 上創建一個空文件夾,它使這些空白的新文件: bootstrap.js和install.rdf的和chrome.manifest用於和inject.js
  3. 進入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>[email protected]</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> 
    
  4. 現在我們可以粘貼更換的0123內容與[email protected]

  5. 讓更新<em:name>我們想要的插件的名字,讓我們將其命名爲Dragonbound Cheater
  6. 現在保存並去到bootstrap.js
  7. 在bootstrap.js粘貼此模板:

    function startup(aData, aReason) {} 
    
    function shutdown(aData, aReason) { 
        if (aReason == APP_SHUTDOWN) return; 
    } 
    
    function install() {} 
    
    function uninstall() {} 
    
  8. 現在有了這個更新內容:

    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://[email protected]/content/inject.js'); 
        } else { 
         recentBrowserWindow.addEventListener('load', function() { 
          recentBrowserWindow.removeEventListener('load', arguments.callee, false); 
          recentBrowserWindow.messageManager.loadFrameScript('chrome://[email protected]/content/inject.js'); 
         }, false); 
        } 
    } 
    
    function shutdown(aData, aReason) { 
        if (aReason == APP_SHUTDOWN) return; 
        browserWinAddedTo.messageManager.removeDelayedFrameScript('chrome://[email protected]/content/inject.js'); 
    } 
    
    function install() {} 
    
    function uninstall() {} 
    
  9. 在chrome.manifest用於補充一點:content dragonboundcheater ./

  10. 在inject.js現在我們可以做任何JS想,還是讓我們首先確保主機相匹配,同時也看到https://developer.mozilla.org/en-US/Firefox/Multiprocess_Firefox/Frame_script_environment這告訴我們,窗口對象refered通過全局變量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] }' } 
    })(); 
    
  11. 然後壓縮所有的東西在文件夾時,它從.zip文件進行重命名。XPI並拖動到Firefox瞧:)

+0

注意我有一個錯誤:在新打開的標籤它不是運行腳本,我不得不考慮的是,將在位 – Noitidart

+0

做我現在會檢查它 –

+0

@wZVanG這個簡單的插件如果你在龍站點打開的時候啓用/安裝它,它將不會出現問題,並且你只有一個帶有選項卡的Firefox窗口,如果你有多個你必須使用迭代器來遍歷所有窗口並附加。 – Noitidart