Skip to content

Commit 4e6b6cd

Browse files
committed
feat: 在response断点那里方便进入callback函数
1 parent 781eece commit 4e6b6cd

File tree

5 files changed

+45
-21
lines changed

5 files changed

+45
-21
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
在进行JS逆向的时候,经常碰到请求是JS类型的,实际上是使用script标签发出的请求,比如一些跨域的请求,一些jsonp请求,
1010
Chrome目前(2024-12-20)没有支持对script类型的请求打条件断点之类的,而这个脚本就是填补这块儿的空白的。
1111

12+
优势:
13+
- 支持对script类型的请求打断点
14+
- script请求之前进入断点
15+
- 直接把断点打到script jsonp回调函数里
16+
1217
## 二、安装
1318
开发中,敬请期待!
1419

src/config/ui/component/debugger-component.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ class DebuggerComponent {
176176

177177
// URL匹配类型
178178
debuggerElt.find(`#${debuggerInformation.id}-url-pattern`).change(function () {
179-
debugger;
180179
const localDebuggerInformation = getGlobalConfig().findDebuggerById(debuggerInformation.id);
181180
localDebuggerInformation.urlPatternType = $(this).val();
182181
getGlobalConfig().persist();

src/debugger/debugger-tester.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,16 +153,8 @@ class DebuggerTester {
153153
return false;
154154
}
155155

156-
// 请求断点
157-
if (debuggerConfig.enableResponseDebugger) {
158-
// 把一些相关的上下文赋值到变量方便断点命中这里的时候观察
159-
// _scriptContext中存放的是与当前的script请求相关的一些上下文信息
160-
const _scriptContext = scriptContext;
161-
const humanReadableScriptInformation = scriptContext.toHumanReadable()
162-
debugger;
163-
}
164-
165-
return true;
156+
// 响应断点是否开启
157+
return debuggerConfig.enableResponseDebugger;
166158
}
167159

168160
/**

src/hook/jsonp-callback-hook.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ class JsonpCallbackHook {
4545
const _this = this;
4646
new ObjectFunctionHook(getUnsafeWindow(), jsonpCallbackFunctionName).addHook(function () {
4747

48-
const responseContext = _this.scriptContext.responseContext = new ResponseContext("", arguments);
48+
const {hookFunctionHolder, args} = arguments[0];
49+
50+
const responseContext = _this.scriptContext.responseContext = new ResponseContext("", args);
4951

5052
// 只在有必要的情况下打印
5153
if (new DebuggerTester().isNeedPrintToConsole(getGlobalConfig(), _this.scriptContext)) {
@@ -54,7 +56,20 @@ class JsonpCallbackHook {
5456
}
5557

5658
const hitDebuggers = getGlobalConfig().testAllForResponse(_this.scriptContext);
57-
});
59+
const isHitDebugger = hitDebuggers.length;
60+
61+
if (isHitDebugger) {
62+
// 把一些相关的上下文赋值到变量方便断点命中这里的时候观察
63+
// _scriptContext中存放的是与当前的script请求相关的一些上下文信息
64+
// humanReadableScriptInformation 存放的是上下文格式化后的一些可读的信息
65+
const humanReadableScriptInformation = _this.scriptContext.toHumanReadable()
66+
debugger;
67+
}
68+
69+
// 跟进去这个函数,就是jsonp的callback函数
70+
hookFunctionHolder.apply(this, args);
71+
72+
}, true);
5873
}
5974

6075
collectJsonpCallbackFunctionNameFromHitDebuggers() {

src/hook/object-function-hook.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ class ObjectFunctionHook {
1818
/**
1919
*
2020
* @param hookCallbackFunction
21+
* @param callByHookCallbackFunction {boolean}
2122
*/
22-
addHook(hookCallbackFunction) {
23+
addHook(hookCallbackFunction, callByHookCallbackFunction = false) {
2324

2425
// 要Hook的函数必须存在
2526
const functionHolder = this.object[this.functionName];
@@ -41,14 +42,26 @@ class ObjectFunctionHook {
4142
// 为函数添加Hook
4243
this.object[this.functionName] = function () {
4344

44-
try {
45-
// TODO 2023-8-21 22:15:09 在函数执行的时候尝试触发各种断点
46-
hookCallbackFunction.apply(this, arguments)
47-
} catch (e) {
48-
console.error(e);
45+
if (callByHookCallbackFunction) {
46+
// 由hook函数自行调用被hook函数
47+
try {
48+
hookCallbackFunction.apply(this, [{
49+
"hookFunctionHolder": functionHolder,
50+
"args": arguments
51+
}]);
52+
} catch (e) {
53+
console.error(e);
54+
}
55+
} else {
56+
// 不干扰流程,hook函数只作为观测
57+
try {
58+
// TODO 2023-8-21 22:15:09 在函数执行的时候尝试触发各种断点
59+
hookCallbackFunction.apply(this, arguments);
60+
} catch (e) {
61+
console.error(e);
62+
}
63+
return functionHolder.apply(this, arguments);
4964
}
50-
51-
return functionHolder.apply(this, arguments);
5265
}
5366
// 设置标记位,防止重复Hook
5467
this.object[this.functionName][hookDoneFlag] = true;

0 commit comments

Comments
 (0)