Assembly

Course
Time
13 hours 15 minutes
Difficulty
Beginner
CEU/CPE
14

Video Transcription

00:01
Hello, This is Dr Miller, and this is Episode 14.2 of Assembly.
00:05
Today we're going to try to talk about structures, will talk about their layout and offsets
00:10
structure and layout.
00:13
So here we're giving a structure. So we have several different members afloat. F A character see an initial D
00:19
and an unsigned character array called T of size six.
00:24
And so we can see inside the code that we are setting different values of each member of the structure.
00:31
And so with the structure, the layout starts at the first declaration of the first variable, and then it rounds to the nearest even bite boundary for the next size. So for bites, it'll just put one after the other, starting at the beginning and going through
00:46
for shorts. If it's at address one, it'll round up to two for floats around up to four energies for
00:53
and then longs on a 32 bit architecture around before and on a 64 world round 28
00:59
and then doubles round 28
01:00
So those are just some examples. Different ones will, depending on the architecture will brown two different sizes.
01:07
But then, if we're on a 32 bit architecture more round to the nearest four byte boundaries. So if we have a double, it'll round to the nearest four by boundary, cause it's just 32 bits.
01:19
And if we're on a 64 bit, then it would go all the way up to possibly an eight by boundary for that structure.
01:26
So here we're gonna have an example. We're gonna use the original code that we saw. So
01:32
when we have a float that's gonna take up four bites and we can see that zero starts the beginning, we can see that we have increasing memory addresses. So 0123 and then here we have increasing memory and justice, so they go up in size.
01:46
So our float takes four bytes. And so we here we fill in the 1st 4
01:52
Now we have a character, so that's going to go with the next bite.
01:55
But then our next object is going to be an imager. And so instead of starting it here, it rounds up to the nearest four byte boundary. So energy takes up four bites. So it starts here and goes up. And the reason why they round up to this is because
02:09
it's faster to access things at even bite boundaries as opposed to odd byte boundaries. So the processor is much, much faster. If it can
02:17
do that rounding automatically
02:21
and then the last, we have a character array of size six.
02:23
So you start here. 01234 and five.
02:28
That gives us our size six.
02:30
So the offsets.
02:34
So here I took the C code, and then I did a disassembly on it, and we can see
02:39
that we have the different offsets. So I've written them here, and we can see that are offsets are starting a B p minus. And then we have a value,
02:47
so are based. Down here is a B P minus 20
02:51
and then as we can go, weaken cr different offsets. So our character is at minus one C.
02:57
We have our inner jer at minus 18 in Hex, which is 24 decimals. I wrote the decimal over here,
03:05
and then we can see that our characters we had a bite. Ah, minus 14. And then we can see this is minus 13 on his 12 minus 11 minus 10
03:14
so we can see that it picked the appropriate byte boundaries. And the reason why it doesn't just compress them willy nilly is because if you bright a program using different compilers, it has to be able to understand. Okay, where would the bite boundary be for this type of structure?
03:30
And so it always follows these different rules.
03:34
But again, if you want to understand where it's gonna go, you can go ahead and disassemble it in order to understand exactly how that structure is working if you have. If you know what it looks like in C and so then we can understand. We can see that we're moving a bite here or removing a D word here
03:50
for each one of those, and we can see that it automatically does the D word, even though we just have FF and that is automatically set by the compiler.
04:01
So today we talked about the structure layout and then offsets.
04:08
Looking forward, we'll take some example structures and look how to reverse engineer them, um, and then there how to program them if we wanted to manipulate them directly.
04:18
So here's a quiz. So given the following structure, what would the offsets be for each variable.
04:29
So here, if we have 32 bit, the character see, is going to start at zero.
04:33
L will start at four, and then D will start at eight.
04:38
And again, we're going negative. So it's going to go the opposite direction. And then let's look at 30 at 64 bit.
04:45
So for 64 bit, we got 08 and 16.
04:49
So we will round this up to the nearest eight byte boundary and then this one up to the nearest 16 because this one will take actually eight bites
04:57
so we can see the offset tier minus 20 minus 18 and minus 10.
05:02
If you have questions, you can email me Miller MJ at you and Kate I e to you. You can find me on Twitter at Milhouse 30

Up Next

Assembly

This course will provide background and information related to programming in assembly. Assembly is the lowest level programming language which is useful in reverse engineering and malware analysis.

Instructed By

Instructor Profile Image
Matthew Miller
Assistant Professor at the University of Nebraska at Kearney
Instructor