MAMEWorld >> Programming
Previous thread Previous  View all threads Index   Next thread Next   Flat Mode Flat  

Heihachi_73
I am the Table!
Reged: 10/29/03
Posts: 1074
Loc: Melbourne, Australia
Send PM
Comparing two files and adding the difference to another
07/30/17 10:31 AM


I have a few files to fix which had been transferred to a server as ASCII instead of binary, how would I go about adding missing bytes to the second file?

As some people may already know, there are a few "identical" ROMs in MAME which have two different dumps of the same set, one set being a bad dump and unusable, and a second set which was a good dump but corrupted by loss of data.

Bad dump:

Code:

54 E8 69 73 0D 39 73 0D 61 9E 0D 65 48 61 6D 70 6C 65 0D 6F 66 0D 64 61 34 61 0D 31 72 33 34 00



Corrupted by ASCII conversion:

Code:

54 68 69 73 69 73 61 6E 65 78 61 6D 70 6C 65 6F 66 64 61 74 61 31 32 33 34 00



I need to restore every 0x0D in the corrupted file by using the 0x0D bytes still in the bad dump to this:

Code:

54 68 69 73 0D 69 73 0D 61 6E 0D 65 78 61 6D 70 6C 65 0D 6F 66 0D 64 61 74 61 0D 31 32 33 34 00



The quickest why I can think of is a program which simply compares both files (ignoring other non-matching bytes since the source file is a bad dump) until it reaches an 0x0D in the bad dump, and then injects the 0x0D it finds into the other file at that location, continuing onto the next, however I don't know how this will work e.g. whether the files will align correctly. There are tens of thousands of these bytes missing so it would take forever to do by hand without any automated program.

False positives (a bad byte which shows up as 0x0D) and bad bytes (where a real 0x0D was a different value and therefore isn't detected) are fine, these can be hand fixed.

Note: The above examples are in plain text for ease of making such an example; the files which need repairing are binary data such as program code, graphics etc. where the bytes are completely random.

The server did not check for 0x0D 0x0A (CRLF), it simply removed each 0x0D it encountered regardless of what was after it.







Entire thread
Subject Posted by Posted on
* Comparing two files and adding the difference to another Heihachi_73 07/30/17 10:31 AM
. * Re: Comparing two files and adding the difference to another krick  07/30/17 02:05 PM
. * Re: Comparing two files and adding the difference to another Heihachi_73  07/30/17 08:16 PM
. * Re: Comparing two files and adding the difference to another redk9258  07/31/17 05:00 AM

Extra information Permissions
Moderator:  Pi 
0 registered and 40 anonymous users are browsing this forum.
You cannot start new topics
You cannot reply to topics
HTML is enabled
UBBCode is enabled
Thread views: 1073