Question: #include #include #include #include #include #define WIN32_LEAN_AND_MEAN using namespace std; constexpr size_t MBR_SIZE = 512; constexpr size_t BYTES_PER_LINE = 4; constexpr size_t NUMBER_OF_LINES = MBR_SIZE
#include #include #include #include #include #define WIN32_LEAN_AND_MEAN using namespace std; constexpr size_t MBR_SIZE = 512; constexpr size_t BYTES_PER_LINE = 4; constexpr size_t NUMBER_OF_LINES = MBR_SIZE / BYTES_PER_LINE; static DWORD ReadMBR(PCHAR lpBuffer) { HANDLE diskHandle = CreateFile(TEXT("\\.\PhysicalDrive0"), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); if (diskHandle == INVALID_HANDLE_VALUE) { return GetLastError(); } ReadFile(diskHandle, lpBuffer, MBR_SIZE, NULL, NULL); CloseHandle(diskHandle); return GetLastError(); } static void PrintMBR(char buffer[MBR_SIZE]) { size_t byteIndex = 0; string lineSeparator; for (size_t i = 0; i < NUMBER_OF_LINES; i++) { cout << lineSeparator; lineSeparator = " "; for (size_t j = 0; j < BYTES_PER_LINE; j++) { char c = buffer[byteIndex++]; for (int k = 7; k >= 0; k--) { cout << ((c >> k) & 1); } cout << " "; } } } int main() { char buffer[MBR_SIZE]; ReadMBR(buffer); PrintMBR(buffer); cin.get(); return 0; }
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
