Welcome back.
I'm super excited because now we are going to learn Somali and we do this by hacking this mobile app
game, the space paying application before we are going to create little pieces of Android applications
that serve a special task, for example, that helps us learning what our registers, what are type
definitions, what values are in there, how does the function code look like?
What are those parameters?
Return values and objects.
So this is a little bit overwhelming if we do this all at once, therefore we do this step by step,
creating our own Android applications that are pretty simple and basic, and where we know what the
source code is like, and then we will figure out how the smiley code looks like.
We are not going to start with the Hello World application because I never did understand the reason
about an Helloworld application.
Most of the time there is already some stuff included there.
We've got a string which consists of chars which is an array.
We've got a function called parameters and things like this.
We start with a little basic program that only consists one integer value and this value is responsible
for the player power.
Then we figure out how all the stuff looks like and the next step.
We try to adjust this value to increase or decrease this player power.
All right, let's go.
Let's switch to our Ubuntu VM and we are going to create our first Android application.
All right, here we are now with our Ubuntu VM.
Let's write our first Android application.
So we go into tools, Android Studio bin and then we've got this studio dot as H script and we simply
run this until we've got the entry point of the Android studio.
So don't worry, you do not need to know anything about Android app development.
We are not going to write fancy animated, complex layout and applications.
We are just simply putting our Java code into this application and hit the compile button.
That's all.
Okay, let's create a new project.
Here.
We've got our first overwhelming window.
What do we have to choose right here?
Well, we use the empty activity.
We know what an activity is.
It's simply a screen content.
And you can select here between different screen contents.
For example, if you want to have Google Maps included or in full screen activity or things like this,
but all the other activities make this layout or the code more complex.
Therefore, we stick to the MBTI activity.
We can also choose no activity, but then we do not have this graphical output, so we stick to empty
activity.
That's good to go.
Now we have to name our application and I name this smiley one.
Here we can see this package name.
It's going to be automatically adjusted within language.
We state to Java and not Colon Chavez.
Way more easier to handle this.
And this one is important minimum SDK.
This means how backwards compatible your application should be.
In our case, I guess our virtual machine is running Android nine or ten, so we would have at least
chosen this one.
In my case, I choose back to marshmallow android six.
You can also go further back.
So for example, 4.4 is also no problem or 2.3 is not included right here.
But four or four is working.
By the way, if you're using your own device, then please make sure that you include at least your
version of your own device over there.
Otherwise, this application might not run on this device.
Okay.
Then we hit the finish button.
Now we get the main layout and this might take a while.
We can observe this at the bottom.
Now it's indexing.
Afterwards, there's a great build happening and yeah, we will come back after all the things has been
finished.
What do we have right here?
Well, this is our very famous hello world application that is overwhelming, complex, and we do not
understand anything about this.
And we also do not have to do this.
But nevertheless, I gave you a short introduction.
So here we have our main activity and this activity extends this activity class.
We do not care about this one.
Then we've got this on create method and this one is important because an activity has a kind of lifecycle.
So if you put your application in the background, then there's this on pause method that gets called
and if you get back your activity to the foreground, then there's this on resume method called in this
activity stack.
In our case, we've got this on create method and this means if the application is going to be created,
this method is going to be called.
And this is definitely the case.
If we start this application and this activity appears on the screen, therefore we can treat this as
our main function.
So do not care about this on create an override stuff over there.
We will take a look into this later on, not in this chapter, but within the runtime analysis that
we take a look at the activity stack.
But for now, let's just say this is our main function
and we do not care about this one, this one and also the parameter over there.
We just put into our code over here.
If we want to run this code, that's all we need to know.
On the left, we've got the structure of this application, so we've got the Android manifest example.
There's one.
And if you take a look into this, we can see, okay, no permissions.
We can see our activity, this main activity over here.
And we can see this well-known intent filter, which means this is our launch activity.
This is our entry point of this application.
All right, then we've got this resource directory over here.
We are also pretty familiar with this one.
And here, by the way, is this values directory that contains, for example, those colors, which
are regarding to our theme we are using and those values get compiled into this resources dot.
RC Just here to wrap this up from the Android structure part, we also do not care about this one.
We could now build and run this application because this is an application that's already finished.
We can now simply hit the build button and we can create our first application without inserting any
line of code because this is our blueprint of our Android application.
To do this we could say build, build, bundle, build APK and this might take a while on the first
time because then all those things get compiled into this.
APK And if we make a modification, then the compiler relies on some cache and this will be a lot faster
in my case.
I've got this now over here build apk generated successful and if I click locate we've got our first
build over here.
So we have built an APK without doing anything which is super great, right?
Okay.
So now let's go back to our real approach.
We want to learn Somali and therefore we have to do this step by step.
And we start with our own Helloworld program, which is an integer value.
Okay, let me close this over here.
All right.
Now we go into this one and we create a new class.
This makes this afterwards a little bit easier.
We named this class, for example, player, and here we define a new value.
We say each power equals ten.
All right.
That's all we do.
Nothing more.
We just do this one now.
We hit, build, make, project.
Great builders is running.
Looks fine.
Now we build bundles, build a bike.
You can always hit, build, bundle apk directly.
You do not have to use make project first.
Okay.
Now we go into this location and here we have our APK.
Let's go with the smiley approach.
To get these smiley classes, we have to decompile this application and we use the APK tool for this
so we stay in the same directory, right click open a new terminal and then we say APK tool the app
debug apk.
This has been finished.
We go into empty back and now we've got the smiley directory.
Let's have a look into this now.
More in detail.
We've got Android, Android, X and com.
These two are regarding to the Android application build system itself.
So if you go back, we cannot see them over here.
And also not there.
But these gets compiled into this application based on here but these get compiled into this application
based on the things we are using.
For example, we extend an class over here and therefore we also need the code for this class.
We do not care about them.
We are just interested in the package.
Com pecking smiley and then the player class.
Let's see, we've got this directory.
Com and this one contains no packing in Google.
So we stick to packing smiley one and here we have now all those smiley classes.
Let's see if we can see our player class.
Here's our player class over here.
Nice.
Let's open this file and have a look into our hello world smiley exercise over there.
Okay.
You can choose between the code editor, she added, or in my case, I'm using the code editor.
So we can simply drag and drop this over here, I guess.
Yes.
And there's no smiley highlight over there, but we can use the Java highlight that's well enough to
get a little bit about this.
Okay.
Before we analyze the smiley code, let me show you some neat tricks over there.
So if you go back to the directory, we can also use Shadi X shade excuse me and we provide this app
debug apk.
And if you go into comm at Hacking Smiley one player, we will find the smiley button underneath this.
And if we hit this, we directly compile our code into smiley so we do not have to use the APK tool
to decompile this, but there's a difference.
Let me show this to you.
Let's put them side by side.
So this is regarding to the compiler and those are different and therefore we also get the different
bytecode output.
Both are, of course.
In this.
Regarding to the decompile, the APK tool is using a different compiler than, say, ADCs, and therefore
we also get the different bytecode.
Both outputs are of course valid.
In my case, I like to stick to the APK tool output because this is a little bit more easier to read.
I give you the solution about this one register means that the compiler named here that we've got two
registers and we can see them over here.
We've got V zero and we also got P zero.
In this case it only says we've got one local register which is V zero and p zero is an parameter.
So we provide a parameter.
At this point, the K tool makes a difference between local registers and parameter registers and on
the right side these are get matched together under the whole topic register.
This might be a little bit confusing at the beginning.
I'm absolutely understanding this, but I just wanted to show you that you get different outputs.
If you use different tools, we would stick to the APK tool output because this is a little bit more
precise if regarding to the naming of those.
Okay, these outputs are different, but the result is the same.
So both apps work in the exact same way.
Last but not least, there's also a plugin for the Android studio itself, so we do not need to compile
this application with the Android studio and decompile it afterwards.
With the APK tool, we can directly do this with an Android studio.
To insert this plug in, we go to file settings.
Plug ins, and then please make sure you have selected the marketplace over here.
And then we search for Java to Somali, this one.
And then we had installed.
Please read carefully through the terms and conditions about this, and if you accept them, we can
install it.
Click.
Okay.
Now the plugin has been included into this ID and we can use this sometimes.
You also have to restart Android studio that this effect takes place.
Okay.
We click on to our player class over here and then we go to build and at the end we have now this button
compile to Smiley.
Let's hit this.
This takes a while.
We can observe this at the bottom of this page, and after it's finished, we get a new top over there.
All right.
And here we have now the decompile Somali code, all of this Java class.
We can see it's also using this approach like it does with the register part.
So we do not split them up between parameters and local variables.
We summarize them and put them into the register.
But in my case, I do not like this approach very much because having the ability to separate them between
local variables and parameters makes Mali even more easier.
Therefore, I like to stick to the APK tool approach, but if you have to do a fast task, then this
can come super handy.
You can write your code over here and then you can simply hit this button and you directly get out your
smiley code over there.
All right, now let's analyze our first output of our Hello World application.
So this Mali output right here, we are going to analyze this on the slides.
So I take this output, put it on a slide, and then we go through this.
Let's switch back and have a look into this.
Okay.
Let's do a quick recap on this.
So we've got our application.
We did insert a new class and we added this variable named power.
We compiled our application and this was our starting point.
After what we did, they compile this application with the APK tool, and then we did end up with the
smiley structure.
And the smiley structure contains single directories, and these single directories are regarding to
the package of this class name.
So if we compare them against each other, we can see the com picking smiley one is exactly the same
package name over there.
This is how our smiley structure looks like and therefore we can find this player dot smiley class immediately.
Okay, this is what we've got.
Now let's take an analysis on our smiley code.
On the left, we've got a player dot smiley and on the right we've got the player or Java.
So the player dot Java looked like this.
We've got our class in power on the left we have the decompile smiley part.
Now let's see what can we understand right now?
And I will be absolutely honest with you, if I do, Mark, anything that we do not understand right
now, then please drop me a message underneath this box.
All right?
Okay.
What do we have here?
Well, let's take a look.
Well, okay.
Hmm.
No, that's awesome.
Yeah.
Okay, I've got it.
Can you spot this?
Can you spot the value ten, maybe on the left side.
But maybe if we strongly concentrate ourself onto the player or Java file, maybe we are able to identify
the value ten on the left side.
So I give you a moment to think about this.
Well, let's see the value turn.
Hmm.
It's definitely not there in the decimal value.
Let's think about what we've got on the left side.
We've got a bunch of really strange words.
We do not understand this, but we've got an zero x, a and zero x.
This might be hex.
I don't know.
Let's see if we're using a python shell.
We can represent this value ten in form of an hex value.
So we open a new python terminal and we type in x ten and then we get this 0xa and the 0xa is also on
the left side over there.
So this might be our value.
Ten We do not know this right now, but it's pretty likely the case.
All right.
Nice.
We have understand our first part with a smiley.
Okay.
So this is a huge step.
And by having this step, we also can do a lot of stuff right now, even if we do not understand all
the rest of this.
You will see this in a moment when we do our first exercise.
But for now, I would like to finish this video because I do not want to stick that much together in
this.
We have taken a look on different approaches, how we can get the smiley code out of this application.
We have seen some really fast techniques.
For example, Che excuse me, the smiley button.
And also if you want to write our own smiley code, we can do this directly in the Android studio.
We write our Java code and then we use the Java to Smiley Plugin.
We've also taken a look into the difference of the compiler regarding to the smiley output.
So we have seen some something compiler summarise those registers to one big block and others split
them up between parameters and local variables.
Then we have analysed our first smiley code and we realized we cannot understand anything about this,
but we might have found the integer value represented in the smiley code and this is a huge deal.
Okay.
And this is also the point.
We stop right now.
We do this step by step, and we will increase our stebbings further and further for now.
That's all.
I'm looking forward to see you in the next video.