折腾:
【未解决】从不同版本的小花生apk中反编译出包含业务逻辑代码的dex和jar包源码
期间,尝试去:
【未解决】dex2jar反编译dex后jar文件包含java代码:throw new VerifyError bad dex opcode
虽然没有解决问题,但是在此期间参考:
“由于大部分逆向工具都是线性读取字节码并解析,当遇到无效字节码时,就会引起反编译工具字节码解析失败。
我们可以插入无效字节码到DEX文件,但要保证该无效字节码永远不会被执行(否则您的程序就会崩溃了!)。
首先我们新建一个测试类。为了绕过Dalvik运行时代码验证,BadCode.java要保证不被调用。(否则运行app,会出现java.lang.verifyerror异常)”
->看来此处的(之前从v1.5的apk去hook出来的)dex文件,之前被使用这种办法,去处理,防止破解的?
->看到:
“Apktool:(很遗憾,新版本已经修复了这个错误)”
那去试试用apktool去试试?
参考前面自己的:
【已解决】用apktool,dex2jar,jd-gui去反编译安卓apk查看app源码
去试试
➜ v1.5 /Users/crifan/dev/dev_tool/android/reverse_engineering/apktool/apktool d ../../../apk/ xiaohuasheng.bkill.com-v1.5.apk I: Using Apktool 2.4.0 on xiaohuasheng.bkill.com-v1.5.apk I: Loading resource table... I: Decoding AndroidManifest.xml with resources... S: WARNING: Could not write to (/Users/crifan/Library/apktool/framework), using /var/folders/46/2hjxz38n22n3ypp_5f6_p__00000gn/T/ instead... S: Please be aware this is a volatile directory and frameworks could go missing, please utilize --frame-path if the default storage directory is unavailable I: Loading resource table from file: /var/folders/46/2hjxz38n22n3ypp_5f6_p__00000gn/T/1.apk I: Regular manifest package... I: Decoding file-resources... I: Decoding values */* XMLs... I: Baksmaling classes.dex... I: Copying assets and libs... I: Copying unknown files... I: Copying original files... ➜ v1.5 ll total 0 drwxr-xr-x 11 crifan staff 352B 3 18 15:15 xiaohuasheng.bkill.com-v1.5 ➜ v1.5 cd xiaohuasheng.bkill.com-v1.5 ➜ xiaohuasheng.bkill.com-v1.5 ll total 72 -rw-r--r-- 1 crifan staff 30K 3 18 15:15 AndroidManifest.xml -rw-r--r-- 1 crifan staff 2.3K 3 18 15:15 apktool.yml drwxr-xr-x 5 crifan staff 160B 3 18 15:15 assets drwxr-xr-x 6 crifan staff 192B 3 18 15:15 lib drwxr-xr-x 3 crifan staff 96B 3 18 15:15 libs drwxr-xr-x 4 crifan staff 128B 3 18 15:15 original drwxr-xr-x 27 crifan staff 864B 3 18 15:15 res drwxr-xr-x 10 crifan staff 320B 3 18 15:15 smali drwxr-xr-x 7 crifan staff 224B 3 18 15:15 unknown
然后去看解码出来的代码:
smali下面,是有目录结构的:
smali/com/huili/readingclub/ConversationListActivity.smali
然后去搜之前接口:
http://www.xiaohuasheng.cn:83/Reading.svc/parentChildReadingBookQuery2 new StringBuilder(" http://www.xiaohuasheng.cn:83/Reading.svc/voteBooklistBook/");
中包含的
Reading.svc
还真的可以搜到的:
const-string v5, " http://www.xiaohuasheng.cn:83/Reading.svc/queryBooklistForAddBook "
不过很明显,没有java源代码。
不过,对于此处,其实最关心的是:
api返回的json的解析的代码
-》希望找到其中的加了密的J如何解码的
继续研究,通过搜:Reading.svc
找到的:
smali/com/huili/readingclub/activity/tabfind/BookInfoActivity.smali
的代码是:
.method private getBookInfo()V .locals 7 .prologue .line 631 const-string v3, "http://www.xiaohuasheng.cn:83/Reading.svc/getServerBookInfo7" .line 633 .local v3, "url":Ljava/lang/String; new-instance v2, Lcom/google/gson/JsonObject; invoke-direct {v2}, Lcom/google/gson/JsonObject;-><init>()V .line 634 .local v2, "jsonObject":Lcom/google/gson/JsonObject; new-instance v0, Lcom/google/gson/JsonObject; invoke-direct {v0}, Lcom/google/gson/JsonObject;-><init>()V .line 635 .local v0, "dataObject":Lcom/google/gson/JsonObject; const-string v4, "userId" sget-object v5, Lcom/huili/readingclub/activity/MainActivity;->userId:Ljava/lang/String; invoke-virtual {v0, v4, v5}, Lcom/google/gson/JsonObject;->addProperty(Ljava/lang/String;Ljava/lang/String;)V .line 636 const-string v4, "bookId" iget v5, p0, Lcom/huili/readingclub/activity/tabfind/BookInfoActivity;->bookId:I invoke-static {v5}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer; move-result-object v5 invoke-virtual {v0, v4, v5}, Lcom/google/gson/JsonObject;->addProperty(Ljava/lang/String;Ljava/lang/Number;)V .line 637 const-string v4, "C" const/4 v5, 0x0 invoke-static {v5}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer; move-result-object v5 invoke-virtual {v2, v4, v5}, Lcom/google/gson/JsonObject;->addProperty(Ljava/lang/String;Ljava/lang/Number;)V .line 638 const-string v4, "J" invoke-virtual {v0}, Lcom/google/gson/JsonObject;->toString()Ljava/lang/String; move-result-object v5 invoke-virtual {v2, v4, v5}, Lcom/google/gson/JsonObject;->addProperty(Ljava/lang/String;Ljava/lang/String;)V .line 640 invoke-static {p0}, Lcom/huili/readingclub/utils/Const;->createAnimationDailog(Landroid/content/Context;)Landroid/app/Dialog; move-result-object v1 .line 641 .local v1, "dialog":Landroid/app/Dialog; sget-object v4, Lcom/lidroid/xutils/http/client/HttpRequest$HttpMethod;->POST:Lcom/lidroid/xutils/http/client/HttpRequest$HttpMethod; invoke-virtual {v2}, Lcom/google/gson/JsonObject;->toString()Ljava/lang/String; move-result-object v5 new-instance v6, Lcom/huili/readingclub/activity/tabfind/BookInfoActivity$13; invoke-direct {v6, p0, v1}, Lcom/huili/readingclub/activity/tabfind/BookInfoActivity$13;-><init>(Lcom/huili/readingclub/activity/tabfind/BookInfoActivity;Landroid/app/Dialog;)V invoke-static {p0, v4, v3, v5, v6}, Lcom/huili/readingclub/network/XutilsHttpClient;->sendHttpJson(Landroid/content/Context;Lcom/lidroid/xutils/http/client/HttpRequest$HttpMethod;Ljava/lang/String;Ljava/lang/String;Lcom/lidroid/xutils/http/callback/RequestCallBack;)V .line 686 return-void .end method
其中的:
C和J,就,很像是发送请求中的参数,或许也是返回json的解码中的C和J?
以及调用gson
com/google/gson/JsonObject
也就是发送或返回json解析时用到的json库
刚有点看懂,最后一句是:
invoke-static {p0, v4, v3, v5, v6}, Lcom/huili/readingclub/network/XutilsHttpClient;->sendHttpJson(Landroid/content/Context;Lcom/lidroid/xutils/http/client/HttpRequest$HttpMethod;Ljava/lang/String;Ljava/lang/String;Lcom/lidroid/xutils/http/callback/RequestCallBack;)V
很明显是调用http的库去发送请求,其中包括json参数
此处重点是找到如何解析返回的json数据
貌似相关代码是:
Lcom/lidroid/xutils/http/callback/RequestCallBack
所以现在是:
- 问题转换为
- smali如何转换为java
- 可尝试之前3.4版本的apktool去decodeapk看看结果如何
- 继续想办法尝试解决bad dex opcode的问题:
- 【未解决】dex2jar反编译dex后jar文件包含java代码:throw new VerifyError bad dex opcode
先继续看看:
【未解决】dex2jar反编译dex后jar文件包含java代码:throw new VerifyError bad dex opcode
后来继续分析代码,注意到了上面的smali中的
invoke-static {p0, v4, v3, v5, v6}, Lcom/huili/readingclub/network/XutilsHttpClient;->sendHttpJson(Landroid/content/Context;Lcom/lidroid/xutils/http/client/HttpRequest$HttpMethod;Ljava/lang/String;Ljava/lang/String;Lcom/lidroid/xutils/http/callback/RequestCallBack;)V
就是此处
com/huili/readingclub/network/XutilsHttpClient.java
的
public static void sendHttpJson(final Context context, final HttpRequest.HttpMethod httpMethod, final String s, final String s2, final RequestCallBack<String> requestCallBack) { if (!isNetWorkAvaiable(context)) { // new(com.lidroid.xutils.exception.HttpException.class) throw new VerifyError("bad dex opcode"); } new RequestParams(); throw new VerifyError("bad dex opcode"); }
即:
- 实际上已经知道了,smali的对应的java源代码了
- 无需再去找办法
- 但问题是,java代码中,代码补全,都是错误的:
- throw new VerifyError(“bad dex opcode”);
所以还是要去解决这个问题,才能看到真正的源码
才能找到返回的json中的J的解密算法
【总结】
此处,可以通过导出得到dex文件,然后再去dex转jar包,jar包转java源码的方式,得到源码,而无需从smali中转出源码。
详见:
【未解决】从不同版本的小花生apk中反编译出包含业务逻辑代码的dex和jar包源码