Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unclarity about usage of LZ functions

Note: this question is about the Windows LZ functions, which are File Management Functions beginning with the prefix LZ: LZOpenFile, LZCopy, LZClose, etc. If Google isn't wrong, these are probably among the most poorly documented functions of the Windows API.

I'm trying to figure out what kind of files are actually suited for usage with the Windows LZ functions. The official documentation mentions "data that was compressed using Compress.exe", but the functions are also able to handle uncompressed files, in which case no decompression is applied.

Now, when I compress a file with the compress.exe utility from the resource kit (using either the -Z or -ZX switches), and then decompress it using the procedure described here, all I get is the source file unchanged, as if it were not compressed as expected. Even with a compressed file from the original Windows XP setup CD (those named with an underscore at the end in the i386 folder), I get the same result. Conclusion: no matter what file I try to decompress, I get it back unchanged.

The code I'm using is pretty straightforward, it basically reproduces the steps described in the MSDN article, so if I have a bug, I guess it must be somewhere else. But I'm still prone to thinking I'm just using the wrong input files. Does anyone have any experience with those LZ functions already? Here's my code in C++.

#include <iostream>
#include <Windows.h>

using namespace std;

int main(int argc, char ** argv) {
    OFSTRUCT ofs1, ofs2;
    INT hfSrc = -1, hfDest = -1;

    if (argc <= 2) {
        cerr << "Usage: LZTEST Source Destination";
        return 1;
    }
    __try {
        hfSrc = LZOpenFile(argv[1], &ofs1, OF_READ);
        if (hfSrc < 0) {
            cerr << "Error invoking LZOpenFile on source file: " << hfSrc;
            return 1;
        }
        hfDest = LZOpenFile(argv[2], &ofs2, OF_CREATE);
        if (hfDest < 0) {
            cerr << "Error invoking LZOpenFile on destination file: " << hfDest;
            return 1;
        }
        INT result = LZCopy(hfSrc, hfDest);
        if (result < 0) {
            cerr << "Error invoking LZCopy: " << result;
            return 1;
        }
    } __finally {
        if (hfSrc >= 0) LZClose(hfSrc);
        if (hfDest >= 0) LZClose(hfDest);
    }
    cout << "Success";
    return 0;
}
like image 844
GOTO 0 Avatar asked Dec 25 '12 18:12

GOTO 0


2 Answers

Try the compress.exe here with no options.

Unless you need to uncompress some old files, use DotNetZip instead.

like image 190
Mark Adler Avatar answered Oct 01 '22 00:10

Mark Adler


I'm trying to figure out what kind of files are actually suited for usage with the Windows LZ functions.

The types of files you would typically use this on were your installation files that you were distributing on floppy disks. Back in the day, most of Microsoft's products were installed from floppy disks, and most of the files were compressed to save on the number of disks that had to be distributed for each customer.

You could generally tell what files were compressed on the floppy disks because the last letter of the extension was usually an underscore:

KEYBOARD.DR_
KEYVIEW.EX_
LANGDUT.DL_
LANGENG.DL_
LANGFRN.DL_
LANGGER.DL_
LANGSCA.DL_
LANGSPA.DL_
LMOUSE.CO_
LMOUSE.DR_
LVMD.38_
LZEXPAND.DL_
MMSOUND.DR_
MOUSE.DR_
MSC3BC2.DR_
MSCMOUSE.DR_

You could uncompress them using the EXPAND.EXE or the functions you reference.

like image 42
GalacticJello Avatar answered Sep 30 '22 22:09

GalacticJello