Skip to content

Commit 6efc1d8

Browse files
committed
make code more stable: 不写死原始脚本的 url
1 parent 10c3bc3 commit 6efc1d8

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

src/http_static_server.js

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const server = http.createServer((req, res) => {
99
'Cache-Control': 'no-cache',
1010
'Content-Type': 'application/x-javascript; charset=utf-8'}
1111
);
12+
var original = decodeURIComponent(req.url.split('original=')[1]);
13+
res.write(`window.wechatOriginalScript="${original}";\n`, 'utf-8');
1214
return res.end(fs.readFileSync(path.join(__dirname, 'wechat_injection.js'), 'utf-8'));
1315
}
1416

src/phantomjs_wechat.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ page.onResourceRequested = function(requestData, networkRequest) {
1414
if (!redirected[url] && url.match(/wx.qq.com\/a\/wx_fed\/webwx\/res\/static\/js\/index_(.+)\.js$/)) {
1515
redirected[url] = true;
1616
console.log('>>> onResourceRequested', url)
17-
networkRequest.changeUrl('http://127.0.0.1:8000/hijacked_wechat_index.js?v=' + new Date().getTime());
17+
networkRequest.changeUrl(
18+
"http://127.0.0.1:8000/hijacked_wechat_index.js?v=" +
19+
new Date().getTime() +
20+
"&original=" +
21+
encodeURIComponent(url)
22+
);
1823
}
1924

2025
if (url.indexOf('/qrcode/') !== -1) {

src/wechat_injection.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,17 @@ console.log("### wechat index js hijacked ###");
9090
}
9191

9292
(function loadOriginalScript() {
93-
var indexScript =
94-
"https://res.wx.qq.com/a/wx_fed/webwx/res/static/js/index_c7d281c.js";
93+
var originalScript = window.wechatOriginalScript;
9594

9695
$.ajax({
97-
url: indexScript,
96+
url: originalScript,
9897
dataType: "text",
9998
success: function(script, textStatus, jqxhr) {
10099
if (jqxhr.status === 200) {
101100
//phantomjs does not support ECMA6 language features
102101
script = script.replace(" let ", " var ");
103102
window.eval(script);
104-
console.log(indexScript + " loaded.");
103+
console.log("original script " + originalScript + " loaded.");
105104
}
106105
}
107106
});

0 commit comments

Comments
 (0)