This commit is contained in:
cilame 2022-03-15 21:12:55 +08:00
parent c1c95f495b
commit d7b09bb163
3 changed files with 48 additions and 1 deletions

View File

@ -1107,6 +1107,13 @@ function injectfunc(e, window) {
if (e["config-hook-domobj"]){
$domobj_placeholder
}
!function(){
try{
$myinject
}catch(e){
v_log('inject error.')
}
}()
}
@ -1231,6 +1238,8 @@ var hookers = [
"config-hook-domobj-func",
"config-hook-regexp-url",
"config-hook-log-at",
"config-myinject",
"config-myinject_toogle",
]
function add_config_hook(input){
for (var i = 0; i < input.length; i++) {
@ -1245,17 +1254,39 @@ function inject_script(code){
var script = document.createElement("script");
script.innerHTML = code;
script.onload = script.onreadystatechange = function(){
script.onreadystatechange = script.onload = null;
script.onreadystatechange = script.onload = null;
}
var head = document.getElementsByTagName("head")[0];
(head || document.body).appendChild( script );
(head || document.body).removeChild( script );
}
function check_format(str){
try{
eval(`function test(){
try{
$myinject
}catch(e){
v_log('inject error.')
}
}`.replace('$myinject', str))
return true
}catch(e){
return false
}
}
chrome.storage.local.get(hookers, function (result) {
if (result["config-hook-global"]){
var myinject = result["config-myinject"]
if (result["config-myinject_toogle"]){
var myinject = check_format(myinject) ? myinject : 'v_log("format error.")'
}else{
var myinject = 'undefined'
}
var replacer_injectfunc = (injectfunc + '').replace('$domobj_placeholder', make_domhooker_funcs())
var replacer_injectfunc = replacer_injectfunc.replace('$make_v_func', make_v+';')
var replacer_injectfunc = replacer_injectfunc.replace('$myinject', myinject+';')
inject_script(`(${replacer_injectfunc})(${JSON.stringify(result)},window)`);
}
})

View File

@ -16,6 +16,7 @@
<nav id="nav">
<ul>
<button class="act">dom对象 hook 配置</button>
<button>注入代码</button>
<button>高级 hook ,修改 response 返回值</button>
<button>AST混淆解密</button>
</ul>
@ -113,6 +114,11 @@
<div id="getsets_1" style="float: left"></div>
<div id="funcs_1" style="float: left"></div>
</section>
<section class="tab">
<label ><input type="checkbox" data-key="config-myinject_toogle">是否注入代码开关</label>
<HR>
<textarea id='myinject' data-key="config-myinject" style="width: 100%; height: 500px"></textarea>
</section>
<section class="tab">
<div>这里的功能:在目标网页上右键菜单选择 “打开 v_jstools 动态调试” 即可开启,使用用插件的方式 hook 住目标页面的所有代码,像是在 node 里面一样使用 ast 将原始的代码修改成期望的样子</div>
<div>这里的 hook 功能在一定的扩展之后,能 hook 住 script 链接中的 js 代码,也能 hook 到 html 内的 js 代码。</div>

View File

@ -491,6 +491,16 @@ fetch_hook.addEventListener("change", function(v){
})
})
var myinject = document.getElementById('myinject');
chrome.storage.local.get([myinject.dataset.key], function (result) {
myinject.value = result[myinject.dataset.key] || '';
})
myinject.addEventListener("change", function(v){
chrome.storage.local.set({
[v.target.dataset.key]: v.target.value
})
})
var get_now = document.getElementById('get_now');
get_now.addEventListener("click", function(){
var show_now = document.getElementById('show_now')