hook java.io.InputStream, + Performance Tweak

This commit is contained in:
iddoeldor 2018-08-08 02:14:53 +03:00 committed by GitHub
parent 6e2a8ac450
commit 86bf7f4af9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -19,6 +19,7 @@
- [Webview URLS](#webview-urls)
- [Await for specific module to load](#await-for-condition)
- [Android make Toast](#android-make-toast)
- [Hook java io InputStream](#hook-java-io-inputstream)
- [TODO list](#todos)
#### Intercept and backtrace low level open
@ -421,6 +422,45 @@ Java.scheduleOnMainThread(function() {
});
```
#### Hook java io InputStream
```
function binaryToHexToAscii(array, readLimit) {
var result = [];
// read 100 bytes #performance
readLimit = readLimit || 100;
for (var i = 0; i < readLimit; ++i) {
result.push(String.fromCharCode( // hex2ascii part
parseInt(
('0' + (array[i] & 0xFF).toString(16)).slice(-2), // binary2hex part
16
)
));
}
return result.join('');
}
function hookInputStream() {
Java.use('java.io.InputStream')['read'].overload('[B').implementation = function(b) {
// execute original and save return value
var retval = this.read(b);
var resp = binaryToHexToAscii(b);
// conditions to not print garbage packets
var reExcludeList = new RegExp(['Mmm'/*, 'Ping' /*, ' Yo'*/].join('|'));
if ( ! reExcludeList.test(resp) ) {
console.log(resp);
}
var reIncludeList = new RegExp(['AAA', 'BBB', 'CCC].join('|'));
if ( reIncludeList.test(resp) ) {
send( binaryToHexToAscii(b, 1200) );
}
return retval;
};
}
// Main
Java.perform(hookInputStream);
```
#### TODOs
- Add GIFs & docs
- Add links to /scripts