Created
October 15, 2020 16:32
-
-
Save iljavs/d2b110a07c18ee89ceb172eee4f3bf52 to your computer and use it in GitHub Desktop.
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
// ZeroRead.cpp : This file contains the 'main' function. Program execution begins and ends there. | |
// | |
#include <Windows.h> | |
#include <stdio.h> | |
void hexdump(unsigned char* p, DWORD len) { | |
DWORD i; | |
for (i = 0; i < len; i++) { | |
if (i && !(i % 16)) { | |
printf("\n"); fflush(stdout); | |
} | |
printf("%02X ", p[i]); fflush(stdout); | |
} | |
printf("\n"); | |
fflush(stdout); | |
return; | |
} | |
int main() { | |
HANDLE f; | |
f = CreateFile(L"\\\\.\\Zero", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); | |
if (f == INVALID_HANDLE_VALUE) { | |
printf("CreateFile() failed\n"); | |
exit(0); | |
} | |
DWORD bytes; | |
char b[128]; | |
BOOL r = ReadFile(f, b, sizeof(b), &bytes, NULL); | |
printf("r: %u\n", r); | |
if (r != TRUE) { | |
printf("ReadFile failed\n"); | |
exit(0); | |
} | |
printf("bytes written: %u\n", bytes); | |
hexdump((unsigned char *)b, bytes); | |
return (0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment