Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

A brief introduction to the extended knowledge of the main bootstrap

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

Hundreds of millions of cloud servers cooperate directly with top computer rooms in many countries around the world to provide servers from Hong Kong, the United States, Japan and other countries and regions. If you need them, please contact the official customer service. High-quality server rental!

We explained the basics of the master bootstrapper earlier, and today we're going to talk about the extension of the master bootstrapper. However, the master bootstrapper has a limit, that is, the amount of code of the master bootstrapper cannot exceed 512 bytes! So how do we break through this limit?

Our basic idea now is to do the following in the main bootstrapper:

1. Complete the most basic initialization work

2. Load the program into memory from the storage medium

3. Transfer the control to the Singapore program for execution

4 、.

So what exactly should we do? The idea is shown in the following figure

So how should the master bootstrap load other programs in the storage media? Through a certain file system format. So what is a file system? It refers to the method of organizing file data on the storage medium (the way in which the data is organized). Here we take the FAT12 file format as an example, why choose it? Because its file format is the simplest and most suitable for learning. The FAT12 file format is shown in the following figure

FAT12 is the early file system of the DOS era; its structure is very simple and has always been used in floppy disks; it has three basic organizational units: Byte is the basic data unit, Sector is the smallest data unit in the disk, and Cluster is one or more sectors. Our solution is: 1, use FAT12 to format the floppy disk (data.img); 2, write the executable program (Loader) and copy it to the floppy disk; 3, the main bootstrap program (boot) looks for Loader;4 in the file system, copies the Loader into memory, and jumps to the entry address to execute.

Our next experiment is to write a file to a virtual floppy disk. Raw materials are FreeDos,Bochs,bximage. The steps are: 1, create a virtual floppy disk (data.img); 2, format (FAT12) in FreeDos; 3, mount data.img into Linux and write to a file.

We first create a virtual floppy disk in Linux, then mount it to the / mnt/hgfs/ directory (the command is mount-o loop data.img / mnt/hgfs/), and then create two files, test.txt and loader.bin, in Linux. The content of test.txt is This is test for virtual floopy..., and the content of loader.bin is D.T.Software of many lines. ; then copy both of them to the virtual floppy disk (copy to the / mnt/hgfs/ directory), and finally uninstall the virtual floppy disk (umount / mnt/hgfs/). Let's look at the files on the virtual floppy disk.

We can see that there are already two files on the virtual floppy disk. Let's take a look at their contents.

We see that the contents of the documents we have written have appeared. So we now have a virtual floppy disk that contains the contents of our own files. So now that we have done the first two steps, our job is to boot to find the target file (Loader) and read the contents of the file! Let's take a closer look at the FAT12 file system, which consists of the boot area, the FAT table, the root entry table, and the file data. As shown in the following figure

The more important information stored in the main boot area of FAT12 is the type of file system, the total number of logical sectors of the file system, the number of sectors contained in each cluster, and so on. The main boot area ends with 0x55AA pulling you a byte, occupying a total of one sector. Its information is shown in the following figure

The next step is to read the file system information in data.img. Steps: 1, create Fat12Header structure type; 2, use file stream to read the first 512 bytes of content; 3, parse and print related information. Next, we conduct related experiments. We write a program to parse Fat12Header in C++ language. The source code is as follows.

# include # pragma pack (push) # pragma pack (1) struct Fat12Header {char BS_OEMName [8]; ushort BPB_BytsPerSec; uchar BPB_SecPerClus; ushort BPB_RsvdSecCnt; uchar BPB_NumFATs; ushort BPB_RootEntCnt; ushort BPB_TotSec16; uchar BPB_Media; ushort BPB_FATSz16; ushort BPB_SecPerTrk; ushort BPB_NumHeads; uint BPB_HiddSec; uint BPB_TotSec32; uchar BS_DrvNum; uchar BS_Reserved1 Uchar BS_BootSig; uint BS_VolID; char BS_VolLab [11]; char BS_FileSysType [8];}; # pragma pack (pop) void PrintHeader (Fat12Header& rf, QString p) {QFile file (p); if (file.open (QIODevice::ReadOnly)) {QDataStream in (& file); file.seek (3) / / offset 3 bytes, because everything related to the file system starts here (in the table above) in.readRawData (reinterpret_cast (& rf), sizeof (rf)); rf.BS_OEMName [7] = 0; / / assigns the last member of the array to a value of 0 and treats them later as string processing rf.BS_VolLab [10] = 0 Rf.BS_FileSysType [7] = 0; qDebug ()

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report