Created
January 30, 2015 06:39
-
-
Save robindegen/c96fcd3ab393c887889f to your computer and use it in GitHub Desktop.
Reading raw data from a physical drive in windows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define _CRT_SECURE_NO_WARNINGS | |
#define WIN32_LEAN_AND_MEAN | |
#include <windows.h> | |
#include <stdio.h> | |
int main(int argc, char *argv[]) | |
{ | |
HANDLE handle = CreateFile( | |
"\\\\.\\PhysicalDrive0", | |
GENERIC_READ, | |
FILE_SHARE_READ | FILE_SHARE_WRITE, | |
NULL, // No security attributes | |
OPEN_EXISTING, | |
0, | |
NULL | |
); | |
if (handle == INVALID_HANDLE_VALUE) | |
return 1; | |
char bootsector[512]; | |
DWORD bytes_read; | |
ReadFile(handle, bootsector, 512, &bytes_read, NULL); | |
CloseHandle(handle); | |
FILE *f = fopen("bootsector.bin", "wb"); | |
fwrite(bootsector, 512, 1, f); | |
fclose(f); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment