-
Notifications
You must be signed in to change notification settings - Fork 38
/
payload.js
107 lines (93 loc) · 3.54 KB
/
payload.js
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
97
98
99
100
101
102
103
104
105
106
107
function bytelist_js_to_java(bytelist) {
return Java.array('byte', bytelist)
// var base64Str = base64Encode(bytelist)
// var androidBase64 = Java.use('android.util.Base64')
// var bytesInJava = androidBase64.decode(base64Str, 0)
// return bytesInJava;
}
function bytelist_java_to_js(bytelist) {
var jsonString = Java.use('org.json.JSONArray').$new(bytelist).toString();
return JSON.parse(jsonString);
}
function decrypt(byteListInJs) {
return Promise(function (resolve, reject) {
try {
Java.perform(function () {
try {
var objCompanion = Java.use('com.stardust.autojs.engine.encryption.ScriptEncryption').class.getField("Companion").get(null)
objCompanion = Java.cast(objCompanion, Java.use('com.stardust.autojs.engine.encryption.ScriptEncryption$Companion'))
var byteListInJava = bytelist_js_to_java(byteListInJs)
var byteListRtnInJava = objCompanion.decrypt(byteListInJava, 8, byteListInJs.length)
var byteListRtnInJS = bytelist_java_to_js(byteListRtnInJava)
resolve(byteListRtnInJS);
} catch (e) {
reject(e)
}
})
} catch (e) {
reject(e)
}
});
}
function encrypt(byteListInJs) {
return Promise(function (resolve, reject) {
try {
Java.perform(function () {
try {
var objCompanion = Java.use('com.stardust.autojs.engine.encryption.ScriptEncryption').class.getField("Companion").get(null)
objCompanion = Java.cast(objCompanion, Java.use('com.stardust.autojs.engine.encryption.ScriptEncryption$Companion'))
var byteListInJava = bytelist_js_to_java(byteListInJs)
var byteListRtnInJava = objCompanion.encrypt(byteListInJava)
var byteListRtnInJS = bytelist_java_to_js(byteListRtnInJava)
resolve(byteListRtnInJS);
} catch (e) {
reject(e)
}
})
} catch (e) {
reject(e)
}
});
}
function get_project_path() {
return Promise(function (resolve, reject) {
try {
Java.perform(function () {
try {
var got = false;
Java.choose('android.app.ContextImpl', {
onMatch: function (instance) {
if (!got) {
got = true;
var filesDir = Java.cast(instance, Java.use('android.app.ContextImpl')).getFilesDir().getAbsolutePath();
resolve(filesDir);
}
return "stop";
},
onComplete: function () {
if(!got){
console.log("bug, unable to found any 'android.app.ContextImpl' instance!!!")
reject();
}
}
})
} catch (e) {
reject(e)
}
})
} catch (e) {
reject(e)
}
});
}
function write_file(full_path, data) {
var f = new File(full_path, 'w')
f.write(data)
f.close()
}
rpc.exports = {
"decrypt": decrypt,
"encrypt": encrypt,
"getprojectpath": get_project_path,
"writefile": write_file,
}