I have been working on a fantasy console type project. I decided to lớn zero a flash drive I had laying around and use it as the ROM input to lớn the fantasy console. While trying to lớn write code to lớn read bytes directly from the drive (rather kêu ca from a tệp tin on the drive) I have found a peculiar bug.
Trying to lớn open the drive via CreateFile
and ReadFile
with the tệp tin path \\.\\PhysicalDrive1
results in the error ""\\.\\PhysicalDrive1" is not a core dump: file format not recognized
"
I have tried changing input options and I have tried alternate tệp tin paths, but anything I try results in the drive either not being found or the error shown above. Information on this issue is very scarse from my research, and what little info I have found is specific to lớn Linux, and involves very different situations.
Here is my code (not the cleanest but it should work):
#include
#include
#include
#include
int main(int argc, char *argv[]) {
printf("Opening %s\n", argv[1]);
HANDLE romf = CreateFile((LPCSTR)argv[1],
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (romf == INVALID_HANDLE_VALUE) {
printf("File %s not found\n", argv[1]);
return -1;
}
uint8_t rom[4] = { 0 };
LPDWORD read = 0;
int res = ReadFile(romf, rom, 4, read, NULL);
if (res == 0) {
printf("Error reading tệp tin (%d)\n", argv[1], GetLastError());
CloseHandle(romf);
return -1;
}
printf("Read $%x bytes\n", read);
printf("%02x %02x %02x %02x\n", rom[0], rom[1], rom[2], rom[3]);
CloseHandle(romf);
return 0;
}
I have used gdb
to lớn debug the code and to lớn get the error message.