flat assembler
Message board for the users of flat assembler.

Index > Windows > Simple compare and patch generator+patch programme

Author
Thread Post new topic Reply to topic
bzdashek



Joined: 15 Feb 2012
Posts: 147
Location: Tolstokvashino, Russia
bzdashek 08 Apr 2012, 21:00
Good evening,

While experimenting with assembler, I ran into a problem of comparing two files of equal size. The "original" and "patched" version.

I wrote two simple programmes in order to do that:
1. fcompare - compares 2 files and writes the result to the *.fcp file.
2. fcp - opens the *.fcp file, searches for original programme with human help, and then turns it magically into fixed version.

I reused the error reporting technique that Tomasz used in FA.asm and some code regarding file operations from fasm\TOOLS\WIN32\SYSTEM.INC.

Structure of *.fcp file:
Code:
4 bytes - signature
2 bytes  - file version
2 bytes - number of entries
4 bytes - original file size
2 bytes - file name length
1..260 bytes - target filename
--- end of header ---
;1 entry
4 bytes - offset from the start of file
1 byte  - original byte
1 byte  - patched byte
....
;n-th entry
4 bytes - offset from the start of file
1 byte  - original byte
1 byte  - patched byte
--- end of file ---
    

Size of Entry - 6 bytes
Maximum number of entries in *.fcp file is 65536.

Hence, maximum *.fcp file size is 14 + (1..260) + 65536*6 = 393230..393489 bytes.

The limit for size of patched file to compare is 100 Mb. Programme reads the whole two files into memory, that might be bad practice, I did consider using 64k blocks for compare procedure, but I was lazy to implement it.

I tested it on number of files, but I might have missed some bugs, so it would be wonderful if you could report bugs in this thread. Or you can fix them yourself. Smile I'm attaching full sources.

I know I'm not the first to write such thing, but I want to hope that it will be useful for the ASM society.

Thanks for your attention.


Description: File Compare & Patch
Download
Filename: fcpatch.7z
Filesize: 8.59 KB
Downloaded: 326 Time(s)



Last edited by bzdashek on 09 Apr 2012, 08:39; edited 1 time in total
Post 08 Apr 2012, 21:00
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2909
Location: 0x77760000
typedef 08 Apr 2012, 21:38
One way also is to use the hashing technique. Very Happy
Post 08 Apr 2012, 21:38
View user's profile Send private message Reply with quote
shutdownall



Joined: 02 Apr 2010
Posts: 517
Location: Munich
shutdownall 08 Apr 2012, 23:51
I would sell this program to Microsoft. For the next patch day. Laughing
Post 08 Apr 2012, 23:51
View user's profile Send private message Send e-mail Reply with quote
bzdashek



Joined: 15 Feb 2012
Posts: 147
Location: Tolstokvashino, Russia
bzdashek 14 Apr 2012, 21:48
This is the standalone patch generator. You compile it specifying a file include directive @ patch_data label (see source). After that patch file is included in exe. You can distribute it afterwards, for example.

At first I tried to combine them with copy /b, but when programme starts, windows loads just what is specified in the header of EXE file. I was lazy to dig the PE specification.


Description: File Patch
Download
Filename: fp.7z
Filesize: 2.06 KB
Downloaded: 330 Time(s)

Post 14 Apr 2012, 21:48
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.