Constants & Functions
Description of constants and functions
Starting from v0.8.2, HyperDbg supports functions in the script engine. Here's a description of how function can be defined within scripts.
Naming convention
We suggest using snake_case as the naming convention. However, you can use any other naming conventions as well.
Functions
HyperDbg functions are defined using the same syntax as the C programming language.
Function: void
This is an example of a function that does not return any value (void). This code defines my_func which prints two integers. It's called three times with arguments (1, 2). Then, it prints the hexadecimal value of variable my_var, which is 79.
? {
void my_func(int var, int var2) {
printf("var = %d, var2 = %d\n", var, var2);
return;
printf("this statement is never shown!\n");
}
for (int i = 0; i < 3; i++) {
my_func(1, 2);
}
int my_var = 79;
printf("%x\n", my_var);
}Function: int
This is an example of functions that return an integer. This code defines four functions: my_func1, my_func2, my_func3, and my_func4.
my_func1 adds 1 to its argument and prints the result.
my_func2 multiplies its argument by 2 and prints the result.
my_func3 also multiplies its argument by 2 and prints the result.
my_func4 calls my_func1, my_func2, and my_func3, then sums their results and prints the total.
Finally, it calls my_func4 with an argument of 2 and prints the result.
Examples
Example 1: Recursive Fibonacci
The following function calculates the nth Fibonacci number recursively.
Example 2: Iterative Fibonacci
This function calculates the nth Fibonacci number iteratively using a loop.
Arrays as Function Parameters
Starting from v0.24, HyperDbg supports arrays (including multi-dimensional arrays) as parameters to functions.
In the following example, myCalculateSum takes a one-dimensional array along with its element count and returns the sum of its elements. myPrintMatrix takes a two-dimensional array along with the number of rows and prints its contents.
Constants
At the moment, dslang does not support constants but the support for these items will be added to the script-engine in future versions!
Last updated