On Wed, 15 Mar 2017 00:35:36 +0100, Roderich Schupp
<[email protected]> wrote:

> If that's the case, the following might work (haven't actually tried
> this).

Finally got to trying this.

>    1. Get any packed executable (e.g. pp a hello-world one liner) from
> your target platform.
>    2. Run the attached script on it (repurposed from
>    contrib/extract-embedded/extract-embedded.pl). This will print
> something like
> 
>    embedded FILEs start at offset 2119320
>    zip starts at offset 3143323
>    size of FILEs section is 1024003
> 
>    3. Chop off the executable after the start of the zip.
>    4. Pack your application into a .par file ("pp -p -o my.par ...")
>    5. Append my.par to the executable stub.
>    6. Compute the SHA1 of the file so far and append it in hex (40 bytes)

Apparently this sha1 is not used for checks, only to form an unique
directory for the cached data.

>    7. Append "\0CACHE"
>    8. Append pack('N', size of FILEs section + size of my.par)

Add another 12 since it must include the sha1 and "\0CACHE".

>    9. Append "\012PAR.pm\012"
>    10. Ta-da, new executable for the target platform

This could work for extremely pure perl modules and scripts...

In my case a bit more is needed since the application uses quite a few XS
and foreign libraries. That's why I mentioned "updating" in the subject.
Luckily, an update usually only involves the perl modules.

This is a procedure that does seem to work:

1. Get a packed executable of a running version of the application.
2. Establish the length of the FILEs section and the location of the zip.
3. Strip off the 58-byte trailer from the exe.
4. Split the exe into preamble and zip.
5. Fix the zip with "zip -A".
6. Update the necessary modules in the zip.
7. Concatenate the preamble and the zip > new.exe
8. Fix the new exe with "zip -A".
9. Append a new trailer:
     a seemingly arbitrary 40-byte sha1
     "\0CACHE"
     pack('N', size of the FILEs section + size of updated zip + 12)
     "\nPAR.pm\n"

The new exe runs correctly using Wine on Linux (which proves that
everything is included!) but I still have some problems to get it running
on a real Windows system.

-- Johan

Reply via email to