Conditional Compilation
For use with DEFINE for more configurable and efficient payloads
As covered in the Constants section, DEFINE
can be used to declare constants used throughout your payloads. Using DEFINE
and some additional commands described below we can gain even more control over the source code that get included into your inject.bin
during compilation.
What problem does this solve?
Imagine you have a payload that you would like to add some optional features to. With the help of a DEFINE
you could provide a set of boolean constants to toggle those features on or off; consider the example below:
Here we have #EnableExtraFeature1
set to TRUE
. At the time of compile IF #EnableExtraFeature1 THEN
will become IF TRUE THEN
which will allow for the code within that IF
statement to be executed.
While the payload user is deciding to enable that feature before compiling their inject.bin
by setting #EnableExtraFeature1
to TRUE
, the USB Rubber Ducky is still evaluating the IF
statement during runtime of the payload even though we know IF TRUE
will always evaluate to TRUE
.
In the opposite case, the features that are disabled are still compiled into the inject.bin
. The USB Rubber Ducky still has to evaluate the IF #EnabledExtraFeature3 THEN
which we know will become IF FALSE THEN
to decide to skip the code within the IF
statement. This becomes not only a waste of space but a waste of computation that could be better used.
Solution
Using IF_DEFINED_TRUE
IF_NOT_DEFINED_TRUE
and ELSE_DEFINED
,we can conditionally include portions of our payload in the resulting inject.bin
.
These act similarly to IF / ELSE
except they are evaluated before compile time and control inclusion or exclusion of blocks of code.
IF_DEFINED_TRUE
With IF_DEFINED_TRUE
, the code within it's body/block will be compiled into the inject.bin
ONLY if the given LABEL
exists and evaluates to TRUE
Syntax
Example
IF_NOT_DEFINED_TRUE
As the opposite of IF_DEFINED_TRUE
, with IF_NOT_DEFINED_TRUE
, the code within it's body/block will be compiled into the inject.bin
if the given LABEL
does not exist or evaluates to FALSE
Syntax
Example
ELSE_DEFINED
Used in combination with IF_DEFINED_TRUE
and IF_NOT_DEFINED_TRUE
to provide the alternative to the provided condition; the negated case. Code within the ELSE_DEFINED
body/block will only be included if the paired IF_DEFINED_TRUE
or IF_NOT_DEFINED_TRUE
case is not met.
Syntax
Example
Last updated