🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #17662

Re: Make executable

#17662
From: Remy Lebeau (TeamB)
Date: Sat, 08 Mar 2003 22:21
59 lines
4141 bytes
What you ask would would be better accomplished by writing a pre-made
patcher app that is general enough to just read the patch changes from a
separate data file and apply the changes that it is told to apply.  Also
write a separate patch-maker app that opens the two files, scans through
them to see what their differences are byte-for-byte, then writes that
information to a third data file that descibes how to apply the differences
to the original file.  Then the patcher app can use that data file as
needed.  In the data itself, you could use a list of structures that
describe each patch, such as the type of patch operation to perform
(overwrite, append, terminate, etc)  as well as the original offset, the
original byte value, the new byte value, etc.

If you don't want to distribute multiple files, you could make a copy of the
patcher app file and append the patch data to the end of it, then append a
starting offset at the end of that.  That way, you are only distributing one
file that, at runtime, can open a read-only handle to itself, then read the
offset from the end of the file, seek to that offset, and read and use the
patch data as need.

With that said, if you still want to dynamically create an entire executable
from scratch, then you need to have full understanding of how executables
work in general.  Have a look at the following article for more information
on that.  You could place the generated patch info into the executable's
resource section and then extract it at runtime to a temporary file (or use
a resource stream) to read the data needed for knowing how th patch the
original file:

    Peering Inside the PE: A Tour of the Win32 Portable Executable File
Format
    http://msdn.microsoft.com/library/en-us/dndebug/html/msdn_peeringpe.asp

Even then, rather than creating the entire executable from scratch, you
could pre-make bits and pieces of it and then then concatenate them together
as needed to produce the final executable file.

Now then, either way, whether you write a dynamic executable from scratch or
write a pre-made generic app, when it comes time to actually apply patches,
you can't insert new bytes into an existing file while keeping the
originals.  You can only overwrite or append bytes, so when patching the
original file, the patch should include the offsets of the changes, then
seek to those offsets and write the new values overwriting the original
values.  If the new file was larger then the original file then append the
remaining bytes at the end of the patched file.  Otherwise, if the new file
was smaller then the original then seek to the new file's file size offset
and set the EOF flag using the SetEndOfFile() function.

Patches also tend to have some kind if checksum information about the
original file as well, so that the patcher can make sure it is patching the
correct file to begin with before actually writing the new values.


Gambit

"ScOe" <sven.savic@zg.hinet.hr> wrote in message
news:3e69a85f@newsgroups.borland.com...

> Standard problem with making patches ...Compare
> two files, and upon diferences make executable that will
> patch old file.
Technical Details
Message-ID: <3e6a6acd$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-09!supernews.com!iad-peer.news.verio.net!news.verio.net!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail
References: <3e69a85f@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,3a3a660f9f2dab38
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-03-08 14:17:39 PST
From: "Remy Lebeau \(TeamB\)" <gambit47@yahoo.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <3e69a85f@newsgroups.borland.com>
Subject: Re: Make executable
Date: Sat, 8 Mar 2003 14:21:30 -0800
Lines: 61
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
NNTP-Posting-Host: 207.175.226.26
Message-ID: <3e6a6acd$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1047161549 207.175.226.26 (8 Mar 2003 14:12:29 -0800)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-09!supernews.com!iad-peer.news.verio.net!news.verio.net!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail