Part 43 – Hacking Post-Increment 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 myNewNumber = ++myNumber;
  5. std::cout << myNewNumber << std::endl;
  6. return 0;
  7. }

We create a variable myNumber = 16 to which we create another variable myNewNumber which post-increments the value of myNumber. We see that when we execute our code it shows 16 as the value of myNewNumber and 17 as the value of myNumber as myNewNumber does not get incremented as only myNumber get incremented as it is a post operator.

When we post-increment the value of the variable is incremented after assigning it to another variable. For example myNumber is 16 so it gets incremented after being assigned to myNewNumber so therefore we get 17.

Let’s debug.

Part 43 – Hacking Post-Increment Operator - 图1

Let’s break on *main+28 and continue.

Part 43 – Hacking Post-Increment Operator - 图2

As we can see the value in r3 is 16 and the value in r2 is 17. We can see that as they are loaded from memory into the registers in *main+12 directly by the mov instruction and *main+24 we add 1 into r3 and then put that value into r2.

Let’s hack this baby!

Part 43 – Hacking Post-Increment Operator - 图3

We know we can now set the value of r3 to our heart’s desire!

Part 43 – Hacking Post-Increment Operator - 图4

As we continue we see the c++ cout function echo our new hacked value to the screen!

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