利用xposed自动获得支付宝个人收款二维码链接和收款记录

一、说明

       现在的App一般都会带有支付功能,而现在比较流行的支付一般有支付宝、微信、银行卡等,一般情况下,应用开发者会直接对接支付宝、微信或者第三方支付公司的Api,以完成支付,但是都需要收取不小的费率,于是,有的第三方支付平台就想到了钻空子的方法,利用一些特殊的手段获得收款二维码以及收款记录,这样就可以绕过支付平台完成支付过程了,本篇文章的目的就是分析如何完成这样一个流程,本文的意图只有一个就是通过分析app学习更多的逆向技术,如果有人利用本文知识和技术进行非法操作进行牟利,带来的任何法律责任都将由操作者本人承担,和本文作者无任何关系,最终还是希望大家能够秉着学习的心态阅读此文:想获得支付宝的个人收款二维码,和用户最近的收款记录,于是研究了一下方法,最终用xposed解决了。流程如下:

1、获得收款二维码链接流程

       服务器推送金额和备注任务到xposed插件(或者xposed插件主动请求任务)--》xposed插件发送广播通知支付宝--》支付宝打开设置金额页面并自动设置金额和备注,点击确认

       --》xposed hook支付宝处理收款二维码链接的回调方法--》获得收款链接--》发送广播将收款链接回传给xposed插件--》xposed插件将二维码链接发送给服务器

2、获得账单信息流程

       服务器推送账单任务到xposed插件(或者xposed插件主动请求任务)--》xposed插件发送广播通知支付宝获得账单消息--》支付宝打开账单页面获得账单信息--》xposed hook支付宝处理账单信息的回调方法-->获得账单信息--》发送广播将账单信息回传给xposed插件--》xposed插件将账单信息发送给服务器

3、自动登录流程

       服务器推送登录任务到xposed插件,信息包括支付宝账号和密码(或者xposed插件主动请求任务)--》xposed插件发送广播通知支付宝自动登录--》支付宝打开登录页面自动设置账号和密码,点击登录--》xposed hook支付宝登录的回调方法-->获得登录状态(是否登录成功)--》发送广播将登录状态回传给xposed插件--》xposed插件将登录状态发送给服务器

4、自动退出登录流程

       服务器推送退出登录任务到xposed插件(或者xposed插件主动请求任务)--》xposed插件发送广播通知支付宝退出登录--》xposed调用支付宝退出登录的代码完成退出任务--》发送广播通知xposed插件退出任务已经完成

5、获得当前登录用户信息流程

       服务器推送获得当前登录用户信息任务到xposed插件(或者xposed插件主动请求任务)--》xposed插件发送广播通知支付宝广播需要获得用户信息--》支付宝广播调用获得当前登录用户信息代码获得用户信息--》xposed发送广播通知插件获得了用户信息-->xposed插件广播接收用户信息--》xposed插件将用户信息发送给服务器

备注:网络通信的过程可以采用推送(websocket长连接)或者轮询(客户端主动发起http请求)的方式,只要能够正常让插件程序和服务端通信就行。

二、问题分析

1、支付宝的个人收钱界面

我用的支付宝版本是10.1.20

获得个人收钱二维码的流程如下:

打开支付宝主界面--》点击收钱---》进入到个人收钱界面--》点击设置金额--》进入设置金额界面--》设置金额和理由--》点击确定--》返回个人收钱界面并刷新收钱二维码

个人收钱界面如下:

设置金额界面如下:

点击个人收钱界面下面的收款记录,我们可以看到用户当天的收款情况,如下:

三、反编译支付宝并分析

反编译应用的方法可以参考:https://blog.csdn.net/xiao_nian/article/details/79391417,这篇文章反编译的是微信的apk,方法是一样的。

1、收款二维码

首先我们用hierarchy view查看设置金额页面,如下:

在反编译代码中找到PayeeQRSetMoneyActivity类,发现下面有一个方法定义如下:


     
     
  1. protected final void a (ConsultSetAmountRes paramConsultSetAmountRes)
  2. {
  3. runOnUiThread( new di( this, paramConsultSetAmountRes));
  4. }

而di的定义如下:


     
     
  1. package com.alipay.mobile.payee.ui;
  2. import android.content.Intent;
  3. import com.alipay.android.hackbyte.ClassVerifier;
  4. import com.alipay.mobile.commonui.widget.APInputBox;
  5. import com.alipay.mobile.payee.R.string;
  6. import com.alipay.mobile.payee.util.Logger;
  7. import com.alipay.transferprod.rpc.result.ConsultSetAmountRes;
  8. final class di
  9. implements Runnable
  10. {
  11. di(PayeeQRSetMoneyActivity paramPayeeQRSetMoneyActivity, ConsultSetAmountRes paramConsultSetAmountRes)
  12. {
  13. if (Boolean.FALSE.booleanValue()) {
  14. ClassVerifier.class.toString();
  15. }
  16. }
  17. public final void run ()
  18. {
  19. PayeeQRSetMoneyActivity.a.b( "call processConsultSetAmountRes(), ConsultSetAmountRes = " + this.a);
  20. if ( this.a != null)
  21. {
  22. if (! this.a.success) {
  23. break label140;
  24. }
  25. Intent localIntent = new Intent();
  26. localIntent.putExtra( "codeId", this.a.codeId);
  27. localIntent.putExtra( "qr_money", this.b.g);
  28. localIntent.putExtra( "beiZhu", this.b.c.getInputedText());
  29. localIntent.putExtra( "qrCodeUrl", this.a.qrCodeUrl);
  30. localIntent.putExtra( "qrCodeUrlOffline", this.a.printQrCodeUrl);
  31. this.b.setResult(- 1, localIntent);
  32. this.b.finish();
  33. }
  34. for (;;)
  35. {
  36. return;
  37. label140:
  38. this.b.alert( "", this.a.message, this.b.getString(R.string.payee_confirm), null, null, null);
  39. }
  40. }
  41. }

di的run方法里面主要是设置用户设置的金额,备注,服务端返回的二维码链接(qrCodeUrl)到intent中,然后再传递给个人收款(PayeeQRActivity)页面,可以看一下个人收款页面的onActivityResult方法


     
     
  1. public void onActivityResult (int paramInt1, int paramInt2, Intent paramIntent)
  2. {
  3. super.onActivityResult(paramInt1, paramInt2, paramIntent);
  4. if ((paramInt1 == 10) && (paramInt2 == - 1) && (paramIntent != null)) {}
  5. try
  6. {
  7. this.c = paramIntent.getStringExtra( "qr_money");
  8. this.d = paramIntent.getStringExtra( "beiZhu");
  9. this.i = paramIntent.getStringExtra( "qrCodeUrl");
  10. this.j = paramIntent.getStringExtra( "qrCodeUrlOffline");
  11. e();
  12. return;
  13. }
  14. catch (Exception paramIntent)
  15. {
  16. for (;;)
  17. {
  18. LoggerFactory.getTraceLogger().warn(a, paramIntent);
  19. }
  20. }
  21. }

这里主要是根据设置金额页面传过来的qrCodeUrl刷新收款二维码。

经过上面分析,可以有这样一种思路,当手机接收要生成收款二维码的请求后,可以启动支付宝的设置金额页面,然后在自动将金额和备注设置到页面上,最后在模拟点击确定按钮,这个时候支付宝就会将备注和金额发送给服务端,请求二维码链接,请求回来后,会调用PayeeQRSetMoneyActivity的

protected final void a(ConsultSetAmountRes paramConsultSetAmountRes)
     
     

方法,ConsultSetAmountRes paramConsultSetAmountRes里面有服务端返回的二维码链接信息,ConsultSetAmountRes类定义如下:


     
     
  1. package com.alipay.transferprod.rpc.result;
  2. import com.alipay.android.hackbyte.ClassVerifier;
  3. public class ConsultSetAmountRes
  4. extends RPCResponse
  5. {
  6. public String codeId;
  7. public String printQrCodeUrl;
  8. public String qrCodeUrl;
  9. public ConsultSetAmountRes ()
  10. {
  11. if (Boolean.FALSE.booleanValue()) {
  12. ClassVerifier.class.toString();
  13. }
  14. }
  15. public String toString ()
  16. {
  17. return "ConsultSetAmountRes{codeId='" + this.codeId + '\'' + ", qrCodeUrl='" + this.qrCodeUrl + '\'' + ", printQrCodeUrl='" + this.printQrCodeUrl + '\'' + "} " + super.toString();
  18. }
  19. }

其中qrCodeUrl即服务端返回的收款二维码链接,我们只需要hook设置金额界面(PayeeQRSetMoneyActivity)的

protected final void a(ConsultSetAmountRes paramConsultSetAmountRes)
     
     

方法,即可得到收款二维码链接


     
     
  1. // hook获得二维码url的回调方法
  2. findAndHookMethod( "com.alipay.mobile.payee.ui.PayeeQRSetMoneyActivity", lpparam.classLoader, "a",
  3. findClass( "com.alipay.transferprod.rpc.result.ConsultSetAmountRes", lpparam.classLoader), new XC_MethodHook() {
  4. @Override
  5. protected void afterHookedMethod (MethodHookParam param) throws Throwable {
  6. log( "com.alipay.mobile.payee.ui.PayeeQRSetMoneyActivity a" + "\n");
  7. Object consultSetAmountRes = param.args[ 0];
  8. String consultSetAmountResString = "";
  9. if (consultSetAmountRes != null) {
  10. consultSetAmountResString = (String) callMethod(consultSetAmountRes, "toString");
  11. }
  12. log( "consultSetAmountResString:" + consultSetAmountResString + "\n");
  13. }
  14. });

安装插件并重启手机后,打开支付宝界面,弹出非法操作弹框,并且不让操作支付宝界面,我擦,支付宝看来是有反hook机制的

那么如何解决呢?支付宝肯定也是通过代码去检查应用是否被hook了,我们只需要用xposed hook住支付宝的检测方法,并且修改返回值,这样就可以骗过支付宝了。代码如下:


     
     
  1. XposedHelpers.findAndHookMethod(Application.class,
  2. "attach",
  3. Context.class, new XC_MethodHook() {
  4. @Override
  5. protected void afterHookedMethod(XC_MethodHook.MethodHookParam param) throws Throwable {
  6. super.afterHookedMethod(param);
  7. Context context = (Context) param.args[0];
  8. ClassLoader appClassLoader = context.getClassLoader();
  9. securityCheckHook(appClassLoader);
  10. }
  11. });
  12. // 解决支付宝的反hook
  13. private void securityCheckHook(ClassLoader classLoader) {
  14. try {
  15. Class securityCheckClazz = XposedHelpers.findClass("com.alipay.mobile.base.security.CI", classLoader);
  16. XposedHelpers.findAndHookMethod(securityCheckClazz, "a", String.class, String.class, String.class, new XC_MethodHook() {
  17. @Override
  18. protected void afterHookedMethod(MethodHookParam param) throws Throwable {
  19. Object object = param.getResult();
  20. XposedHelpers.setBooleanField(object, "a", false);
  21. param.setResult(object);
  22. super.afterHookedMethod(param);
  23. }
  24. });
  25. XposedHelpers.findAndHookMethod(securityCheckClazz, "a", Class.class, String.class, String.class, new XC_MethodReplacement() {
  26. @Override
  27. protected Object replaceHookedMethod(XC_MethodHook.MethodHookParam param) throws Throwable {
  28. return (byte) 1;
  29. }
  30. });
  31. XposedHelpers.findAndHookMethod(securityCheckClazz, "a", ClassLoader.class, String.class, new XC_MethodReplacement() {
  32. @Override
  33. protected Object replaceHookedMethod(MethodHookParam param) throws Throwable {
  34. return (byte) 1;
  35. }
  36. });
  37. XposedHelpers.findAndHookMethod(securityCheckClazz, "a", new XC_MethodReplacement() {
  38. @Override
  39. protected Object replaceHookedMethod(MethodHookParam param) throws Throwable {
  40. return false;
  41. }
  42. });
  43. } catch (Error | Exception e) {
  44. e.printStackTrace();
  45. }
  46. }

在应用加载完成后hook住支付宝的检测是否被hook的方法,修改返回值。重新运行并重启手机,发现没有弹出非法操作弹框。

或者将securityCheckHook代码修改为如下代码也可以:


     
     
  1. // 解决支付宝的反hook
  2. private void securityCheckHook (ClassLoader classLoader) {
  3. try {
  4. Class securityCheckClazz = XposedHelpers.findClass( "com.alipay.mobile.base.security.CI", classLoader);
  5. XposedHelpers.findAndHookMethod(securityCheckClazz, "a", securityCheckClazz, Activity.class, new XC_MethodReplacement() {
  6. @Override
  7. protected Object replaceHookedMethod (MethodHookParam param) throws Throwable {
  8. return null;
  9. }
  10. });
  11. } catch (Error | Exception e) {
  12. }
  13. }

第一种方式是通过修改支付宝检查是否被hook的方法的返回值来骗过支付宝,第二种方式是通过替换支付宝弹出非法操作弹框方法执行逻辑的方式来屏蔽非法操作弹框弹出。

下面我们来分析一下怎样找到支付宝反hook的代码的,首先用hierarchy view查看非法操作弹框布局,如下:

反编译代码中全局搜索"非法操作,当前手机不安全!",没有找到对应的信息,全局搜索"R.id.message",发现有好几个地方有用到这个id,经过加入log测试都不是非法操作弹框使用的,换一种思路,既然是弹框,肯定会继承"android.app.Dialog"类,弹框显示的时候肯定会调用其"show"方法,我们只需要hook住"android.app.Dialog"类的"show"方法,然后打印出方法调用的堆栈来跟踪代码调用逻辑,不就可以知道支付宝弹框非法操作弹框的代码了吗?代码如下:


     
     
  1. findAndHookMethod(Dialog.class, "show", new XC_MethodHook() {
  2. @Override
  3. protected void afterHookedMethod (MethodHookParam param) throws Throwable {
  4. super.afterHookedMethod(param);
  5. try {
  6. throw new NullPointerException(); // 故意抛出一个异常以便打印堆栈信息
  7. } catch (Exception e) {
  8. XposedLogUtils.log( "securityCheckHook:" + Log.getStackTraceString(e)); // 打印堆栈信息分析代码的调用逻辑
  9. }
  10. }
  11. });

打开支付宝,弹出非法操作弹框后,可以看到以下日志:


     
     
  1. 06-02 15:26:23.449 I/Xposed ( 5792): securityCheckHook:java.lang.NullPointerException
  2. 06-02 15:26:23.449 I/Xposed ( 5792): at com.hhly.pay.alipay.Main$6.afterHookedMethod(Main.java:266)
  3. 06-02 15:26:23.449 I/Xposed ( 5792): at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:374)
  4. 06-02 15:26:23.449 I/Xposed ( 5792): at android.app.Dialog.show( <Xposed>)
  5. 06-02 15:26:23.449 I/Xposed ( 5792): at android.app.AlertDialog.show(AlertDialog.java:1246)
  6. 06-02 15:26:23.449 I/Xposed ( 5792): at android.app.AlertDialog$Builder.show(AlertDialog.java:1126)
  7. 06-02 15:26:23.449 I/Xposed ( 5792): at com.alipay.mobile.base.security.CI.a(CI.java:2463)
  8. 06-02 15:26:23.449 I/Xposed ( 5792): at com.alipay.mobile.base.security.CI$1.run(CI.java:114)
  9. 06-02 15:26:23.449 I/Xposed ( 5792): at android.os.Handler.handleCallback(Handler.java:739)
  10. 06-02 15:26:23.449 I/Xposed ( 5792): at android.os.Handler.dispatchMessage(Handler.java:95)
  11. 06-02 15:26:23.449 I/Xposed ( 5792): at android.os.Looper.loop(Looper.java:148)
  12. 06-02 15:26:23.449 I/Xposed ( 5792): at android.app.ActivityThread.main(ActivityThread.java:5666)
  13. 06-02 15:26:23.449 I/Xposed ( 5792): at java.lang.reflect.Method.invoke(Native Method)
  14. 06-02 15:26:23.449 I/Xposed ( 5792): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:775)
  15. 06-02 15:26:23.449 I/Xposed ( 5792): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
  16. 06-02 15:26:23.449 I/Xposed ( 5792): at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:107)

在日志中,我们可以看到,弹出非法操作的弹框的代码在"com.alipay.mobile.base.security.CI"的"a"方法中,打开lipay.mobile.base.security.CI"类,发现其中有如下方法定义:


     
     
  1.     static /* synthetic */ void a (CI ci, Activity activity) {
  2.         try {
  3.             // 显示非法操作弹框
  4.             Builder builder = new Builder(activity);
  5.             builder.setMessage( new String(Base64.decode( "6Z2e5rOV5pON5L2c77yM5b2T5YmN5omL5py65LiN5a6J5YWo77yB", 0), SymbolExpUtil.CHARSET_UTF8)); // 弹框提示内容,这里支付宝对提示文字进行了加密
  6.             builder.setPositiveButton( new String(Base64.decode( "56Gu5a6a", 0), SymbolExpUtil.CHARSET_UTF8), new c(ci, activity)); // 确认按钮
  7.             builder.setNegativeButton(R.string.detail, new d(ci, activity)); // 查看详情按钮
  8.             builder.setCancelable( false);
  9.             builder.show();
  10.         } catch (Exception e) {
  11.         }
  12.     }

其中确认按钮和查看详情按钮的点击事件最终都会调用到"com.alipay.mobile.base.security.CI"的下面方法:


     
     
  1. static /* synthetic */ void a (Activity activity) {
  2. try {
  3. AlipayApplication.getInstance().getMicroApplicationContext().exit(); // 退出应用
  4. } catch (Throwable th) {
  5. activity.finish(); // 退出应用
  6. System.exit(- 1);
  7. }
  8. }

在"com.alipay.mobile.base.security.CI"类中,还有一些检查是否被hook的方法,这里不具体分析了。

打开支付宝设置金额界面,设置金额和备注并点击确认,在xposed的log中可以看到以下日志:

04-10 17:11:09.647 I/Xposed  ( 7116): consultSetAmountResString:ConsultSetAmountRes{codeId='1804106465231431', qrCodeUrl='HTTPS://QR.ALIPAY.COM/FKX007021VPOLKNEMJRV5C', printQrCodeUrl='HTTPS://QR.ALIPAY.COM/FKX024385RNIN3NEYG3MDD'} RPCResponse{success=true, code='null', message='null'}
     
     

其中qrCodeUrl即收款二维码的支付链接,可以通过支付链接生成一个二维码,然后用支付宝客户端扫码即可向用户付款。

2、用户的收款记录

点击收款记录进入收款记录页面,发现是一个h5的页面,用Charles抓包工具抓包,发现收款记录的请求信息如下:


     
     
  1. url
  2. https://mbillexprod.alipay.com/enterprise/simpleTradeOrderQuery.json?beginTime=1523289600000&limitTime=1523376000000&pageSize=20&pageNum=1&channelType=ALL&ctoken=Sf6-M33mBqAxZZKNtUxr8BfA
  3. Referer
  4. https://render.alipay.com/p/z/merchant-mgnt/simple-order.html?beginTime=2018-04-10&endTime=2018-04-10&fromBill=true&channelType=ALL
  5. Cookie
  6. JSESSIONID=RZ13WJ3MUC3KkSLP9Hl0p50jfGkM8464mobilegwRZ13; session.cookieNameId=ALIPAYJSESSIONID; JSESSIONID=DB2789AEA01160BC04A582168D1E5F56; devKeySet={"apdidToken":"2TvE1a0uTmOgw66ehO7iVGekSrqGuHzgMYEaoqbZS\/mgr+jE6sCfYgEB"}; ALIPAYJSESSIONID=RZ13xrqd7gCXa98nzw9FjaXQj5XCC564mobilegwRZ13GZ00; ctoken=Sf6-M33mBqAxZZKNtUxr8BfA; zone=RZ13B; rtk=z02vdaECH12mfnbsHEjoVSXRlX+5t9MESl8UVjAWb0Pkt9vKHEK; ssl_upgrade=0; spanner=B6pqxJF5iOiQ90i4CSoZsIIs1GQtygX7
  7. Method
  8. GET
  9. User-Agent
  10. Mozilla/5.0 (Linux; U; Android 6.0.1; zh-CN; PRO 6 Plus Build/MMB29T) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/40.0.2214.89 UCBrowser/11.6.4.950 UWS/2.11.1.49 Mobile Safari/537.36 UCBS/2.11.1.49_180322095406 NebulaSDK/1.8.100112 Nebula AlipayDefined(nt:WIFI,ws:360|0|4.0) AliApp(AP/10.1.20.556) AlipayClient/10.1.20.556 Language/zh-Hans useStatusBar/true

其中beginTime表示查询的开始时间,limitTime表示查询的截止时间,将上面的信息用浏览器请求,发现能够返回数据,注意编辑请求设置上面的信息,如下:

 

 

 

 

 

经过尝试发现url中的ctoken可以去除,并且Referer可以简化成Referer: https://render.alipay.com/p/z/merchant-mgnt/simple-order.html,后面的参数全部去除,然后Cookie中只需要设置ALIPAYJSESSIONID就可以了,User-Agent可以不修改,最终请求信息如下:


     
     
  1. url: https://mbillexprod.alipay.com/enterprise/simpleTradeOrderQuery.json?beginTime=1522425600000&limitTime=1523289600000&pageSize=20&pageNum=1&channelType=ALL
  2. Cookie: ALIPAYJSESSIONID=RZ115A3WmakZXV6KlujBgYoG0I9HoS31mobilegwRZ11GZ00;
  3. Referer: https://render.alipay.com/p/z/merchant-mgnt/simple-order.html
  4. user-agent:Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1

也就是说,我们只需要ALIPAYJSESSIONID就可以获得到用户的收款记录了,查询时间可以自己设置,这个查询时间间隔好像不能超过1个月,超过了就会返回{"exception_marking":"搜索条件的范围过大"}。

我们再postman中模拟发送数据:

可以看到,我们拿到了支付宝的账单数据,但是账单数据里面没有备注,要想获得备注信息,我们还需要查询单个账单的详情,接口如下:


     
     
  1. https: / /tradeeportlet.alipay.com /wireless /tradeDetail.htm?tradeNo = 2018040421001004450524815080
  2. Cookie:ALIPAYJSESSIONID =RZ 13ik 0FHP 2IeX 6b 6LsZrDBFM 1yHW 464mobilegwRZ 13;

其中tradeNo表示订单号,这个在账单列表中有返回,其他的只需要设置Cookie就可以了,用Postman模拟请求:

返回的是一个html页面,我们再页面中可以找到订单的备注信息,上面的订单对应的备注信息是“收款”。

接下来我们只需要想办法获得ALIPAYJSESSIONID就可以了,在反编译代码中全局搜索“ALIPAYJSESSIONID”,发现AmnetUserInfo类中有相关的信息,ALIPAYJSESSIONID类中有如下代码:


     
     
  1. private static String getSessionid ()
  2. {
  3. for (;;)
  4. {
  5. try
  6. {
  7. if (MiscUtils.isInAlipayClient(ExtTransportEnv.getAppContext())) {
  8. continue;
  9. }
  10. str1 = "";
  11. }
  12. catch (Throwable localThrowable)
  13. {
  14. String str1;
  15. LogCatUtil.error( "ext_AmnetUserInfo", "getSessionid ex:" + localThrowable.toString());
  16. LogCatUtil.debug( "ext_AmnetUserInfo", "getSessionid return null");
  17. String str2 = "";
  18. continue;
  19. str2 = getSessionidFromCookiestr(CookieAccessHelper.getCookie((String)localObject, ExtTransportEnv.getAppContext()));
  20. if (TextUtils.isEmpty(str2)) {
  21. continue;
  22. }
  23. Object localObject = new java/lang/StringBuilder;
  24. ((StringBuilder)localObject).<init>( "sessionidFromCookieStore:");
  25. LogCatUtil.debug( "ext_AmnetUserInfo", str2);
  26. continue;
  27. }
  28. return str1;
  29. localObject = ReadSettingServerUrl.getInstance().getGWFURL(ExtTransportEnv.getAppContext());
  30. str1 = getSessionidFromCookiestr(GwCookieCacheHelper.getCookie((String)localObject));
  31. if (TextUtils.isEmpty(str1)) {
  32. continue;
  33. }
  34. localObject = new java/lang/StringBuilder;
  35. ((StringBuilder)localObject).<init>( "sessionidFromCache:");
  36. LogCatUtil.debug( "ext_AmnetUserInfo", str1);
  37. }
  38. }
  39. private static String getSessionidFromCookiestr (String paramString)
  40. {
  41. try
  42. {
  43. if (!TextUtils.isEmpty(paramString)) {
  44. break label12;
  45. }
  46. paramString = "";
  47. }
  48. catch (Throwable paramString)
  49. {
  50. for (;;)
  51. {
  52. label12:
  53. int j;
  54. int i;
  55. LogCatUtil.error( "ext_AmnetUserInfo", "getAlipayJsessionidFromCookiestr ex:" + paramString.toString());
  56. label96:
  57. paramString = "";
  58. }
  59. }
  60. return paramString;
  61. paramString = paramString.split( "; ");
  62. j = paramString.length;
  63. for (i = 0;; i++)
  64. {
  65. if (i >= j) {
  66. break label96;
  67. }
  68. CharSequence localCharSequence = paramString[i];
  69. if ((!TextUtils.isEmpty(localCharSequence)) && (localCharSequence.contains( "ALIPAYJSESSIONID")))
  70. {
  71. paramString = localCharSequence.substring(localCharSequence.indexOf( "=") + 1);
  72. break;
  73. }
  74. }
  75. }

其中getSessionid方法感觉就是获得ALIPAYJSESSIONID的方法,在xposed中调用该静态方法并打印返回值,发现返回的是字符串“ALIPAYJSESSIONID”,在hook getSessionidFromCookiestr方法,打印传入的参数,结果就是我们抓包获得的cookie,而cookie中是包含ALIPAYJSESSIONID的信息的,通过


     
     
  1. localObject = ReadSettingServerUrl.getInstance().getGWFURL(ExtTransportEnv.getAppContext());
  2. str1 = getSessionidFromCookiestr(GwCookieCacheHelper.getCookie((String)localObject));

这两行代码,我们知道可以通过如下代码获得cookie

      cookieStr = getSessionidFromCookiestr(GwCookieCacheHelper.getCookie((String)ReadSettingServerUrl.getInstance().getGWFURL(ExtTransportEnv.getAppContext())));
     
     

在xposed中对应的代码如下:


     
     
  1. String cookieStr = "";
  2. // 获得cookieStr
  3. Context context = (Context) callStaticMethod(findClass( "com.alipay.mobile.common.transportext.biz.shared.ExtTransportEnv", lpparam.classLoader), "getAppContext");
  4. if (context != null) {
  5. Object readSettingServerUrl = callStaticMethod(findClass( "com.alipay.mobile.common.helper.ReadSettingServerUrl", lpparam.classLoader), "getInstance");
  6. if (readSettingServerUrl != null) {
  7. String gWFURL = (String) callMethod(readSettingServerUrl, "getGWFURL", context);
  8. cookieStr = (String) callStaticMethod(findClass( "com.alipay.mobile.common.transport.http.GwCookieCacheHelper", lpparam.classLoader), "getCookie", gWFURL);
  9. }
  10. }

打印日志如下:

04-10 17:11:09.647 I/Xposed  ( 7116): cookieStr:session.cookieNameId=ALIPAYJSESSIONID; ssl_upgrade=0; spanner=PWDKfHD/i7Rh9gQCMkMP+DTzT8PATh824EJoL7C0n0A=; ctoken=Sf6-M33mBqAxZZKNtUxr8BfA; rtk=vokrGCgjMQ9UdSJNIgY0Tnw6Os8MF2zV3TThTYLGJohQF2zBIgB; ALIPAYJSESSIONID=RZ13nkgR2GBxkRKbRrX11rVYzOI6Vi64mobilegwRZ13; devKeySet={"apdidToken":"oBdC1a0uTmOgw66ehO7iVGekSnlK3Y00XLuw5BGCZ6yVyRla+q2qYgEB"}; zone=RZ13A
     
     

可以看到其中包含了ALIPAYJSESSIONID的信息。

备注:上面获得的账单信息有一个明显的缺点,就是接口返回的账单数据中没有备注信息,而一般我们是需要根据备注信息来确认账单的唯一性,从而判断是否收款成功,之后会进行优化。

 

四、xposed插件和支付宝应用通信

我们写的插件是单独一个进程,而支付宝也是单独一个进程,两个进程之间的通信有很多方法,比如Binder,Socket,BroadcastReceiver等,这里选择最简单的BroadcastReceiver。

xposed插件的主界面如下:

添加收钱按钮的点击事件:


     
     
  1. mShouQianButton.setOnClickListener( new View.OnClickListener() {
  2. @Override
  3. public void onClick (View v) {
  4. Intent intent = getPackageManager().getLaunchIntentForPackage(ALIPAY_PACKAGE_NAME);
  5. intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  6. startActivity(intent);
  7. Intent broadCastIntent = new Intent();
  8. Random random = new Random();
  9. broadCastIntent.putExtra( "qr_money", String.valueOf(random.nextInt( 100) + 1));
  10. broadCastIntent.putExtra( "beiZhu", "测试");
  11. broadCastIntent.setAction(AlipayBroadcast.INTENT_FILTER_ACTION);
  12. sendBroadcast(broadCastIntent);
  13. }
  14. });

点击收钱按钮后,会切换到支付宝应用,并且随机生成一个1-100的金额,设置备注,然后将信息通过广播的形式发送出去,支付宝要收到对应的广播,必须先要注册广播,我们可以在支付宝的主界面注册广播,hook支付宝主界面的onCreate方法,注册广播,hook支付宝主界面的onDestory方法,销毁广播,代码如下:


     
     
  1. // hook 支付宝主界面的onCreate方法,获得主界面对象并注册广播
  2. findAndHookMethod( "com.alipay.mobile.quinox.LauncherActivity", lpparam.classLoader, "onCreate", Bundle.class, new XC_MethodHook() {
  3. @Override
  4. protected void afterHookedMethod (MethodHookParam param) throws Throwable {
  5. log( "com.alipay.mobile.quinox.LauncherActivity onCreated" + "\n");
  6. launcherActivity = (Activity) param.thisObject;
  7. alipayBroadcast = new AlipayBroadcast();
  8. IntentFilter intentFilter = new IntentFilter();
  9. intentFilter.addAction(AlipayBroadcast.INTENT_FILTER_ACTION);
  10. launcherActivity.registerReceiver(alipayBroadcast, intentFilter);
  11. }
  12. });
  13. // hook 支付宝的主界面的onDestory方法,销毁广播
  14. findAndHookMethod( "com.alipay.mobile.quinox.LauncherActivity", lpparam.classLoader, "onDestroy", new XC_MethodHook() {
  15. @Override
  16. protected void afterHookedMethod (MethodHookParam param) throws Throwable {
  17. log( "com.alipay.mobile.quinox.LauncherActivity onDestroy" + "\n");
  18. if (alipayBroadcast != null) {
  19. ((Activity) param.thisObject).unregisterReceiver(alipayBroadcast);
  20. }
  21. launcherActivity = null;
  22. }
  23. });


广播类定义如下:


     
     
  1. package com.hhly.pay.alipay.boradcast;
  2. import android.content.BroadcastReceiver;
  3. import android.content.Context;
  4. import android.content.Intent;
  5. import com.hhly.pay.alipay.Main;
  6. import de.robv.android.xposed.XposedHelpers;
  7. import static de.robv.android.xposed.XposedBridge.log;
  8. /**
  9. * Created by dell on 2018/4/4.
  10. */
  11. public class AlipayBroadcast extends BroadcastReceiver{
  12. public static String INTENT_FILTER_ACTION = "com.hhly.pay.alipay.info";
  13. @Override
  14. public void onReceive (Context context, Intent intent) {
  15. if (intent.getAction().contentEquals(INTENT_FILTER_ACTION)) {
  16. String qr_money = intent.getStringExtra( "qr_money");
  17. String beiZhu = intent.getStringExtra( "beiZhu");
  18. log( "AlipayBroadcast onReceive " + qr_money + " " + beiZhu + "\n");
  19. if (!qr_money.contentEquals( "")) {
  20. Intent launcherIntent = new Intent(context, XposedHelpers.findClass( "com.alipay.mobile.payee.ui.PayeeQRSetMoneyActivity", Main.launcherActivity.getApplicationContext().getClassLoader()));
  21. launcherIntent.putExtra( "qr_money", qr_money);
  22. launcherIntent.putExtra( "beiZhu", beiZhu);
  23. Main.launcherActivity.startActivity(launcherIntent);
  24. }
  25. }
  26. }
  27. }

可以看到,支付宝在接受到广播后会打开设置金额页面,并且将金额和备注传过去,接下来我们需要hook住设置金额页面的onCreate方法,取得金额和备注,设置到界面上并且模拟点击确认按钮,这样我们只需要hook住设置金额的"a"方法,

protected final void a(ConsultSetAmountRes paramConsultSetAmountRes)
     
     

就获得到付款链接了,可以在这里顺便获得cookie,然后通过广播的形式发送给xposed插件,代码如下:


     
     
  1. findAndHookMethod( "com.alipay.mobile.payee.ui.PayeeQRSetMoneyActivity", lpparam.classLoader, "a",
  2. findClass( "com.alipay.transferprod.rpc.result.ConsultSetAmountRes", lpparam.classLoader), new XC_MethodHook() {
  3. @Override
  4. protected void afterHookedMethod (MethodHookParam param) throws Throwable {
  5. log( "com.alipay.mobile.payee.ui.PayeeQRSetMoneyActivity a" + "\n");
  6. String cookieStr = "";
  7. // 获得cookieStr
  8. Context context = (Context) callStaticMethod(findClass( "com.alipay.mobile.common.transportext.biz.shared.ExtTransportEnv", lpparam.classLoader), "getAppContext");
  9. if (context != null) {
  10. Object readSettingServerUrl = callStaticMethod(findClass( "com.alipay.mobile.common.helper.ReadSettingServerUrl", lpparam.classLoader), "getInstance");
  11. if (readSettingServerUrl != null) {
  12. String gWFURL = (String) callMethod(readSettingServerUrl, "getGWFURL", context);
  13. cookieStr = (String) callStaticMethod(findClass( "com.alipay.mobile.common.transport.http.GwCookieCacheHelper", lpparam.classLoader), "getCookie", gWFURL);
  14. }
  15. }
  16. Object consultSetAmountRes = param.args[ 0];
  17. String consultSetAmountResString = "";
  18. if (consultSetAmountRes != null) {
  19. consultSetAmountResString = (String) callMethod(consultSetAmountRes, "toString");
  20. }
  21. Intent broadCastIntent = new Intent();
  22. broadCastIntent.putExtra( "consultSetAmountResString", consultSetAmountResString);
  23. broadCastIntent.putExtra( "cookieStr", cookieStr);
  24. broadCastIntent.setAction(PluginBroadcast.INTENT_FILTER_ACTION);
  25. Activity activity = (Activity) param.thisObject;
  26. activity.sendBroadcast(broadCastIntent);
  27. log( "consultSetAmountResString:" + consultSetAmountResString + "\n");
  28. log( "cookieStr:" + cookieStr + "\n");
  29. }
  30. });

同样,在xposed插件中需要注册广播:

在xposed插件的MainActivity的onCreate方法中注册广播,并在其onDestory中销毁广播,如下:


     
     
  1.     @Override
  2.     protected void onCreate(Bundle savedInstanceState) {
  3.         super.onCreate(savedInstanceState);
  4.         setContentView(R.layout.activity_main);
  5.         pluginReceiver = new PluginBroadcast();
  6.         IntentFilter intentFilter = new IntentFilter();
  7.         intentFilter.addAction(PluginBroadcast.com.eg.android.AlipayGphone.info);
  8.         registerReceiver(pluginReceiver, intentFilter);
  9.     }
  10.     @Override
  11.     protected void onDestroy() {
  12.         super.onDestroy();
  13.         unregisterReceiver(pluginReceiver);
  14.     }

PluginBroadcast的定义如下:


     
     
  1. package com.hhly.pay.alipay.boradcast;
  2. import android.content.BroadcastReceiver;
  3. import android.content.Context;
  4. import android.content.Intent;
  5. import com.hhly.pay.alipay.App;
  6. /**
  7. * Created by dell on 2018/4/4.
  8. */
  9. public class PluginBroadcast extends BroadcastReceiver{
  10. public static String INTENT_FILTER_ACTION = "com.eg.android.AlipayGphone.info";
  11. @Override
  12. public void onReceive (Context context, Intent intent) {
  13. if (intent.getAction().contentEquals(INTENT_FILTER_ACTION)) {
  14. App.dealAlipayInfo(context, intent);
  15. }
  16. }
  17. }

dealAlipayInfo方法的定义:


     
     
  1. public static void dealAlipayInfo (Context context, Intent intent) {
  2. String consultSetAmountResString = intent.getStringExtra( "consultSetAmountResString");
  3. String cookieStr = intent.getStringExtra( "cookieStr");
  4. String toastString = consultSetAmountResString + " " + cookieStr;
  5. Log.i( "liunianprint:", toastString);
  6. Toast.makeText(context, toastString, Toast.LENGTH_SHORT).show();
  7. }

这里只是打印了consultSetAmountResString和cookieStr,正常流程是应该将信息上传给服务端,打印的日志如下:

04-10 18:47:03.288 7097-7097/? I/liunianprint:: ConsultSetAmountRes{codeId='1804106465250342', qrCodeUrl='HTTPS://QR.ALIPAY.COM/FKX03573WKXOYREEFL2686', printQrCodeUrl='HTTPS://QR.ALIPAY.COM/FKX01907CEYS5GOWTI9PB1'} RPCResponse{success=true, code='null', message='null'} session.cookieNameId=ALIPAYJSESSIONID; ssl_upgrade=0; spanner=PWDKfHD/i7Rh9gQCMkMP+DTzT8PATh824EJoL7C0n0A=; ctoken=Sf6-M33mBqAxZZKNtUxr8BfA; rtk=vokrGCgjMQ9UdSJNIgY0Tnw6Os8MF2zV3TThTYLGJohQF2zBIgB; ALIPAYJSESSIONID=RZ13nkgR2GBxkRKbRrX11rVYzOI6Vi64mobilegwRZ13; devKeySet={"apdidToken":"oBdC1a0uTmOgw66ehO7iVGekSnlK3Y00XLuw5BGCZ6yVyRla+q2qYgEB"}; zone=RZ13A

     
     

到此为止,我们已经可以在插件中获得收款链接和ALIPAYJSESSIONID,只需要将其发送给服务端就可以了,服务端可以根据收款链接生成收款二维码,根据ALIPAYJSESSIONID请求到收款记录。

顺便说一句,支付宝请求收款二维码链接是通过rpc协议进行的,在PayeeQRSetMoneyActivity如下方法:


     
     
  1. final void a ()
  2. {
  3. ConsultSetAmountReq localConsultSetAmountReq = new ConsultSetAmountReq();
  4. localConsultSetAmountReq.amount = this.g;
  5. localConsultSetAmountReq.desc = this.c.getUbbStr();
  6. localConsultSetAmountReq.sessionId = this.h;
  7. new RpcRunner( new dk( this), new dj( this)).start( new Object[] { localConsultSetAmountReq });
  8. }

点击确认按钮后会调用该方法去向支付宝的服务器请求支付链接,用Charles抓取不到rpc的请求,后面可以考虑直接模拟rpc请求直接向支付宝的服务器请求付款链接。

 

五、优化账单

通过上面的接口获得的账单信息中是没有备注的,估计支付宝为了安全没有将这块信息加入到接口中,但是在服务端判断收款是否到账就是根据收款记录中的备注信息确认的,只需要将设置金额页面的备注信息设置为每个账单唯一,就可以根据备注信息确认收款是否到账,在支付宝的账单页面,我们可以看到账单的备注信息,如下:

那下面就从账单页面入手,找到带备注信息的账单数据,用hierarchy view看一下账单界面,如下:

可以看到账单页面对应的activity为"com.alipay.mobile.bill.list.ui.BillListActivity_",在反编译代码中搜索"BillListActivity_"类,发现找不到这个类,通过xposed hook这个类,也提示无法找到该类。代码如下:


     
     
  1. findAndHookMethod( "com.alipay.mobile.bill.list.ui.BillListActivity_", mClassLoader, "onCreate", Bundle.class, new XC_MethodHook() {
  2. @Override
  3. protected void afterHookedMethod (MethodHookParam param) throws Throwable {
  4. XposedLogUtils.log( "com.alipay.mobile.bill.list.ui.BillListActivity_" + ":onCreated");
  5. mBillActivity = (Activity) param.thisObject;
  6. }
  7. });

报错信息如下:


     
     
  1. 05-24 17:07:14.977 E/Xposed ( 6047): de.robv.android.xposed.XposedHelpers$ClassNotFoundError: java.lang.ClassNotFoundException: com.alipay.mobile.bill.list.ui.BillListActivity_
  2. 05-24 17:07:14.977 E/Xposed ( 6047): at de.robv.android.xposed.XposedHelpers.findClass(XposedHelpers.java:71)
  3. 05-24 17:07:14.977 E/Xposed ( 6047): at de.robv.android.xposed.XposedHelpers.findAndHookMethod(XposedHelpers.java:260)
  4. 05-24 17:07:14.977 E/Xposed ( 6047): at com.sunny.aliplugin.hook.AliHook.o(AliHook.java:497)
  5. 05-24 17:07:14.977 E/Xposed ( 6047): at com.sunny.aliplugin.hook.AliHook.b(AliHook.java:58)
  6. 05-24 17:07:14.977 E/Xposed ( 6047): at com.sunny.aliplugin.hook.AliHook$6.afterHookedMethod(AliHook.java:245)
  7. 05-24 17:07:14.977 E/Xposed ( 6047): at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:374)
  8. 05-24 17:07:14.977 E/Xposed ( 6047): at com.alipay.mobile.quinox.classloader.BundleClassLoader. <init>( <Xposed>)
  9. 05-24 17:07:14.977 E/Xposed ( 6047): at com.alipay.mobile.quinox.classloader.c.run(BundleClassLoaderFactory.java:213)
  10. 05-24 17:07:14.977 E/Xposed ( 6047): at com.alipay.mobile.quinox.asynctask.PipelineRunnable.run(PipelineRunnable.java:124)
  11. 05-24 17:07:14.977 E/Xposed ( 6047): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
  12. 05-24 17:07:14.977 E/Xposed ( 6047): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
  13. 05-24 17:07:14.977 E/Xposed ( 6047): at java.lang.Thread.run(Thread.java:818)
  14. 05-24 17:07:14.977 E/Xposed ( 6047): Caused by: java.lang.ClassNotFoundException: com.alipay.mobile.bill.list.ui.BillListActivity_
  15. 05-24 17:07:14.977 E/Xposed ( 6047): at java.lang.Class.classForName(Native Method)
  16. 05-24 17:07:14.977 E/Xposed ( 6047): at java.lang.Class.forName(Class.java:324)
  17. 05-24 17:07:14.977 E/Xposed ( 6047): at external.org.apache.commons.lang3.ClassUtils.getClass(ClassUtils.java:823)
  18. 05-24 17:07:14.977 E/Xposed ( 6047): at de.robv.android.xposed.XposedHelpers.findClass(XposedHelpers.java:69)
  19. 05-24 17:07:14.977 E/Xposed ( 6047): ... 11 more
  20. 05-24 17:07:14.977 E/Xposed ( 6047): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.alipay.mobile.bill.list.ui.BillListActivity_" on path: DexPathList[[zip file "/system/framework/org.simalliance.openmobileapi.jar", zip file "/data/app/com.eg.android.AlipayGphone-1/base.apk"],nativeLibraryDirectories=[/data/user/0/com.eg.android.AlipayGphone/app_plugins_lib, /data/app/com.eg.android.AlipayGphone-1/lib/arm, /data/app/com.eg.android.AlipayGphone-1/base.apk!/lib/armeabi, /vendor/lib, /system/lib]]
  21. 05-24 17:07:14.977 E/Xposed ( 6047): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
  22. 05-24 17:07:14.977 E/Xposed ( 6047): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
  23. 05-24 17:07:14.977 E/Xposed ( 6047): at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
  24. 05-24 17:07:14.977 E/Xposed ( 6047): ... 15 more
  25. 05-24 17:07:14.977 E/Xposed ( 6047): Suppressed: java.lang.ClassNotFoundException: HostClassLoader

那这样就奇怪了,既然支付宝能够显示账单页面,那么对应的代码肯定是存在的,考虑一下,是不是支付宝用了分包技术,账单页面在其他的jar包中呢?在需要显示账单页面时才去加载对应的jar包,如果是这样,那么我们在当前apk的主ClassLoader就无法找到账单页面。现在需要想办法验证一下我们的想法,首先如果我们能够知道账单页面对应的ClassLoader,就可以打印出ClassLoader的名称,就能知道账单页面对应的代码所在位置。那么如何获得账单页面对应的ClassLoader呢?我们知道,Class类有一个getClassLoader()方法,如果能够获得账单页面对应的对象,然后通过getClass()方法获得其对应的Class,再调用Class的getClassLoader()方法,就可以知道账单页面对应的ClassLoader了。那么如何获得账单页面Activity对象呢?我们现在是不知道账单页面对应的ClassLoader的,也就找不到其对应的Class,无法在Xposed中注册Hook它的方法,额,感觉有点麻烦了,换个角度思考一下,BillListActivity_是一个Activity,那么它肯定是要继承Activity类的,BillListActivity_在创建时肯定会调用到Activity的onCreate方法,我们可以Hook Activity类的onCreate方法,获得当前Activity对象,然后获得当前Activity对象对应的类名,再来比较类名是不是账单页面对应的类名,如果是,那么当前Activity对象就是BillListActivty_对象,那么就可以打印出其对应的ClassLoader了。代码如下:


     
     
  1. findAndHookMethod(Activity.class, "onCreate", Bundle.class, new XC_MethodHook() {
  2. @Override
  3. protected void afterHookedMethod (MethodHookParam param) throws Throwable {
  4. if (param.thisObject != null && param.thisObject.getClass().getName().contentEquals( "com.alipay.mobile.bill.list.ui.BillListActivity_")) {
  5. XposedLogUtils.log(param.thisObject.getClass().getClassLoader().toString());
  6. }
  7. }
  8. });

打印结果如下:

05-24 17:43:17.051 I/Xposed  ( 6055): BundleClassLoader[/data/user/0/com.eg.android.AlipayGphone/lib/libandroid-phone-wallet-billlist.so]
     
     

可以看到账单页面的代码在lib目录的"libandroid-phone-wallet-billlist.so"这个库中,打开apk的lib目录下,发现可以找到这个库:

并且ClassLoader对应的类名为"BundleClassLoader",我擦,居然是一个so库,我们知道,so库是不能直接看到代码的,如果是so库就难搞了,尝试将"libandroid-phone-wallet-billlist.so"重命名为"libandroid-phone-wallet-billlist.zip"并且解压,对应目录如下:

呃呃呃,原来是一个假的so库,其实和apk包是一样的,反编译一下classes.dex,获得账单页面对应的jar包,如下:

获得账单页面对应的jar包并且用jd-gui打开,搜索BillListActivity_,可以看到BillListActivity_的代码:

ok,现在我们获得账单页面的代码了,接下来就是Hook账单页面对应的方法然后获得账单数据,搞到这里又会发现一个问题,想要hook账单页面的方法首先需要获得账单页面对应的class,而class是需要从ClassLoader中找的,账单页面的ClassLoader是动态加载的,只有当启动支付宝后首次打开账单页面时,才会去加载账单页面对应的库,从而生成对应的ClassLoader,我们上面获得账单页面对应的ClassLoader的步骤如下:

1、hook Activity的onCreate方法

2、通过类名判断当前Activity是否是账单页面

3、如果是账单页面,则可以通过getClass().getClassLoader()获得账单页面对应的ClassLoader

4、记录账单页面的ClassLoader当静态变量中

5、之后要使用账单页面的ClassLoader就可以直接使用静态变量中的ClassLoader了

上面方法有一个问题是我们必须要在支付宝启动后手动打开一次账单页面,这样支付宝才会去加载账单页面对应的库,然后才能找到其对应的ClassLoader,有没有什么办法可以不用手动打开账单页面呢?通过查看点击进入账单页面的方法,最终我们发现可以通过下面的代码打开账单页面:

    LauncherAppUtils.a("20000003");
     
     

LauncherAppUtils应该是支付宝为了启动动态库中的Activity而写的一个辅助类,"20000003"应该代表账单页面,这个在支付宝AppId类中有配置:

我们可以在支付宝的首页启动时调用该方法,从而实现在支付宝启动后自动打开支付宝的账单页面,这样就可以获得账单页面对应的ClassLoader了。代码如下:


     
     
  1. // hook 支付宝主界面的onCreate方法,获得主界面对象并注册广播
  2. findAndHookMethod(AliParamUtils.mLauncherActivityClassfullName, classLoader, "onCreate", Bundle.class, new XC_MethodHook() {
  3. @Override
  4. protected void afterHookedMethod (MethodHookParam param) throws Throwable {
  5. XposedLogUtils.log(AliParamUtils.mLauncherActivityClassfullName + ":onCreated方法");
  6. mLauncherActivity = (Activity) param.thisObject;
  7. if (AliParamUtils.mBillListActivityIsFromSoLib) {
  8. // 打开账单页面,并加载其对应的库
  9. callStaticMethod(findClass( "com.alipay.android.phone.home.manager.LauncherAppUtils", classLoader), "a", "20000003", null);
  10. }
  11. }
  12. });

另外一个问题是,我们不想通过hook Activity的onCreate方法,然后判断类名的方式获得账单页面对应的ClassLoader,那么有没有其他的办法呢?通过上面的对应账单页面ClassLoader的打印,我们知道,账单页面的ClassLoader对应的类名为"BundleClassLoader",在反编译代码中搜索"BundleClassLoader",可以看到如下代码:

观察"BundleClassLoader"所有的构造方法,发现其最终都会调用下面的这个构造方法:


     
     
  1. @SuppressLint({"DefaultLocale"})
  2. public BundleClassLoader (ClassLoader paramClassLoader, Bundle paramBundle, BundleManager paramBundleManager, HostClassLoader paramHostClassLoader)

并且在该构造方法中可以看到如下代码:

 if ((Build.HARDWARE.toLowerCase().contains("mt6592")) && (paramBundle.getLocation().endsWith(".so")))
     
     

猜想paramBundle.getLocation()应该是获得动态库的路径,我们可以打印paramBundle.getLocation()的值,在首次打开账单页面时可以看到如下日志:

05-12 10:55:28.861 I/Xposed  ( 6891): ------------so库    /data/user/0/com.eg.android.AlipayGphone/lib/libandroid-phone-wallet-billlist.so
     
     

说明paramBundle.getLocation()就是获得动态库的路径,既然这样,我们就可以通过动态库的名称来判断当前的ClassLoader是否是账单页面的ClassLoader,代码如下:


     
     
  1. // hook BundleClassLoader构造方法,获得so库对应的classloader并hook来自so库中的类
  2. findAndHookConstructor( "com.alipay.mobile.quinox.classloader.BundleClassLoader", classLoader,
  3. ClassLoader.class,
  4. findClass( "com.alipay.mobile.quinox.bundle.Bundle", classLoader),
  5. findClass( "com.alipay.mobile.quinox.bundle.BundleManager", classLoader),
  6. findClass( "com.alipay.mobile.quinox.classloader.HostClassLoader", classLoader),
  7. new XC_MethodHook() {
  8. @Override
  9. protected void afterHookedMethod (MethodHookParam param) throws Throwable {
  10. try {
  11. if (param.args[ 1] != null) {
  12. String soLibName = (String) XposedHelpers.callMethod(param.args[ 1], AliParamUtils.mBundleGetLocationMethodName); // 获得so库名称
  13. if (soLibName != null) {
  14. if (soLibName.contains( "wallet-billlist")) {
  15. mBillListActivityClassLoader = (ClassLoader) param.thisObject;
  16. XposedLogUtils.log( "账单页面classloader: " + mBillListActivityClassLoader.toString());
  17. hookBillListActivityMethod();
  18. }
  19. }
  20. }
  21. } catch (Exception e) {
  22. }
  23. }
  24. });

首次打开账单页面,可以看到如下日志:

05-12 10:55:28.861 I/Xposed  ( 6891): 账单页面classloader: BundleClassLoader[/data/user/0/com.eg.android.AlipayGphone/lib/libandroid-phone-wallet-billlist.so]
     
     

到现在为止,我们已经可以在支付宝应用启动后自动获得账单页面的ClassLoader并将其保存在静态变量mBillListActivityClassLoader中,终于能够正常hook账单页面的方法了,接下来我们就通过hook账单页面来获得账单数据。

用hierarchy view查看账单界面,如下:

发现其账单信息是在一个APListView控件中,并且ApListView外面又套了一个APPullRefreshView,这个应该是可以猜到的,账单页面是一个列表,并且支持下拉刷新和上拉加载更多,一般的套路就是下拉刷新控件套上一个ListView或者RecyclerView,既然这样,那么如果我们找到ListView对应的Adpater,账单的数据应该就存在Adpater中的某个类型为List的对象中,直接在反编译代码中查看BillListActivity_的代码,如下:

并没有找到对应的APPullRefreshView或者ApListView之类的信息,打开其父类BillListActivity,如下:


     
     
  1. @EActivity(resName="activity_bill_list")
  2. public class BillListActivity
  3. extends BillListBaseActivity
  4. {
  5. private BroadcastReceiver A;
  6. private BroadcastReceiver B;
  7. private boolean C = false;
  8. private boolean D = false;
  9. private boolean E = false;
  10. private boolean F = false;
  11. private long G = 0L;
  12. private String H;
  13. private boolean I = false;
  14. private RpcRunner J;
  15. private String K;
  16. private String L;
  17. private String M;
  18. private boolean N;
  19. private String O;
  20. private boolean P;
  21. private String Q;
  22. private RpcRunner R;
  23. private RpcRunner S;
  24. private List<EntrancePBModel> T;
  25. private SelectDateWindow U;
  26. private CategoryListRes V;
  27. private boolean W;
  28. private String X;
  29. private AUFloatMenu Y;
  30. private BillCacheManager Z;
  31. private BillCacheManager aa;
  32. private BillListNewCategoryManager ab;
  33. private boolean ac = false;
  34. private FilterPopUpWindow ad;
  35. private NewCategoryFilterPopUpWindow ae;
  36. private boolean af;
  37. private String ag;
  38. private String ah;
  39. private boolean ai = true;
  40. private boolean aj = false;
  41. private boolean ak = false;
  42. private String al;
  43. private boolean am = false;
  44. private boolean an = true;
  45. @ViewById(resName="bill_list_title_bar")
  46. protected AUTitleBar c;
  47. @ViewById(resName="bill_list_view")
  48. protected APListView d;
  49. @ViewById(resName="bill_list_container")
  50. protected View e;
  51. @ViewById(resName="bill_list_month_header")
  52. protected ViewGroup f;
  53. @ViewById(resName="bill_list_pull_refresh")
  54. protected APPullRefreshView g;
  55. @ViewById(resName="bill_list_loading")
  56. protected View h;
  57. protected BillListFilterBar i;
  58. protected BillListFilterBar j;
  59. protected TextView k;
  60. private ViewGroup l;
  61. private ViewGroup m;
  62. private TextView n;
  63. private View o;
  64. private BadgeView p;
  65. private String q;
  66. private APOverView r;
  67. private AuthService s;
  68. private String t = "NO";
  69. private QueryListReq u;
  70. private boolean v = false;
  71. private boolean w = true;
  72. private boolean x = false;
  73. private BillListViewFooterView y;
  74. private BillListAdapter z;

可以看到其中有如下字段的定义:


     
     
  1. @ViewById(resName="bill_list_pull_refresh")
  2. protected APPullRefreshView g;
  3. @ViewById(resName="bill_list_view")
  4. protected APListView d;
  5. private BillListAdapter z;

可以看到账单页面对应的Adapter为BillListAdater,字段名称为"z",打开BillListAdater类,可以看到如下代码:


     
     
  1. public List<SingleListItem> a = new ArrayList();
  2. public final void a (List<SingleListItem> paramList)
  3. {
  4. this.a.addAll(paramList);
  5. notifyDataSetChanged();
  6. }

其中字段"a"应该就是账单列表的数据,而方法"a"应该是用来添加账单数据到列表中的方法,在这个类中搜索"this.a.add",发现只有这个方法中有添加账单数据到列表中,由此,我们可以判断,只要账单数据有增加,肯定会调用该方法。我们可以通过hook 该方法,一旦账单数据有添加,我们就可以监控到,代码如下:


     
     
  1. findAndHookMethod( "com.alipay.mobile.bill.list.ui.adapter.BillListAdapter", mBillListActivityClassLoader, "a", List.class, new XC_MethodHook() {
  2. @Override
  3. protected void afterHookedMethod (MethodHookParam param) throws Throwable {
  4. XposedLogUtils.log( "com.alipay.mobile.bill.list.ui.adapter.BillListAdapter" + "a called" + "\n");
  5. if (param.args[ 0] != null) {
  6. Field billListFiled = XposedHelpers.findField(param.thisObject.getClass(), "a"); // 通过反射找到账单数据列表对应的字段
  7. final Object billList = billListFiled.get(param.thisObject); // 获得账单数据列表
  8. List<Object> bList_obj = (List) billList;
  9. if (bList_obj != null) {
  10. sendBillListBroadCast(bList_obj); // 将账单数据列表通过广播发送回给插件程序
  11. }
  12. }
  13. }
  14. });

其中sendBillListBroadCast(bList_obj)的作用是将账单数据列表通过广播发送回给插件程序,通过上面的分析我们知道账单数据的类型为SingleListItem,打开SingleListItem类,可以看到如下字段的定义:


     
     
  1. @ProtoField(tag=15)
  2. public ActionParam actionParam;
  3. @ProtoField(tag=1, type=Message.Datatype.STRING)
  4. public String bizInNo;
  5. @ProtoField(tag=6, type=Message.Datatype.STRING)
  6. public String bizStateDesc;
  7. @ProtoField(tag=10, type=Message.Datatype.STRING)
  8. public String bizSubType;
  9. @ProtoField(tag=9, type=Message.Datatype.STRING)
  10. public String bizType;
  11. @ProtoField(tag=11, type=Message.Datatype.BOOL)
  12. public Boolean canDelete;
  13. @ProtoField(tag=23, type=Message.Datatype.STRING)
  14. public String categoryName;
  15. @ProtoField(tag=3, type=Message.Datatype.STRING)
  16. public String consumeFee;
  17. @ProtoField(tag=4, type=Message.Datatype.STRING)
  18. public String consumeStatus;
  19. @ProtoField(tag=2, type=Message.Datatype.STRING)
  20. public String consumeTitle;
  21. @ProtoField(tag=26, type=Message.Datatype.INT32)
  22. public Integer contentRender;
  23. @ProtoField(tag=8, type=Message.Datatype.STRING)
  24. public String createDesc;
  25. @ProtoField(tag=16, type=Message.Datatype.STRING)
  26. public String createTime;
  27. @ProtoField(tag=14, type=Message.Datatype.STRING)
  28. public String destinationUrl;
  29. @ProtoField(tag=7, type=Message.Datatype.INT64)
  30. public Long gmtCreate;
  31. @ProtoField(tag=18, type=Message.Datatype.BOOL)
  32. public Boolean isAggregatedRec;
  33. @ProtoField(tag=17, type=Message.Datatype.STRING)
  34. public String memo;
  35. @ProtoField(tag=13, type=Message.Datatype.STRING)
  36. public String month;
  37. @ProtoField(tag=5, type=Message.Datatype.STRING)
  38. public String oppositeLogo;
  39. @ProtoField(tag=20, type=Message.Datatype.STRING)
  40. public String oppositeMemGrade;
  41. @ProtoField(tag=12, type=Message.Datatype.ENUM)
  42. public RecordType recordType;
  43. @ProtoField(tag=19, type=Message.Datatype.STRING)
  44. public String sceneId;
  45. @ProtoField(tag=25, type=Message.Datatype.STRING)
  46. public String statistics;
  47. @ProtoField(tag=24, type=Message.Datatype.STRING)
  48. public String subCategoryName;
  49. @ProtoField(label=Message.Label.REPEATED, tag=21, type=Message.Datatype.STRING)
  50. public List<String> tagNameList;
  51. @ProtoField(tag=22, type=Message.Datatype.INT32)
  52. public Integer tagStatus;

根据名称,我们大致可以猜测出每一个字段代表的意思,比如consumeFee应该代表进账或者消费的金额,我们在插件程序中创建一个BillObject类,并且实现Parcelable接口,以便其能够被序列化,如下:


     
     
  1. /**
  2. * 账单信息对象
  3. */
  4. public static class BillObject implements Parcelable {
  5. public String bizInNo;
  6. public String bizStateDesc;
  7. public String bizSubType;
  8. public String canDelete;
  9. public String bizType;
  10. public String consumeFee;
  11. public String consumeStatus;
  12. public String consumeTitle;
  13. public String createDesc;
  14. public String createTime;
  15. public String destinationUrl;
  16. public String gmtCreate;
  17. public String isAggregatedRec;
  18. public String memo;
  19. public String month;
  20. public String oppositeLogo;
  21. public String oppositeMemGrade;
  22. public String sceneId;
  23. public BillObject () {
  24. }
  25. protected BillObject (Parcel in) {
  26. bizInNo = in.readString();
  27. bizStateDesc = in.readString();
  28. bizSubType = in.readString();
  29. canDelete = in.readString();
  30. bizType = in.readString();
  31. consumeFee = in.readString();
  32. consumeStatus = in.readString();
  33. consumeTitle = in.readString();
  34. createDesc = in.readString();
  35. createTime = in.readString();
  36. destinationUrl = in.readString();
  37. gmtCreate = in.readString();
  38. isAggregatedRec = in.readString();
  39. memo = in.readString();
  40. month = in.readString();
  41. oppositeLogo = in.readString();
  42. oppositeMemGrade = in.readString();
  43. sceneId = in.readString();
  44. }
  45. public static final Creator<BillObject> CREATOR = new Creator<BillObject>() {
  46. @Override
  47. public BillObject createFromParcel (Parcel in) {
  48. return new BillObject(in);
  49. }
  50. @Override
  51. public BillObject[] newArray( int size) {
  52. return new BillObject[size];
  53. }
  54. };
  55. @Override
  56. public String toString () {
  57. return "bizInNo:" + bizInNo + "," +
  58. "bizStateDesc:" + bizStateDesc + "," +
  59. "bizSubType:" + bizSubType + "," +
  60. "canDelete:" + canDelete + "," +
  61. "bizType:" + bizType + "," +
  62. "consumeFee:" + consumeFee + "," +
  63. "consumeStatus:" + consumeStatus + "," +
  64. "consumeTitle:" + consumeTitle + "," +
  65. "createDesc:" + createDesc + "," +
  66. "createTime:" + createTime + "," +
  67. "destinationUrl:" + destinationUrl + "," +
  68. "gmtCreate:" + gmtCreate + "," +
  69. "isAggregatedRec:" + isAggregatedRec + "," +
  70. "memo:" + memo + "," +
  71. "month:" + month + "," +
  72. "oppositeLogo:" + oppositeLogo + "," +
  73. "oppositeMemGrade:" + oppositeMemGrade + "," +
  74. "sceneId:" + sceneId + "\n";
  75. }
  76. @Override
  77. public int describeContents () {
  78. return 0;
  79. }
  80. @Override
  81. public void writeToParcel (Parcel dest, int flags) {
  82. dest.writeString(bizInNo);
  83. dest.writeString(bizStateDesc);
  84. dest.writeString(bizSubType);
  85. dest.writeString(canDelete);
  86. dest.writeString(bizType);
  87. dest.writeString(consumeFee);
  88. dest.writeString(consumeStatus);
  89. dest.writeString(consumeTitle);
  90. dest.writeString(createDesc);
  91. dest.writeString(createTime);
  92. dest.writeString(destinationUrl);
  93. dest.writeString(gmtCreate);
  94. dest.writeString(isAggregatedRec);
  95. dest.writeString(memo);
  96. dest.writeString(month);
  97. dest.writeString(oppositeLogo);
  98. dest.writeString(oppositeMemGrade);
  99. dest.writeString(sceneId);
  100. }
  101. }

然后将账单数据存到我们自己的Object对象中,并且发送广播给插件:


     
     
  1. /**
  2. * 发送账单数据广播
  3. *
  4. * @param objectList
  5. * @throws IllegalAccessException
  6. */
  7. private void sendBillListBroadCast (List<Object> objectList) throws IllegalAccessException {
  8. boolean isFound = false; // 是否查到相应位置
  9. boolean isLast = false; // 已是最新数据
  10. int invalidCount = 0; //
  11. ArrayList<BillObject> billObjectList = new ArrayList<>();
  12. XposedLogUtils.log( "objectList size:" + objectList.size());
  13. for ( int i = 0; i < objectList.size(); i++) {
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值