Skip to content

Instantly share code, notes, and snippets.

@rainb3rry
Created December 15, 2022 18:37
Show Gist options
  • Save rainb3rry/6a59a2d0098a3d260f6f1aed63780f76 to your computer and use it in GitHub Desktop.
Save rainb3rry/6a59a2d0098a3d260f6f1aed63780f76 to your computer and use it in GitHub Desktop.
setTimeout(function() { // avoid java.lang.ClassNotFoundException
Java.perform(() => {
console.log('');
console.log('======');
console.log('[#] Android OKHttp logging by M4v3r1ck [#]');
console.log('======');
//Create a new instance of HttpLoggingInterceptor class
function getInterceptor() {
try {
const HttpLoggingInterceptor = Java.use('okhttp3.logging.HttpLoggingInterceptor');
const Level = Java.use('okhttp3.logging.HttpLoggingInterceptor$Level');
const MyLogger = Java.registerClass({
name: 'MyLogger',
superClass: Java.use('java.lang.Object'),
implements: [Java.use('okhttp3.logging.HttpLoggingInterceptor$Logger')],
methods: {
log: [{
returnType: 'void',
argumentTypes: ['java.lang.String'],
implementation: function(message) {
console.log(' [LOG] ' + message);
}
}]
},
});
var logInstance = HttpLoggingInterceptor.$new(MyLogger.$new());
//If you want to log at the logcat just change to the line bellow
//var logInstance = HttpLoggingInterceptor.$new();
logInstance.setLevel(Level.BODY.value);
return logInstance;
} catch (err) {
console.log("[-] Error creating interceptor")
console.log(err);
console.log(err.stack)
return null;
}
}
try {
var Builder = Java.use('okhttp3.OkHttpClient$Builder')
var build = Builder.build.overload();
build.implementation = function() {
console.log('[+] OkHttpClient$Builder ==> Adding log interceptor')
//Add the new interceptor before call the 'build' function
try {
this.addInterceptor(getInterceptor());
} catch (err) {
console.log('[-] OkHttpClient$Builder.addInterceptor error');
//console.log(err);
}
return build.call(this);
}
} catch (err) {
console.log('[-] OkHttpClient$Builder error');
//console.log(err);
}
});
}, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment