Reference: https://github.com/ssh333/Monster-Party
Files
The main subject of this reverse-engineering effort is a Flutter app (怪兽派对.apk, arm64-v8a). The app scans for devices over Bluetooth and, once a device is successfully identified, adds it to the app’s device queue. The physical device we obtained has two DC motors, which the app can control separately by adjusting the PWM frequency.
Exploration
Unpacking with jadx shows that all the code is obfuscated and that the business logic is not in the Java layer. We can also see that the lib directory contains libflutter.so and libapp.so, where libapp.so holds the Dart 3.11 AOT business logic. In addition, libflutter_blue_plus_android.so is present — the native layer of the BLE plugin. That one is a library, so we won’t reverse it.
Because this app depends on Bluetooth and I don’t have a rooted phone on hand, dynamic debugging isn’t convenient, so I could only hunt for clues through string searches.
The searches pinned down a few key strings:
mix_device— the package name of the vendor’s in-house SDKwriteMotor— the motor command identifierAES— this points tobasic/v3; there is alsov1andv2before it, and thev3protocol uses AES encryptionwrite*— the command entry-point functions
This reveals that the device involves three kinds of protocol, using the v1, v2, and v3 protocols.
All three protocols involve a lot, so reverse engineering them is fairly difficult. Using Android HCI logs, I remote-controlled the toy with the original software and captured the logs. Log analysis confirmed:
- Protocol: v2
- Target device name: Ankni
- GATT service:
00009000-0000-1000-8000-00805f9b34fb
This also gives a glimpse of part of the protocol design:
1 | write characteristic: 0x9002 |
Native-layer Reverse Engineering
Next, let’s dig into the native layer.
After Flutter/Dart AOT compilation, all symbols are stripped. Plain disassembly only exposes addresses and registers, and class names, method names, and field offsets cannot be recovered. blutter recovers those symbols by parsing the object pool inside the Dart VM snapshot. blutter’s output is extremely high quality and very readable.
Key objects in the pp file:
1 | [pp+0x5bb60] AnonymousClosure: (0x163ff8c), in [package:mix_device/src/bluetooth/v2/ble_device_v2.dart] BLEDeviceV2::_handleOperate (0x163f868) |
1 | // from _handleOperate (0x163f868) |
field_93=0x9001= the op characteristic, Write With Response, used for reads and configuration writes
Also:
1 | [pp+0x5bd00] AnonymousClosure: (0x160ae80), in [package:mix_device/src/bluetooth/v2/ble_device_v2.dart] BLEDeviceV2::_handleFunction (0x160a9f0) |
1 | // from _handleFunction (0x160a9f0) |
field_97=0x9002= the function characteristic, Write Without Response, used for vibration/power-off
Both fields live in ble_device_v2.dart.
Analyzing this function lets us determine the frame structure:
1 | byte[0] = CMD |
Let’s analyze the 0xA0 command, which is our main recovery target; the main code is in writeMotor.
1 | ; AllocateArray r2=#0x2 (SMI tagged: 2>>1 = 1+1 = 2, but payload = [N] + pwms) |
SMI tag verification: in blutter’s comment, movz x1, #0x64 → logical 50 (0x64 >> 1 = 50, but 0x64 = 100 decimal). In fact, movz #0x64 at the battery clamp = 100, consistent with 0x64 = 100 decimal. The ÷2 for SMI is only needed when decoding with asr #1; byte payloads are written directly.
The resulting vibration frame is:
1 | A0 [0x80|((N+1)<<3)] N pwm[0] pwm[1] ... pwm[N-1] |
Example: 1 motor at 50% → A0 90 01 32; stop → A0 90 01 00.
The response mechanism lives mainly in onValueReceived; taken together with handleOperate:
- Reads go over
0x9001(Write With Response), sending[cmd, 0x00](header byte = 0 means read) - The device’s reply comes back via notify;
onValueReceivedmatches the pending list by thecmdbyte (firstWhereOrNull) and completes the Future - Timeout:
timeoutCallback @ 0x16402a8,Future.delayed(raw 0x258 >> 1 = 300ms), no retry
The internal logic of onValueReceived is:
1 | data[0] = cmd |
Device-initiated push events (Action = 1):
0x14: battery level,payload[0]= 0–1000x15: heartbeat (device-initiated; no app-side heartbeat needed)0xA1: button event →onReceivedKeyData, type byte0x10/0x11/0x20/0x30/0x60
Next let’s look at the operation queue GlobalBLEOperationQueue; the file is global_ble_operation_queue.dart. The following facts can be established:
- Global singleton; all GATT operations are strictly serialized (
_isProcessingmutex) execute @ 0x16078d8→_enqueue @ 0x16085dc→_processQueue @ 0x1607ba4- Priority ordering: sorted by priority int on insertion, lowest first
- 3 s watchdog (Timer,
0x1607dc0); on timeout it marks the entry cancelled and does not retry
Then a potential bug emerged: when the underlying BLE future never settles, the 3 s watchdog does not advance the queue.
The data models live in mix_model.dart, including MixDeviceMotorLevel:
1 | field_7 (offset 0x8) = b0, default 0 |
This is used by the 0x17 motor strength configuration command.
The PWM generation pipeline is in motor_pwm_transformer.dart:
defaultSinglePwmRange = (min=10, max=100)defaultPwmRanges(3 presets):(10,50),(20,80),(40,100), selected by gesture classapplyMotorRange: 0 → 0; non-zero → clamped to[max(min,10), min(max,200)]- Two-toy mapping:
_buildSyncPwmByIndex: aligns by index, padding with the trailing value when short_buildInterleavePwmByAverage: the secondary device runs the inverse of the primary device’s average (100 - avg)
We were also able to find the v3 protocol. A shallow analysis: the v3 protocol is very complex. It calls the backend POST /basic/v3/auth/signature/secret to obtain a per-device unique key, and the frame contents appear to involve AES encryption.
The main functional points are listed below:
| Feature | Location |
|---|---|
| Outbound frame construction (function path) | BLEDeviceV2._handleFunction@ 0x160a9f0 |
| Outbound frame construction + op send (op path) | BLEDeviceV2._handleOperate@ 0x163f868; _dispatchOperateWithTimeout@ 0x163f7c0 |
| Vibration | BLEDeviceV2.writeMotor@ 0x17e1108(cmd 0xA0) |
| Notification parsing + dispatch | BLEDeviceV2.onValueReceived@ 0x162bff0; button parsing onReceivedKeyData@ 0x162c… |
| Read-response timeout (300 ms) | timeoutCallback@ 0x16402a8( Future.delayed, raw 0x258→300) |
| Init / discovery / MTU / notifications | init@ 0x1634d34; initCharacteristics@ 0x16350e8; _initMtu@ 0x163580c |
| Characteristic fields | field_97= 0x9002 (write/function); field_93= 0x9001 (op) |
| Queue | GlobalBLEOperationQueue.execute@ 0x16078d8; _processQueue@ 0x1607ba4; timeout 3 s @ 0x1607dc0 |
| Models | MixDeviceMotorLevel( mix_model.dart@ 0x163c8fc); PWM MotorPwmTransformer( motor_pwm_transformer.dart) |
Reconstruction
GATT Profile
Characteristics are located solely by their 16-bit UUID — the app flattens all discovered characteristics (across every service) into a single Map<uuidString, characteristic> and looks them up by UUID. No parent-service UUID filtering is applied, so only the characteristic UUID matters. (16-bit UUIDs are expanded using the SIG base UUID 0000XXXX-0000-1000-8000-00805f9b34fb.)
| UUID (16-bit) | Code name (field) | Role | How the app writes here | Notifications |
|---|---|---|---|---|
0x9002 |
“function” (field_97) |
Real-time function commands (vibration 0xA0, power-off 0xA2, extend 0xA3) |
Write Without Response (fire-and-forget) | Enabled |
0x9001 |
“op” (field_93) |
Operation commands and queries (all reads + configuration writes: 0x01…0x18) |
Write With Response (waits for notification) | Enabled |
0x2902 |
CCCD descriptor | Enables notifications on both characteristics | — | — |
Note: the naming in the code is counter-intuitive — the “function” characteristic (
0x9002) carries vibration data, while the “op” characteristic (0x9001) carries control/query commands.setNotifyValue(true)is applied to both, and both feed into the sameonValueReceivedparser.
Connection and Initialization
BLEDeviceV2.init() runs after the BLE link is established:
discoverServices()(through the queue).await Future.delayed(25 ms)← stabilization wait.requestMtu()(Android). The negotiated MTU is stored/logged (communicate mtu = …). Frames are small (≤ about 18 bytes), so MTU is not a control constraint.await Future.delayed(50 ms)← stabilization wait.- Build the
uuid → characteristicmap; assert that it contains"9002"and"9001". If either is missing →"init characteristics failed". initCharacteristics():setNotifyValue(true)on both0x9001and0x9002(writing the CCCD0x2902), and register a value-change handler (onValueReceived) on both.- The service layer then performs device bring-up (polymorphic, order approximate): toy verification
0x00, device-info reads (0x01deviceID,0x02firmware,0x03MAC,0x04SN,0x06productID,0x05variantID,0x09hardwareID), and device initialization0x0B. Failure here → session"init_failed"/"设备初始化失败:无法完成初始化流程"(device initialization failed: could not complete the initialization flow).
v2 has no encryption gate (unlike v3). The 0x00 verification is a lightweight handshake; no server-issued key is needed to control the device. Once notifications are enabled, you can send vibration frames on 0x9002.
Frame Format
Every v2 frame — outbound and inbound — is:
1 | byte[0] = CMD // command code |
Bit layout of the header byte byte[1]:
1 | bit: 7 6 5 4 3 2 1 0 |
- No checksum / CRC. No STX/ETX.
- Inbound validation: the parser requires
total >= 2andtotal == LEN + 2; otherwise it logs"on op received invalid length data"and drops the frame. - Since
LENis 4 bits, the per-frame payload is ≤ 15 bytes.
There are two transmission paths:
| Path | Used by | Characteristic | Write type | Wait for a reply? |
|---|---|---|---|---|
_handleFunction(cmd, data) |
0xA0vibration, 0xA2power-off, 0xA3extend |
0x9002 |
Write Without Response | No (fire-and-forget) |
_handleOperate(OPModel)via _dispatchOperateWithTimeout |
All reads + configuration writes (0x01…0x18) |
0x9001 |
Write With Response | Yes — match the notification, 300 ms timeout |
Complete Command Set
CMD codes (from the in-code label map). Direction: ↑ app→device, ↓ device→app.
| CMD | Name | Direction | Path/Notes |
|---|---|---|---|
0x00 |
Toy verification | ↕ | op path; connection handshake |
0x01 |
Device ID | ↑request/↓response | read; response payload = 4 bytes → uint32 |
0x02 |
Firmware version | ↑/↓ | read |
0x03 |
MAC address | ↑/↓ | read |
0x04 |
SN | ↑/↓ | read |
0x05 |
Variant ID | ↑/↓ | read |
0x06 |
Product ID | ↑/↓ | read |
0x07 |
Combo product ID | ↑/↓ | read |
0x08 |
Combo variant ID | ↑/↓ | read |
0x09 |
Hardware ID | ↑/↓ | read |
0x0A |
Clear data | ↑ | op write |
0x0B |
Device initialization | ↑ | op write; connection |
0x10 |
Travel lock | ↕ | op write; payload = TravelLockModel.toData()(about 1 byte) |
0x11 |
Power-on heating parameters | ↑ | op write; payload = HeatingModel.toData()(multi-byte) |
0x12 |
Light brightness | ↑ | op write; payload = [level](1 byte) |
0x13 |
Set heating state | ↑ | op write; payload = [on?1:0] |
0x14 |
Battery | ↑request/↓push | battery%=payload[0] |
0x15 |
Heartbeat | ↓ | device push |
0x17 |
Motor level (strength configuration) | ↕ | op; payload = MixDeviceMotorLevel.toData()= [b0, b1], default [0,100] |
0x18 |
Extended peripheral status | ↕ | op |
0xA0 |
Write vibration | ↑ | function path |
0xA1 |
Button/key | ↓ | device push → MixDeviceKeyEvent |
0xA2 |
Power off | ↑ | function path; payload = empty → on the wire A2 80 |
0xA3 |
Work-unit extension | ↑ | function path; payload = a caller-supplied List<int>(pass-through) |
0xA4 |
Pressure-report toggle | ↑ | op write; payload = [on?1:0] |
0xA5 |
Sensor-report toggle | ↑ | op write; payload = [on?1:0] |
Among these, 0xA0 is the most important: it sets the instantaneous strength of each motor. The payload for this CMD is:
1 | payload = [ N, pwm_0, pwm_1, ..., pwm_{N-1} ] |
The complete on-air frame for a Write Without Response to 0x9002:
1 | [0] = 0xA0 |
For example:
| Intent | Bytes (hex) |
|---|---|
| 1 motor @ 50 | A0 90 01 32 |
| 1 motor @ 100 | A0 90 01 64 |
| 1 motor OFF | A0 90 01 00 |
| 2 motors @ (100, 0) | A0 98 02 64 00 |
| 2 motors OFF | A0 98 02 00 00 |
| 3 motors @ (30,60,90) | A0 A0 03 1E 3C 5A |
Rules
At runtime the following rules must be observed for control to succeed:
- Deduplication: the app drops a frame identical to the previously sent frame (
_isSamePwm). If you re-send the same PWM, it may be a no-op at the app layer — send on change; the device holds the state of the last command until a new frame or power-off. To stop, send zeros (A0 … 00 …) or0xA2. - Value range:
pwm_i ∈ [0,100]. In the app’s own pipeline, an active motor is floored to 10 (values 1–9 are raised to 10; 0 stays 0) and clamped to the device’s per-motor[min,max](default max 100; the format tolerates up to 200, but no factory default exceeds 100). If you drive the device directly, you can send any value 0–100; the device firmware is expected to accept 0–100. - Cadence: the waveform/playback engine ticks at a high rate (nominally about 8 ms, raw 16 on the internal timer) and calls the send path on every tick, but the serial queue (§11) + the dedup gate determine the actual over-the-air rate. In practice: send only on PWM change; there is no artificial minimum interval in the queue, but keep BLE reasonable (≤ about 50–60 Hz).
- Written as Write Without Response → no ACK, lowest latency
Reference Pseudocode
1 | WRITE_CHAR = 0x9002 # function: vibration/power-off/extend, Write Without Response |
The connection sequence to follow:
connect → discoverServices → sleep 25ms → requestMtu → sleep 50ms → enable notify (CCCD) on 0x9001 & 0x9002 → (optional) verify 0x00 + read info → ready
Then stream vibrate frames whenever there is a change.