如何让微信丢骰子永远只出“666”

转:http://www.freebuf.com/articles/terminal/146413.html


每次宅寝室一起点外卖谁下去拿都是个大问题,小编寝室一般选择微信色子谁小谁去拿,但是小编运气不太好 总是输,所以寻思着能不能每次都让色子是6点,皇天不负有心人,果然找到了方法。

准备工作

需要一台已经root并且安装了Hook神奇Xposed框架。在Hook过程中最重要的一点就是要找到Hook点这也是最难的部分。找到Hook点之后编写Xposed模块就比较简单了。

本次实验使用的weixin版本是6513.

猜想假设

我们先猜测微信摇色子是怎么实现的。如果有简单编程经验的朋友肯定会猜测是random函数。其实我也是这么猜的。

逆向分析

反编译apk

进行简单的准备工作:使用apktool反编译apk。使用Jadx打开微信的apk。微信较大,打开会比较慢。

找到色子对应控件的id

这一步可以借助AndroidSDK提供的一个工具:uiautomatorviewer.bat。可以看到下面的界面。

如何让微信丢骰子永远只出“666”

<img alt="1.png" src="http://image.3001.net/images/20170906/15046685806536.png!small" width="690" height="437"></p>

可以看到色子控件对应的id是cph。然后在public.xml中找到cph对应的值为0x7f100d28。

如何让微信丢骰子永远只出“666” 

<img alt="2.png" src="http://image.3001.net/images/20170906/15046685944283.png!small" width="450" height="112"> </p>

最后用这个值去R类里面找到真正使用的名称为bfq

如何让微信丢骰子永远只出“666” 

<img alt="3.png" src="http://image.3001.net/images/20170906/15046686135980.png!small" width="480" height="90"> </p>

查找Hook点

最难的部分就是查找hook点。在jadx中全局搜索bqf。显然这个findViewById()才是我们要找的东西,双击点进去看代码。如果有多个需要一个一个看。

如何让微信丢骰子永远只出“666” 

<img alt="4.png" src="http://image.3001.net/images/20170906/15046686273903.png!small" width="690" height="288"> </p>

上下查看这个类包含的内容。可以知道这是一个baseAdapter类。但是getView方法中没有设置点击事件。

如何让微信丢骰子永远只出“666” 

<img alt="5.png" src="http://image.3001.net/images/20170906/15046686382119.png!small" width="484" height="224"> </p>

如何让微信丢骰子永远只出“666” 

<img alt="6.png" src="http://image.3001.net/images/20170906/15046686483855.png!small" width="300" height="118"> </p>

 如何让微信丢骰子永远只出“666”

<img alt="7.png" src="http://image.3001.net/images/20170906/15046686678436.png!small" width="690" height="545"></p>

全局搜索调用这个函数的地方进行查找。

如何让微信丢骰子永远只出“666” 

<img alt="8.png" src="http://image.3001.net/images/20170906/15046686995822.png!small" width="455" height="330"> </p>

如何让微信丢骰子永远只出“666” 

<img alt="9.png" src="http://image.3001.net/images/20170906/15046687094424.png!small" width="690" height="431"> </p>

双击进入代码查看,看到是SmileyGrid类型的控件。查看SmileyGrid定义。

如何让微信丢骰子永远只出“666” 

<img alt="10.png" src="http://image.3001.net/images/20170906/15046687225042.png!small" width="545" height="184"> </p>

对onItemClick中的方法一个一个分析,最后发现红框中才是我们要找的方法。

如何让微信丢骰子永远只出“666” 

<img alt="11.png" src="http://image.3001.net/images/20170906/15046687448590.png!small" width="690" height="480"> </p>

查看a函数代码,可以看到最下面两个是toast,显然不是。接下来就需要对剩下的分支进行查看。

如何让微信丢骰子永远只出“666” 

<img alt="12.png" src="http://image.3001.net/images/20170906/15046687617249.png!small" width="690" height="636"> </p>

查看之后我们知道是第一个也就是c c = ((com.tencent.mm.plugin.emoji.b.c) h.j(com.tencent.mm.plugin.emoji.b.c.class)).getEmojiMgr().c(cVar);

根据导入的包信息我们可以知道是com.tencent.mm.kernel.h并且类型是com.tencent.mm.plugin.emoji.b.c继续看这几处的代码进行分析。

如何让微信丢骰子永远只出“666” 

<img alt="13.png" src="http://image.3001.net/images/20170906/15046687916467.png!small" width="438" height="56"> </p>

下面是h.j的代码,返回是j。

如何让微信丢骰子永远只出“666”

<img alt="14.png" src="http://image.3001.net/images/20170906/15046688025144.png!small" width="574" height="124"></p>

下面是emoji.b.c的代码,我们可以知道是一个接口。

如何让微信丢骰子永远只出“666” 

<img alt="15.png" src="http://image.3001.net/images/20170906/1504668815913.png!small" width="373" height="230"> </p>

在做到这里的时候卡了好久没什么思路了,然后写了一个简单的xposed模块hook了com.tencent.mm.kernel.h的j函数看看返回的类型是什么。

如何让微信丢骰子永远只出“666” 

<img alt="16.png" src="http://image.3001.net/images/20170906/15046685159574.png!small" width="690" height="120"> </p>

将模块装安装重启后,打开weixin清空logcat然后点击色子,看到了下面的输出,可以知道输入参数的类型是com.tencent.mm.plugin.emoji.b.c返回的类型是com.tencent.mm.plugin.emoji.PluginEmoji。然后看看PluginEmoji的代码。

如何让微信丢骰子永远只出“666” 

<img alt="17.png" src="http://image.3001.net/images/20170906/15046684725471.png!small" width="464" height="45"> </p>

看到PluginEmoji包含了getEmojiMgr方法,重点看这个方法。

如何让微信丢骰子永远只出“666” 

<img alt="18.png" src="http://image.3001.net/images/20170906/15046688328600.png!small" width="248" height="219"> </p>

如何让微信丢骰子永远只出“666” 

<img alt="19.png" src="http://image.3001.net/images/20170906/15046688467336.png!small" width="468" height="158"> </p>

有了前面的经验,这里就在前面的那个模块也hook了这个方法看看返回的具体是什么。点击之后在上面的提示出现了另一行。返回的具体是com.tencent.mm.plugin.emoji.e.g再去看emoji.e.g的代码。

如何让微信丢骰子永远只出“666”

<img alt="20.png" src="http://image.3001.net/images/20170906/15046688569714.png!small" width="690" height="92"></p>

如何让微信丢骰子永远只出“666” 

<img alt="21.png" src="http://image.3001.net/images/20170906/15046688644278.png!small" width="465" height="57"> </p>

重点当然是分析emoji.e.g的c方法。代码如下。通过yH.movToPosition(dM)知道dM才是关键,继续追踪bf.dM的代码。通过导入的包可以知道来自com.tencent.mm.sdk.platformtools.bf。

如何让微信丢骰子永远只出“666” 

<img alt="22.png" src="http://image.3001.net/images/20170906/15046688753733.png!small" width="690" height="161"> </p>

如何让微信丢骰子永远只出“666” 

<img alt="23.png" src="http://image.3001.net/images/20170906/15046688855403.png!small" width="341" height="53"> </p>

看到这个Random函数还真是有点小激动啊。估摸应该是这里了。同样hook看一下输入参数和返回的参数是什么。

如何让微信丢骰子永远只出“666” 

<img alt="24.png" src="http://image.3001.net/images/20170906/15046689003007.png!small" width="667" height="121"> </p>

如何让微信丢骰子永远只出“666”

<img alt="25.png" src="http://image.3001.net/images/20170906/15046689089847.png!small" width="690" height="173"></p>

输入的参数都是5和0,输出的正好和点数相对应,3对应4点,1对应2点,1对应0点.

如何让微信丢骰子永远只出“666”

<img alt="26.png" src="http://image.3001.net/images/20170906/15046689161241.png!small" width="339" height="122"></p>

如何让微信丢骰子永远只出“666”

<img alt="27.png" src="http://image.3001.net/images/20170906/1504668929651.png!small" width="690" height="1200"></p>

编写模块

找到随机数的返回点,接下来写hook模块就简单了。还有一点要注意的是,石头剪刀布也是用的这个随机函数。所以写的时候要注意一下。

如何让微信丢骰子永远只出“666” 

<img alt="28.png" src="http://image.3001.net/images/20170906/15046689397007.png!small" width="690" height="214"> </p>

最后体验一下效果如何。

如何让微信丢骰子永远只出“666”

<img alt="29.png" src="http://image.3001.net/images/20170906/15046689482485.png!small" width="690" height="1200"></p>

这下终于不用拿外卖了。

总结

1. 找id:对于控件的点击事件可以用uiautomatorviewer定位到控件的id,然后通过public.xml和R类找到真正使用的类名和十六进制id。

2. 定位到关键代码:接下来最难的就是定位到关键代码,通常要花很多时间,多练习能够提高速度。

3. 编写xposed模块:找到关键函数以后,编写模块就比较简单了。有些app有分包的时候要注意一下。




<img alt="1.png" src="http://image.3001.net/images/20170906/15046685806536.png!small" width="690" height="437"></p>


<img alt="2.png" src="http://image.3001.net/images/20170906/15046685944283.png!small" width="450" height="112"> </p>


<img alt="3.png" src="http://image.3001.net/images/20170906/15046686135980.png!small" width="480" height="90"> </p>



<img alt="4.png" src="http://image.3001.net/images/20170906/15046686273903.png!small" width="690" height="288"> </p>


<img alt="5.png" src="http://image.3001.net/images/20170906/15046686382119.png!small" width="484" height="224"> </p>


<img alt="6.png" src="http://image.3001.net/images/20170906/15046686483855.png!small" width="300" height="118"> </p>


<img alt="7.png" src="http://image.3001.net/images/20170906/15046686678436.png!small" width="690" height="545"></p>


<img alt="8.png" src="http://image.3001.net/images/20170906/15046686995822.png!small" width="455" height="330"> </p>


<img alt="9.png" src="http://image.3001.net/images/20170906/15046687094424.png!small" width="690" height="431"> </p>


<img alt="10.png" src="http://image.3001.net/images/20170906/15046687225042.png!small" width="545" height="184"> </p>


<img alt="11.png" src="http://image.3001.net/images/20170906/15046687448590.png!small" width="690" height="480"> </p>


<img alt="12.png" src="http://image.3001.net/images/20170906/15046687617249.png!small" width="690" height="636"> </p>


<img alt="13.png" src="http://image.3001.net/images/20170906/15046687916467.png!small" width="438" height="56"> </p>


<img alt="14.png" src="http://image.3001.net/images/20170906/15046688025144.png!small" width="574" height="124"></p>


<img alt="15.png" src="http://image.3001.net/images/20170906/1504668815913.png!small" width="373" height="230"> </p>


<img alt="16.png" src="http://image.3001.net/images/20170906/15046685159574.png!small" width="690" height="120"> </p>


<img alt="17.png" src="http://image.3001.net/images/20170906/15046684725471.png!small" width="464" height="45"> </p>


<img alt="18.png" src="http://image.3001.net/images/20170906/15046688328600.png!small" width="248" height="219"> </p>


<img alt="19.png" src="http://image.3001.net/images/20170906/15046688467336.png!small" width="468" height="158"> </p>


<img alt="20.png" src="http://image.3001.net/images/20170906/15046688569714.png!small" width="690" height="92"></p>


<img alt="21.png" src="http://image.3001.net/images/20170906/15046688644278.png!small" width="465" height="57"> </p>


<img alt="22.png" src="http://image.3001.net/images/20170906/15046688753733.png!small" width="690" height="161"> </p>


<img alt="23.png" src="http://image.3001.net/images/20170906/15046688855403.png!small" width="341" height="53"> </p>



<img alt="24.png" src="http://image.3001.net/images/20170906/15046689003007.png!small" width="667" height="121"> </p>


<img alt="25.png" src="http://image.3001.net/images/20170906/15046689089847.png!small" width="690" height="173"></p>


<img alt="26.png" src="http://image.3001.net/images/20170906/15046689161241.png!small" width="339" height="122"></p>


<img alt="27.png" src="http://image.3001.net/images/20170906/1504668929651.png!small" width="690" height="1200"></p>


 

<img alt="28.png" src="http://image.3001.net/images/20170906/15046689397007.png!small" width="690" height="214"> </p>



<img alt="29.png" src="http://image.3001.net/images/20170906/15046689482485.png!small" width="690" height="1200"></p>