WEBVTT

00:00.630 --> 00:02.249
Hello, this is Dr. Miller, and this

00:02.250 --> 00:03.869
is Episode thirteen point one of

00:03.870 --> 00:04.870
Assembly.

00:05.430 --> 00:06.629
Today, we're going to talk about the

00:06.630 --> 00:08.247
compilation process and then some

00:08.460 --> 00:10.529
tools like Binary Format

00:10.530 --> 00:12.599
Readers and dissemblers.

00:13.940 --> 00:15.140
Compilation process.

00:16.530 --> 00:17.902
So we have a few examples of

00:18.420 --> 00:20.470
some different compilers, like

00:20.760 --> 00:22.260
Visual Studio or

00:22.590 --> 00:24.460
GW, which is a DCC

00:24.540 --> 00:26.429
compiler and a compiler, is just

00:26.430 --> 00:28.230
a program that translates some

00:28.350 --> 00:29.879
computer code that somebody has

00:29.880 --> 00:31.829
written from one programing

00:31.830 --> 00:33.299
language into another.

00:34.050 --> 00:35.618
And so we have our source, which

00:35.940 --> 00:37.079
is generally written in in a high

00:37.080 --> 00:38.399
level language, and then we have

00:38.400 --> 00:39.420
some sort of target.

00:40.110 --> 00:41.729
And generally what we're going to do

00:41.730 --> 00:42.719
is we're going to take high level

00:42.720 --> 00:44.369
code and we're going to turn it into

00:44.370 --> 00:45.959
a binary machine readable

00:46.260 --> 00:48.299
code that we can then execute on

00:48.300 --> 00:49.300
a system.

00:51.300 --> 00:53.039
So the process is it takes in a high

00:53.040 --> 00:54.363
level program and then will

00:54.840 --> 00:56.729
generally produce an intermediate

00:56.730 --> 00:58.289
representation so that you could

00:58.290 --> 01:00.090
have multiple

01:00.630 --> 01:02.579
different inputs and be able

01:02.580 --> 01:04.499
to apply the same optimizations

01:04.500 --> 01:05.730
to different inputs.

01:06.210 --> 01:08.069
So, for example, C Sharp allows you

01:08.070 --> 01:09.689
to write something in a variety of

01:09.690 --> 01:11.579
different languages and then

01:11.580 --> 01:12.809
it compiles them all down to

01:13.560 --> 01:16.049
a common intermediate representation

01:16.350 --> 01:17.699
and then is able to apply

01:17.700 --> 01:19.559
optimizations to any code written

01:19.560 --> 01:21.149
despite the language it's written

01:21.150 --> 01:22.049
in.

01:22.050 --> 01:23.669
And then it generates the output

01:23.670 --> 01:25.200
program or the binary file.

01:27.560 --> 01:29.299
So the output that's going to depend

01:29.300 --> 01:30.859
on the target architecture,

01:31.760 --> 01:33.189
so few examples here,

01:33.590 --> 01:35.250
so you might be running Windows XP

01:35.290 --> 01:37.819
86 or OS 10 x 86

01:37.850 --> 01:39.319
or Android UNarm

01:39.800 --> 01:40.800
or iOS unarm.

01:41.000 --> 01:42.764
And you could have also Linux on ARM

01:42.830 --> 01:43.910
or six.

01:44.810 --> 01:46.280
And so your output is going to

01:46.310 --> 01:48.349
highly depend on what architecture

01:48.350 --> 01:49.810
you're wanting to save for.

01:49.880 --> 01:51.590
So we've seen to this course

01:51.950 --> 01:53.469
it's six code and then arm code

01:54.080 --> 01:55.459
and those are going to be different

01:55.460 --> 01:57.109
pieces of code that are generated.

01:59.580 --> 02:01.409
And what's generated is

02:01.410 --> 02:03.269
a binary file format,

02:03.600 --> 02:05.579
and so what we have

02:05.580 --> 02:07.050
is we have a format defined by

02:07.620 --> 02:09.384
the operating system, something that

02:09.539 --> 02:11.249
is readable by each of us.

02:11.940 --> 02:13.190
So some examples.

02:13.200 --> 02:14.915
So we have the format which is used

02:15.030 --> 02:16.030
for Linux.

02:16.140 --> 02:17.708
We have the cough or some common

02:18.150 --> 02:20.279
object file format or file

02:20.610 --> 02:21.419
for Windows.

02:21.420 --> 02:23.669
And then Austin has Mocho.

02:25.340 --> 02:27.169
So here's some examples, so

02:27.560 --> 02:29.128
if we look on the left hand side

02:29.300 --> 02:30.917
here, we can see that we have the

02:31.160 --> 02:32.160
actual ASCII

02:33.050 --> 02:35.129
characters or hex characters.

02:35.320 --> 02:36.447
So these are aski these

02:37.280 --> 02:39.259
are going to be hacks that show

02:39.260 --> 02:40.583
exactly what is in the file

02:41.210 --> 02:43.300
at exactly what offset.

02:43.340 --> 02:44.919
So we can see offset zero,

02:45.290 --> 02:46.909
we have an M and a Z.

02:47.960 --> 02:49.399
Additionally, inside of here, we can

02:49.400 --> 02:51.066
see there's a P and an E and those

02:51.410 --> 02:53.269
are going to relate

02:53.270 --> 02:54.499
to these different headers.

02:54.500 --> 02:56.089
And so the header is basically tell

02:56.090 --> 02:58.129
the operating system exactly

02:58.130 --> 02:59.159
how the files laid out.

02:59.600 --> 03:01.639
So in a portable executable or a p

03:01.640 --> 03:03.306
e we have a DOS header and then we

03:03.530 --> 03:04.530
have a P header.

03:05.060 --> 03:06.139
Right. And as it says here.

03:06.140 --> 03:07.519
Right, the doctor says this is a

03:07.520 --> 03:08.794
binary file and then the P

03:09.560 --> 03:10.969
header says, oh, it's by the way,

03:10.970 --> 03:12.649
it's not DOS, it's this new version

03:12.650 --> 03:13.650
called P.

03:14.930 --> 03:16.129
And then inside of that we have

03:16.130 --> 03:17.809
additional headers or optional

03:17.810 --> 03:19.280
headers and those will give it

03:19.370 --> 03:21.079
information about what system it can

03:21.080 --> 03:22.879
run on what

03:22.910 --> 03:24.379
what is the image base that was used

03:24.380 --> 03:26.020
to compile this and link it.

03:26.840 --> 03:28.039
And then we have the final part,

03:28.040 --> 03:29.040
which is the code.

03:29.090 --> 03:30.979
And so inside the code, then

03:30.980 --> 03:32.629
we would have the binary for

03:32.960 --> 03:33.960
move X 42 and we

03:34.820 --> 03:36.160
can see that in here.

03:36.170 --> 03:37.689
And then the return is going to

03:38.030 --> 03:39.030
be C three.

03:39.740 --> 03:41.779
And so this is an example

03:41.780 --> 03:43.489
of a pedophile and

03:44.030 --> 03:45.500
the designer of this does the

03:45.530 --> 03:47.449
basically the smallest pedophile he

03:47.450 --> 03:48.830
can get, which is why it's called.

03:50.510 --> 03:51.860
But we can see that the format

03:52.250 --> 03:54.139
really specifies exactly

03:54.140 --> 03:55.610
what we need in binary.

03:57.470 --> 03:59.087
Now, here, the same designer here

03:59.360 --> 04:00.949
we have the Moscow file format.

04:01.370 --> 04:02.899
And again, we have different

04:03.290 --> 04:04.729
what we call magic numbers.

04:04.730 --> 04:06.530
So we can see inside of this one,

04:06.890 --> 04:08.310
it says feed face.

04:08.480 --> 04:10.399
So that's the magic number for AMOC.

04:10.400 --> 04:12.389
Oh, I don't know why they did

04:12.390 --> 04:13.390
it, but that's what they did

04:14.300 --> 04:15.589
back here. A little bit of history.

04:15.590 --> 04:17.180
So MSG's stands for

04:18.050 --> 04:19.765
Mark and then I think Zippel Wig is

04:20.000 --> 04:20.809
the name of the guy.

04:20.810 --> 04:22.039
And so he designed the format.

04:22.040 --> 04:23.690
So he put his initials in it.

04:24.380 --> 04:25.850
And here we have feed face and

04:26.360 --> 04:27.740
then we have different segments,

04:28.550 --> 04:30.439
threads, and then at the end we

04:30.440 --> 04:31.440
have our code.

04:31.820 --> 04:33.470
And so, again, you can see that

04:33.920 --> 04:35.750
when it's going to do an exit right

04:35.960 --> 04:38.179
here, it's doing an entity versus

04:38.180 --> 04:39.169
our previous one.

04:39.170 --> 04:41.089
We just did see three or

04:41.090 --> 04:42.090
return end.

04:42.660 --> 04:44.839
And so the output format

04:44.840 --> 04:46.309
is highly dependent on the

04:46.310 --> 04:48.139
architecture that you are saving

04:48.140 --> 04:49.140
to.

04:50.290 --> 04:52.139
And then finally, we have the ELF

04:52.230 --> 04:53.847
format or executable and linkable

04:54.220 --> 04:56.199
format, and we can see inside

04:56.200 --> 04:57.915
of it it has the magic number seven

04:58.360 --> 04:59.360
F and then the ASCII

05:00.220 --> 05:01.360
letters, L.F..

05:02.590 --> 05:04.480
And again, we have some headers

05:04.810 --> 05:06.182
and a table and then we have

05:06.790 --> 05:07.689
a code.

05:07.690 --> 05:09.249
And so each one of these

05:09.820 --> 05:10.959
is the smallest sort of

05:10.960 --> 05:12.669
representation that you can have or

05:12.670 --> 05:14.379
minimal representation of that

05:14.380 --> 05:15.380
binary format.

05:16.920 --> 05:18.869
So some tools, so

05:18.870 --> 05:20.879
if you want to look into exactly

05:20.880 --> 05:22.448
what code is generated by a high

05:22.740 --> 05:24.504
level, you can use several different

05:24.600 --> 05:26.549
ones so we can use preview

05:26.550 --> 05:27.550
on windows.

05:27.870 --> 05:29.480
And so that allows us to look at P

05:29.550 --> 05:31.314
files and see the internal structure

05:31.620 --> 05:32.489
of them.

05:32.490 --> 05:34.200
Additionally, we have object dump.

05:34.480 --> 05:35.939
And so this is going to display

05:35.940 --> 05:37.829
information about object files

05:38.700 --> 05:39.700
and also some binary

05:40.560 --> 05:42.209
files and then we'll have some

05:42.210 --> 05:43.210
dissemblers.

05:44.870 --> 05:46.159
So, again, object dump is a

05:46.160 --> 05:48.019
dissembler, it has the ability to do

05:48.020 --> 05:49.196
disassembly for it, it's

05:49.970 --> 05:51.391
free, it's on all versions of

05:51.410 --> 05:52.999
Lendix. And so it's pretty easy to

05:53.000 --> 05:54.225
use, but it's very basic.

05:54.440 --> 05:55.519
It just does some text,

05:56.270 --> 05:58.369
whereas these three so either pro,

05:58.370 --> 05:59.959
binary ninja and Ghidorah

06:00.410 --> 06:02.449
are all commercial

06:02.520 --> 06:04.129
dissemblers. And so they have a lot

06:04.130 --> 06:05.449
more features like being able to

06:05.450 --> 06:07.549
rename things and color coding.

06:08.900 --> 06:10.223
Usually Eita Pro is sort of

06:10.730 --> 06:12.589
the default standard, but the

06:12.590 --> 06:14.109
price tag on it is a little bit

06:14.240 --> 06:15.240
prohibitive.

06:15.530 --> 06:16.969
You know, nine hundred twenty eight

06:16.970 --> 06:18.409
hundred is a little bit of a lot of

06:18.410 --> 06:19.410
people's range.

06:21.020 --> 06:22.637
Binary ninja is a little cheaper.

06:23.120 --> 06:24.139
It doesn't have quite as many

06:24.140 --> 06:25.429
features as I do pro.

06:25.430 --> 06:27.194
It's about three hundred dollars and

06:27.350 --> 06:28.575
then Ghidorah is free and

06:29.180 --> 06:31.129
it has been developed by the NSA and

06:31.130 --> 06:32.140
then released.

06:32.780 --> 06:34.399
And so it's sort of a new tool that

06:34.400 --> 06:35.527
just came out recently.

06:35.720 --> 06:37.309
And so a lot of people are looking

06:37.310 --> 06:39.679
into it as a alternative

06:39.680 --> 06:40.680
to either pro.

06:40.790 --> 06:42.409
But any of these are going to allow

06:42.410 --> 06:43.439
you to disassemble or

06:44.300 --> 06:45.439
look at the code that gets

06:45.440 --> 06:46.440
generated.

06:48.470 --> 06:50.059
And then, heck, senators allow you

06:50.060 --> 06:51.889
to view and edit possibly

06:52.340 --> 06:53.467
and save files that are

06:54.200 --> 06:55.910
in hexadecimal representation.

06:56.150 --> 06:58.430
So HEX is numbers

06:58.460 --> 07:00.579
zero through nine and A through F,

07:00.590 --> 07:02.509
and those represent four bits

07:02.510 --> 07:03.510
for each one of those.

07:04.010 --> 07:05.999
So some examples, hÃÂ¸st

07:06.020 --> 07:07.020
or cheat engine.

07:07.340 --> 07:08.340
So those are

07:09.380 --> 07:11.299
just do hex editing,

07:11.690 --> 07:13.429
but also all of the dissemblers will

07:13.430 --> 07:14.869
actually show you hexadecimal

07:14.870 --> 07:15.870
dump's.

07:16.160 --> 07:17.779
And so this one's from Binary Ninja

07:17.780 --> 07:19.759
showing a hex dump of a binary

07:20.540 --> 07:21.540
that I loaded.

07:24.120 --> 07:25.688
And then if you want to, you can

07:25.800 --> 07:28.049
also read these binary formats using

07:28.050 --> 07:29.520
libraries, so I just pick some

07:29.730 --> 07:31.319
example Python ones here

07:31.920 --> 07:33.809
so you can read a p e file or

07:33.810 --> 07:34.986
an L file or a mock file

07:35.910 --> 07:37.529
all from within Python.

07:38.670 --> 07:40.049
And so these have the ability to

07:40.050 --> 07:41.471
parse those files and then to

07:42.000 --> 07:43.421
understand what the different

07:44.040 --> 07:44.939
parts are and give you

07:44.940 --> 07:46.379
representation so that if you want

07:46.380 --> 07:47.639
to do some programing on it, you

07:47.640 --> 07:48.640
have that ability.

07:49.140 --> 07:50.219
Additionally, there are a lot of

07:50.220 --> 07:51.809
other languages. I just picked some

07:51.810 --> 07:52.950
some examples here.

07:55.040 --> 07:56.630
So today, we talked about

07:57.020 --> 07:58.784
compilers and what they do and their

07:58.850 --> 08:01.250
process and then some tools

08:01.280 --> 08:02.750
like binary format readers and

08:02.900 --> 08:04.519
binary formats and what they were,

08:04.880 --> 08:06.644
and then some disassembly tools that

08:06.740 --> 08:07.740
you can use.

08:09.300 --> 08:10.439
So looking forward, we're going to

08:10.440 --> 08:11.549
look at the reverse engineering

08:11.550 --> 08:13.410
process so that we can understand

08:13.830 --> 08:15.389
how to break apart binaries if we

08:15.390 --> 08:16.679
write something new and we don't

08:16.680 --> 08:18.620
understand how it works and

08:18.630 --> 08:20.069
we'll set up a miniature reverse

08:20.070 --> 08:21.779
engineering lab so that we can look

08:21.780 --> 08:23.544
at some of these sea constructs that

08:23.610 --> 08:25.079
are high level constructs within the

08:25.080 --> 08:26.080
sea language.

08:28.050 --> 08:29.399
So what does a compiler do?

08:31.930 --> 08:33.369
It turns high level code into

08:33.370 --> 08:34.899
machine readable code that is

08:34.900 --> 08:36.549
executable on a system.

08:37.860 --> 08:39.239
If you have questions, you can email

08:39.240 --> 08:41.200
me Miller, MJ at Unclutter

08:41.250 --> 08:42.869
Edu, and you can find me on Twitter

08:42.870 --> 08:43.860
at Milhouse 30.

