| 1 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
| 2 |
<html> |
| 3 |
<head> |
| 4 |
<title>So you want to reverse engineer a USB protocol</title> |
| 5 |
</head> |
| 6 |
|
| 7 |
<body> |
| 8 |
<h1>So you want to reverse engineer a USB protocol</h1> |
| 9 |
|
| 10 |
<p> |
| 11 |
So you bought the new fancy (insert device here) and it's all USB |
| 12 |
capable n stuff. Problem is (company name here) doesn't support |
| 13 |
your OS, and no one is working on software for it so you can't |
| 14 |
just sit back and wait.</p> <p>No problem you say, I'm a |
| 15 |
hard-core (insert OS name here) user, I can make my own |
| 16 |
stuff.</p> <p>Good for you, now lets get down to work.</p> |
| 17 |
|
| 18 |
<h2>Getting set up</h2> |
| 19 |
|
| 20 |
<p>If you're rich, have a sugar |
| 21 |
daddy/momma who is, or have a good company budget on your side |
| 22 |
the way to go is to have a dedicated machine running one of the |
| 23 |
supported OS's and have a hardware/software combo bus and |
| 24 |
protocol analyzer like the one from <a |
| 25 |
href="http://www.catc.com/products/chief.html">CATC</a>.</p> |
| 26 |
|
| 27 |
<p>On the other hand if you're a person of moderate income, cheap |
| 28 |
or for whatever reason something like this is not an option, a |
| 29 |
few guys came to your rescue and produced <a |
| 30 |
href="http://www.wingmanteam.com/usbsnoopy/">USB Snoopy</a>. A software |
| 31 |
based decoder that works for most versions of Microsoft |
| 32 |
Windows.</p> |
| 33 |
|
| 34 |
<p>The next problem for some people is getting something set up to |
| 35 |
run the supported OS. If you do not have dedicated hardware for |
| 36 |
this one solution is <a href="http://www.vmware.com">VMWare |
| 37 |
Workstation</a><p> |
| 38 |
|
| 39 |
<P>VMWare allows you to run an Operating System |
| 40 |
inside of a virtual machine which shows up as a window in your |
| 41 |
current Operating System. The cost is somewhat prohibitive at |
| 42 |
300 USD, and that of course does not include a license for the |
| 43 |
needed OS.</P> |
| 44 |
|
| 45 |
<P>2 open source solutions may be viable, however I have not tested |
| 46 |
them. <a href="http://www.plex86.org">Plex86</a> and |
| 47 |
<a href="http://bochs.sourceforge.net/">Bochs</a>.</p> |
| 48 |
|
| 49 |
<p>Bochs is the only solution for someone running non Intel |
| 50 |
compatible hardware and needs to run Microsoft Windows or other |
| 51 |
Intel based OS, as Bochs |
| 52 |
is a emulator not a hardware virtualizer (I'm not prepared to go |
| 53 |
into the difference, however the latter uses the existing |
| 54 |
hardware while the former pretends it IS hardware).</P> |
| 55 |
|
| 56 |
<p>Plex86 recently moved so the |
| 57 |
<a href="http://savannah.gnu.org">Savannah project management |
| 58 |
site</a>. It takes a more VMWare based virtualization approach |
| 59 |
from what I understand. The project is closely related to Bochs |
| 60 |
and they share code/have a similar user interface.</p> |
| 61 |
|
| 62 |
<h2>OK, I'm running the OS and have a way of getting the USB |
| 63 |
data.</h2> |
| 64 |
|
| 65 |
<p>Any examples I give have the assumption that you chose VMWare |
| 66 |
and USB Snoopy as that's what I'm using.</p> |
| 67 |
|
| 68 |
<p>What you need to do is get your protocol analyzer in place and |
| 69 |
ready to capture, then install the driver/software that drives |
| 70 |
the USB device. After that you need to break down the |
| 71 |
capabilities of the device that you are interested in. Rank |
| 72 |
these capabilities in terms of how easy you think they will be |
| 73 |
to figure out. Remember, baby steps. Not only will small |
| 74 |
successes bolster your ego and drive to keep going, but it will |
| 75 |
get you familiar with the protocol that you are dealing |
| 76 |
with.</p> |
| 77 |
|
| 78 |
<p>Some protocols are well put together, simple to understand and |
| 79 |
are easy to work with. You will probably never see one of these |
| 80 |
protocols as they are like many other mythical things, often |
| 81 |
talked about, never seen.</p> |
| 82 |
|
| 83 |
<p>Now we begin, with everything in place start up the software |
| 84 |
that will talk to the device, the logger should be |
| 85 |
running. When the software has finished starting up if it |
| 86 |
communicated with the device you should have data, some software |
| 87 |
polls different status information on the device while running, |
| 88 |
if this is true you should see patterns in the data and pulses |
| 89 |
going down the USB port (a nice thing about VMWare is the icon |
| 90 |
that represents the USB port will flash to show data). Stop the |
| 91 |
logger, save the data using a name like applicationstartup.log |
| 92 |
or whatever and move down your list a couple of times getting |
| 93 |
different data samples to work with, nothing complex just 2 or 3 |
| 94 |
different samples to compare.</p> |
| 95 |
|
| 96 |
<p>An understanding of the URB format is critical at this point, |
| 97 |
an URB is the basic structure for every USB request (URB stands |
| 98 |
for USB Request Block), its not an overly complex structure so |
| 99 |
take a minute to review it</p> |
| 100 |
|
| 101 |
<p>This is where a bad protocol gets frustrating, the data looks |
| 102 |
like garbage, the analyzer probably saves everything in hex |
| 103 |
making life even harder when trying to deal with simple |
| 104 |
text. Using hex is good however, because binary data wouldn't |
| 105 |
look like much and hex is portable across platforms and |
| 106 |
languages.</p> |
| 107 |
|
| 108 |
<p>If you will be dealing with simple text I have |
| 109 |
<a href="http://gargoyles.monochromatic.net/cgi-bin/viewcvs.cgi/netmd">some |
| 110 |
source</a> which takes in chars and outputs hex, and takes in hex |
| 111 |
and output's simple printable chars or .'s</p> |
| 112 |
|
| 113 |
<p>From here every protocol is different, things to look for and |
| 114 |
take notes on are Request #'s Index #'s and of course Value, |
| 115 |
which is the binary data. Transfer flags and URBLink's may also |
| 116 |
come into play on your device, URBLinks connect URB's |
| 117 |
together.</p> |
| 118 |
|
| 119 |
<p>A few sample protocol spec's that can be found on the web are |
| 120 |
the one for the <a |
| 121 |
href="http://rio500.sourceforge.net/rio_protocol.html">Rio500</a> |
| 122 |
and the one I'm working on for |
| 123 |
<a |
| 124 |
href="http://gargoyles.monochromatic.net/cgi-bin/viewcvs.cgi/netmd">Sony's NetMD Minidisc products.</a> |
| 125 |
</p> |
| 126 |
|
| 127 |
<hr> |
| 128 |
<address><a href="[email protected]">Marc Britten</a></address> |
| 129 |
<!-- Created: Sat Apr 27 10:01:23 EDT 2002 --> |
| 130 |
<!-- hhmts start --> |
| 131 |
Last modified: Sun May 12 00:49:16 EDT 2002 |
| 132 |
<!-- hhmts end --> |
| 133 |
</body> |
| 134 |
</html> |
| 135 |
<!-- LocalWords: USB |
| 136 |
--> |