Thread View: borland.public.cppbuilder.nativeapi
2 messages
2 total messages
Started by ScOe
Sat, 08 Mar 2003 08:22
Make executable
Author: ScOe
Date: Sat, 08 Mar 2003 08:22
Date: Sat, 08 Mar 2003 08:22
20 lines
1553 bytes
1553 bytes
How can i dynamically make executable file ?
Standard problem with making patches ...Compare two files, and upon
diferences make executable that will patch old file.
--
,,,
(o o)
*===============ooo0====(=)====0ooo================*
| ScOe (mailto:sven.savic@zg.hinet.hr)
|
| Homepage:
|
| http://free-zg.hinet.hr/ScOe/
|
| ICQ# : 9947311
|
*================================================*
"In the End, we will remember not the words of our enemies,
but the silence of our friends. " - Martin Luther King Jr. (1929-1968)
Re: Make executable
Author: Remy Lebeau (TeamB)
Date: Sat, 08 Mar 2003 22:21
Date: Sat, 08 Mar 2003 22:21
59 lines
4141 bytes
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.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads