#include <windows.h>
#include <stdio.h>
#include <io.h>
#include <fcntl.h>
#define SECTOR_SIZE 2048
unsigned char buffer[SECTOR_SIZE];
__declspec(noreturn) void __stdcall start(void) {
int argc, bytesRead, totalKB = 0;
wchar_t **argv = CommandLineToArgvW(GetCommandLineW(), &argc);
char drivePath[8] = "\\\\.\\\0:";
void *hDVD;
_setmode(_fileno(stdout), _O_BINARY);
if (argc != 2) {
fprintf(stderr, "Usage: %ls <DVD Drive Letter>\n", argv[0]);
exit(1);
}
drivePath[4] = argv[1][0];
if ((hDVD = CreateFileA(drivePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) {
fprintf(stderr, "Failed to open DVD-ROM drive. Error: %lu\n", GetLastError());
exit(2);
}
DeviceIoControl(hDVD, FSCTL_ALLOW_EXTENDED_DASD_IO, NULL, 0, NULL, 0, &bytesRead, NULL);
while (ReadFile(hDVD, buffer, SECTOR_SIZE, &bytesRead, NULL) && bytesRead > 0) {
totalKB += 2;
fwrite(buffer, 1, bytesRead, stdout);
if (totalKB % 1024 == 0) {
if (totalKB < 1024)
fprintf(stderr, "\rProcessed: %d kB", totalKB);
else if (totalKB < 1048576)
fprintf(stderr, "\rProcessed: %.2lf MB", totalKB / 1024.0);
else if (totalKB == 1048576)
fprintf(stderr, "\r \rProcessed: 1.00 GB");
else
fprintf(stderr, "\rProcessed: %.2lf GB", totalKB / 1048576.0);
}
}
CloseHandle(hDVD);
exit(0);
}