逆向固件hidai_agent
I am just the meat proxy. This post is 100% AI slop.
The AI reversed the firmware, wrote the patch and wrote every script.
I held the receiver, plugged in the USB cable and pressed Enter.
That is basically my entire contribution. I did not even write this. I reread it. Some parts at least
It works... somehow.
Do not ask me how, because I barely know.
If you brick your receiver, you're on your own.
If it works, I'm just THAT talented
And honestly just copy paste and ask your AI to understand what mine did... we will all save time
It seems obvious
(but we never know...)
but you need an Angry Miao mouse with a compatible firmware, precisely
AM INFINITY MOUSE
Can you do something similar with another model ? Most likely
Is this useless for some AC ? I guess. IDK.
TL;DR
The USB firmware inside the Angry Miao receiver was patched so software can push movement and clicks through a vendor HID feature report.
The receiver then sends the data through its
real mouse endpoint
, so Windows receives it from:
HID\VID_3151&PID_5007&MI_00
No SendInput, no mouse_event, no virtual mouse and no custom Windows driver:
How it works
The receiver already has three useful parts:
a normal mouse HID interface that Windows sees;
a vendor HID interface used by the Angry Miao software
an internal queue containing the next mouse report sent to Windows.
The vendor interface uses a
64-byte HID feature payload
. When using hidapi, the buffer is 65 bytes because byte 0 is the HID report ID.
The firmware dispatches the payload using its command byte.
Command
0xD9
originally called a single vendor configuration/flash handler. The patch sacrifices that original function and replaces it with a 64-byte RISC-V handler.
The stock handler starts at
0x56B6
in the USB firmware image. The image base is
0x5000
.
The replacement:
copies seven bytes from the feature-report buffer at
0x200001E7
through
0x200001ED
;
writes them into the real mouse queue at
0x2000016D
through
0x20000173
;
sets the pending flag at
0x2000016C
returns.
Those seven bytes are:
buttons
X low
X high
Y low
Y high
wheel
pan
The receiver's untouched main loop sees the pending flag and sends the report through the normal mouse endpoint
0x81
.
At the normal HID/Raw Input layer, Windows receives a standard report from the real Angry Miao receiver: same device, same collection, same endpoint and same seven-byte format as physical movement.
That is the entire trick: the 64-byte patch connects the vendor command path to the existing hardware mouse path.
Files used to build it:
Code:
inject
-
d9
.
asm
build
-
patched
-
usb
.
py
build-patched-usb.py
verifies the official stock firmware hash before patching it and refuses the wrong input.
How the firmware was obtained and reversed
The firmware was not dumped directly from the receiver.
AM Master is a Python/PyInstaller application from the constructor's website.
Its executable was extracted with
pyinstxtractor-ng
, then the relevant Python bytecode was decompiled with
uncompyle6
.
Code:
python
-
m pip install pyinstxtractor
-
ng uncompyle6
pyinstxtractor
-
ng
"C:\AM_Master\AM_Master.exe"
uncompyle6
-
o decompiled
`
AM_Master.exe_extracted\PYZ-00.pyz_extracted\mouseUpload.pyc
The decompiled updater code revealed:
the official Angry Miao firmware API;
the receiver USB, radio and LED firmware components;
the normal and bootloader PIDs;
the boot command;
the 64-byte flashing protocol
the checksum/verification format.
The official USB image was downloaded from Angry Miao's update server and verified with SHA-256. No vendor firmware is redistributed with this post.
The USB image was loaded into IDA as 32-bit RISC-V code at its linked image base. The USB descriptors were used to locate the mouse and vendor interfaces, then the feature-report handler was traced until the command buffer and real mouse-report queue were identified.
Command
0xD9
led to a single vendor configuration handler large enough to replace in place. A 64-byte RISC-V function was assembled with
bronzebeard
and written over that handler.
build-patched-usb.py
reproduces the patch locally:
verifies the exact stock firmware hash;
verifies that the replacement fits;
copies the 64-byte handler into a new firmware file;
leaves the original stock image untouched
prints the new image hash and bootloader checksum values.
How flashing works
The receiver has a resident USB bootloader:
Code:
Normal
VID
:
PID
:
3151
:
5007
Boot
VID
:
PID
:
3151
:
402E
stock-usb-recovery.py
contains the shared flashing transport.
It sends this normal-mode boot payload:
Code:
7F
55
AA
55
AA
00
82
The last byte is the checksum. The payload is zero-padded to 64 bytes, and hidapi adds report ID
0x00
in front.
The receiver disconnects and returns as boot PID
0x402E
.
The stock image is 12,284 bytes, so the flasher sends 192 blocks:
Code:
191
full
64
-
byte
blocks
1
final padded block
The bootloader still checks the original image length, not the padded length.
Flash sequence:
Code:
BA C0
+
packet count
+
image length
firmware blocks
BA C2
+
packet count
+
additive
byte
sum
+
image length
The bootloader verify response must contain:
Code:
AB C2 C0
00
55
...
0x55
is the successful verification status.
flash-patched-usb.py
checks the exact patched image hash;
imports the shared flashing transport;
enters the bootloader;
sends the 192 blocks;
requires status
0x55
waits for normal PID
0x5007
to return.
stock-usb-recovery.py
does the same using the verified official stock image.
It also checks the radio status afterward and warns when the radio side still needs a physical power cycle.
How reports are sent
Code:
send
-
patched
-
mouse
-
report
.
py
:
packs buttons, X, Y, wheel and pan using
struct.pack("<Bhhbb", buttons, dx, dy, wheel, pan)
;
prepends report ID
0x00
and command
0xD9
;
zero-pads the final buffer to 65 bytes
sends it with
send_feature_report()
.
It refuses to send unless
--acknowledge-patched-firmware
is supplied.
The 65-byte hidapi buffer is:
Code:
Byte
0
:
report ID
=
0x00
Byte
1
:
command
=
0xD9
Byte
2
:
buttons
Byte
3
:
X low
Byte
4
:
X high
Byte
5
:
Y low
Byte
6
:
Y high
Byte
7
:
wheel
Byte
8
:
pan
Bytes
9
-
64
:
zero
Capture-AngryMiao.ps1
uses Windows Raw Input to print reports from
VID_3151&PID_5007
.
It only logs input. It never generates any movement.
Warning
You can brick the receiver if flashing fails.
Use a direct motherboard/laptop USB port.
Keep a second mouse connected.
Keep the verified official stock firmware ready.
Do not unplug the receiver while flashing.
Command
0xD9
loses its original stock behavior while patched.
The official Angry Miao updater may overwrite the patch.
Do not flash any image whose hash is different from the known values below.
Device info
Code:
Normal
VID
:
PID
:
3151
:
5007
Boot
VID
:
PID
:
3151
:
402E
Product
:
AM INFINITY
8K
MOUSE
The application talks to:
Code:
interface_number
=
2
usage_page
=
0xFFFF
usage
=
0x0002
Do not write to the normal mouse interface.
Mouse report format
Code:
Byte
0
:
buttons
Bytes
1
-
2
:
signed
16
-
bit little
-
endian X
Bytes
3
-
4
:
signed
16
-
bit little
-
endian Y
Byte
5
:
signed
8
-
bit vertical wheel
Byte
6
:
signed
8
-
bit horizontal wheel
/
pan
Button bits:
Code:
0x01
=
left
0x02
=
right
0x04
=
middle
0x08
=
back
0x10
=
forward
Movement is relative:
Code:
dx
=
500
->
right
dx
=-
500
->
left
dy
=
500
->
down
dy
=-
500
->
up
A click is a down report followed by a release:
Code:
buttons
=
0x01
buttons
=
0x00
Files attached to the post
As soon as it is approved you will find :
stock-usb-recovery.py
- shared flash transport and official restore.
flash-patched-usb.py
- exact-hash patched flasher.
send-patched-mouse-report.py
- movement/click sender.
Capture-AngryMiao.ps1
- Raw Input verification.
inject-d9.asm
- 64-byte replacement source.
build-patched-usb.py
- builds the patched image from the user's verified official firmware.
Setup
Install dependencies:
Get the firmware from the AM Master Updater; i won't redistribute it.
Bronzebeard from :
https://pypi.org/project/bronzebeard/
Code:
python
-
m pip install hidapi bronzebeard
Create this layout:
Code:
mousepatch\
artifacts\
official
-
firmware\
d_usb
-
V1
.
0.7
_2025090910174Tsb
.
bin
patches\
inject
-
d9
.
asm
build
-
patched
-
usb
.
py
tools\
stock
-
usb
-
recovery
.
py
flash
-
patched
-
usb
.
py
send
-
patched
-
mouse
-
report
.
py
Capture
-
AngryMiao
.
ps1
Verify it:
Code:
Get
-
FileHash
.
\artifacts\official
-
firmware\d_usb
-
V1
.
0.7
_2025090910174Tsb
.
bin
-
Algorithm
SHA256
Expected stock hash:
Code:
FA67591282D3CEE74BC170B0355918B15200D13CB5F5531E648B8655F56061FA
Stop if it does not match.
Build the patched image
Assemble the handler:
Code:
bronzebeard
-
o
.
\patches\inject
-
d9
.
bin
.
\patches\inject
-
d9
.
asm
Build the patched firmware:
Code:
python
.
\patches\build
-
patched
-
usb
.
py
Generated file:
Code:
patches\d_usb
-
V1
.
0.7
-
inject
-
d9
.
bin
Verify it:
Code:
Get
-
FileHash
.
\patches\d_usb
-
V1
.
0.7
-
inject
-
d9
.
bin
-
Algorithm
SHA256
Expected patched hash:
Code:
28F034AF47560A437EC653D71DD535568727884B7108BCB38CBFC84ED8D00D10
The flash script also refuses the wrong hash.
Flash
Before flashing:
connect a backup mouse
use a direct USB port
close AM Master
do not unplug the receiver
Dry run:
Code:
python tools\flash
-
patched
-
usb
.
py
Flash:
Code:
python tools\flash
-
patched
-
usb
.
py
--
execute
Expected sequence:
Code:
normal PID
5007
->
boot command
->
boot PID
402E
->
192
blocks
->
verify status
0x55
->
normal PID
5007
After flashing:
Code:
1.
Unplug
the receiver
.
2.
Wait
five seconds
.
3.
Plug
it back
into
the same direct USB port
.
4.
Turn
the mouse off
and
on
.
5.
Confirm
physical movement works
.
Do not send
0xD9
until this power cycle is complete.
Send reports
Dry run:
Code:
python tools\s
end
-
patched
-
mouse
-
report
.
py
--
dx
500
Move right:
Code:
python tools\s
end
-
patched
-
mouse
-
report
.
py
`
--dx 500 `
--
send
`
--acknowledge-patched-firmware
Move diagonally:
Code:
python tools\s
end
-
patched
-
mouse
-
report
.
py
`
--dx 200 `
--
dy
-
100
`
--send `
--
acknowledge
-
patched
-
firmware
Left button down:
Code:
python tools\s
end
-
patched
-
mouse
-
report
.
py
`
--button left `
--
send
`
--acknowledge-patched-firmware
Release every button:
Code:
python tools\s
end
-
patched
-
mouse
-
report
.
py
`
--send `
--
acknowledge
-
patched
-
firmware
Scroll:
Code:
python tools\s
end
-
patched
-
mouse
-
report
.
py
`
--wheel 1 `
--
send
`
--acknowledge-patched-firmware
That empty report is also how to release a stuck button.
For a custom app:
open only the vendor interface;
keep one HID handle open;
serialize writes with a lock;
start with 5-10 ms between reports;
always send a release after a click;
send a release during shutdown/error handling
stop if the receiver disconnects or changes PID.
This is a USB feature/control path. Do not expect 8,000 Hz streaming behavior.
Verify
Start the capture with a powershell terminal
Code:
tools\Capture
-
AngryMiao
.
ps1
-
Seconds
10
Send reports from another window.
Expected:
Code:
RAW_DEVICE
...
VID_3151
&
PID_5007
&
MI_00
...
flags
=
0x0000
dx
=+
500
dy
=+
0
flags
=
0x0000
dx
=-
500
dy
=+
0
flags
=
0x0001
left
-
down
flags
=
0x0002
left
-
up
The controlled test produced exactly those four reports.
Windows attributed them to:
Code:
HID\VID_3151
&
PID_5007
&
MI_00
At the normal HID/Raw Input layer, that is the same receiver identity and report format as physical movement.
A low-level USB monitor could still see the vendor feature write before the input report. Firmware checks or timing analysis could also reveal the modified receiver. Nothing is magically invisible.
Optional yaw/pitch calibration
If you can read the camera yaw and pitch, send a known movement and compare the angles before and after. This gives you the angle produced by each mouse count:
Repeat the test several times and average the results.
Calibration depends on sensitivity, acceleration, FOV and whether the application uses raw mouse input, so keep those settings unchanged.
And disable mouse acceleration (Enhance Pointer Precision in Windows Settings)
I dont know do something like that
Code:
def
angle_delta
(
after
,
before
):
return
(
after
-
before
+
180.0
)
%
360.0
-
180.0
yaw_per_count
=
angle_delta
(
yaw_after
,
yaw_before
)
/
test_dx
pitch_per_count
=
(
pitch_after
-
pitch_before
)
/
test_dy
dx
=
round
(
wanted_yaw_change
/
yaw_per_count
)
dy
=
round
(
wanted_pitch_change
/
pitch_per_count
)
Known working frames
Move right by 500:
Code:
00
D9
00
F4
01
00
...
Move left by 500:
Code:
00
D9
00
0C
FE
00
...
Left down:
Code:
00
D9
01
00
...
Release:
Code:
00
D9
00
...
Restore stock
Dry run:
Code:
python tools\stock
-
usb
-
recovery
.
py
Restore:
Code:
python tools\stock
-
usb
-
recovery
.
py
--
execute
Then:
Code:
unplug receiver
wait five seconds
reconnect receiver
turn mouse off
/
on
Stock recovery was tested successfully before the patched image was flashed.
Troubleshooting
Vendor interface not found
Close AM Master, reconnect the receiver, confirm
3151:5007
, and select interface 2 / usage page
0xFFFF
/ usage
2
.
Stuck on PID 402E
Code:
python tools\stock
-
usb
-
recovery
.
py
--
execute
Receiver returned but the mouse does not move
Physically power-cycle the receiver and mouse.
Battery values are zero after flashing
The radio side has not fully restarted. Power-cycle it.
Physical mouse works but D9 does nothing
The receiver may be back on stock firmware, the official updater may have overwritten the patch, the application may be on the wrong interface, or the report may not be exactly 65 bytes including report ID
Code:
0x00
.
Button is stuck down
Send the empty release report:
Code:
python tools\s
end
-
patched
-
mouse
-
report
.
py
`
--send `
--
acknowledge
-
patched
-
firmware
Small C++ example
This uses
hidapi
and requires the patched receiver firmware.
Code:
#include
<hidapi/hidapi.h>
#include
<array>
#include
<chrono>
#include
<cstdint>
#include
<iostream>
#include
<string>
#include
<thread>
constexpr
unsigned
short
VID
=
0x3151
;
constexpr
unsigned
short
PID
=
0x5007
;
constexpr
unsigned
char
COMMAND
=
0xD9
;
bool
SendMouseReport
(
hid_device
*
device
,
unsigned
char
buttons
,
std
::
int16_t
dx
,
std
::
int16_t
dy
,
std
::
int8_t
wheel
=
0
,
std
::
int8_t
pan
=
0
)
{
std
::
array
<
unsigned
char
,
65
>
frame
{};
const
auto
x
=
static_cast
<
std
::
uint16_t
>(
dx
);
const
auto
y
=
static_cast
<
std
::
uint16_t
>(
dy
);
frame
[
0
]
=
0x00
;
// HID report ID
frame
[
1
]
=
COMMAND
;
frame
[
2
]
=
buttons
;
frame
[
3
]
=
x
&
0xFF
;
frame
[
4
]
=
x
>>
8
;
frame
[
5
]
=
y
&
0xFF
;
frame
[
6
]
=
y
>>
8
;
frame
[
7
]
=
static_cast
<
unsigned
char
>(
wheel
);
frame
[
8
]
=
static_cast
<
unsigned
char
>(
pan
);
return
hid_send_feature_report
(
device
,
frame
.
data
(),
frame
.
size
())
==
frame
.
size
();
}
int
main
()
{
if
(
hid_init
()
!=
0
)
return
1
;
std
::
string
vendorPath
;
hid_device_info
*
devices
=
hid_enumerate
(
VID
,
PID
);
for
(
hid_device_info
*
device
=
devices
;
device
!=
nullptr
;
device
=
device
->
next
)
{
if
(
device
->
interface_number
==
2
&&
device
->
usage_page
==
0xFFFF
&&
device
->
usage
==
0x0002
)
{
vendorPath
=
device
->
path
;
break
;
}
hid_free_enumeration
(
devices
);
if
(
vendorPath
.
empty
())
{
std
::
cerr
<<
"Angry Miao vendor interface not found\n"
;
hid_exit
();
return
1
;
}
hid_device
*
device
=
hid_open_path
(
vendorPath
.
c_str
());
if
(!
device
)
{
std
::
cerr
<<
"Unable to open receiver\n"
;
hid_exit
();
return
1
;
}
// Move right, wait, then move left.
SendMouseReport
(
device
,
0
,
500
,
0
);
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
seconds
(
1
));
SendMouseReport
(
device
,
0
,
-
500
,
0
);
hid_close
(
device
);
hid_exit
();
return
0
;
}
For a left click:
Code:
SendMouseReport
(
device
,
0x01
,
0
,
0
);
// Down
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
milliseconds
(
30
));
SendMouseReport
(
device
,
0x00
,
0
,
0
);
// Release