Hi everyone. In this video, we want to talk about the compilation process before we can jump in to the 1
actual reverse engineering. 2
So if you remember our previous videos we talked about how an operating system loads and executable 3
into the machine, how exactly it runs, how the linked objects basically run that executable how the operating 4
system manages memories and stuff like that so in this video we basically want to move a step back and 5
talk about how we create the executable which you run on the operating systems. 6
Now when you're trying to build up a software you would obviously be choosing one or the other programming 7
language in which you can write your high level codes. 8
Now those high level codes have to be converted into machine-understandable code so that different 9
computers or different architectures can basically run their operating systems. 10
So the reason why software has gained so much popularity is because when you create a software it can 11
run on any device on on whatever operating system that it supports it's not just dependent on one machine 12
or one single device it can run on all these similar operating systems that your software can support. 13
So that's that's the reason why there was an exponential growth in in the software development field. 14
So this was only possible because those software can be converted into machine understandable 15
codes that can universally run everywhere 16
so if we talk about compiler based high level languages like C++ then when you're writing your software 17
you will basically be creating your program in the language you would start defining your functions 18
you would start defining what kind of operations can happen then when your function is executed and 19
things like that. 20
So once you have completed writing the code you basically run it through a compiler. 21
Now the compiler follows four stages before it creates the final executable. 22
So the four stages are the first one is called the pre processing stage. 23
So as the name suggests it's a pre-processing stage. The steps that happened before processing. 24
So what exactly does that take to removes all the extra payments that you might have added in your code. 25
It expands all the macros that you might have added if you have things like regex says and all then 26
all those things gets expanded. 27
It also starts expanding the included files. 28
For example if you're if you're using if you're importing different C libraries into your program then 29
all those things will start getting expanded in the pre processing stage. From there the control flows 30
to the compiling stage. 31
So in the compiling stage the result of the pre processing is used to generate the assembly language 32
so assembly language is a low level programming language which kind of gives you some understanding 33
of how the execution will look like at the processor level. 34
Along with giving you the ability to write those instructions so it's not completely machine code but 35
it's also not completely like a high level programming language like C or Java. 36
It's somewhere in between. 37
That's why it's called a low level programming language. 38
It's it's pretty old and it's based on the initial days when the computer architecture was still being 39
developed. So assembly language or having the idea of interpreting assembly language is going to be 40
a key skill when we would be reverse-engineering the malware. From compiling stage processing then moves 41
to the assembly stage. So the assembler will convert the assembly code into pure binary codes or the 42
machine code. The zeros and ones. 43
So as you know computers can only understand the binary values the zeros and ones they cannot understand 44
the high level programming languages that we write. 45
It's just the abstraction level which makes it easy for us to write our code in a high level understandable 46
language like C or Python or Java. 47
But ultimately what computers clearly need is the binary level information so that's where the assembly 48
stage comes into the picture. 49
It generates the final machine code that the computers can understand and execute. So after 50
assembly it moves to the final stage which is the linking stage. 51
So what the linker does is that it combines all the information gathered from the previous three phases 52
and for example when you write a software it's not just one single program that you write. 53
Basically a bunch of different programs and you are using the features of all those different programs. 54
So what Linker does is that it starts combining all those together into a single module and finally 55
generates your EXE file or the executable file. Enough of text. 56
Let's look at a pictorial representation as well. 57
It's pretty much what we just talked about but in a much shorter and myself way. 58
So consider the example where you have your source code written in C so the source code file will have 59
an instruction of dot c it goes through the pre processor phase which is the pre processing phase it 60
means it removes all the comments that expands the headers and everything. From there, 61
The control comes to the compiler. 62
The compiler generates the assembly code. 63
That's where I'm stressing a little bit because we are going to be with a lot of assembly code in future. 64
Now this generative assembly code then flows through the assembler which creates the object file or 65
the final binary instruction which the computer can understand. 66
Now using all those information Linker then finally creates your executable file or the exe file which 67
you can then distribute across and it can run on any operating system. 68
So that's all for this video. 69
Thanks for watching.