一.安装smalidea
https://github.com/JesusFreke/smali/wiki/smalidea
1. 进入IntelliJ IDEA/Android Studio开始安装插件,进入Settings->Plugins点击Install plugin from disk选中下载好的压缩包
2. apply->restart Android Studio
3. 该调试方法的原理
采用 hook 方式达到开启所有应用调试的目的,xposed 插件代码如下
publicclassDebugimplementsIXposedHookLoadPackage {
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
protected void before HookedMethod(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);
}
});
}
}
二.安装调试工具
安装Xposed框架
1.下载相关工具
XposedInstaller下载
http://repo.xposed.info/module/de.robv.android.xposed.installer
XposedBridged.jar下载
https://github.com/rovo89/XposedBridge/releases
2.安装XposedInstaller并激活
激活步骤: 启动XposedInstaller -> 框架 -> 安装更新 ->模拟器重启 (ps:模拟器会直接屏幕黑掉,直接结束进程即可,不行就反复试几下 )
激活后这里会有绿色的数字信息

安装XInstaller
1.XInstaller下载地址
XInstaller源码
https://github.com/pylerSM/XInstaller
XInstaller APK下载
http://repo.xposed.info/module/com.pyler.xinstaller
2.安装后启动一下,并在Xposed的模块中勾选,重启系统

3.配置XInstaller
3.1启动砖家模式

3.2设置调试应用
其他设置->调试应用

三.项目设置
1.生成smali文件
baksmali-2.0.5.jar 360.apk -o 360/projects/360/src
2.Android Studio导入项目
启动Android Studio->File->New->Import Project
选择上面生成的路径,选定src的上层目录

选择Create Project from existing sources

选择Make Directory AS->Sources Root

File->Project Structure 选择对应的SDK版本

配置调试选项
Run->Edit Configurations

四.开始调试
1. 方法一: 使用DDMS进行调试(一定要开启DDMS)
真机
a.勾选USB调试
b勾选USB调试通知
c.在开发者选项中->选择调试的应用->选择你要调试的程序->勾选等待调试器
d.启动程序,程序会停在等待调试器界面
此时ddms可以看到

Android Studio中对代码下好断点->Run->Debug->DebugOnly即可开始调试
Console控制台输出
Connected to the target VM, address: 'localhost:8700', transport: 'socket'
调试截图如下:

2. 方法二:使用adb调试
在AndroidManifest.xml得到主Activity如下:
com.qihoo.antivirus.desktopclean.ui.DesktopQuickCleanActivity
调试启动目标程序
adb shell am start -D -W -n com.qihoo.antivirus/.desktopclean.ui.DesktopQuickCleanActivity
设置端口转发
adb shell ps | grep antivirus
u0_a36 5766 154 907116 29496 ffffffff b7544d11 S com.qihoo.antivirus
adb forward tcp:8700 jdwp:5766

PS:使用Windows自带的cmd将会找不到grep, 如果一定要用cmd,可以把cygwin和mingw64的路径添加到环境变量
Android Studio中对代码下好断点->Run->Debug->DebugOnly即可开始调试
实际测试方法二Droid4x上可以断下来
网友评论