引言
最近要开发一个相机小视频的功能。可以直接分享到WeChat上,和vivo相机的小视频模式类似。网上so了很多关于微信小视频开放接口,无奈没有可用的资料,就想反编译vivoCamera,看看它关于这方面的实现。
准备工作
- 找到一个vivo xplay5的样机
- 打开adb调试,查找vivoCamera的包名。
adb shell dumpsys activity | grep camera
127|shell@PD1522A:/system/priv-app $ dumpsys activity | grep camera
#15: BroadcastRecord{4135232 u0 com.android.camera.ACTION_START_PREVIEW}
act=com.android.camera.ACTION_START_PREVIEW flg=0x10
#16: BroadcastRecord{3f16b83 u0 com.android.camera.ACTION_OPEN_CAMERA}
act=com.android.camera.ACTION_OPEN_CAMERA flg=0x10 (has extras)
-> 22051:com.android.camera/u0a87 s1/1 u0/0 +5h25m44s214ms
-> 22051:com.android.camera/u0a87
* Recent #0: TaskRecord{bcf135 #38 A=com.android.camera.CameraActivity U=0 sz=1}
TaskRecord{bcf135 #38 A=com.android.camera.CameraActivity U=0 sz=1}
Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x30200000 cmp=com.android.camera/.CameraActivity }
Hist #0: ActivityRecord{1fedc4f u0 com.android.camera/.CameraActivity t38}
Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x30200000 cmp=com.android.camera/.CameraActivity bnds=[1067,2216][1395,2546] }
ProcessRecord{a00ae2f 22051:com.android.camera/u0a87}
TaskRecord{bcf135 #38 A=com.android.camera.CameraActivity U=0 sz=1}
Run #16: ActivityRecord{1fedc4f u0 com.android.camera/.CameraActivity t38}
mResumedActivity: ActivityRecord{1fedc4f u0 com.android.camera/.CameraActivity t38}
mFocusedActivity: ActivityRecord{1fedc4f u0 com.android.camera/.CameraActivity t38}
Proc # 0: fore F/A/T trm: 0 22051:com.android.camera/u0a87 (top-activity)
com.qti.service.colorservice/.ColorServiceApp<=Proc{22051:com.android.camera/u0a87}
发现vivo相机的包名为com.android.camera。
-
通过包名找到apk所在系统的位置
adb shell pm path com.android.camerashell@PD1522A:/system/priv-app $ pm path com.android.camera package:/system/app/VivoCamera/VivoCamera.apk
导出adb pull /system/app/VivoCamera。
反编译流程
常见反编译工具
- jeb
- apktool
- smali
- apkdb,http://idoog.me/?p=2933
- dextra,http://newandroidbook.com/tools/dextra.html
- SVADeodexerForArt,https://forum.xda-developers.com/galaxy-s5/general/tool-deodex-tool-android-l-t2972025
JEB
说明:
jadx
官方下载:github搜索jadx
jadx依赖dx.jar,使用jadx反编译Android7.0会出现错误,建议更新dx.jar,该包位于AOSP/out/host/linux-x86/framework/dx.jar
拷贝该文件覆盖jadx/lib/dx-1.10.jar
jadx -d jadx --show-bad-code system@priv-app@SystemUI@SystemUI.apk@classes.dex
反编译较大包时,jadx会卡住,请在jadx脚本开头中加入如下代码:
JAVA_OPTS="-server -Xms1024m -Xmx8192m -XX:PermSize=256m -XX:MaxPermSize=1024m"
更多用法参考其自带help
OTA提取dex
dextra,http://newandroidbook.com/tools/dextra.html
用法是:
dextra.ELF64 -dextract xxx.odex
更多用法参考其自带help
dex转smali
baksmali
地址:https://github.com/JesusFreke/smali
实操
逆向vivoCamera ,进入目录(从system/app/VivoCamera/ dump出来的):
$ tree
.
├── lib
│ └── arm
│ ├── libCameraShowYUV.so
│ ├── libivw30.so
│ ├── libjni_jpegutil.so
│ ├── libjni_tinyplanet.so
│ └── libvivoIvw36.so
├── oat
│ └── arm
│ └── VivoCamera.odex
└── VivoCamera.apk
1. 解压dex包
$ dextra.ELF64 -dextract oat/arm/VivoCamera.odex
M (PR3) OAT file (064)
Dex header @0x7f8f4139f71c (4318 classes) at 0x471c: /system/app/VivoCamera/VivoCamera.apk
Written to system@app@VivoCamera@VivoCamera.apk@classes.dex
2. 合并dex包到apk中
生成dex后,可使用jadx/jdeb/baksmali等工具直接反编译dex文件。但jadx支持直接反编译apk包,因此我们可以将dex重新合并到VivoCamera.apk中。命令如下
$ mv system@app@VivoCamera@VivoCamera.apk@classes.dex classes.dex
$ jar -uvf VivoCamera.apk classes.dex
adding: classes.dex(in = 5356484) (out= 2162623)(deflated 59%)
3. 反编译apk包
$ jadx -e --show-bad-code VivoCamera.apk
19:32:17 INFO - output directory: VivoCamera
19:32:17 INFO - loading ...
19:32:17 INFO - processing ...