rovo89 / Xposed

The native part of the Xposed framework (mainly the modified app_process binary).
Other
7.45k stars 1.47k forks source link

Hooking method from Google Play Service Library #289

Open SebastianZimmeck opened 7 years ago

SebastianZimmeck commented 7 years ago

Edit: There is some confusion with getBirthday and setBirthday in the code below. However, that confusion is not the source of the problem.

I am trying to hook the [getBirthday](https://developers.google.com/android/reference/com/google/android/gms/ads/AdRequest.html#getBirthday()) method from the Google Play library. However, it seems that below code is not working. Any suggestions on what may be wrong would be appreciated.

    hookAllMethods(Class.forName("com.google.android.gms.ads.AdRequest"),
            "getBirthday", new XC_MethodHook() {

                // after method was called, log call to Xposed log
                @Override
                protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                    XposedBridge.log("Relevant API, " + lpparam.packageName);
                }
            });

I wrote an app to test the above code. The app works fine. However, the hook code above does not seem to detect invocation of the method. Here is some relevant app code (ignore location parts):

...
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;

public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
   ...
    }
    ...
    // Define a listener that responds to location updates
    LocationListener locationListener = new LocationListener() {
        public void onLocationChanged(Location location) {
         ...
            // Called when a new location is found by the network location provider.
            AdView mAdView = (AdView) findViewById(R.id.adView);
            AdRequest adRequest = new AdRequest.Builder()
   ...
                   .addTestDevice("<test device number>")
                   .setBirthday(new GregorianCalendar(1985, 3, 1).getTime())
   ...
hrhthegreat commented 7 years ago

Hello, Where did you try to hook the method? Maybe if you try to hook it at initZygote, It would work.

SebastianZimmeck commented 7 years ago

Thanks, @hrhthegreat. Are you referring to this API? How concretely would I change my code to try your suggestion?

hrhthegreat commented 7 years ago

Here is an example to hook android.content.ContextWrapper.getExternalFilesDir(String): First your class XXX implements IXposedHookZygoteInit Then @Override public void initZygote(IXposedHookZygoteInit.StartupParam startupParam) throws Throwable { XposedBridge.hookAllMethods(Class.forName("android.content.ContextWrapper"), "getExternalFilesDir", new XC_MethodHook() { @Override protected void beforeHookedMethod(MethodHookParam param) throws Throwable { XposedBridge.log("Before -- " + param.args[0]); } @Override protected void afterHookedMethod(MethodHookParam param) throws Throwable { XposedBridge.log("After -- " + param.args[0]); } }); }

SebastianZimmeck commented 7 years ago

@hrhthegreat, I implemented code according to your example. However, it does not seem to work.