-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAndroid-Base64-CaptureEncode.js
42 lines (40 loc) · 1.23 KB
/
Android-Base64-CaptureEncode.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
Java.perform(function () {
// Get a class handler of the Base64 class
// https://developer.android.com/reference/android/util/Base64
const base64 = Java.use('android.util.Base64');
// Overload the method "encodeToString" to capture the input parameters
base64.encodeToString.overload('[B','int').implementation = function (input, flags) {
// Log the successful hook to fridas console
console.log('[+] new Base64 operation found!');
// Log the Base64 input to the console after converting it to a string
console.log('Content: '+stringFromUTF8Array(input));
// Call the original function to keep the app working
return this.encodeToString(input, flags);
}
});
function stringFromUTF8Array(data)
{
const extraByteMap = [ 1, 1, 1, 1, 2, 2, 3, 0 ];
var count = data.length;
var str = "";
for (var index = 0;index < count;)
{
var ch = data[index++];
if (ch & 0x80)
{
var extra = extraByteMap[(ch >> 3) & 0x07];
if (!(ch & 0x40) || !extra || ((index + extra) > count))
return null;
ch = ch & (0x3F >> extra);
for (;extra > 0;extra -= 1)
{
var chx = data[index++];
if ((chx & 0xC0) != 0x80)
return null;
ch = (ch << 6) | (chx & 0x3F);
}
}
str += String.fromCharCode(ch);
}
return str;
}