个人实战经验:
1.apktool_2.0.3.jar 之前的版本可以使用-d选项,重打包后,使用Android Studio调试,可以直接在变量窗口看到v0,v1,v2等,个人感觉可以替代Netbeans,Ecllipse.
2.apktool_2.0.3.jar之后的版本不可以使用-d选项.原生APK,不需要重打包,可以使用Android Studio调试,可以在监控窗口看到v0,v1,v2,p0等。
注意:smalidea-0.03插件在Android Studio 1.5系列,支持单步调试。Android Studio 2.0系列不可以单步调试,会发生错乱跳或者崩溃。
3.ecllipse的smali调试,必须要使用-d选项重打包。
参考:http://drops.wooyun.org/tips/7181
参考:http://www.tuicool.com/articles/uumiQfA
参考:http://www.bubuko.com/infodetail-1419699.html
smalidea是一款 IntelliJ IDEA/Android Studio的 smali 插件
Install plugin from disk
选中下载好的压缩包.apply
要调试一个apk里面的dex代码,必须满足以下两个条件中的任何一个:
可选方案:
个人觉得改 boot.img和二次打包比较麻烦,所以这里采用 hook 方式达到开启所有应用调试的目的,xposed 插件代码如下
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) throws Throwable {
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", new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
/*
public static final Process.ProcessStartResult start(String processClass,
String niceName,
int uid,
int gid,
int[] gids,
int debugFlags,
int mountExternal,
int targetSdkVersion,
String seInfo,
String[] zygoteArgs)Start a new process.
If processes are enabled, a new process is created and the static main() function of a processClass is
executed there. The process will continue running after this function returns.
If processes are not enabled, a new thread in the caller's process is created and main() of processClass
called there.
The niceName parameter, if not an empty string, is a custom name to give to the process instead of using
processClass. This allows you to make easily identifyable processes even if you are using the same base
processClass to start them.
Parameters:
processClass - The class to use as the process's main entry point.
niceName - A more readable name to use for the process.
uid - The user-id under which the process will run.
gid - The group-id under which the process will run.
gids - Additional group-ids associated with the process.
debugFlags - Additional flags.
targetSdkVersion - The target SDK version for the app.
seInfo - null-ok SE Android information for the new process.
zygoteArgs - Additional arguments to supply to the zygote process.
Returns:
An object that describes the result of the attempt to start the process.
Throws:
RuntimeException - on fatal start failure
*/
int id = 5;
int flags = (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);
}
});
}
}
效果如下图
如果遇到如下错误
Adb rejected connection to client
可以使用重启 adb server 来解决
adb kill-server adb start-server
注意:IDEA 14.1及以上版本才支持单步调试,Android Studio 1.5版本才支持单步调试
使用 baksmali 反编译应用
baksmali myapp.apk -o ~/projects/myapp/src
Android Studio导入项目
启动Android Studio->File->New->Import Project,选择上面生成的路径,选定src的上层目录
~/projects/myapp
选择Create project from existing sources
成功导入工程后右键点击 src 目录,即smali的顶级目录,设定Mark Directory As->Sources Root
打开Module setting
设置对应的 JDK
安装debug应用
adb install com.zkj.guimi.apk
找到debug应用进程,启动应用
如果不用 ddms 可以使用如下步骤:
» adb shell am start -D -W -n com.zkj.guimi/.ui.SplashScreen » adb shell ps |grep guimi 1 ↵ u0_a157 9879 242 883420 36360 ffffffff 00000000 S com.zkj.guimi » adb forward tcp:8700 jdwp:9879
在 IDEA 配置远程调试(Run->Edit Configurations),更改debug端口为8700
Run->Debug
Connected to the target VM, address: 'localhost:8700', transport: 'socket'
断点触发后就可以单步调试
http://www.kanxue.com/bbs/showthread.php?p=1338639
https://github.com/JesusFreke/smali/wiki/smalidea
https://github.com/pylerSM/XInstaller