本编转自于http://blog.csdn.net/betabin/article/details/10263951
用到的工具:
dex2jar (Google code)顾名思义,可以将APK转为Jar包
apktool (Google code)主要是解析APK里面各种资源,汉化组必备利器
jd-core-java (GitHub) 这个将Jar包反编译到Java
(小小吐槽下,jd-core这东西造福大众,不过没发布出来。其作者提到了“Release JD-Core is not a priority for me”,所以GitHub就有人顺应大众给出了个解决方案:“This is hack around the IntelliJ IDE plugin. It fakes the interfaces of the IDE, and provides access to JD-Core.”,给咱提供了批处理接口呀~。~)
大概步骤:
1、通过dex2jar,写个脚本去跑。把脚本翻到解压的dex2jar里面,设置apk的文件路径之后,自动去遍历生成各个apk的jar包,jar包存放在dex2jar文件夹下。(这里没找到输出位置选项,就自己拷贝出来吧……)
Windows下脚本如下:
- @echo off
- set apkSrcPath=F:\analysis\apkSrc
- for %%i in ("%apkSrcPath%\*.apk") do call "d2j-dex2jar.bat" "%%i"
在Ubuntu下脚本如下:
- #!/bin/bash
- author="BetaBin"
- echo $author is the author!
- apkPath="../apk/"
- for apk in "${apkPath}"*;
- do
- #call jd-core
- . d2j-dex2jar.sh "$apk"
- done
2、通过apktool,同样在windows下也写了个脚本来批处理。不过由于apktool生成的多余资源实验不需要,所以就另外写了个脚本去删除掉,只剩下AndroidManifest.xml。
生成资源的Windows脚本如下,放置到apktool解压文件夹内,设置apk的文件夹路径,然后跑完就能在该路径下得到资源文件夹了……(这里表示也没找到输出位置设置……)
- @echo off
- setlocal ENABLEDELAYEDEXPANSION
- ::Author:BetaBin
- set apkSrcPath=F:\analysis\apkSrc
- for %%i in ("%apkSrcPath%\*.apk") do (
- set tempname=%%i
- call "apktool.bat" d -f "%%i" "!tempname:~0,-4!"
- )
然后在上面输出文件夹内,我又写了个Python脚本来过滤掉多余资源,只保存xml。(如果脚本放到其他地方,把os.getcwd()替换了吧……我错了,我不该偷懒,该加个变量的……)
- #Author:BetaBin
- #Function: Clear rubbish files create by apktool
- import os
- import shutil
- for folder in os.listdir(os.getcwd()):
- if os.path.isdir(folder):
- for apkfile in os.listdir(os.getcwd()+ os.sep + folder):
- if cmp("AndroidManifest.xml", apkfile):
- rubbish = os.getcwd() + os.sep + folder + os.sep + apkfile
- print rubbish
- if os.path.isdir(rubbish):
- shutil.rmtree(rubbish)
- else:
- os.remove(rubbish)
3、还有最后一个脚本……也就是利用jd-core-java,来批量反编译。只是这东西“But this wrapper only supports Linux 64-bit.”,所以又得郁闷去配置一台Ubuntu 64-bits来跑下。make之后就可以用了,方法也很简单。直接给出批量脚本如下:(放置到jd-core-java文件夹下,修改输入输出,然后就跑了。)
- #!/bin/bash
- author="BetaBin"
- echo $author is the author!
- apkJarPath="../apkJar/"
- apkJavaPath="../apkJava/"
- for apkjar in "${apkJarPath}"*;
- do
- #delete apk jar path's prefix, like "../apkJar/".
- pathPrefixLen="${#apkJarPath}"
- jarName=${apkjar:pathPrefixLen}
- #delete apk jar path's suffix, like "-dex2jar.jar".
- appNameLen="${#jarName}"
- let appNameLen-=12
- appName=${jarName:0:$appNameLen}
- #call jd-core
- java -jar jd-core-java-1.0.jar "$apkjar" "$apkJavaPath/$appName"
- done
然后吧……把2和3步骤生成的文件夹合并就可以了。