Practical Reverse Engineering Exercise Solutions: Page 79 / Exercise 9
Exercise 9 on page 79 of the book Practical Reverse Engineering specifies the following ARM disassembly of a function called mystery9
:
|
|
First of all, mystery9
has a striking similarity to the previously decompiled function mystery8
. Its disassembly uses Thumb mode, as we can see for instance from the 16 bit instruction width.
In contrast to mystery9
, it takes only two arguments of type char* (strings) and no additional limiting variable. The return value is a signed 32 bit integer, as we can see from line 23. The provisional function prototype is as follows:
|
|
Merely by looking at the disassemblies, we see that mystery9
’s functionality can be considered a subset of mystery8
’s functionality. With the decompilation, the similarity becomes even more evident:
|
|
The variable byteArray
has the same properties as in the function mystery8
, i.e. it is an array holding the entire byte value range at the corresponding index : {0, 1, …, 0xFE, 0xFF}. Likewise, the usage of byteArray can be omitted, since the index and array value are identical:
|
|
As already mentioned, it essentially performs the same computations as mystery8
, however, it does not take a limiting parameter. As a result, it continues in the main loop until the end of both strings or a differing character is found. The return value is the numerical difference between the first differing characters in the strings and thus, when no difference can be found, the value 0.
Therefore, the possible return values are:
0
: Both strings are equal>0
: The numerical value of the first differing character is greater in arg1 than in arg2<0
: The numerical value of the first differing character is smaller in arg1 than in arg2
Lastly, we provide a more descriptive version of mystery9
:
|
|