Cloning CompactFlash Cards using WinHex
2009-07-05 12:16 by Ian
A procedure for making byte-for-byte copies of CF cards. Written while working at a camera repair shop that needed this capability, but it’s also useful for lifting partitions from a development system using a conventional hard drive and dropping them onto a CF card for operation in a finished condition (after appropriate edits).
This was written for people who were already comfortable with technical things, but not necessarily computers.
Procedure for making a 1:1 copy of a CF card in WinHex:
A sector is a group of (usually) 512 bytes.
The CompactFlash spec includes the ability of any given CF card to be used as an ATA hard drive. This is what a USB card reader does. All sectors of a hard drive MUST be accessible. It follows that NO manufacturer can hide data, and simultaneously conform to the CF spec. So we take advantage of this.
The basic idea is to read (verbatim) every sector of the source CF card, and then write the sectors in the same order (and starting at the same point) to the target card.
1. Open WinHex and insert your source CF card into the reader. Find a target card that is close to the same size as your source card. More on this later. If the target card is smaller than the source card, this procedure might work, but for the sake of compatibility, should be avoided.
2. In WinHex, goto “Tools->Disk Editor” (or push F9) and select the drive letter that corresponds to your source card. You will be presented with a frightening field of hexadecimal numbers. These numbers each have an offset value that is located on the far left of the field.
3. The most reliable way to copy all the data sectors is to be SURE you are at offset 00000000, click the first element in the row. Hit ALT+1 to designate it as the start of the data. Next scroll all the way to the end of the data (or to the bottom of the field), double-click the last element, and hit ALT+2 to define the last element.
4. CTRL+C to copy the block. If you wish, at this point, you may goto “Edit->Copy Block->Into new file”. This will allow you to keep a liquid copy of the source data.
5. Eject the source card, and replace it with the target card.
6. Again, BE SURE you are at offset 00000000. The first element in the row. CTRL+V to paste the data.
7. After pasting the data, goto “File->Save Sectors”. After this has finished, the copy process has been completed.
Here is what you have just done as it relates to the computer:
When a computer/camera/whatever is made to access files from
a CF/Hard disk, the media always contains two basic things:
- A media descriptor (or master boot record)
- a File Allocation Table (FAT)
Media descriptors tell the computer what format of media is being used, and where to find the FAT. The FAT is used to locate and provide boundaries for specific chunks of data that usually correspond to files. The key idea here is that the descriptor and the FAT contain ALL of the metadata that is needed to reproduce a data structure. But without modification, there are a few relevant constraints that come with this ability…
- You must always have the descriptor, FAT and the data at the same location relative to offset 00000000, AND at the same location relative to one another. If these conditions are not met the copy will not only be bad, but will be so corrupt that it will be unrecognizable to cameras and computers alike. This is why you must always copy/paste to/from offset 00000000.
- All the data and data structures must be present in their entirety. If the structures (FAT/descriptor) are missing or incomplete, the data is just noise. If the data is missing or incomplete, the structure has only empty meaning.
- The target CF card will be nothing more than a shell for the source data. This means that if your target card is 128MB and the source card is 16MB then after the copy the 128MB card will show up as a 16MB card. The space is not lost forever, but a format (and so, data loss) is required to regain the space. When you do a “quick-format”, the data is untouched, and the structure (FAT) is re-written. This is how data is recovered after a format, and why quick formatting is insecure.
- If the target CF card is smaller than the source card, bad things can happen. It is the electronic equivalent of telling a blind driver that the freeway they are driving on continues for miles when in fact they are speeding toward a barricade. You can expect to see an fantastic crash of an unpredictable nature. Data loss, lock-ups, etc… Computers are all blind.
Olympus used to use a technique of embedding a series of digits in “less accessible” areas of SmartMedia cards to enable features like panoramic capture. Olympus used this strategy to make people purchase their media cards from them at a premium. The key thing to remember at all times when dealing with data, is that if it was ever accessible, it can be so again. And therefore we can reproduce it with the same types of techniques described above.