Binary patch

Microsoft Windows vista ultimate w/ sp1...
April 22, 2010 at 14:25:16
Specs: Windows Vista Ultimate SP2, 3GB
Hi, does anyone know if there is a command-line utility that takes three arguments:

sourcefile.exe diff.txt targetfile.exe

where the first is an existing binary file, the second is an existing text file, and the third is a binary file it creates.

The second argument specifies a text file that contains differences (in hex) required to turn sourcefile.exe into targetfile.exe. Its format is as follows: each line begins with an offset (in hex) and up to 16 bytes (in hex, space-separated). It then overwrites those bytes at the given offset. The format is a bit like what you get with the Unix cmp -l command, except it's all in hex.

So is there a patch utility that works on such a file? If not, I can write one in C++, but I would prefer to save time and not reinvent the wheel.


See More: Binary patch

Report •

#1
April 22, 2010 at 15:33:18
http://www.golden-triangle.com/chan...


=====================================
Helping others achieve escape felicity

M2


Report •

#2
April 22, 2010 at 15:40:11
it sounds like you could do it using batch and debug.
assuming each change is on its own line, like:
4CD2 1A 3C 6D AA...
all you need to do is put E in front of it:
E4CD2 1A 3C 6D AA
for each line, like (where file1 is the textfile you described):
for /f "tokens=*" %%a in file1 do >> file2 echo E%%a
then:
>>file2 echo nbinary2
>>file2 echo w
>> file2 echo q
then:
debug binary1<file2
at least, it seems like this would work...

Report •

#3
April 23, 2010 at 02:01:12
Thanks both for your answers.

@nbrane: Good idea, but doesn't DEBUG start at address 0100? That means I will have to add 100 to the hex value at the start of each line. It's doable though. Also, I'm not sure how to handle more than 64KB. Luckily, the file I'm trying to change is just under 64 KB so it's not an issue.

@M2: thanks, I'll take a look at the utility to see if it processes the diffs file in that format.


Report •

Related Solutions

#4
April 23, 2010 at 02:51:00
I think Bruce Guthrie's CHANGE will do you.

As to debug, it loads a file at 100 by default but you can tell it where to load.

I think the main snag with scripting debug for a binary file is that a binary file doesn't have 'lines', as defined by 0d0a breaks. And yeah, 64K is about it.


=====================================
Helping others achieve escape felicity

M2


Report •

Ask Question