So in this video, we'll be seeing how to add the section to the P file so you can add another section
and you need to modify some other fields.
And those fields are the number of sections count in the file header.
You need to increment this one and the size of image.
So the image size increase this and how to calculate this is the last sections virtual address plus
virtual size.
This gives the image size and the size of headers.
So we have the header size you need to increase by one image, a section header.
Well, I think these three and finally, we're going to paste that section here after this.
This section.
So let's get started.
I have already written these add section 60 for the data and they are working fine.
So let's do this again.
So I have corrected the file alignment.
So the file alignment tells us at which multiple of this one does actually start.
So here we have five alignment 200.
So if, if there is a section at the starting of 400 and the section only occupied 100 hexadecimal bytes,
then the next section should not start at 500, it should start at 600 because this should be the section
starting should be multiple of this one file.
So that's why I had featured the file alignment.
So the function takes two parameters.
One is the P file, and the second one is the shared code.
So if you look at the P file in Excel, the hex editor.
You can see the last one is section is obviously not allowed so you can open calculator one zero.
One year, one year zero zero divided by 200 gives you.
This calculator does not use or shows the reminder.
So this one is the best one year zero zero divided by 200.
So if you calculate this one, you get a reminder zero.
So that means we are good to go.
Sometimes you will have some extra bites here.
In that case, what you need to do is you need to.
First let's calculate the P file length.
So this gives me the whole size of the rap file.
So it should be divided with the file alignment.
So one year zero zero is divided by 200.
Which gives me the quotient.
So the quotient is.
In this case, it's a D and the reminder is zero.
So what we're going to do is if, suppose, assume that there are extra some ten bytes, then what you
need to do is you need to skip this from one year 002 plus 200, which gives you 100.
So you need to start the section at that offset because there are ten bytes and you cannot continue
at one year or something.
So you need to add 200 for this.
So what we can do is.
So let's, uh, let's just assume for now, uh, 100.
There are already null bytes has been added to the section so that we can directly add these bites.
So at the end of this video, we are will be fixing this one.
So let's, uh.
B five dot.
By file airline.
And we need to add a plus one to this one.
And we need to multiply with this file line.
So.
So the question will be the 202 de plus one, that is, you get this 1300.
So let's say 202 into E, so which gives us one zero.
So perfect.
So this.
This is going to give us the.
How?
The total size after the section was added.
So that's got this new section size.
New section sizes, this one and this category total size is equal to.
Total size p length and we need to add that new section size.
So let's run this.
So I think the new section says we will have the 1600.
So it's.
Okay.
So we have added one year zero zero and 100 so that we can remove this one in section size.
So we can see the total size is 100.
And.
Sorry for this.
We need to add the share code.
Yes, share code run by file align.
So both will be, I think, similar.
So the new section size is 200 and we can add this P file length.
So in the previous case, what we have done is we have calculated the new total section from this one.
But here we are taking the shared code length, which is some 100 bytes and we are dividing with this
file aligned.
So you get some quotient and you add plus one to this and multiply with five again.
So you get the new section size.
So we got the total size.
One.
See how much we want to get so we can say.
What your Iraq.
Tortorella says.
And the production time should be.
They reiterate.
So we have allocated the size.
And at last, we need to free this one.
Mature.
Free.
So you can specify zero for the size and we can say memory is.
Let's also print the best address.
So now at this point, we can copy the first copy the P file.
Be filed at length.
So this should copy the AP file and then we need to copy the.
Four.
Serco, Serco zero and based address press.
Be forgotten.
And the rent or rent?
So let's put a breakpoint here and let's run this.
And if I go and step this one, I should see the p file here and we can see the p file has been copied.
So if I go and next step into this, I should see the share code.
There is my share called.
So here, this is my grocery cart that you can see 100.
You can see at the one ending of one, we have the circle.
So I think we are good to go now.
So he has successfully copied them.
The file and the section are shared according to the.
So what you need to do is we need to modify this one, these members.
So.
Well, let's go ahead and pass these headers.
Mitch.
Darth Vader instead does not share the pointer to structure.
But his address.
Type of dust header.
So.
Are we getting the door at that venue so we can get the P offset?
And the next one is let's create a new entity, Hitler, 64.
And he had a signature.
So the first four bytes of he header is the signature.
So martial art pointer to structure and the pointer is based address press or dos header dot e or the
venue and the type of, uh.
I'll you.
So.
So it's not a structure.
It's just for bytes.
So we can say martial art reading 32 base address press.
Does either dot e the venue, so they should do fine.
Now we are good to go.
We have the signature and then we can send dot file header equals to marshall dot pointer to structure
based address.
Best address press dos.
Press does header dot l have a new plus form because the signature is four bytes and the type of.
Randy had a 64 so we are good to go now until the 64 so.
Oh, sorry.
Sorry.
It's fine.
So for goodness.
If I had so.
Now we need to pass this optional.
Monitor naught pointer to such.
So this is going to be somewhere big because we need to get starting from base entrance press does header
dot e venue.
Press for.
Press.
So the size of file header is 20 wide.
So I can just say 20 bytes or you can say masher the size of this integrated file.
So.
So I think
everything is personal.
Let's just go and print this one and 3.5. number of sections.
We should see the output as three.
So here we can see the number of sections are three.
So let's also pass these sections.
Image section header.
All the sections is equal to new sections of how many sections are there and header dot option of five
header dot number of sections.
So let's go and root for this.
I guess, then.
So we can say.
This address plus
does better.
So this gives me the P offset.
So now what I can say is my shirt size is off and so this gives me directly the offset to the anti header.
And after anti header we will have sections.
At this point.
You can see all the sections of I.
Calls to.
So we are passing this section of after passing one section header, you need to jump skip that, that
length of the first section.
So how you're going to do is we can say plus.
Are you into?
Martial arts is off.
A pulse section had a.
So what this use is for every iteration, I'm going to fast.
For the first iteration I use zero.
So I'll be getting the exact offset to the first section header for a equals equal to one.
I'm getting the offset to the first section header.
I'm adding again the size of this section header, which gives me the offset to the second section header.
So in that way I'm going to loop all over this one are all the sections now I can say all sections of
my dot name, so we can say a new string.
And if we go ahead and run this.
So let's run this.
And here we can see we got all the sections so we are good to go now.
So we have parser everything, the sections and all we need to do is we going to update these values.
So the first one is sections comp.
Updating sections count.
So we need to find the offset of this section's count so that we can update in the byte area.
First let's find the Marshall offset.
Tough.
Let's find the offset.
Let's find the offset of this section's count.
Remember from the file we can see the file had its to do weights.
I guess this one and this one is for weight.
So let's just find out.
I pass.
File header.
So in this structure, I want to find the member.
That is a number of sections.
So this thing should be unique.
I mean, this string should be the member of this structure.
So you can see the number of sections.
Make sure all of these uppercase and lowercase are correct.
And we need to set a date to enter the 32.
So you get sections.
Exceptions can't offset.
Now we got the sections count of set piece sections.
Of is equals two.
So from the starting that is does header dot e revenue plus.
The signature is four, so you need to add this one.
Now you will get the.
Sections come.
So the election's count is 16 bits or two bytes.
What we can do is.
Let's just print this P file off.
Sections.
Condorcet.
But as one.
So we can see we got the three.
So I think we are good to go.
Let's go and modify this one.
So let's marshal that right into 16.
So we'll be writing to this, our memory allocated and then after that we can finally save all those
memory into the file.
Base address.
Press Section's count offset.
Sections.
So we need to update the value so we can say anti header, not fire header number of sections plus one.
So we are updating the sections in the memory.
So let's put a breakpoint here and let's run this one.
So we have this.
You can see the P.
So here we can see 0003.
So this is in return.
So zero three is the number of sections.
If I go and step into this one, I should see the four.
So let's run this and we can see the four.
So we have three updated the sections in a similar manner which we are going to update all of this one.
Size of image.
So size of image is so first created.
So let's create a new section header.
That's a new section is equal to a new section.
So we need to update the values of this new section, members like this one.
So new section dot name is equals to.
Encoding, not as key yet by itself.
So here we need to give the name eight characters because later we are going to copy into the memory.
So it's going to give some error.
So let's just do the dot domain 69.
It takes exactly eight characters.
A new section dot.
Number of line numbers zero.
Relocations.
Zero.
This one is also zero.
Now pointer to ras data.
So the pointer to data is the P file length so that the next way to this one we have written the our
circle.
New Section DOT.
Size of raw data.
Size of raw data is this one.
U.S. says so the U.S. size is the size of the data.
A new section dot portugal size what your address so what Chaucer addresses.
Virtual addresses.
You can see the large sections, virtual addresses for 4000.
So let's first define what Chaucer is.
So there is some math you should do for what Schroders or Chaucer sizes share code length.
Now there is a problem I have encountered whenever this virtual size is greater than section alignment.
So that means our section alignment is 1000.
And if the actual size of any of the previous section is 2000, or let's say 1500.
Now what we need to do is we need to divide this one over to a size with this section arrangement.
So 1500 by 8000.
So we use the quotient one.
So Quotient one, we need to add plus one to this one and we need to multiply the section element.
So this gives the
actual virtual size or even the next.
What's your address to this one?
So we got the 2000.
So this 2000 should be added to this.
What sort of size?
So it will be added to 4000.
Now the result will be 6000.
So you can see 4500 virtual size and the new section is 6000.
So it should be.
It should be it should not give any error.
So let's go and get the old sections off.
So to get the last section member of an area so we can say what are the sections dot length minus one.
So this should the last member dot virtual size.
What you say should be diverted by section 11.
So.
Sexual harassment is not optional, but section alignment.
So they should give me the quotient.
And even if the what you're saying is 190 here, so you can see what sort of size is 190, which is
less than the thousand.
So we can say 190 divided by 1000.
You get the value of the question zero zero plus 1000.
So it gives me the value of 5000.
So it should not be a problem of the previous section.
So what you're saying is.
Okay.
So now I'm going to add plus one to this one plus one to this one.
And I'm going to multiply the section amendment.
To this one.
So this gives me the perfect value to be added to the old sections of all the sections.
Length minus one.
Not virtual size.
So that is adding to this, the previous virtual address.
What's your address?
So this entire thing is U.S. dot.
What's your address?
Okay, we are good to go.
My new section is ready.
And one more.
Few more things we need to update our.
This one size of image, sizes of image, size of feathers.
So what we can do is in the headers dot adoption and adoption or dot.
Size of females.
So size of.
Emergency calls to.
The latest sections.
What's your address?
Press choices.
This gives me the latest size of image.
All right.
We need to update this value or.
By finding the offset of this.
I love image, so I'm just going to copy this one.
So it's similar to this updating values.
So let's copy this and paste it in our code.
So we are finding a size of image.
And then the P offset press, signature press.
The file header breast size of image offset.
So we can say this one is updating the mail size.
Okay.
In similar way, you can update the size of headers as well.
So copy this.
And.
So these are factors.
So they see the size of us offset.
Mark shared our.
Best address press DOS Header LFA New Press four signature press 20.
File Header.
Press sizeof header offset.
So at this point, I want to update with Andy that Andy had a dot option.
So.
Option header dot size of headers press.
Martial arts is off.
So we are simply we are adding one section so we can see the size of a male section.
I think, uh, uh, we should be good to go.
So let's put a breakpoint here and let's run this.
And at this point, the sections, a number of sections I'm sorry, sections can't.
It also hit the breakpoints.
So a03 should be changed to zero four.
Yes, we can see.
And now the SEC.
Where is this bullet point so that we can continue at this point?
Immelt says.
So he made size his 4190.
So the new images size will be.
This one.
Now.
What's your address?
Press.
The size what yours is.
So if you click on this one and you can see 5114.
So 5000 is the virtual address and 114 is the virtual size.
So let's continue this one.
We should see size of head offset.
So the size section header is 40 bytes.
So.
40 so.
14 hexadecimal is 28.
So if I add 28 the section size to this to 48 section heterozygous to this to 48, I should get to 70.
So let's run this one and I should see 0270 270.
So we are good to go.
One last thing is.
We need to copy the section header information.
Right after this section.
So how do you get the offset is?
Anti header dot option file header a number of sections.
This gives me the old number of sections.
That is three.
What we can do is we can directly rate using this one size of factors.
So you can copy this one.
This is the character offset.
We can write.
So.
Martial art.
Separate this section structure.
We need to convert this into byte area.
So first, let's get some memory.
So we had allocated some memory.
Uh, and it can be pointed by Pointer.
And we need to master the structure to the point.
So the structure is new section pointer.
True.
So at this point, the section will be.
Copied into this pointer will be pointed to that structure data.
So then we can copy this one.
You can copy into this new section by its.
So first one is pointer and the next one is new section by its start index and then this new section
by bytes dot length.
So that's the breakpoint.
And let's run this.
And pipe pointer.
So let's run this one.
And here we can see the structure, a new section structure.
You can see the first one is the name Dummy 69, and the next one are the members of the structure.
Those are 40 bytes were written into this one.
So we can we are copying from this one to the new section bytes.
So we are good to go now.
And final thing is, we need to copy this by today to exactly before this section header.
So my shelled art.
Copy.
New section bytes start index zero destination is.
Based address press and d header dot option header dot size of headers.
New section bytes dot.
So let's put a break here and run this.
And the base address is this one.
So here we can see the after this fifth section after 45.
This is the end of the section.
We should see the new section here, the dummy section.
So let's run this.
And here we can see.
The sexual information.
So we have successfully written this one.
So we have successfully added the section.
All we need to do is now we need to
create an area.
Let's say a new file is equals two new byte of.
Total size.
Want to share our copy sources.
The best address.
New file
size.
So you're copying the entire, uh, memory bytes into the file.
So we can see a file dot.
Right.
All bites.
So we can say the smarter teaming tools.
And then you fight.
So it's going to run this.
And here we can see the tree has been popped up.
So let's go and view that character in see where.
And here we can see the number of sections has been increased to four and the size of the size of others.
And you can see there is a dummy section.
So the characters are of characteristics.
So you can copy the characteristics of this one.
New section dot.
So these characteristics test whether section is readable or executable.
So there is a enumeration data section, flags a dot memory execute and data section flags dot memory
read and data section flags dot.
I think it's for.
So if you hold on to this, you will see the enum code executable readable.
Content.
So we are good to go now.
So let's run this again.
And now I rewrote this one and we should see the characteristics, same as each section.
You can change these characteristics as well.
You can just say readable.
So that server, this video you can add if you want to add another section, you can re randomize this
number and you can go in a loop of adding sections.