Bye.
Come back.
Let's do another practice exercise.
So I have extended our player smiley file a little bit and now even more because we already talked about
those floating point numbers.
So I added one to get also practice on this one.
Let's go and therefore I switch to the ubuntu VM and I have attached you to file as an APK to download.
I've already got this over here and our downloads directory and this one and I put this into apps and
let's make a new challenge practice.
Smiley Okay, let's decompile this with the APK tool.
And then we will have a look at this Marley code.
And afterwards I show you the original Java code.
And also if you take a look into Jade, what's different?
I guess there is something different regarding to optimization of the compiler, but let's see this
at the end.
First, let's reverse engineer this application.
Okay, so we've got this over here.
Practice Smiley I opening this whole directory once again within Visual Studio code.
There we go.
And here we have our player, Dot Smiley.
We change to Java and we kick that.
We keep clicking these annoying pop ups and here we go.
I'm going to make a screenshot of this, put it on my graphic tablet, and then we will analyze it there.
So I see you in a few seconds.
All right.
Here, we've got this file right now and you can see this file is massive, but we do this step by step
and we go through this each instruction after each other.
We also include what we've learned in the last video.
Therefore, we do not dive into a method over here.
We start at the beginning of this file.
And by going through this file we will reconstruct the Java source code out of the Somali code over
here and therefore let's go.
What do we have here?
We've got our class public, and then we've got this capital, which means we've got a class reference.
This reference ends at the semicolon over here, which means we've got a class named player.
Let's write this down.
Class player.
All right, then.
We've got the superclass over here.
The superclass is travelling object.
This means our player class is a subclass from travelling object.
But we are not extending a certain special class over here.
This means we are already at the end regarding to the class definition.
I guess I wait with the end because we might scroll down a little bit.
All right.
So we also get this one and this one and this one is simply just the the name play action of the file.
So this was the header?
Not that hard.
All right.
Okay, then let me choose a different color and we make our way through this one.
We've got our hashtag over here, which means we've got a new separator in this case, static fields.
So now we've got our static fields for this class, and we only have one static field because here at
the end we already have a new separator regarding to the instance fields.
Okay, let's see what static field we've got.
We've got public static lives.
This is the label.
So our static field is lives and lives is from type integer.
We can simply write this down exactly same way.
So we write this down as public.
Static.
End.
And then we have lives.
All right.
We can see no register, no initialization value.
So simply trust this public static int loves OC.
Next, let's have a look over here.
We have now our instance field and we've got two instance fields.
One is power and one is shared.
Power is from type integer and is from type.
Correct boolean.
Also, let's add these information.
So we've got end power.
And we also got bully and shield.
All right.
Then we get to this one.
These are all our instance, fields.
Next, we've got the direct methods, which means we've got constructors and private methods.
In this case, we skip this because this constructor contains some object references and we didn't talk
about this one yet.
We will learn this in a few sections, but for now, let's skip this because I guess we still got lots
of stuff to do.
Okay.
So these are our private methods.
We do not have a private method.
We only have this constructor, but we skip this.
Okay.
Then I need to scroll down a little bit.
Let's do it this way that we can still see our instance fields and therefore we just add our code now
underneath.
Okay.
What do we have right here?
We've got now our virtual methods, which means we've got now our public methods.
Our public method is named at power.
So we've got a public method at power.
At Paula.
This method at power has now three parameters new color.
This one, we've got one, two, three, all from the type integer.
Okay, but now let's take to the register labels.
So in this case, we are using P one, P two and P three.
We know our P zero is reference for this object.
Therefore, our parameters start with p one.
And by keeping or sticking to the register labels, we do not have to look things up in the code.
Therefore, we can execute each line after each other like the CPU does.
Regarding to the parameters.
Yeah, of course we already got them here.
But regarding to the local variables or local registers, we would have to look them up if you want
to address those labels immediately.
And this is something we do not want to do.
My approach when I do my smart reverse engineering is I go through this each line after each other and
let's try this out here.
All right.
So we've got three parameters, all type integer.
So our first one is in P one.
Next one is in tpy two.
And then we've got into P three.
Okay.
And we can also see this one over here.
We've got the return while return type from type V.
Do you still know what this Capital D is?
Correct.
It's doubled.
So we are returning in double value here.
All right.
We already got our function definition over here based on one line of smiley.
Isn't this amazing?
It absolutely is.
All right.
Now we've got this locals five.
And this is exactly what I was talking about in our case.
Right now, we just take a snowed we've got five local registers.
Five local wrecks, which means we've got register from the zero.
We want B to be three and also V four because we start counting with v zero.
We do not do this in the parameter taps because p zero is a special register reserved for the this option.
All right.
So we get this line also.
We also got these and yeah, if we want to, we can address those labels here so we can say P one is
A.
P2 is P and P three is factor B and this one here is factor.
Okay, let's do it in this way.
So then we've got this one, this one and this one.
Now we've got our first real smiley instruction.
Yes, I would call this this way.
So we've got slash 4000.
Do you still know what this instruction does?
So this instruction starts w value zero into v zero, but it only stores four bit of this value in v
zero.
In our case it doesn't matter because four bits of 01234 is still equal zero.
But we are limited to four bits.
In this case, we cannot store a value, for example like 20.
In this way we would have to adjust this const over here, this slash form to something like slash 16
or remove this part for if you want to override or patch this application, this instruction here.
All right.
For now, let's get rid of this one.
So there we go.
And we simply write this down.
What does instruction do?
We've got the zero is now equals zero.
Okay.
Next one, we've got those over here.
Ah, and here we can see the register.
This V0 is now being addressed as a variable and this variable is named sum and it's from type integer.
Okay.
We make this note over here.
So we've gotten some.
Sorry.
Let me clean this up real quick.
So.
All right.
So we've cut some from type integer.
So we've got into some and some is equals zero based on this instruction before this one over here.
All right.
And by doing this, we do not have to look this up first.
So we go through this each instruction after each other slowly progress through the smiley method over
here.
And this is the approach I like to do.
So go through this instruction after each other, and therefore we stick to those registers over here
and we take notes of the Java code on the right.
All right.
Next, we've got this cons.
There should might be one, then we've got this really strange looking value.
But we also got this hint over here.
So we do not know what cornstarch right does.
And this is something we have to look this up regarding to the first section.
We know this value gets thought in B.C. and we want sorry, this value gets taught and we want over
here in this register and this value is represented by this strange hex representation.
This is a floating point number.
And therefore here we have our sign, which we have our Manchester and we have our exponent.
We do not care about this because we've got the value right here.
But what does Const Dash VI do?
Because this is important that we look up instruction where we are not sure what they are doing.
This might affect our result in this register later on.
So let's have a look.
Therefore we go into our Ubuntu VM and really hope you have bookmarked your pick up codes page.
So let's see, const dash white puts the integer constant into v x and we x plus one registers extending
the integer constants into a long constant.
All right.
What this does is.
But let me check something quick.
Okay.
We have to take care.
Let's see.
We've got this lit 16.
In our case, we've got a const value.
Let's see.
Do we have other conspired in structure?
No.
So let's get back and.
Yes.
Okay.
It's within the description there.
We get this crystal clear.
So we've got const dash wide V two and then we've got our long variable over here or our double variable
in our case.
And here we can see we are putting 64 bits into X because otherwise we would have this Dash 32 declaration
at our instruction over there.
Okay.
So now we know we are definitely putting 64 bits into our register v x in this case it's V one.
There we go.
All right.
So let me clear this up a little bit.
So.
So we are putting we can make this as a node 64 bit at least this value here into our register we want.
Let's write this down.
We one is equals 2.3 and we do not care about this one over here.
And Och, yeah, that's all we know for this instruction over here.
And the next one we can now see, okay, we've got we want and we want us now also on variable named
bias and it's from type double.
So we've got a double.
Bias.
And this one is 2.3.
So we also got these two.
Then we've got our ED in construction over here.
At it.
And what it does is it takes P one exit to P two and stores the result into V three.
So we've got av3 as equals P one plus p two.
And here we can see we haven't used V three yet.
Therefore, let's keep this open for now.
Next we can see we three is still not reference as in variable, but we do not care about this because
we go through this code, each instruction after each other.
Therefore, if we three is never been assigned to one variable, we do not care.
We are just interested in the value or the command over here.
What this instruction does and in this case we know we are adding A plus B and stored this into V three
in this register.
And this is why I like keeping the approach or sticking to those register values.
You do not have to bother about Oh, does it now become a variable or not?
Might it be?
Might it not be?
Who knows?
We don't care.
Okay, so let's drill down a little bit and move on and decode.
What we've got here.
We've got now mile dash int and this instruction is new.
It's pretty clear what this instruction do.
But anyway, let's look it up because then we can be sure and we do not make dumb mistakes where we
have assumed that this instruction is doing the following thing and at the end it does something else,
something different.
So let's look this up real quick.
I mean, it's super fast.
If you have your type to type your password, it takes a little bit longer, but it's still super fast.
So we're looking for multiply int this one over here multiplies we set with w y and puts the result
into the x oh.
I think I have encountered something.
Yes, this one over here seems to be a mistake.
This seems to be a typo.
I would assume this might be b y.
But nevertheless, this website is amazing.
Okay, let's write this down.
So we've got the x equals, then we've got v y multiplied by v set regarding to a multiplication, I
guess regarding to the arithmetic operation.
Yes.
It doesn't make a difference if you multiply this with this or vice versa.
And so if you swap those parameters, this doesn't really matter.
But I'm pretty sure it should be in this in this order.
Let's see what we've got here.
Yes.
Have you also got this typo?
And you?
We do a multiplication from two registers and store the result into weeks.
All right.
That's what this instruction does and good that we look this up because then we realize there's a little
bit of a typo over here.
So let's get back.
Okay.
We are multiplying B three with p three and we start this result back in V three.
Let's write this down.
So I'm going to make a slight note where we are in this code over here we three is equals v three multiplied
by p three.
We can now also do some fancy math and replace v three over here with this.
But let's do not do this.
So we do this each instruction after each other and we execute and insert our values later on in the
exact same way.
Okay?
So please do not try some math operations and get rid of parameters or values.
All right.
So next one, what do we have?
We've cut end local v zero.
This is interesting.
I never I guess I also didn't recognize this variable in this way right now, but this seems to be the
end of v zero.
So we are not using v zero at this point anymore.
Nice.
And for me also super interesting.
What's also nice we can see this register v three gets now reused.
We get now with three aligned to some super interesting and we also see this integer type over here.
So of course we do still have our sum, but now our V three is going to be referenced with some.
And at least at this point, I mean, I didn't prepare it in this way, but it's nice to see it over
here.
But at least at this point, I would be super confused if we stick to those variable names over here.
Regarding to the registers, I mean, we do not care.
We move on with our code and we really do not care about if this B three is not some or B zero is some.
We are just interested in the values this register holds and therefore I really like this approach regarding
to sticking to those registers even more.
Okay, so let's move on and let's see what we've got.
Next we are adding int litt eight.
So we know this is eight bit.
And we are adding the three.
Nice.
We are adding three with minus one and we start the result back in with three.
So what we've got here is we are not adding to values, we are subtracting values.
And I'm not sure why the compiler has chosen this instruction because there's also an subtract and I
guess let's look this up.
Yeah, it's already it's just above this instruction over here.
SAP end calculates revi minus V set.
So this might be regarding to compiler optimization.
The compiler or the program might be faster if it adds minus one instead of using the sub instruction.
Super ridiculous.
But okay, this is what the compiler does.
It's funny to see this in this way.
All right, so let's write this down.
B three is now b three.
We can write this as plus minus one.
And now we have our fancy math operation here.
But for me, this is a little bit confusing.
So let's do this in a different way.
Let's write this as it is.
Alright.
Okay.
Next, we've got a new instruction.
What might this be?
No one knows.
I guess so.
We've got div dash int p one, v three, p two.
So you see with those registers it's now getting a little bit, let's say.
Yeah, complicated or confusing.
But if we insert our values afterwards and go through the step by step, you will see it's not that
hard to execute this code afterwards on our paper.
So let's see this instruction first oc this int that we've got the correct order.
Yes.
Result.
All right.
So device v vi with V set and puts the result into weeks.
Hmm.
Let's see the inch.
We've got p one.
So we are at this instruction right now.
P one is equals v three divided by p two.
And yet we can try to insert our labels over here.
So let's see.
p1i have to scroll up.
P one is a a is equals some because some from this point is now and register v three.
We can also write this here.
Sum is equals sum minus one.
Okay.
We were at this point some divided by P to P two is P.
Okay.
Yes.
All right.
Next, we've got this instruction x orders in XO.
Let's look this up.
Excellent.
INT And here we can see we've got this to address.
We are not looking for this one.
We are looking for this one.
Let's get rid of this.
Calculates we buy what we set and put the result into weeks.
Okay.
So we've got we zero.
Zero is equals 33x or with p one.
In this case.
We zero is now.
And that's grown up a little bit.
Oh, it's so interesting.
We can see right now we are using the zero as a register, but at this point we have switched from the
zero to be three for the register or the label some.
And this means we have now a new free register.
This one over here.
This one is now reassigned and newly reused.
So this is a whole new register over here.
Therefore, we cannot make an Yeah label for this over here.
Again, this is why I like sticking to registers and not always try to adjusting those variable names
because in this case we don't have a variable name for this one right now.
We know this one is some and we note this one is a was this a yes?
Okay.
So we know this one is some and this one is export with a, but we do not have a label for this one
right here.
So we have to move on in the code.
So the CPU simply executes this command, some export with a and starts the result into B zero.
By the way, if you do not or if you are not familiar with the XOR instruction, I have attached an
own section within the cheat sheet of this course document.
So within there I describe some XOR operations, what XOR does and why it's really useful and helpful
to understand XOR, because export is used a lot regarding to cryptographic functions and strange cryptographic
functionalities which are written by the developer itself and also regarding to assembly for example,
for clearing out registers and things like this.
So the instruction itself is not that really complicated, but it's super nice if you understand or
if you know about the tricks you can do with X or to get some cryptographic keys back and things like
this.
Therefore, please have a look at the slides and I might be also creating an own bonus section regarding
to XOR.
All right.
Please look this up in the material.
Also in the bonus video.
I'm yeah, I'm pretty sure I create this one.
And if you have questions anyway, then yeah, feel free to write me a message about this.
All right.
Okay.
Yes, interesting.
So now we've got end local B be three.
So our sum variable from type integer is now finished on the register with three.
There's not any more holding the sum.
This is what this instruction do.
And here we can see restart low can be zero sum from type integer.
So here we can see we are reusing this register v0 as the sum variable.
This means we zero becomes.
Some back again.
All right.
And at this point, we know, okay, this one is also some but a little bit different.
So this one in this case is some kind of placeholder.
So we've got a placeholder for some.
And afterwards we recycled be three.
So this register gets recycled and then we create our sum over here for V zero.
Okay.
If you stick to those labels, it's getting a little bit complicated.
Let's clean this up and let's write this down as the instruction tells us.
So we've got this one over here.
This was this part.
And then we've got return local V0 to some.
This one is this part, but these are not real instructions.
So we do not make progress within our code right now until.
So we also got this one.
Yes.
Until we go into this one, because now we can see into double v3v0.
So let's check what int to double.
Do it to double.
Congrats the integer and b y into the double in b, x and b x plus one and this b x plus one, by the
way.
And this means if the value doesn't fit into one register, we are using two.
So let's say we are using v three, then this will be v three, this v x so v three is v x or y is better.
Let's say a different v x is b three and then we are also using v x plus one, which means we are also
using V for the register.
And I guess you can find this.
Let's see.
In the description.
Yes.
Yeah.
Here you can see this.
Plus one means we are using to register to store this value.
For example, if we have an Yeah larger value, which is going into an smaller register, then we split
this value up into two registers, for example.
Okay, so what do we have right here?
Our instruction says we are converting the three to V zero.
Sorry.
I have to look this up once again.
Converts the integer in v.
So this one is the integer two and double.
Okay.
So this one is the integer.
And this this one is the double afterwards.
Yes.
This makes sense.
Okay.
And let's try to write this down.
This is a little bit hard.
Let's see.
So this one is inch and this one is double.
So we've got we three is.
Double me zero.
Okay.
And this means B three is also from type double.
But let's not write this over here.
Let's write this down.
What's here?
Okay.
So this should be.
Yeah, this would be fitting.
All right.
And then we've got the return by V three.
Let's see if you also find this instruction over here.
Return dash white.
Return with double or long result in and so on.
Okay, so we are returning with zero and we won in the register and these registers and this is just
the return of a double or long value.
So we are returning B three over here.
Right.
And this is our code.
If you get back on this.
So this is the method at power.
This is what a power does.
And we can now simply insert some values over here.
And then we can we can go through this code over here and check what's the result at this point?
And let's see.
Maybe we do this.
Yes, we make this or we do this for the next section.
And then I also show you then the Java code.
We execute this method with the values we are inserting right here.
And then we have a look at the Java code, but the Java code puts as a result out of this function and
also what we got out of this function.
And yeah, let's take some values already that you can start practicing if you want to.
S values.
Let's see we take for a.
One, three, three, seven.
Yes.
These are our values we are inserting, all of which we are using to call this method.
One, three, three, one, three, three, seven.
Yes.
Let me get rid of this ping.
So let's write this once again.
One, three, three, seven.
I hope it's working in this way because I didn't check the code regarding to overflows or things like
this, but I'm not sure what we are doing with B, so B is p two.
Let's check this code real quick.
We've got p two over here.
We are dividing.
So therefore, if B would be zero, this would be bad because we cannot divide by zero.
Yes, but the rest looks fine.
OC Yeah, so there seems to be a nice exercise and before we do this, let's step back a little bit,
take a look at the picture and see what we've done.
We have reversed and more complex Java code based on Smiley.
So we reconstructed the Java code out of this.
And this is pretty amazing in my opinion, because we already start learning smiley and we can already
resolve complex method names or method tasks over here.
So in my opinion, I'm super impressed where we are at this moment right now, and I hope you feel the
same.
Otherwise, don't be very.
We increase the tempo later on, so we will do even more fancy and advanced stuff.
But for now, yeah, let's enjoy this moment and insert those values, some kind of exercise work.
And afterwards we go through this together.
Have fun and I will see you in the next video.