A Brief Introduction to Android's Principle of Grabbing Wechat Red Packet by Auxiliary Function

Keywords: Android Mobile github SDK

With the address of the Red Pack Open Source Project, the code has been changed to Kotlin. It has been adapted to the latest version of Weixin 7.0.5. If it helps you, please star t. https://github.com/xbdcc/Grab...

Preface

It is believed that many people have seen that there will always be people snatching red envelopes very quickly in the crowd, or someone may have used the red envelope plug-in, so what principle do they achieve?

  • At present, the most commonly used method is through the Accessibility Service barrier-free service monitoring UI simulation click implementation, this method does not need the mobile phone Root.
  • Another way is to call the code of Hook Wechat directly through Xposed. Hook requires mobile phone Root or Xposed virtual environment installation, and decompilation combined with source code analysis to find the key Hook points.

Today, I will briefly introduce how to achieve Android Writing RedPack without Root. If you have written some Android scripts with Uiautomator or Appium, you should know that the implementation process is actually very simple. Note: The following is based on the Android version of Wechat 7.0.3.

Knowledge Points

This article will use the relevant knowledge tools, if you do not know about Google, you will know:
DDMS, Accessibility Service, Kotlin Language

UI Analysis

  • First, we open the installed SDK directory. Under MAC, we can enter it quickly by pressing Shift+Command+G shortcut in Finlder.

For example, my SDK directory is / Users/caochang/Library/Android/sdk. Go to the tool folder and open the monitor analysis tool. If it's Eclipse, you can open DDMS directly.

  • Connect your mobile phone to your computer and turn on USB debugging. You can check the connection by adb devices command. If the connection is unsuccessful, you can try adb kill-server and adb start-server.
  • The process name of the current page view is selected when the mobile phone is connected. The current test APP is selected as follows. Clicking on the icon in the circle will show the current top-level Activity view as follows:

  • Send a red envelope and look at the view below. We can find id and text:

  • Similarly, when we click on the red envelope and enter the red envelope bullet box, we can find the ID of the click and disassemble as shown in the figure:

code implementation

This example uses some tool classes in'com.github.xbdcc:Cutils:0.0.10', and the code has been formatted in Code Style-Kotlin.

  • First, we decide whether the current notification or interface or content has changed in our onAccessibilityEvent method, which inherits the implementation of the AccessibilityService class.
        when (event.eventType) {
            AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED -> {
                LogUtils.d("Notification of change:$event")
            }
            AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED -> {
                LogUtils.d("Interface change:$event")
                openRedEnvelope(event)
            }
            AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED -> {
                LogUtils.d("Content change:$event")
                clickRedEnvelope()
            }
        }
  • Find the relevant Activity class name and id or text code:
    private val WECHAT_PACKAGE = "com.tencent.mm"
    private val WECHAT_LUCKYMONEY_ACTIVITY =
        "$WECHAT_PACKAGE.plugin.luckymoney.ui.LuckyMoneyNotHookReceiveUI" //Wechat Red-envelope Bomb

    private val RED_ENVELOPE_FLAG_ID = "com.tencent.mm:id/aq7" //Chat Page Differentiates Red Packet id
    private val RED_ENVELOPE_ID = "com.tencent.mm:id/aou" //Chat Page Red Packet Click Box Control id
    private val RED_ENVELOPE_OPEN_ID = "com.tencent.mm:id/cyf" //Click on control id for red envelope page
  • Discover the red envelope and click on the red envelope code:
    private fun clickRedEnvelope() {
        //If you don't find the red envelope, don't go on.
        if (!AccessibilityServiceUtils.isExistElementById(
                RED_ENVELOPE_FLAG_ID,
                rootInActiveWindow
            )
        ) return
        //Click on the red envelope
        AccessibilityServiceUtils.findAndClickOneById(RED_ENVELOPE_ID, rootInActiveWindow)
    }
  • The red envelope bullet box page appears to open the red envelope code:
    private fun openRedEnvelope(event: AccessibilityEvent) {
        //If the current page is not a Wechat Red Packet pop-up box, it will not continue to execute
        if (WECHAT_LUCKYMONEY_ACTIVITY != event.className) return
        AccessibilityServiceUtils.findAndClickOneById(RED_ENVELOPE_OPEN_ID, rootInActiveWindow)
    }

Test results

epilogue

Above is a simple demo that can automatically grab red envelopes by Wechat. You can also do some optimization to do the monitoring notification page to judge whether the red envelope has been grabbed, and delay clicking on the filter password to determine whether the red envelope has been grabbed.

Demo full code address

https://github.com/xbdcc/Grab...

Snatch Red Pack APP Download Address:

http://xbdcc.cn/GrabRedEnvelo...

Posted by sirup_segar on Wed, 31 Jul 2019 10:23:35 -0700