Conditionals & Loops
Description of conditional statements and loops
Conditional Statements
Conditional statements are used to perform different actions based on different conditions.
if
The if statement executes some code if one condition is true.
Syntax
if (condition) {
code to be executed if condition is true;
}Example 1
if (@rax == 55) {
printf("rax is equal to %llx\n", @rax);
}Example 2
if (poi(@rcx + 0x10) == ffff7080deadbeef && @rdx != 55 || $pid == 4) {
printf("condition is met\n");
}else
The else statement is executed if the if condition is false.
Syntax
Example
elsif
Multiple if...else statements can be nested to create an elsif clause. Note that there is one elsif (in one word) keyword in HyperDbg script engine.
Syntax
Example
Loops
The following statements are used to create loops in HyperDbg's script engine.
for
The for statement creates a loop that consists of three expressions, enclosed in parentheses and separated by semicolons, followed by a block statement to be executed in the loop.
Syntax
Example 1
Example 2
while
With the while loop, we can execute a set of statements as long as the condition is true.
Syntax
Example
do, while
The do..while loop is similar to the while loop with one important difference. The body of do...while loop is executed at least once. Only then, the test expression is evaluated.
Syntax
Example
Last updated