executable = exe + data

René Berber r.berber@computer.org
Fri Dec 30 08:04:00 GMT 2005

Sam Steingold wrote:

> CLISP consists of a run time (a normal executable lisp.exe, 2.5M)
> and a memory image (a binary data file lispinit.mem 2MB-10GB).
> It is normally invoked as "lisp.exe -M lispinit.mem", i.e., the
> application consists of two files instead of a single executable which
> is generally not considered desirable by the users, one of whom
> suggested the following:
> copy /y /b lisp.exe + marker.txt + lispinit.mem myapp.exe
> This should work, but I would rather not search the executable for the
> marker text (for performance reasons - I do not want to increase the
> start-up time), I would prefer to know where the executable ends right
> away.
> Is it possible?


> simply put, it it possible to write something like this:
> int main () {
>   size_t my_length;
>   <some magic>
>   printf("exe size=%lld\n",my_length);
>   return 0;
> }
> so that when it is compiled, my_length contains the length of the
> executable file as it was created by the compiler.
> e.g.:
> $ ./myprog.exe
> exe size=1234567
> $ copy /y /b myprog.exe + myprog.exe myprog2.exe
> $ ./myprog2.exe
> exe size=1234567
> -- and not 2469134
> one of the main requirements is portability.
> (nothing woe32-specific or cygwin-specific &c)

Portable?  The only problem I can think of is an OS with enough security that
checks executable file size vs. file header specified size (in Windows the exe
header does contain the file size in blocks, but Windows doesn't check; I don't
know if other operating systems / executable formats are set up to do this kind
of check).

> the only idea I have had so far is this:
>    char string[]="this is a buffer into which I will be writing my stuff";
>    size_t my_length = atol(string);
> and then have a post-processor edit lisp.exe and replace the contents of
> string with the actual lisp.exe file length (I need the long initial
> junk there so that the post-processor will be able to find where it is to
> write the length).
> any suggestions?

Your idea works, I used to do something similar for copy protection purposes.

The steps would be something like:

1. Compile program, say "gcc -mwindows h.c -o h";

2. Record file size;

3. Concatenate program and data, say "cat h.exe h.data > longh.exe";

4. Run through post-processor (with longh.exe and size as parameter).

Of course a smarter post-processor could do steps 2 through 4 itself, no need
for parameters except perhaps the target string.
René Berber

Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

More information about the Cygwin mailing list