Tuesday, May 14, 2013

Reverse engineering a Windows USB driver

For a while, I was really into reverse-engineering USB drivers. Don't ask why. The heart wants what the heart wants. I didn't finish this "hairball" post, but it has some info in it that still might be good.

I recently stumbled across this post and it inspired me. I decided to try to reverse engineer the USB protocol for my Omron pedometer, which can upload your step data, but only to a Windows computer.

There are two parts to writing a Linux driver for a new USB device: reverse-engineering the USB protocol, and writing the Linux program.

Reverse-engineering the USB protocol

Typically your problem is that a device only runs under Windows. Like it or not, that means that you're going to need something that runs Windows. It can be a Windows computer, or you can get fancy and run Windows as a "guest" operating system using something like VMWare to do virtualization. That is, you'd install Linux, then install VMWare, then install Windows to run under VMWare. But let's start simple.

Step 0. Find the Vendor ID and Product ID of your device

Every USB device should have a Vendor ID plus a Product ID (sometimes called a device ID) that identifies it. You'll need to discover this information before you can talk to the device. I plugged my Omron pedometer into a linux machine and typed "lsusb". You'll get a lot of information back. I saw a line like

Bus 002 Device 018: ID 0590:0028 Omron Corp.

That tells me that the vendorid is hexadecimal value 0×0590 (which is 1424 in decimal) and the productid is hex value 0×0028 (which is 40 in decimal). For other operating systems, this post tells you how to find your vendor id and product id under Mac and Windows. For Windows XP, it looks like you can run "msinfo32.exe" and then look under "Components" and then "USB" and look for "VID_" (vendor id) and "PID_" (product id).

QR: Inline image 1