Welcome back.
In this video, we check out our last method regarding to patching.
If instructions, which is patching chum statements so we do not have some slides here.
We directly jump into our last example and modify this a little bit because let's say we got lucky that
the if statement laid out in the correct way.
Therefore we could simply remove the first if line and increase our power.
But what if you get it?
What if what if the if statement has been switched?
We are not having our year preferred if statement at the beginning.
We are having it at the end and therefore perpetuating the if statement or removing the if line above.
We get in the code we do not want to, therefore we simply switch the chop.
We are not going through the first.
We are going to jump into our second by having this condition.
But before we make it too complicated talking about this, let's dive into this.
Okay.
Here we have the Ubuntu VM and I already opened the Android studio.
So this is our example from the last section.
Okay, let's have a look into this.
So we do not have a master cap over here and this means we cannot or did not get into this condition,
which would increase our power level by 100.
Therefore this was not possible.
We end up in the old statement and only increases it by ten after what we return out.
Okay, so this was the regular code, but this was something we didn't accept because we do not want
just ten.
We want a power upgrade of 100.
So what we did was the following.
We removed this line over here and this leads to this becoming a regular instruction, which means we
are having in power upgrade of 100 and this part right now will be skipped because we cannot enter this
statement anymore.
Okay.
So I would say this was a fair approach for us.
Yes.
So we got a power upgrade by 100 immediately without having a condition over there.
That's nice.
But let's say we got a little bit lucky with this.
Why?
Let's say things get switched, so let's say we've cut it in the following way.
Our power upgrade is now not within this statement anymore, it's within this statement.
And we are also having this set to true.
Okay, let's see how good our approach now works.
So we are going to delete this line over here.
Okay.
This means we get the power upgrade of ten OC.
Not bad, but we cannot reach the CIF statement anymore or the LS case of this statement.
So we are going out of this function with only having ten.
And yeah, to be honest, this is not acceptable for us, right?
Absolutely.
Therefore, what we are going to do right now is the following.
So I click the screen once again.
All right, so we are having the master cap and this is acceptable for us.
So we are going into this statement because we have it set to.
True.
All right.
Then we've gotten power upgrade of ten OC and now instead of leaving this function here.
A pitching it that we reach this for the spot.
This would lead to another power upgrade of 100 once again.
So we are getting 110 right now.
And we can do this with changing the Trump instruction.
So before we go out at this point, we simply go in back again and we can do this with the condition.
So let's play this application and have a look at this smiley output.
Okay, so here we had the smiley code.
Let's have a look into this.
We've got our has item and I try to improve my writing.
Let's see.
Yes, item.
There we go.
We've gotten player object.
Player.
We are returning white.
All right.
So we've got a local register.
We've got our player as parameter.
Yes.
And now we are fetching the param at the instance from our parameter, which means MasterChef.
So this is player dot MasterChef and we start into we zero.
So we zero as equals player.
Dot master cap.
And this is from type boolean.
Okay.
Then we've got our statement and let's do this together.
If we zero is equals zero, we jump to condition zero.
So if we zero equals zero, we jump to this condition and this one is here.
So we we do this jump, which means we are increasing the player power by 100.
So I just yeah.
Let's wrap these three lines up in this one over here because we already analyze this function player
dot power.
Plus equals 100.
Okay.
Otherwise we get into this one, which means we are getting the player power and just increasing it
by ten.
So our ad spot over here is out.
Player dot power.
Plus equals ten.
All right, so our master cap is a Boolean value, and this one is set to true in our case right now.
This means we do not take this jump because our V0 is not false.
So if false equals equals false.
This is not the case.
What we have here is if true.
Equals equals false.
Therefore, we go into the add statement and this means we increase our player power by plus ten.
All right, so how can we change this regarding to the champion structure?
Well, let's have a look.
So let's clean this up real quick.
Okay.
Let's go through this once again.
So we are having not this condition.
This one is false.
We end up here.
Okay.
This means we increase our power level by ten.
And then we've got this go to jump here, which means we are jumping from here to here regularly.
All right.
What if we take this go to and instead of this, go to label, let's say we we insert condition, underscore
zero.
Then in this case, instead of jumping downwards, we should jump to the condition zero label, which
is just underneath, which means we get into this one over here, which means we get another up right
of plus 101 second.
So we're getting plus ten and plus 100.
And afterwards, we do our stuff over here and then we've got this go to label.
But this gets simply ignored because it's not in jump instruction and we return out.
So let's see how this works out.
Okay.
All right.
Let me clean the screen real quick.
Okay.
So we've got our if equals zero condition zero.
We do not meet this condition.
Therefore, we go into this one and here we've got this jump out of this and this will now be replaced
with condition underscore zero.
So exactly this yes.
This means this jumps to this condition and this now also jumps into this.
And this should lead to an power level increase moment or power level upgrade of 110.
Let's see.
Okay.
So I built this app.
I signed it.
I do not want to bore you with those steps again.
So I guess you have seen this a lot in the past.
And I will cut this video at this right now.
All right.
We already got our connection to the device.
Let's get this.
There we go.
Now let's install it.
All right, we open this application.
Our power level is now ten, which means if I hit the button, we should have an power level of 120
because.
Ten plus 100.
Let's see.
There we go.
I hit it once again, 230.
We increased it again with 110 and so on.
We can do this as long as we want.
So what we're doing right now is we're going into this condition, but instead of jumping out, we get
into this.
And this is by changing the champ.
Sorry.
And this is by changing the champ instruction over here.
Nice.
Okay.
So to recap this real quick, I restart the original state.
All right, so what can we do?
We can change the champ level over here.
All right, that's nice.
We have seen this regarding to this one here.
What's also possible is we can move the Champ label around so we can take this one and simply add it
over here.
This will also work and restart back.
Okay.
What we also can do is we can invert those.
So instead of if equals zero, we can say if not equals zero.
And what's also working is we can change the register value just right before the if statement.
So if we get this one over here, we can simply say count slash for the zero is now true or is now false,
whatever we want.
These are the options we've got right now.
And this leads us to patching every if instruction we want to have designed in our way.
To be honest, I'm not using the champ instruction very often, but sometimes it can come super handy.
Okay.
Regarding to inserting new code like this one over here.
We didn't talk about this yet, but we will do pretty soon.
So we are close to this topic right now.
I just want to show you this option that this is impossibility because yeah, patching smartly gives
us unlimited power.
We can do whatever we want here.
All right.
So that's all for if statements right now.
The only thing we didn't talk about was a switch case, but a switch case is just multiple if statements.
So if we're having a switch case with four values, one, two, three, four, the compiler simply generates
four if statements if equals one equals two equals three.
Therefore, we do not need to talk about this.
This is just multiple if statements and this is all you need to know about this.
If statements, you also know how to patch them in certain ways.
Regarding to this one, I have introduced this right now, but we will also learn this in the in the
inserting smiley section.
Okay.
Therefore, you are now better prepared regarding to if statements and you've got a lot of power already
and we will take this and yeah, do our first real world application patching.
We will circumvent a routine detection.
So this will be the next exercise.
I have prepared one on a non code, but I've also got an application which is designed as an routing
detector and this comes super handy if you want to perform penetration tests and have to circumvent
routine detections.
There are nice frameworks out there that yeah, do a good job, but sometimes they fail because the
implementation is quite unique and yeah, it's not known to the program, but by analyzing and patching
the code you can circumvent this right now.
Therefore, I see you in the next video.