过程:

在调用加密函数前面插入以下代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
Hlclient.prototype.connect = function () {
console.log('begin of connect to wsURL: ' + this.wsURL);
var _this = this;
try {
this.socket["ySocket"] = new WebSocket(this.wsURL);
this.socket["ySocket"].onmessage = function (e) {
try{
let blob=e.data
blob.text().then(data =>{
_this.handlerRequest(data);
})
}catch{
console.log("not blob")
_this.handlerRequest(blob)
}

}
} catch (e) {
console.log("connection failed,reconnect after 10s");
setTimeout(function () {
_this.connect()
}, 10000)
}
this.socket["ySocket"].onclose = function () {
console.log("connection failed,reconnect after 10s");
setTimeout(function () {
_this.connect()
}, 10000)
}

};
Hlclient.prototype.send = function (msg) {
this.socket["ySocket"].send(msg)
}

Hlclient.prototype.regAction = function (func_name, func) {
if (typeof func_name !== 'string') {
throw new Error("an func_name must be string");
}
if (typeof func !== 'function') {
throw new Error("must be function");
}
console.log("register func_name: " + func_name);
this.handlers[func_name] = func;
return true

}

//收到消息后这里处理,
Hlclient.prototype.handlerRequest = function (requestJson) {
var _this = this;
var result=JSON.parse(requestJson);
//console.log(result)
if (!result['action']) {
this.sendResult('','need request param {action}');
return
}
var action=result["action"]
var theHandler = this.handlers[action];
if (!theHandler){
this.sendResult(action,'action not found');
return
}
try {
if (!result["param"]){
theHandler(function (response) {
_this.sendResult(action, response);
})
}else{
var param=result["param"]
try {
param=JSON.parse(param)
}catch (e){
console.log("")
}
theHandler(function (response) {
_this.sendResult(action, response);
},param)
}

} catch (e) {
console.log("error: " + e);
_this.sendResult(action+e);
}
}

Hlclient.prototype.sendResult = function (action, e) {
this.send(action + atob("aGxeX14") + e);
}

var hlc = new Hlclient("ws://127.0.0.1:12080/ws?group=zzz&name=hlg");
hlc.regAction("getenc", function (resolve,param) {
var myenc = a.encryptedData(param)
resolve(myenc);

}),

a.encryptedData是目标js文件里的加密函数

然后输入账号密码登录,js rpc 上线成功。

访问:http://127.0.0.1:12080/go?group=zzz&name=hlg&action=getenc&param=ffff

测试成功,不要关闭刷新网页。

python调用代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import requests,time
from concurrent.futures.thread import ThreadPoolExecutor
tp = ThreadPoolExecutor(max_workers=50)
def fetch_response(url):
response = requests.get(url)
return url,response.text

def callback_successed(f):
print(f.result())

start_timestamp = time.time()
for i in range(100):
tp.submit(fetch_response,"http://localhost:12080/go?group=zzz&name=hlg&action=getenc&param={}".format(i)).add_done_callback(callback_successed)
tp.shutdown()
end_timestamp = time.time()

print("每个请求时间开销:{}ms".format(round(end_timestamp-start_timestamp,3) *1000 / 100))

参考链接:

https://jason-yep.notion.site/JS-fc9829a45c4347d3bc3ab2bac37c85f3#dfc92edcea27497297541c095d1e8421

https://github.com/jxhczhl/JsRpc