-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
57 lines (53 loc) · 1.13 KB
/
main.cpp
File metadata and controls
57 lines (53 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
// Function to read the boot sector of an MBR
void ReadBootSector(string filename)
{
ifstream mbr_file(filename);
if (mbr_file.is_open())
{
char buffer[512];
mbr_file.read(buffer, 512);
cout << "Boot Sector: \n";
for (int i = 0; i < 512; i++)
{
cout << buffer[i];
}
cout << endl;
}
else
{
cout << "Error opening file \n";
}
mbr_file.close();
}
// Function to parse the MBR and extract the partition table
void ParsePartitionTable(string filename)
{
ifstream mbr_file(filename);
if (mbr_file.is_open())
{
char buffer[512];
mbr_file.read(buffer, 512);
cout << "Partition Table: \n";
for (int i = 446; i < 486; i++)
{
cout << buffer[i];
}
cout << endl;
}
else
{
cout << "Error opening file \n";
}
mbr_file.close();
}
int main()
{
string mbr_file_name = "mbr.bin";
ReadBootSector(mbr_file_name);
ParsePartitionTable(mbr_file_name);
return 0;
}