rovo89 / XposedBridge

The Java part of the Xposed framework.
3.91k stars 1.1k forks source link

Can XposedBridge replace a non Java, native CPP method? #52

Closed StevenStanleyBayes closed 9 years ago

StevenStanleyBayes commented 9 years ago

I realise this place is for non programming questions and I think this question is in regards of the capabilities of the XposedBridge and not so much of programming.

Android has a lot of native language CPP functions / methods. I would like to ask whether XposedBridge can hook and or replace these too. XposedBridge needs to be given the package, the class and the name of the Java method. Can XposedBridge replace CPP functions and what does XposedBridge need to be given instead of these?

In case possible, a simple example would be very nice, otherwise, just yes or no answer would shine some light.

Thanks.

manvir-singh commented 9 years ago

Already answered: http://forum.xda-developers.com/showpost.php?p=54196552&postcount=3

StevenStanleyBayes commented 9 years ago

Thanks. I have searched intensively but unable to find this post. However, the post does not give much of a detail of how this can be done. Do you have any simple example?

manvir-singh commented 9 years ago

You may want to read the full post http://forum.xda-developers.com/xposed/xposed-hook-native-methods-t2817927/post54196552#post54196552

StevenStanleyBayes commented 9 years ago

OK. Thanks. I have just read the whole post. I understand, from the post, the answer is :

No, unless these are declared in and called by Java code.

In other words, the java package and class and name of the declared there method / function can be hooked and replaced but not the CPP originals.

There is some confusion because the first answer was yes, but not as simple.

Thanks.

rovo89 commented 9 years ago

It depends on what you see as a "native method". In that thread, the question was explicitely about JNI methods, i.e. those declared in and used by Java code, but implemented in (usually) C++. Those can be hooked just like "normal" Java methods. The hint about System.loadLibrary() shouldn't be necessary anymore on Android 5.0 and later.

However, it seems that you want to hook pure C++ methods, e.g. used by the various daemons, drivers and command line tools. Those cannot be hooked with Xposed.

StevenStanleyBayes commented 9 years ago

Thank you. As usually, your answers are immediate and clear. Thank you for this excellent service.

You are right, I want to go as close to the hardware as possible. I realise this is not possible. Because I am interested in Android KitKat 4.4.4, I wonder whether there is any simple example anywhere which uses the hint System.loadLibrary().

Thanks anyway.