我正在使用Java Instrumentation + Javaassit构建一个探查器,以拦截所有方法,构造函数调用。我还想拦截Class Field访问(希望监视静态字段数据以防止滥用)。
private void getAppRam() {
String DeviceModel = android.os.Build.MODEL;
String DeviceName = android.os.Build.MANUFACTURER;
String sdk = Build.VERSION.RELEASE;
System.out.println("DeviceModel...." + DeviceModel);
System.out.println("DeviceName ...." + DeviceName);
System.out.println("sdk ...." + sdk);
ActivityManager actManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo();
actManager.getMemoryInfo(memInfo);
long totalMemory = memInfo.totalMem / (1024 * 1024);
System.out.println("ram...." + totalMemory);
}
这有可能拦截他们吗?在此先感谢
答案 0 :(得分:1)
Javassist的FieldAccess具有方法replace,用您自己的代码替换字段访问。我想这可以用来实现您想要的。
另请参阅http://www.javassist.org/html/javassist/expr/ExprEditor.html