smalidea是一款 IntelliJ IDEA/Android Studio的 smali 插件
条件
开启应用调试
(1)安装Smalidea插件
(2)要调试一个apk里面的dex代码,必须满足以下两个条件中的任何一个:
apk中的AndroidManifest.xml文件中的Application标签包含属性android:debuggable=”true”
/default.prop中ro.debuggable的值为1
可选方案:
apktool 反编译app 后在AndroidManifest.xml文件中插入android:debuggable=”true”
hook system debug (Xinstaller)
修改boot.img
最优: HOOK 方式
public class Debug implements IXposedHookLoadPackage {
public boolean debugApps =true;
public static final int DEBUG_ENABLE_DEBUGGER =0x1;
public String tag ="IDG";
@Override
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam)throwsThrowable {
if(lpparam.appInfo ==null||
(lpparam.appInfo.flags & (ApplicationInfo.FLAG_SYSTEM | ApplicationInfo.FLAG_UPDATED_SYSTEM_APP)) !=0){
return;
}
tag = tag + lpparam.packageName;
XposedBridge.hookAllMethods(Process.class,"start",newXC_MethodHook() {
@Override
protectedvoidbeforeHookedMethod(MethodHookParam param)throwsThrowable {
intid =5;
intflags = (Integer) param.args[id];
Log.d(tag,"flags is : "+flags);
if(debugApps) {
if((flags & DEBUG_ENABLE_DEBUGGER) ==0) {
flags |= DEBUG_ENABLE_DEBUGGER;
}
}
param.args[id] = flags;
Log.d(tag,"flags changed : "+flags);
}
});
}
}
调试步骤
(1)反编译获取smali代码 baksmali myapp.apk -o ~/projects/myapp/src
(2)在Intellidea中创建java工程。。经smali代码导入src文件夹下
(3)在DDMS中选中调试应用 ,或者
» adb shell am start -D -W -n com.zkj.guimi/.ui.SplashScreen(packageName/classname)
» adb shell ps |grep 查找进程ID 1 ↵
u0_a157 9879 242 883420 36360 ffffffff 00000000 S com.zkj.guimi
» adb forward tcp:8700 jdwp:9879
(4)IDEA 新建远程调试(Run->Edit Configurations),更改debug端口为8700
(5)设置断点 Run->Debug