I haven't seen any tutorial that has mentioned this so I will share this very simple way to patch/change the value that get passed in as a function argument.
Game Used: Cafeland
A function often has one or more parameters and when that function is called, it requires the caller to pass in those values as arguments.
Example
Function in IDA:
Function in Dump.cs:
So in this case DecreaseCash function has 5 parameters which are (*this, value, tweenPosition, reasonId, reasonItemId)
The *this parameter will always be the first parameter of a non-static function
You can find more info about this pointer in this tutorial:
In Arm64, the function's arguments is stored in the registers from X0 to X7
Therefore, you can visualize it like this:
Now, There are many ways you can make this hack work but in this tutorial I want to show you how to alter the value of the argument
In this example I want to change the X1 value to 0 so that this function will decrease 0 cash from my wallet
Normally at the start of the function you will see something like this:
At the lines with the red arrow, you can see the arguments is getting moved to the respective registers or you can understand it as the function is loading the value of the passed in arguments
Remember which registers correspond to which value in the parameters
Now, Instead of loading the X1's original value, we load int 0 instead so that it decrease 0 amount from our cash
MOV x19, x1
- Change to
MOV x19, #0
And It is that simple
This is just one of many ways to achieve a certain hack/feature
Thanks for reading ❤️