delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2005/12/30/02:17:16

X-Spam-Check-By: sourceware.org
To: cygwin AT cygwin DOT com
From: =?ISO-8859-1?Q?Ren=E9_Berber?= <r DOT berber AT computer DOT org>
Subject: Re: executable = exe + data
Date: Fri, 30 Dec 2005 01:16:52 -0600
Lines: 84
Message-ID: <dp2mt4$4ij$1@sea.gmane.org>
References: <uek3vqivg DOT fsf AT gnu DOT org>
Mime-Version: 1.0
User-Agent: Mozilla Thunderbird 1.0.7 (Windows/20050923)
In-Reply-To: <uek3vqivg.fsf@gnu.org>
OpenPGP: url=ldap://keyserver.pgp.com
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

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
[snip]
> 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.
>=20
> Is it possible?

Yes.

> simply put, it it possible to write something like this:
>=20
> int main () {
>   size_t my_length;
>   <some magic>
>   printf("exe size=3D%lld\n",my_length);
>   return 0;
> }
>=20
> 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=3D1234567
> $ copy /y /b myprog.exe + myprog.exe myprog2.exe
> $ ./myprog2.exe
> exe size=3D1234567
> -- and not 2469134
>=20
> 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 th=
at
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 d=
on'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:
>=20
>    char string[]=3D"this is a buffer into which I will be writing my stuf=
f";
>    size_t my_length =3D atol(string);
>=20
> 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).
>=20
> any suggestions?

Your idea works, I used to do something similar for copy protection purpose=
s.

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 ne=
ed
for parameters except perhaps the target string.
--=20
Ren=E9 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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019