MAMEWorld >> Programming
View all threads Index   Threaded Mode Threaded  

Pages: 1

Heihachi_73
I am the Table!
Reged: 10/29/03
Posts: 954
Loc: Melbourne, Australia
Send PM


Comparing two files and adding the difference to another
#368391 - 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.



krick
Get Fuzzy
Reged: 02/09/04
Posts: 4207
Send PM


Re: Comparing two files and adding the difference to another new [Re: Heihachi_73]
#368400 - 07/30/17 02:05 PM


Beyond Compare can do a side-by-side compare files as binary but I don't think it can be automated beyond replacing using regular expressions. This might be enough for what you're trying to do.

https://www.scootersoftware.com/

If not, it sounds like maybe you'd need to write a custom program (as in Java or C++) to do what you're trying to do. Do you code?



GroovyMAME support forum on BYOAC



Heihachi_73
I am the Table!
Reged: 10/29/03
Posts: 954
Loc: Melbourne, Australia
Send PM


Re: Comparing two files and adding the difference to another new [Re: krick]
#368413 - 07/30/17 08:16 PM


> Beyond Compare can do a side-by-side compare files as binary but I don't think it can
> be automated beyond replacing using regular expressions. This might be enough for
> what you're trying to do.
>
> https://www.scootersoftware.com/
>
> If not, it sounds like maybe you'd need to write a custom program (as in Java or C++)
> to do what you're trying to do. Do you code?

I don't code unfortunately (I'm limited to patching code such as in MAME, it's trivial to rearrange or duplicate code that is already there e.g. adding ROMs).

I have Hex Workshop which also compares files, but I could really do with a program which could automatically add single 0x0D bytes into the other file after comparing both. I'm currently in the process of hand-fixing koalamnt but it's a pain to do it manually because the source ROM is a bad dump (most of the koalamnt ROMs have bad bytes between 6C000-70000 except u8 which is bad between 2C000-30000 - u10 and u14 seem to be OK), so I have to not only go through both files but fix the bad dump and hope that I don't stuff everything up by missing a 0D in the process. I have (hopefully) hand fixed 3 ROMs in the set so far but I am not really confident, at least until the game boots to graphics, because that means the three internal checksums are passing and there are no errors at all!

Update: Game is now fixed and working!

Edited by Heihachi_73 (07/30/17 10:08 PM)



redk9258
Regular
Reged: 09/21/03
Posts: 3965
Loc: Troy, Illinois USA
Send PM


Re: Comparing two files and adding the difference to another new [Re: Heihachi_73]
#368421 - 07/31/17 05:00 AM


This probably would have worked...
https://mh-nexus.de/en/hxd/


Pages: 1

MAMEWorld >> Programming
View all threads Index   Threaded Mode Threaded  

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