All pastes #100440 Raw Edit

clayne

public c v1 · immutable
#100440 ·published 2006-07-26 04:05 UTC
rendered paste body
/* raw disk read on windows */#include <windows.h>#include <stdio.h>#include <stdlib.h>int main(int argc, char **argv){        HANDLE h;        char disk[256];        char sect[1024 * 1024];        size_t br;        int pd;        if (argc < 2) return -1;        pd = strtol(argv[1], NULL, 10);        snprintf(disk, sizeof disk, "\\\\.\\%s%ld",                "PHYSICALDRIVE", pd);        h = CreateFile(                disk,                GENERIC_READ,                FILE_SHARE_READ | FILE_SHARE_WRITE,                NULL,                OPEN_EXISTING,                FILE_FLAG_NO_BUFFERING,                NULL);        if (h == INVALID_HANDLE_VALUE)                return -1;        while (ReadFile(h, sect, sizeof sect, &br, NULL))                fwrite(sect, sizeof sect, 1, stdout);        CloseHandle(h);        return 0;}#include <windows.h>#include <stdio.h>#include <stdlib.h>int main(int argc, char **argv){        HANDLE h;        char disk[256];        char sect[1024 * 1024];        size_t br;        int pd;        if (argc < 2) return -1;        pd = strtol(argv[1], NULL, 10);        snprintf(disk, sizeof disk, "\\\\.\\%s%ld",                "PHYSICALDRIVE", pd);        h = CreateFile(                disk,                GENERIC_READ,                FILE_SHARE_READ | FILE_SHARE_WRITE,                NULL,                OPEN_EXISTING,                FILE_FLAG_NO_BUFFERING,                NULL);        if (h == INVALID_HANDLE_VALUE)                return -1;        while (ReadFile(h, sect, sizeof sect, &br, NULL))                fwrite(sect, sizeof sect, 1, stdout);        CloseHandle(h);        return 0;}