UP | HOME

Reverse engineering my usb mouse

Table of Contents

Prologue

Hi everyone, I have been interesting in making drivers for Linux, principally, to help friends who are switching to Linux and want support for their devices. This blog post will attempt to show you my setup and resources for an easy and quick driver for my logitech g203 lightsync mouse.

Check the source code at g203d.

Tools

  • tshark
  • termshark
  • qemu

Dramatis personae

  • Linux: any linux distribution.
  • Mouse: a logitech g203 Lightsync mouse.
  • window$s: a windo$ws vm with the official logitech driver installed.

Where the reverse engineering begins

I wanted to start with doing reverse engineering in a controlled environment, this means using abstraction already made by the kernel, which in this case would the HIDRAW interface. I mean, I could have made a kernel-space driver but that could be more risky and I do not feel comfortable enough to do that, at least that was what I thought.

Like I said on previous paragraphs, I did reverse engineering to a g203L mouse, It was kinda easy, I only had to use Wireshark (I refer to the wireshark suite of tools no the GUI program) with usbmon and sniff HID packets that window$s send to the mouse.

I, kinda, finish the userland driver, it only changes the rgb color of the mouse and add some specific effects, it is not by any means a full blown replacement of Openrgb or any other tool. I made this only to test my reverse engineering, I think it was pretty fun until I stopped to do the reverse engineering part and I had to be more focus on repetitive task like coding a CLI client and so on.

You cheater, say the truth

Well… I still need to improve a lot, this world of reverse engineering is tricky and has a lot of rough edges, corporation and device makers tend to do tricks to obscure and confused the behavior of their devices.

To be honest, I did use help to understand how the mouse works, I went to the source code of OpenRgb to compare and acknowledge or refused my inferences of the mouse's behavior, therefore It could have taken me more time but I skimmed Openrgb's code.

Other methods

I could have used other tools, maybe other interface, but I end up doing it the way I did. I would like to test Ghidra or any other tool, the thing is that this kind of tools can take a lot of time because they have to decompile and assemble code from a binary, and some binaries (most in windows) are a huge piece of bloated software.

Conclusion

I did not find that hard to reverse engineering this mouse, although I did not make it alone. I will try to reverse engineering devices that do not have any project or tool already made, there are some embedded devices that I would like to use. I think that there is so much fun on this field, but sometimes it is overwhelmed by the more iterative part, that is the coding, I mean, I do not think coding is boring, but this kind of programming feels repetitive and boring, and the fun part is cracking the device down to the most basic level.

Resources