diff options
author | NateN1222 <nathannichols454@gmail.com> | 2017-08-12 15:31:30 -0500 |
---|---|---|
committer | NateN1222 <nathannichols454@gmail.com> | 2017-08-12 15:31:30 -0500 |
commit | db7dc60155b625c3ca30fe56495f41937d69daee (patch) | |
tree | 264b01853281a1651c35926bba559cf975016a95 | |
parent | ab4a4a9c49c25e2703b1fded3272d0a4cfb35838 (diff) |
Started implementing a version of the JS parsing as a content script
-rw-r--r-- | eval_test.js | 140 | ||||
-rw-r--r-- | main_background.js | 29 | ||||
-rw-r--r-- | test.html | 0 |
3 files changed, 129 insertions, 40 deletions
diff --git a/eval_test.js b/eval_test.js index c432b61..d0de7e5 100644 --- a/eval_test.js +++ b/eval_test.js @@ -2,10 +2,31 @@ * This file is the "skeleton" of the final system to determine * if a script is accepted or blocked. * -* +* Some assets taken from script_detector.js * */ +// the list of all available event attributes +var intrinsicEvents = [ + "onload", + "onunload", + "onclick", + "ondblclick", + "onmousedown", + "onmouseup", + "onmouseover", + "onmousemove", + "onmouseout", + "onfocus", + "onblur", + "onkeypress", + "onkeydown", + "onkeyup", + "onsubmit", + "onreset", + "onselect", + "onchange" +]; /* NONTRIVIAL THINGS: - Fetch @@ -23,16 +44,7 @@ - In the first script tag, declare the license with @licstart/@licend */ -var license_regexes = { - // Looks like - // "// @license [magnet link] [identifier]" - // "// @license-end" - "license" :{ - "start": /\/\/\s*@license\s+magnet:?.*\s\w+/g, - "end": /\/\/\s*@license\-end/g - } -} var licenses = { 'Apache-2.0':{ 'URL': 'http://www.apache.org/licenses/LICENSE-2.0', @@ -121,7 +133,7 @@ var licenses = { }, // No identifier was present 'X11':{ - 'URL': 'http://www.xfree86.org/3.3.6/COPYRIGHT2.html#3' + 'URL': 'http://www.xfree86.org/3.3.6/COPYRIGHT2.html#3', 'Magnet link': 'magnet:?xt=urn:btih:5305d91886084f776adcf57509a648432709a7c7&dn=x11.txt' }, // Picked one of the two links that were there @@ -131,43 +143,95 @@ var licenses = { } } - +var license_regexes = { + // Comments on a single line only + "JScomment": /(\/\/.*\n)|(\/\*.*\*\/)/g, + "JSallcomment": /(\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\/)|(\/\/.*)/g, + // "@license [magnet link] [identifier]" + "license_start": /@license[^\S\n]+magnet:\S+[^\S\n]+\S+/g, + // "@license-end" + "license_end": /\/\/\s*@license\-end/g +} /** * * Runs regexes to search for explicit delcarations of script -* licenses on the argument. +* licenses on the argument. (// @license, //@license-end) +* +* Returns the identifier string or "fail". * */ function license_read(script_src){ - - + var license_attempts = []; + var comment_regex = new RegExp(license_regexes["JSallcomment"]); + var comments = script_src.match(comment_regex); + if(comments == null){ + comments = []; + } + console.log("%c comments:","color:green;") + console.log(comments); + for(var i = 0; i < comments.length; i++){ + if(comments[i] !== undefined){ + if(comments[i].match(license_regexes["license_start"]) != null){ + console.log("License start:"); + console.log(comments[i]) + } + + if(comments[i].match(license_regexes["license_end"]) != null){ + console.log("License end:"); + console.log(comments[i]) + } + } + } } +// The Javascript evaluation can be tested as a content script until we have +// the API features we need to make it run before the page's scripts do. + +// To run this, set it as a content script active on all URLs in the manifest.json. + + +// called when invoked by the button +function handler(){ + for(var i = 0; i < document.scripts.length; i++){ + if(document.scripts[i].src != ""){ + var name = document.scripts[i].src; + var xml = new XMLHttpRequest(); + xml.open("get", document.scripts[i].src); + xml.onload = function(response){ + console.log("%c Script " + i + ": (src: " + name + ")","color:red;"); + license_read(this.responseText); + } + xml.send(); + } else{ + name = "inline"; + source = document.scripts[i].innerText; + console.log("%c Script " + i + ": (src: inline)","color:red;"); + license_read(document.scripts[i]); + } + } +} +var button_i = 0; +if(document.getElementById("abc123_main_div") !== null){ + document.getElementById("abc123_main_div").remove(); +} +function new_debug_button(name_text,callback){ + if(document.getElementById("abc123_main_div") === null){ + var to_insert = '<div style="opacity: 0.5; font-size: small; z-index: 2147483647; position: fixed; right: 1%; top: 4%;" id="abc123_main_div"></div>'; + document.body.insertAdjacentHTML('afterbegin', to_insert); + } + var button_html = '<input id="abc123_button_' + button_i + '" value="' + name_text +'"type="button"></input><br>'; + document.getElementById("abc123_main_div").insertAdjacentHTML('afterbegin', button_html); + document.getElementById("abc123_button_"+button_i).addEventListener("click",callback); + button_i = button_i + 1; +} - - - - - - - - - - - - - - - - - - - - - - - +new_debug_button("Evaluate scripts",handler); +new_debug_button("Remove these buttons",function(){ + if(document.getElementById("abc123_main_div") !== null){ + document.getElementById("abc123_main_div").remove(); + } +}); diff --git a/main_background.js b/main_background.js index 5242348..1e31d64 100644 --- a/main_background.js +++ b/main_background.js @@ -32,6 +32,14 @@ function set_webex(){ * */ function options_listener(changes, area){ + // The cache must be flushed when settings are changed + // TODO: See if this can be minimized + function flushed(){ + console.log("cache flushed"); + } + var flushingCache = webex.webRequest.handlerBehaviorChanged(flushed); + + console.log("Items updated in area" + area +": "); var changedItems = Object.keys(changes); @@ -323,7 +331,22 @@ function init_addon(){ webex.runtime.onConnect.addListener(connected); webex.storage.onChanged.addListener(options_listener); webex.tabs.onRemoved.addListener(delete_removed_tab_info); - + + /** + * Callback for request traffic. + * + */ + /* + function script_request(details){ + console.log("Request:"+details.type) + //return {redirectUrl: "about:blank"}; + return true; + } + webex.webRequest.onResponseStarted.addListener(script_request,{ + urls:["<all_urls>"] + }); + */ + /**************** some debugging: ***************************/ // Valid input for update_popup var example_input = { @@ -369,7 +392,9 @@ function test_url_whitelisted(url,callback){ webex.storage.local.get(storage_got); } - +/** +* Loads the contact finder on the given tab ID. +*/ function inject_contact_finder(tab_id){ function executed(result) { console.log("[TABID:"+tab_id+"]"+"finished executing contact finder: " + result); diff --git a/test.html b/test.html new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test.html |