在进行Android逆向分析的时候,经常需要进行动态调试栈回溯,查看Java函数的调用流程,Android的smali动态调试又不是很方便,因此使用Android的Java Hook的方法,打印Java函数调用堆栈信息辅助静态分析。
package com.xposeddemo;
import java.util.Map;
import android.util.Log;
import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam;
public class Module implements IXposedHookLoadPackage {
@Override
public void handleLoadPackage(LoadPackageParam lpparam) throws Throwable {
// 判断是否是要Hook的包名
if (lpparam.packageName.equals("com.lenovo.anyshare.gps")){
XposedBridge.log("Loaded App:" + lpparam.packageName);
// 查找要Hook的函数(需要打印堆栈调用的目标函数)
XposedHelpers.findAndHookMethod(
"com.lenovo.anyshare.frv", // 被Hook函数所在的类com.lenovo.anyshare.frv
lpparam.classLoader,
"a", // 被Hook函数的名称a
new XC_MethodHook(){
@Override
protected void beforeHookedMethod(MethodHookParam param)
throws Throwable {
// Hook函数之前执行的代码
//传入参数1
//XposedBridge.log("beforeHookedMethod userName:" + param.args[0]);
}
@Override
protected void afterHookedMethod(MethodHookParam param)
throws Throwable {
// Hook函数之后执行的代码
//函数返回值
//XposedBridge.log("afterHookedMethod result:" + param.getResult());
// 函数调用完成之后打印堆栈调用的信息
// 方法一:
Log.i("