I had a quick C++ job once for a client that eventually bailed out on me. So I decided to share the code so other may find good uses for it. This is a short write-up describing the issue the client had and a simple way to get around it.
The client needed RAW access to arbitrary blocks on a Flash drive for both reading and writing, especially in the unused portion of the drive. So I decided to bite the bullet and created a working solution. And it was fun too!
It appears as if Windows will block raw access to certain sectors if Flash drive is NTFS formatted. For FAT or FAT32 there are no problems accessing anything on the Flash drive. The big revelation idea is to simply use DeviceIoControl with FSCTL_LOCK_VOLUME to actually unlock the Flash immediately after opening it like so:
BOOL success = DeviceIoControl(m_hDevice, FSCTL_LOCK_VOLUME, NULL, 0, NULL, 0, &dwReturned, NULL);
After doing this, all of Flash is directly accessible for both reading and writing. Basically, you can render the Flash unreadable and destroy your data unless you know what you are doing. You won’t destroy the Flash physically of course. All you need to do after playing is reformat it and all will be well.
So here is the full source code. Please rename remove DOC extension. It is just a 7-zip file.