‫Instructor: Hi.
‫Within this lecture,
‫we're gonna take a look at Dalvik bytecode,
‫and we will try to understand how it works
‫and how we can change it,
‫and how we can build an APK manipulated APK after all.
‫Okay?
‫So, this is our Dalvik bytecode,
‫and as you can see, it starts with the class name.
‫Actually it is our package name,
‫so com.atilsam.myreverseapp,
‫and after that we see the source name
‫which is MainActivity.java, in our case.
‫So if you see MainActivity.KT for example,
‫it will be a Kotlin file as well.
‫But it wouldn't matter very much in this case,
‫since we are actually seeing Dalvik bytecode.
‫So we are going to see some methods after all,
‫like direct methods and virtual methods.
‫So over here, we will see some similar things
‫that we have seen in Java as well.
‫What do I mean?
‫I mean the method names, for example.
‫You will see onCreate method over here, like this.
‫So this is the same onCreate method
‫that we used to see in Java.
‫Remember what onCreate does?
‫It's first method to be called
‫when an activity is created.
‫So whatever is writing over here happens
‫actually even before user sees it.
‫So we can understand what's happening over here
‫by looking at these hints, like this.
‫For example, locals three means
‫that we have three local variables,
‫we have three variables under our onCreate.
‫So you don't have to do this,
‫but I'm going to open my Dalvik bytecode
‫and I'm going to open my Android Studio as well.
‫And side by side, we will have the chance
‫to compare the codes to follow
‫and see what's going on.
‫For example, over here we'll see onCreate,
‫and we see the bundle,
‫and it's called savedInstanceState.
‫There is a variable over here,
‫it is savedInstanceState.
‫And we can actually see that savedInstanceState
‫in Dalvik bytecode as well.
‫In fact, we see everything that is going on over here
‫converted into Dalvik bytecode.
‫So I'm going to open this side by side, like this.
‫Okay?
‫So let me make this a little bit smaller.
‫So over here, you can actually see the line numbers as well.
‫So here it says that, yeah,
‫savedInstanceState is a parameter,
‫and then after all you can see
‫line 12, line 13, line 16, line 17.
‫Okay?
‫So over here, you can understand
‫by looking at this that
‫yeah, this is a variable and this is a parameter
‫that has been passed into some kind of functional method.
‫Maybe you cannot understand everything
‫when you are reading Dalvik bytecode,
‫but surely you will get some idea.
‫For example,
‫let's go over here where you can see
‫there's something called cast.
‫Like in this case, in line 16 and 17,
‫you see the local v0, which is TextView.
‫Okay?
‫Then you can understand that there
‫is a TextView definition going on in this case.
‫And it's the same thing for line 16 and line 17.
‫As you can see,
‫we used findViewByID,
‫and we are calling view class
‫and we are defining them as variables.
‫Okay?
‫And this is clearly a TextView.
‫So in line 16 we are defining a TextView,
‫in line 17, we are defining a TextView as well.
‫And after that, obviously we are going
‫to change the TextView texts.
‫So you can actually follow along with the lines,
‫like line 19, line 20, over here
‫to see your version as well.
‫Maybe you have used some different text,
‫other than Hello World.
‫But as you can see, we can see the Hello World
‫and Hello World2, in this case, over here.
‫And they are defined as some constant strings.
‫So when you see a cast,
‫it means that there is some kind of variable going on
‫inside of Dalvik bytecode.
‫So maybe we can manipulate this variable,
‫maybe we can change it
‫so that we can actually change the app itself.
‫And I get your point at this moment,
‫most probably you're thinking that,
‫yeah, maybe we can make some sense
‫out of this Dalvik bytecode,
‫but it's very hard to understand,
‫and it's very hard to write.
‫Right?
‫So yeah, it's very hard to write,
‫and it is not for writing over here,
‫it's just for converting
‫Java source code into Dalvik bytecode
‫so we can actually run it in the Dalvik virtual machine
‫in an Android operating system.
‫However, you have to learn the basics,
‫or you have to have a cheat sheet like this, for example,
‫in order to understand it better.
‫Most of the time, you will change at most,
‫one or two lines in Dalvik bytecode
‫in order to manipulate it.
‫But you have to know the basics,
‫and I found a very good cheat sheet online,
‫and I will share this link with you
‫on the resources of this lecture
‫so that you can refer to this list whenever you are in need.
‫That's exactly what I'm doing in my daily life
‫when I try to decompile an APK.
‫I open this Dalvik bytecode cheat sheet
‫and I actually refer to these operation code names
‫and operation explanations.
‫For example, move vx vy means
‫that moves the content of vy into vx.
‫So if you can scroll down a little bit,
‫you can see that constants' over here as well,
‫like what I have been talking about, like this.
‫So this is constant 16,
‫and it's kind of putting the 16 bit constant
‫into some register called vx.
‫And you can see this constant strings, constant integers,
‫and other variables, other data types as well.
‫And let me scroll down a little bit.
‫For example, we see the constant string,
‫we see new array.
‫Okay?
‫So these are things
‫that we were seeing over here, right?
‫Like constant string, cast v1,
‫like invoke-virtual.
‫So you can find what all of these things
‫do in Dalvik bytecode by looking at over here.
‫And you clearly understand
‫that this is creating a constant string,
‫this is creating a string variable
‫over here, in this line,
‫and we can actually change it in a way that we want.
‫So this is very basic.
‫We are finding a variable
‫that we have to, or we want to manipulate,
‫and we are trying to make some operations
‫regarding to that variable.
‫And we can do that for methods,
‫and we can do that for more advanced things as well.
‫And we will do that within this section, don't worry.
‫But right now, I'm just trying
‫to get you understand how Dalvik works
‫and how you can actually refer to Dalvik codes
‫when you are in need.
‫So as a practice now, consider suppose that
‫you actually have this APK,
‫you opened it, you found
‫that it shows Hello World and Hello World2
‫in the TextViews.
‫Okay?
‫You don't even need Android Studio,
‫right now, you only have APK, for example.
‫Okay?
‫And you want to change the TextViews,
‫you want to change the text inside of TextViews.
‫Of course, you can do that.
‫You can come over here and delete it,
‫and say Hello Dalvik,
‫instead of Hello World, for example.
‫And then you have to save it,
‫and then you have to close this down.
‫And make sure you don't change anything else,
‫just the text inside of the double quotation marks,
‫so that you don't break the code inside of Dalvik.
‫And then the moment of truth
‫is that we're going to recompile
‫as we're going to compile, build this,
‫rebuild these codes,
‫so that we can create an APK out of the manipulated code.
‫This is the basis for Android APK tool
‫reverse engineering corporations,
‫because we can decompile it,
‫and the big thing is we can actually rebuild it
‫whenever we want.
‫That's what we're going to do
‫within the next lecture.