You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.
Hi guys, I'm trying to hook the constructor of okhttp3.OkHttpClient$Builder in order to add an interceptor that converts any OkHttp call into a curl call and log it (see Ok2Curl library by @mrmike). But I'm having problems with reflection, say I must haven't understood it pretty well...
The idea is to call .addInterceptor(okhttp3.Interceptor) method JUST after the OkHttpClient$Builder instance has been constructed, but it's more painful than expected. (See code and code comments for further details)
@OverridepublicvoidhandleLoadPackage(XC_LoadPackage.LoadPackageParamlpparam) throwsThrowable {
ClassbuilderClass = XposedHelpers.findClassIfExists("okhttp3.OkHttpClient$Builder", lpparam.classLoader);
if(builderClass != null){
XposedBridge.hookAllConstructors(builderClass, newXC_MethodHook() {
@OverrideprotectedvoidafterHookedMethod(MethodHookParamparam) throwsThrowable {
CurlInterceptorinterceptor = newCurlInterceptor(newLoggable() {
@Overridepublicvoidlog(Stringmessage) {
Log.v("Ok2Curl", message);
}
});
/* Attempt nº1: Cannot do it this way, it throws an exception because there's not (and there's actually not) a method 'okhttp3.OkHttpClient$Builder#addInterceptor(CurlInterceptor)' since CurlInterceptor is from the Ok2Curl library. Maybe the '.callMethod()' cannot make implicit casting? */Objectattempt1 = XposedHelpers.callMethod(param.thisObject, "addInterceptor", interceptor);
/* Attempt nº2: Declaring explicitly the argument classes that addInterceptor(···) has, does not help. I get an exception: it could not find an ".addInterceptor(java.lang.Class, ...CurlInterceptor)" method, so this means Interceptor.class was taken as one of the method arguments and not as an argument type. Anyways, given the results from attempt 1, it seems that .callMethod() will not do implicit casting whatsoever... */Objectattempt2 = XposedHelpers.callMethod(param.thisObject, "addInterceptor", Interceptor.class, interceptor);
/* Attempt nº3: Explicit casting from CurlInterceptor to okhttp3.Interceptor did not help... java.lang.NoSuchMethodError: okhttp3.OkHttpClient$Builder#addInterceptor(com.moczul.ok2curl.CurlInterceptor)#bestmatch */Objectattempt3 = XposedHelpers.callMethod(param.thisObject, "addInterceptor", (okhttp3.Interceptor) interceptor);
}
});
}
}
Thanks in advance!
The text was updated successfully, but these errors were encountered:
ElJaviLuki
changed the title
Casting and reflection issues in a method argument. okhttp3.OkHttpClient$Builder.addInterceptor(···)
Casting and reflection issues in a method argument. okhttp3.OkHttpClient$Builder;->addInterceptor(···)Sep 21, 2021
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Hi guys, I'm trying to hook the constructor of
okhttp3.OkHttpClient$Builder
in order to add an interceptor that converts any OkHttp call into a curl call and log it (see Ok2Curl library by @mrmike). But I'm having problems with reflection, say I must haven't understood it pretty well...The idea is to call
.addInterceptor(okhttp3.Interceptor)
method JUST after theOkHttpClient$Builder
instance has been constructed, but it's more painful than expected. (See code and code comments for further details)Thanks in advance!
The text was updated successfully, but these errors were encountered: