Part 37 – Hacking SizeOf Operator

For a complete table of contents of all the lessons please click below as it will give you a brief of each lesson in addition to the topics it will cover. https://github.com/mytechnotalent/Reverse-Engineering-Tutorial

Let’s re-examine our code.

  1. #include <iostream>
  2. int main(void) {
  3. int myNumber = 16;
  4. int myNumberSize = sizeof(myNumber);
  5. std::cout << myNumberSize << std::endl;
  6. return 0;
  7. }

Part 37 – Hacking SizeOf Operator - 图1

Remember that we create a variable myNumber = 16 to which we create another variable myNumberSize which holds the value of the size of myNumber. We see that when we execute our code it shows 4 therefore we see that the SizeOf operator indicates an integer is 4 bytes wide.

Let’s review last week’s code as we start with debugging and breaking on main.

Part 37 – Hacking SizeOf Operator - 图2

Let’s break on main+20 as we can see the value of 4 being moved into r3.

Part 37 – Hacking SizeOf Operator - 图3

Let’s examine what is going on at main+16 as we can see that we are storing into the value of $r11-8 that which exists in r3 which in our case is 16. This makes sense as when we examine our original code the value of myNumber was in fact 16. We can see this here when we examine the value inside $r11-8.

Part 37 – Hacking SizeOf Operator - 图4

As we can see above the value inside $r11-12 is 4 as that represents the value that SizeOf is returning as the integer 16 is in fact 4 bytes wide.

Part 37 – Hacking SizeOf Operator - 图5

Finally when we continue execution we in fact see the value 4 echoed to the terminal.

Let’s hack!

Part 37 – Hacking SizeOf Operator - 图6

We run and break on main+28.

Part 37 – Hacking SizeOf Operator - 图7

We see the value in r3 is 4 which is expected.

Part 37 – Hacking SizeOf Operator - 图8

We break on main+36.

Part 37 – Hacking SizeOf Operator - 图9

We see the value in r1 is 4 which should make logical sense as the value was stored from r3 into r11-12 and then back to r1.

Part 37 – Hacking SizeOf Operator - 图10

Let’s hack the value in r1!

Part 37 – Hacking SizeOf Operator - 图11

Success! We have hacked the machine!

Next week we will dive into the Pre-Increment Operator.