32LiTE <<( 32-bit DOS Executable Packer )>> Copyright (c) 1998, 1999 Oleg Prokhorov (olegpro@mail.ru) Copyright (c) 1998, 1999 Joergen Ibsen (jibz@hotmail.com) All Rights Reserved 1. Preface. Since the very ZX-Spectrum times the executable compression problem interested me much. Saving more games on one tape without losing workability was my desire. And it was even more important for disks. Once I found a cool (based on a RLE-like method) compressor source in a ZX magazine, I retyped it and the effect was amazing. Compressed files were really smaller in size. So I spent a few days compressing my disks, and I got a couple of almost free disks! Later when I had changed from ZX to PC it was not a problem to compress executables. There were a lot of executable packers for MS-DOS (from the ancient DIET and PKLITE to the better ones like AINEXE and UCEXE). Besides, the first proggy which I downloaded from the Internet was an executable packer called WWPACK. I wanted it very much, because it was the best at that time. Unfortunately it was the latest and last version, because the authors stopped it's development. I thought that there would be nobody that could excel it (should I mention this verb as a MicroSoft TM? You see, one day they will trademark the whole English language :). But soon I found a man, Joergen Ibsen, who was smart and courageous enough to challenge the best MS DOS executables packer in the world. And HE has succeeded! His aPACK has started a new era in executable packing technology. But still we all know MS DOS is dead! Nobody develops MS-DOS programs nowadays. Only Watcom C/C++ & DOS4GW guard us against the final Windows domination. And it was a real disappointment that there was no good packer for WATCOM "LE" executables. In fact they really need packing. So with the help of aPLib I've started this thing: 32LiTE -- the 32-bit DOS Executable Packer. --------------------------------------------------------------------------- 2. License. 32LiTE is CREDIT-WARE for non-profitable use (if nobody charges money for programs that are packed with it) which means that if you use it, then you must credit Oleg Prokhorov in your files or docs (well, ain't that cheap!). If you (or anybody else) plans to sell a program packed with 32LiTE then contact Joergen Ibsen (jibz@hotmail.com) for information on how to register. 32LiTE can be registered alone, or you can obtain a combination license for both 32LiTE and the 16bit DOS executable packer aPACK (at a discount, of course). You may not distribute 32LiTE without the rest of the files (32LiTE.HTM, CHANGES.TXT and the images in the zip). And you may not edit any of the files or sell 32LiTE for money (except for charging for the media). Feel free to upload 32LiTE to any BBS or site, or including it on a CD.. #ifndef _COMMON_SENCE This software is provided "as is". In no event shall I, the author, be liable for any kind of loss or damage arising out of the use, abuse or the inability to use this software. USE IT ENTIRELY AT YOUR OWN RISK! This software comes without any kind of warranty, either expressed or implied, including, but not limited to the implied warranties of merchantability or fitness for any particular purpose. If you don't agree with these terms or if your juristdiction does not allow the exclusion of warranty and liability as stated above you are NOT allowed to use this software at all. #else Bla bla bla .. the usual stuff - you know it anyway: If anything goes even remotely wrong - blame yourself, NOT me! #endif --------------------------------------------------------------------------- 3. Supported Formats. Watcom "LE" Executables You can compress numerous executables files which were created with Watcom C/C++ compiler. This compiler is the most frequently used for creating DOS 32-bit executables. Especially games (i.e. DOOM 1/2, Mortal Kombat, Decent), demonstration programs (i.e. Vivid Experiment, Toasted, Square, Tribes), shareware and commercial programs. 32LiTE supports the majority of extenders (PMODE/W, EOS, CauseWay, DOS/32 Advanced, Zurenava DOS extender) as well as the original DOS4G/W extender. The latest versions of the WDOS/X extender should also work ok, but if you want to use it you should refer to the WDOS/X article. "LE" format supports zero based flat model. 32LiTE can compress every WATCOM "LE" file, unlike other packers. (i.e. UPX and XE are not able to handle 16-bit segments fixups). DJGPP2 "COFF" Executables DJGPP version 2 is the DOS version of the GNU C/C++ compiler. It's almost free, so there are a lot of DOS 32-bit programs made with it. Original stub, PMODEDJ and WDOS/X stubs are supported. "COFF" format supports nonzero based flat model. DOS32 version 3.00-3.03 and 3.50 Executables DOS32 is an old dos extender by Adam Seychell. Complete DOS32 package includes extender and OMF linker. But the latest version (3.50) was still beta and dated 07 Aug 1996, so it's really out of date now. But it has an original set of C like functions, and the format is supported by several compilers (eg. Pascal Pro). WDOS/X can handle DOS32 executables so it is also supported. Mind that DOS32 3.00-3.03 and 3.50 are not compatible, so you are not able to run old DOS32 executables with the latest version of the extender. DOS32 has an original compression which is worse than 32LiTE's. "DOS32" format supports both zero and nonzero based flat model. 32LiTE gives the best compression ratios for DOS32 executables. DPMI "PE" Executables "PE" format is the basic executable format for Win9x/NT, and there are lots of compilers and linkers which support it. So it's possible to create 32-bit MS-DOS executables in this format (like Virtual Pascal does). Since the extenders function set is not defined we assume DPMI. I.e. WDOS/X provides support for "PE" with DPMI function set. Mind that "PE" support is very limited, don't expect any exporting / importing stuff. "PE" format supports zero based flat model. PHARLAP "P3" Executables Another old dos extender. It was used for 3DS, ANIMATOR and FOXPRO. But nowadays it's completely forgotten. Nevertheless WATCOM C/C++ supports it, so we do too. "P3" format supports nonzero based flat model. Note that additional memory allocating in depacker is not supported for this format. So all your files will be compressed as if "-m" option is specified. 32LiTE gives the best compression rates for PHARLAP executables. TMT Pascal Executables TMT Pascal is another 32-bit Pascal compiler for DOS, OS/2, WIN95. TMT Pascal is available in commercial and free restricted version. The TMT executable format is just a variant of the DOS32 format, because it was originally derived from it. A number of stubs were developed to handle TMT executables, and PMODE, WDOS/X, PMODE/W and DOS4G/W (WSTUB) based stubs are supported. "TMT" format supports zero based flat model. WATCOM W32RUN Executables It's an internal format of WATCOM C/C++ executables (like BINW/wcc.exe, BINW/wpp.exe), at least I have never seen this format anywhere else. The main advantage of this format is that executables are able to be run under OS/2 as well as under DOS. So the executable is both an OS/2 and a DOS executable. "W32" format supports zero based flat model. Note that additional memory allocating in depacker is not supported for this format. So all your files will be compressed as if "-m" option is specified. 32LiTE gives the best compression rates for WATCOM W32RUN executables. WDOS/X Executables WDOS/X is a free DOS extender by Michael Tippach. "WDOS/X" format supports both zero and nonzero based flat model. It's very small, has original compression and it handles a variety of file formats besides original "MZ" which is supported by 32LiTE. So if you want to run your executable under WDOS/X extender you should use it's original format for the compression. 32LiTE gives the best compression rates for WDOS/X executables. --------------------------------------------------------------------------- 4. Usage guide. The general usage is 32LiTE [options] this means that you should always give the file name which you wish to compressed. Multiple filenames and wildcards are supported. Examples: * 32LiTE.exe 1.exe Simply compress "1.exe". * 32LiTE.exe *.exe Compress all "*.exe" files. * 32LiTE.exe 1.exe 2.exe Compress both "1.exe" and "2.exe". General options You can specify several options which will affect the compression procedure: "-8" and "-9" Force jumps or calls optimization limits. Optimization rearranges executable image data looking for calls and jumps to provide better compression rates. Examples: * 32LiTE.exe 1.exe /8:0 No calls optimization (calls optimization limit=0). * 32LiTE.exe 1.exe /9 No jumps optimization (jump optimization limit=0). * 32LiTE.exe 1.exe /9:0xFFFFFFFF Provide jumps optimization for the whole image (jumps optimization limit=0xFFFFFFFF) * 32LiTE.exe 1.exe /8:FFFFFFFFh Provide calls optimization for the whole image (calls optimization limit=0xFFFFFFFF) * 32LiTE.exe 1.exe /9:FFFFFFFF Provide jumps optimization for the whole image (jumps optimization limit=0xFFFFFFFF) * 32LiTE.exe 1.exe /8:3434 Provide calls optimization for the first 0x3434 bytes of image (calls optimization limit=0x3434) "-j" Force storing additional data required for unpacking (i.e. fixups), instead of packing it together with the executable image. Generally increases packed file size. Suitable only for nonzero based executable formats. "-m" Use depacker without memory allocation. The default depacker allocates some memory for the packed data, but this alternative depacker uses BSS space. Because we are not able to guess whether BSS space will be enough or not the alternative method is optional. "-o" Specify output name. If want 32LiTE to save your packed executable to a name different from the original you should use this option. Examples: * 32LiTE.exe 1.exe -o 2.exe * 32LiTE.exe oldname.exe -o newname.exe "-r" Remove overlay. Removing overlay data is not recommended, unless you're sure that it's garbage (eg. debugging info). "-s" Moving startup code. For "COFF" and "LE" executables, unlike the others, there's a possibility to put some startup data in a fixed place within the executable. This feature is default. But still it can cause incompatibilities with certain executables. Please, try this option first before sending a bug report. "-v" Verbose info. You can see some "secret" information about your executables and the packing process, which is unuseful until you're experiencing a problem. So if it looks like 32LiTE bug you can send me this info. "-wmz" Force WDOS/X "MZ" input format. WDOS/X uses "MZ" as one of supported formats. But 32LiTE is able to detect automatical just WDOS/X ver 0.95 and newer. So if you're sure that your file is WDOS/X "MZ", where WDOS/X's version is older, please, specify this switch for compression. Changing output file format 32LiTE gives you an opportunity of setting the output file format different from the original one. Nevertheless there's a restriction. It's impossible to pack executables in Zero Based format into Non Zero Based ones and vice versa. The most painless way of using it is packing "LE" as WDOS/X executables. Since WDOS/X provides a sufficient set of DPMI functions you'll save something on the difference in size of the stubs (since WDOS/X is the smallest DPMI compatible extender). Note that output file will be written without stub. So you are required to stub the correspondent extender to it. But don't expect your file to work properly. You've changed the extender, and extenders aren't compatible with each other. They provide different sets of services and even register start-up values are different. But still this option can be useful. Once I experienced a problem with WLINK -- it crashed linking certain files. It worked OK with DLINK but it didn't produce an output file in "LE" format. As I definitely needed an "LE" executable, I linked it with DLINK then compressed it with 32LiTE as "LE" output format. The following will help you to stub your file. Instead of you are to put the correct name of your packed file. "-coff" DJGPP package is available at http://www.delorie.com/djgpp/. To bind stub to the executable use the following directions: STUBIFY.EXE "-dos32" DOS32 extender ver 3.03 package is available at ftp://ftp.elf.stuba.sk/pub/pc/utilprog/dos32v33.zip. To bind stub to the executable use the following directions: copy /b dos32.exe + out.tmp del ren out.tmp DOS32 extender ver 3.50 package is available at ftp://ftp.hornet.org/pub/demos/code/pmode/dos32b35.zip. To bind stub to the executable use the following directions: copy /b dos32.exe + out.tmp del ren out.tmp "-le" There are a few extenders for this format -- lets name several of them: PMODE/W DOS extender package is available at ftp://ftp.elf.stuba.sk/pub/pc/utilprog/pmw133.zip. To bind stub to the executable use the following directions: PMWBIND.EXE /B WDOS/X DOS extender package is available at http://www.wuschel.demon.co.uk/. To bind stub to the executable use the following directions: STUBIT.EXE DOS/32A extender package is available at ftp://ftp.hornet.org/pub/demos/code/hardware/pmode/dos32a_5.zip. To bind stub to the executable use the following directions: SB.EXE -B Zurenava DOS extender (ZRDX) package is available at http://www.zrdx.da.ru/. To bind stub to the executable use the following directions: ZRXBIND.EXE -r "-p3" For binding you should have BIND386.EXE. Since I don't have it, I'm not able to help you. "-pe" WDOS/X DOS extender package is available at http://www.wuschel.demon.co.uk/. To bind stub to executable use the following directions: STUBIT.EXE "-tmt" TMT Pascal package is available at http://www.tmt.com/. To bind stub to the executable use the following directions: copy /b tmtstub.exe + out.tmp del ren out.tmp WDOS/X DOS extender package is available at http://www.wuschel.demon.co.uk/. To bind stub to the executable use the following directions: STUBIT.EXE "-w32" As it's an internal WATCOM C/C++ format binding tool is not available. "-wdx" & "-wdxmz" WDOS/X DOS extender package is available at http://www.wuschel.demon.co.uk/. To bind stub to the executable use the following directions: STUBIT.EXE --------------------------------------------------------------------------- 5. Known bug and limitations. These are some issues which require special support: Mortal Kombat II There's something wrong with MK2. If you compress mk2.exe after losing a match you'll see a dark screen instead of "Press F1 to continue". It's seems to be an incompatibility between MK2 and the original DOS/4GW Professional extender. To solve this problem you should rebind mk2.exe with DOS32 Advanced or compress it as WDOS/X output. --------------------------------------------------------------------------- 6. Tricks and Tips. There are some additional ways to improve compression ratios with 32LiTE: Use depacker without memory allocation. Since this compression mode is not available for all executables, but for the majority, try to use this switch first. If the compression is successful you'll get rid off a few bytes (depending on the output format). Change size of calls and jumps optimization area. 32LiTE tries to set the optimal values of jumps/calls optimization limit, the result is not always the real optimal ones. So if size really matters for you force this values by command line (i.e. set to zero, full code section size, or something between these two). It's recommended to force jumps optimization limit to calls limit or to zero. Remove overlay data. You should be an expert user to determine whether it's possible or not. But if you are sure that the overlay data is garbage (eg. debugging info) remove it. Use the WDOS/X output format (for WATCOM "LE" input). Use this smallest (about 8800 bytes long) extender which provides you with a sufficient set of DPMI functions. If you plan to use your application under control of WDOS/X it is not necessary to keep the original executable file format. For the formats different from "MZ" WDOS/X uses loaders in "MZ" format which just load your applications in its original format and mainly don't have any other features. Also this would help you to avoid the incompatibilities of WDOS/X's "LE" loader which is sometimes not able to load 32LiTE packed executables properly. This is WDOS/X's fault, it's not able to handle some "LE" features. --------------------------------------------------------------------------- 7. 32LiTE vs UPX There's another 32-bit executable compressor which is worth mentioning. It's UPX by Markus F.X.J. Oberhumer & Laszlo Molnar. In fact it is the only one besides 32LiTE which is a real 32-bit exepacker. Others (like PMWLITE, XE, VE) do not follow one significant (as I think) principle. They change the file format! The packed file is stored in a different format or as a loader in the original format + the packed data as an overlay. Thus restricts the output file to the specific DOS Extender or increases compressed file size by adding functions for loading packed overlays to the code. 32LiTE has the following advantages over UPX: * 32LiTE has a multiple formats support. This means that if your executable has a combined structure, there're several 32-bit formats in it (like WDOS/X "MZ" + TMT Pascal), 32LiTE will compress all of them. * For zero based formats 32LiTE has better fixups packing method. * 32LiTE supports several file formats (WDOS/X, DOS32, W32RUN, PHARLAP "P3") which are not supported by UPX. * 32LiTE has flexible calls/jumps optimisation. And last but not the least, the main UPX disadvantage is that for WATCOM "LE", TMT, "PE" formats the compressed file will have less free memory than the original one. It will have as much less free memory as the size of the packed data. It doesn't matter if the packed file is small, but if it is several MBs? But to be honest, UPX has one significant advantage over 32LiTE: generally it compresses better (especially big files). But Jibz ( a.k.a. Joergen Ibsen) promisses to improve aPLib. In Jibz we trust :) aPACK packs most simple DOS exe files much better than UPX. --------------------------------------------------------------------------- 8. Do you wanna write to me ? Please, read the following before bothering me with e-mails. "I found a bug !" A good reason for a mail, but don't send me any big file (greater than 50KB unpacked) without my permission. Mind that the best way is to send me an URL to the files. And are you really sure that it's 32LiTE's fault ? "Would you support "PE" or "NE" executables?" Never!!!! Note that 32LiTE is a 32-bit DOS executable compressor. Besides there's no need to create another Windows executable compressor. There's already a heap of them, even a couple based on aPLib. As for other formats I will not add support for them unless they are supported by a High Level Language compiler. You see, nobody uses assembler nowadays. There's no need to support a new format just to be able to pack a few files. --------------------------------------------------------------------------- 9. Greetings. The author is glad to thank the following people: Snoopy you're a hacker - sapiens:) Markus Oberhumer & Laszlo Molnar for creating UPX. Rustam Gadeyev, JauMing Tseng, Avery Lee for working on the same problem (32-bit executables packing). Michael Tippach for the smallest and free WDOS/X DOS extender. Sergey Belyakov for creating nice free Zurenava DOS extender & sharing its source code Nu-mEga for Soft-Ice. --------------------------------------------------------------------------- Products and company names mentioned may be the trademarks of their respective owners.