search

Home  >  Q&A  >  body text

java - Xposed hook函数内有匿名内部类该怎么写?

sensorManager.registerListener(new SensorEventListener() {
    @Override
    public void onSensorChanged(SensorEvent event) {
    
    }
    
    @Override
    public void onAccuracyChanged(Sensor sensor, int accuracy) {
    
    }
    }, sensorGravity, SensorManager.SENSOR_DELAY_NORMAL);

怎么hook这里的SensorEventListener?


目标是hook住android.hardware.SensorManager.registerListener(SensorEventListener listener, Sensor sensor, int samplingPeriodUs) listener里的onSensorChanged(SensorEvent event)这个函数.

XposedHelpers.findAndHookMethod("android.hardware.SensorManager", loadPackageParam.classLoader, "registerListener", SensorEvent.class, new XC_MethodHook() {
    @Override
    protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
        SensorEventListener event = (SensorEventListener) param.args[0];
    }
});

在官方教程里找不到描述这种hook的方法

黄舟黄舟2769 days ago1010

reply all(2)I'll reply

  • PHPz

    PHPz2017-04-17 17:35:02

    Personal test: Use dollar sign to connect inner classes, see:

    http://stackoverflow.com/questions/22528...

    reply
    0
  • 阿神

    阿神2017-04-17 17:35:02

    I don’t know about xposed (sweat), but anonymous classes in Java classes are processed as subclasses when compiled, and class files are generated independently, such as SensorManager$1.class. It is recommended that you study it from this perspective#🎜🎜 #

    reply
    0
  • Cancelreply