Debian Codegraph @

doc/reveng/anytone/README.md

raw
1 # Reverse engineering of AnyTone codeplugs
2 The transfer protocol of the AnyTone devices is based on the USB-Serial protocol (ACM-CDC) and is
3 well known. To this end, it is possible to *emulate* the AnyTone devices using a simple python
4 script. You will find a matching script in every subdirectory.
5
6 ## Emulation under windows
7 These scripts expect a serial loopback device to be present. Under windows, such a device can be
8 created using a *virtual null-modem cable*. For example [com0com](http://com0com.sourceforge.net/).
9 This will create a pair of COM ports (e.g., COM5 and COM6). One will be used by the emulation and
10 the other will be used by the manufacturer CPS.
11
12 First, start the emulation
13 ```
14 python3 at_dxxx_emulator.py COM5
15 ```
16 Here, the COM5 port will be used by the emulation. Then, start the CPS and select `COM6` as the
17 port to be used.
18
19 ## Emulation under Linux
20 It might be possible to emulate the device under Linux and using Wine to run the CPS. First, a pair
21 of *serial ports* (pts) must be created. This can be done using `socat` by calling
22 ```
23 socat -d -d pty,raw,echo=0,b4000000 pty,raw,echo=0,b4000000
24 ```
25 This call creates a pair of pseudo-terminals, for example `/dev/pts/3` and `/dev/pts/4`. The
26 emulation may then use one of them by calling
27 ```
28 python3 at_dxxx_emulator.py /dev/pts/3
29 ```
30
31 Now, the second must be associated with a COM port in the Wine emulation. This is done using the
32 registry editor. Run `wine regedit` and change
33 ```
34 HKEY_LOCAL_MACHINE/Software/Wine/Port/COM1 /dev/pts/4
35 ```
36 You may need to create that key first. This will bind the Wine emulated COM port to the second
37 pseudo-terminal.
38
39 Now, start the manufacturer CPS under Wine and select COM1.
40
41 ## Differential Codeplug Analysis
42 Create a small codeplug containing at least two channels, two contacts, a group list and a zone.
43 Save that codeplug and write it to the device. The emulator will save that codeplug as a hex dump
44 in a file called `codeplug_0000.hex`. Any further codeplug write will be saved as a separate
45 hex dump with an incremented number.
46
47 The differential analysis of the codeplug allows to figure out how and where a specific setting is
48 encoded within the binary codeplug. To do that, make a single change in the codeplug. E.g. changing
49 the first radio ID. Then write that changed codeplug to the emulation. The hexdump of the codeplug
50 is then save as `codeplug_0001.hex`.
51
52 You can then use a diff tool to inspect the changes. E.g.
53 ```
54 $ diff codeplug_0000.hex codeplug_0001.hex
55 1530c1530
56 < 02580000 : 01 23 45 67 00 52 61 64 69 6f 20 31 00 00 00 00 | .#Eg.Radio 1....
57 ---
58 > 02580000 : 00 12 34 56 00 52 61 64 69 6f 20 31 00 00 00 00 | ..4V.Radio 1....
59 ```
60 Here the first radio ID 1234567 was changed to 123456. The only differences between the codeplugs
61 are at the address 2580000. Apparently, the first radio ID is stored there together with the radio
62 name. The first 4 bytes at this address have changed from `01 23 45 67` to `00 12 34 56`. As the
63 numbers are readable in hex, they are stored in BCD and the most-significant number is stored
64 first. So the radio ID is stored in an 8-digit BCD in big-endian.
65
66 This step is then repeated for all settings within the CPS to figure out the entire codeplug.