// Detect It Easy: detection rule file
// Author: LinXP
// Rewritten by BJNFNE

// https://github.com/libyal/assorted/blob/main/documentation/Windows%20Imaging%20%28WIM%29%20file%20format.asciidoc
meta("archive", "Windows Imaging Format (.WIM)");

function detect() {
    if (Binary.getSize() >= 9) {

        if (Binary.compare("'MSWIM'000000")) {
            if (Binary.isVerbose()) sOptions = "{" + Binary.read_UUID(0x18) + "}";
            bDetected = true;

            switch (Binary.read_uint16(0x12)) {
                case 0: sOption("No compression"); break;
                case 2: sOption("XPRESS compression"); break;
                case 4: sOption("LZX compression"); break;
                case 8: sOption("LZMS compression"); break;
                default: bDetected = false;
            }
            sOption("Part Number:" + Binary.read_uint16(0x28) + "/" + Binary.read_uint16(0x2A));

        } else if (Binary.compare("'WLPWM'000000")) { // https://wimlib.net/
            sName += ", wimlib";
            bDetected = true;
        }

    }

    return result();
}