​ Replaying Strategy and String command

A project log for Ugly USB

After the Good and the Bad here you are the Ugly USB!

danjovic 04/21/2017 at 13:170 Comments
The interpreter use a flag named 'Replaying' to differentiate the first time the Replay token is found from the consecutive times.

Whenever the Replay command is found during the execution the 'Replaying' is check. If its False (zero) then the amount of times to repeat (Replay_Counter) is read from eeprom as an unsigned 16 bit and the flag is set True (not zero) and the 'loop' address is set by attributing to the current address (EEprom_Addr) the last address recorded for this purpose (Last_EEprom_Addr).
The next iterations, with Relaying flag set, will decrement the variable Replay_Counter until it reaches zero. When it occurs, the current address is added by three so it points right after the Replay command.

The last address recorded is in practice a Return Address and it is recorded everytime the interpreter gets a 0x00 command. Thus to repeat a command it shall be preceeded by 0x00. This subtle detail makes possible to repeat not only the last command, but rather it allows to repeat a block of commands.

The way the interpreter is implemented makes the STRING command (0xAC) rather useless, since the HID codes are simply typed in. One remark though, is that shifted characters shall be transmitted as a hold+shift+character

STRING hello!
h    e    l    l    o    hold shift 1
0x0b 0x08 0x0f 0x0f 0x12 0xA8 0xE1 0x1E