-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconscrypt.js
110 lines (97 loc) · 3.82 KB
/
conscrypt.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
108
109
110
var data = {};
function saveData(byteArray, offset, byteCount, hashCode, direction) {
var intArray = byteArrayToIntArray(byteArray, offset, byteCount);
if (hashCode in data) {
data[hashCode] = data[hashCode].concat(intArray);
} else {
data[hashCode] = intArray;
};
send(
{
TYPE: 'data',
DIRECTION: direction,
STREAM_ID: hashCode,
LENGTH: byteCount,
},
intArray
);
send(
{
TYPE: 'combined-data',
DIRECTION: direction,
STREAM_ID: hashCode,
LENGTH: data[hashCode].length,
},
data[hashCode]
);
}
function byteArrayToIntArray(array, offset, length) {
var result = [];
for (var i = offset; i < offset + length; ++i) {
result.push(
parseInt(
('0' + (array[i] & 0xFF).toString(16)).slice(-2), // binary2hex part
16
)
);
}
return result;
}
function processData(byteArray, offset, byteCount, outputStream, direction) {
saveData(byteArray, offset, byteCount, outputStream.hashCode(), direction);
/*
// Log current stack trace
Java.perform(function() {
console.log(Java.use("android.util.Log").getStackTraceString(Java.use("java.lang.Exception").$new()))
});
*/
}
Java.perform(() => {
console.log("Starting javascript");
console.log(`Android version: ${Java.androidVersion}`);
const ActivityThread = Java.use('android.app.ActivityThread');
const processName = ActivityThread.currentProcessName();
if (processName === 'org.thoughtcrime.securesms') {
// Signal loads Conscrypt differently
var conscrypt_id = 'org.conscrypt';
} else {
var conscrypt_id = 'com.android.org.conscrypt';
}
// Android 8 Conscrypt
const FileDescriptorOutputStream = Java.use(conscrypt_id + '.ConscryptFileDescriptorSocket$SSLOutputStream');
FileDescriptorOutputStream.write.overload('[B', 'int', 'int').implementation = function(byteArray, offset, byteCount) {
processData(byteArray, offset, byteCount, this, 'sent');
this.write(byteArray, offset, byteCount);
}
const FileDescriptorInputStream = Java.use(conscrypt_id + '.ConscryptFileDescriptorSocket$SSLInputStream');
FileDescriptorInputStream.read.overload('[B', 'int', 'int').implementation = function(byteArray, offset, byteCount) {
var ret = this.read(byteArray, offset, byteCount);
processData(byteArray, offset, byteCount, this, 'received');
return ret;
}
// Android 12 Conscrypt
const EngineSocketOutputStream = Java.use(conscrypt_id + '.ConscryptEngineSocket$SSLOutputStream');
EngineSocketOutputStream.write.overload('[B', 'int', 'int').implementation = function(byteArray, offset, byteCount) {
processData(byteArray, offset, byteCount, this, 'sent');
this.write(byteArray, offset, byteCount);
}
const EngineSocketInputStream = Java.use(conscrypt_id + '.ConscryptEngineSocket$SSLInputStream');
EngineSocketInputStream.read.overload('[B', 'int', 'int').implementation = function(byteArray, offset, byteCount) {
var ret = this.read(byteArray, offset, byteCount);
processData(byteArray, offset, byteCount, this, 'received');
return ret;
}
/*/ Used by WhatsApp
const SocketOutputStream = Java.use('java.net.SocketOutputStream');
SocketOutputStream.socketWrite.overload('[B', 'int', 'int').implementation = function(byteArray, offset, byteCount) {
processData(byteArray, offset, byteCount, this, 'sent');
this.socketWrite(byteArray, offset, byteCount);
}
const SocketInputStream = Java.use('java.net.SocketInputStream');
SocketInputStream.socketRead0.overload('java.io.FileDescriptor', '[B', 'int', 'int', 'int').implementation = function(fd, byteArray, offset, byteCount, timeout) {
var ret = this.socketRead0(fd, byteArray, offset, byteCount, timeout);
processData(byteArray, offset, byteCount, this, 'received');
return ret;
}*/
console.log("Finished javascript");
});