MCPcopy
hub / github.com/r0ysue/r0capture / initializeGlobals

Function initializeGlobals

script.js:31–87  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

29 return 0;
30}
31function initializeGlobals() {
32 var resolver = new ApiResolver("module");
33 var exps = [
34 [Process.platform == "darwin" ? "*libboringssl*" : "*libssl*", ["SSL_read", "SSL_write", "SSL_get_fd", "SSL_get_session", "SSL_SESSION_get_id"]], // for ios and Android
35 [Process.platform == "darwin" ? "*libsystem*" : "*libc*", ["getpeername", "getsockname", "ntohs", "ntohl"]]
36 ];
37 // console.log(exps)
38 for (var i = 0; i < exps.length; i++) {
39 var lib = exps[i][0];
40 var names = exps[i][1];
41 for (var j = 0; j < names.length; j++) {
42 var name = names[j];
43 // console.log("exports:" + lib + "!" + name)
44 var matches = resolver.enumerateMatchesSync("exports:" + lib + "!" + name);
45 if (matches.length == 0) {
46 if (name == "SSL_get_fd") {
47 addresses["SSL_get_fd"] = 0;
48 continue;
49 }
50 throw "Could not find " + lib + "!" + name;
51 }
52 else if (matches.length != 1) {
53 // Sometimes Frida returns duplicates.
54 var address = 0;
55 var s = "";
56 var duplicates_only = true;
57 for (var k = 0; k < matches.length; k++) {
58 if (s.length != 0) {
59 s += ", ";
60 }
61 s += matches[k].name + "@" + matches[k].address;
62 if (address == 0) {
63 address = matches[k].address;
64 }
65 else if (!address.equals(matches[k].address)) {
66 duplicates_only = false;
67 }
68 }
69 if (!duplicates_only) {
70 throw "More than one match found for " + lib + "!" + name + ": " + s;
71 }
72 }
73 addresses[name] = matches[0].address;
74 }
75 }
76 if (addresses["SSL_get_fd"] == 0) {
77 SSL_get_fd = return_zero;
78 } else {
79 SSL_get_fd = new NativeFunction(addresses["SSL_get_fd"], "int", ["pointer"]);
80 }
81 SSL_get_session = new NativeFunction(addresses["SSL_get_session"], "pointer", ["pointer"]);
82 SSL_SESSION_get_id = new NativeFunction(addresses["SSL_SESSION_get_id"], "pointer", ["pointer", "pointer"]);
83 getpeername = new NativeFunction(addresses["getpeername"], "int", ["int", "pointer", "pointer"]);
84 getsockname = new NativeFunction(addresses["getsockname"], "int", ["int", "pointer", "pointer"]);
85 ntohs = new NativeFunction(addresses["ntohs"], "uint16", ["uint16"]);
86 ntohl = new NativeFunction(addresses["ntohl"], "uint32", ["uint32"]);
87}
88initializeGlobals();

Callers 1

script.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected