diff --git a/background.js b/background.js index 9ba68ef..2a2487c 100644 --- a/background.js +++ b/background.js @@ -82,4 +82,10 @@ function AttachDebugger() { }); } ); -} \ No newline at end of file +} + +chrome.cookies.onChanged.addListener(function(info){ + chrome.tabs.query({ active: true, currentWindow: true }, function(tabs){ + chrome.tabs.sendMessage(tabs[0].id, {action: {type:'getcookie', info: info}}, function(){}) + }) +}); \ No newline at end of file diff --git a/inject.js b/inject.js index 8ba7fec..bd862a7 100644 --- a/inject.js +++ b/inject.js @@ -1304,9 +1304,9 @@ function inject_script(code){ script.onload = script.onreadystatechange = function(){ script.onreadystatechange = script.onload = null; } - var head = document.getElementsByTagName("head")[0]; - (head || document.body).appendChild( script ); - (head || document.body).removeChild( script ); + var html = document.getElementsByTagName("html")[0]; + html.appendChild( script ); + html.removeChild( script ); } function check_format(str){ @@ -1335,6 +1335,7 @@ chrome.storage.local.get(hookers, function (result) { } }) +var cookie_cache = {} chrome.extension.onMessage.addListener(function(msg, sender, sendResponse) { if (msg.action.type == 'error'){ inject_script(`console.error(${JSON.stringify(msg.action.info)})`) @@ -1348,4 +1349,10 @@ chrome.extension.onMessage.addListener(function(msg, sender, sendResponse) { if (msg.action.type == 'alerterror'){ inject_script(`alert(${JSON.stringify(msg.action.info)})`) } + if (msg.action.type == 'getcookie'){ + var cookie = msg.action.info.cookie + cookie_cache[cookie.domain] = cookie_cache[cookie.domain] || {} + cookie_cache[cookie.domain][cookie.name] = cookie.value + inject_script('window.vilame_setter='+JSON.stringify(cookie_cache)) + } }); \ No newline at end of file diff --git a/manifest.json b/manifest.json index d87be2f..5d89cf3 100644 --- a/manifest.json +++ b/manifest.json @@ -35,7 +35,7 @@ "name": "v_jstools", "version": "0.0.0", "description": "v_jstools js hook工具", - "permissions": ["storage", "unlimitedStorage", "activeTab", "tabs", "debugger", "storage", "contextMenus"], + "permissions": ["storage", "unlimitedStorage", "activeTab", "tabs", "debugger", "storage", "contextMenus", "cookies"], "content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'", "browser_action": { "default_popup": "popup.html" diff --git a/tools/model_funcs.js b/tools/model_funcs.js index 2a27115..f6808e0 100644 --- a/tools/model_funcs.js +++ b/tools/model_funcs.js @@ -45,11 +45,10 @@ var server = wss.createServer(function(conn){ if (info == 'browser:start'){ global.conn = conn }else{ - info = {message: info} try{ info = JSON.parse(info) }catch(e){} - resqueue.pop().json(info) + resqueue.pop().json({message: info}) } }) conn.on("error", function(){ console.log("error") }) @@ -164,7 +163,12 @@ function mk_websocket_hook_code(){ console.log('websocket.onmessage', info) if (info.evalstring){ // 这里让你可以通过 /?evalstring=123 传入代码直接执行, - websocket.send(v_eval(v_decodeURIComponent(info.evalstring))) + try{ + var ret = v_eval(v_decodeURIComponent(info.evalstring)) + }catch(e){ + var ret = e.stack + } + websocket.send(ret) }else{ // 这里处理请求参数以及对应rpc函数调用,返回参数用字符串传递回 websocket。回传字符串即可。 var ret = '你好'