User Tools

Site Tools


blog:pushbx:2025:0629_june_work

June work

2025-06-29

lDOS boot

lDebug

insref

Add the section iref-prefix listing all prefixes (8086, 286, 386). Additionally, add the REPZ and REPNZ synonyms for REPE and REPNE.

wwwecm.scr

Add lzexe to automatic current release builds, and to documentation builds, and add toolchain for FreePascal i8086 DOS target. (The FreePascal build of lzexe isn't used by the current builds yet.)

webecm

List LZEXE in a section on the page, and add a news item about it.

LZEXE

Robert pointed out the recent source release of Fabrice Bellard's LZEXE executable packer to me (on 2025-05-24). Initially it seems the release wasn't accompanied by a free software license so I didn't want to look into it. However, a while later someone else blogged about it and noted the MIT license is applicable to the sources. That's when I picked up the sources and started porting and extending them. (It seems that Robert did initially load an archive without the license, but it was silently added later.)

Building the initial source release proved difficult. The A86 source for the depacker stub was missing a segmentation directive and a label with a public directive. It's a riddle how this was supposed to build. I tried out several A86 versions and none of them worked with the file as is.

Next, the stub size was hardcoded in lzexe.pas which is a bizarre choice. I did fix this later also.

It also became clear that the provided sources do not exactly match any of the three binaries of LZEXE. This may be in part due to the choice of compiler and its version. (I use TurboPascal 5.0 to build.) But the v0.91 lzexe.exe file also contains a "chemin" keyword in its help display that doesn't match the provided sources.

The documentation does exactly match v0.91 though. This revision of the documentation was all in french, much like most comments and messages in the sources.

The new stub format

I iterated on the stub format several times, producing the LZE0 to LZE6 formats and finally LZX0. In the final format:

The /1 option won't recreate an exactly identical output file to v0.91 because of some assembly encoding choices, and several or reg, reg to test reg, reg changes I did to the original stub.

As unlzexe 0.9G2 (via) uses part of the stub to detect the format, it very likely will fail to depack files written by our LZEXE with the /1 switch.

Relocation table format

The compressed data format for the LZX0 image did not change, much like between LZEXE v0.90 and v0.91. The relocation table format changed slightly from v0.91: Instead of a first byte equal to 0 being the encoding for a longer table entry, now the first byte equal to 255 is used for this purpose.

This allows to encode zero-difference entries. This includes duplicate relocation entries (more than one pointing at the same address) as well as a relocation entry at the very beginning of the executable image. The former is arguably invalid, albeit DOS supports it. But the latter could very well occur in a valid file.

LZEXE v0.91 would corrupt its relocation table upon encountering a zero-difference relocation. In our fork, selecting the v0.91 format with the /1 switch will instead detect and reject files with such zero-difference relocation entries.

Porting

The A86 to NASM port was trivial with fixmem and ident86. (exepack.nas, lzss.nas fixmem and identicalising.)

The Pascal files originally built with TurboPascal 5.0 and I ported them to also build with FreePascal 3.2.2 using its i8086 msdos target. Needed changes:

The added export keywords as well as some compiler options that generate warnings in FreePascal are gated using {{$IFDEF FPC}} constructs that fortunately are supported by both compilers.

Other changes

You could leave a comment if you were logged in.
blog/pushbx/2025/0629_june_work.txt · Last modified: 2025-06-29 20:30:01 +0200 Jun Sun by ecm