【问题标题】:Using xposed to hook a method with a custom class array as an argument使用 xposed 以自定义类数组作为参数挂钩方法
【发布时间】:2018-08-13 04:16:09
【问题描述】:

如何挂钩包含自定义类数组的方法?

[Lcom/samsung/android/uniform/widget/notification/NotificationItem;

这是 smali 参数。我可以使用XposedHelpers.findClass() 获取课程,但我无法创建它的数组..

【问题讨论】:

  • 好像是 ClassLoader 问题?

标签: android xposed


【解决方案1】:

试试这个。

Class<?> notificationItemClass = Class.forName("...NotificationItem");
Class<?> notificationItemClassArray = java.lang.reflect.Array.newInstance(notificationItemClass, 2).getClass();

这是一个演示:

package com.aegis.log.controller.open;

import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * Created by gallonyin on 2019/1/25.
 */
public class TestReflection {

  public static void main(String[] args) throws ClassNotFoundException,
    InstantiationException, IllegalAccessException,
    IllegalArgumentException, SecurityException,
    InvocationTargetException, NoSuchMethodException {

    Class<?> relativeClass = Class.forName("com.aegis.log.controller.judgetool.Relative");
    Object relativeFather = relativeClass.newInstance();
    Object relativeMother = relativeClass.newInstance();
    relativeClass.getMethod("setName", String.class).invoke(relativeFather,
      "father");
    relativeClass.getMethod("setName", String.class).invoke(relativeMother,
      "mother");

    Class<?> personClass = Class.forName("com.aegis.log.controller.judgetool.Person");
    Object personObject = personClass.newInstance();

    Object[] temp = (Object[]) Array.newInstance(relativeClass, 2);
    temp[0] = relativeFather;
    temp[1] = relativeMother;

    Class<?> relativeArrayClass = Array.newInstance(relativeClass, 2).getClass();
    Method setParents = personClass.getMethod("setParents", relativeArrayClass);
    setParents.invoke(personObject, relativeArrayClass.cast(temp));
    personClass.getMethod("getParents").invoke(personObject);
  }
}

public class Person {
  private Relative[] parents;

  public void getParents() {
    for (Relative r : parents)
      r.getName();
  }

  public void setParents(Relative[] parents) {
    this.parents = parents;
  }
}

public class Relative {
  private String name;

  public void getName() {
    System.out.println(name);
  }

  public void setName(String name) {
    this.name = name;
  }
}

【讨论】:

    【解决方案2】:

    试试这个:

    XposedHelpers.findAndHookMethod(class, "xxxMethod", "com.samsung.android.uniform.widget.notification.NotificationItem[]", new XC_MethodHook() {
                ...
            });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-05
      相关资源
      最近更新 更多