// Detect It Easy: detection rule file
// Author: LinXP

// https://github.com/inikep/lizard/blob/lizard/doc/lizard_Frame_format.md
meta("archive");

function detect() {
    if (Binary.getSize() >= 9) {
        bDetected = true;
        switch (Binary.read_uint32(0x00, _BE)) {
            case 0x02214C18: sName = "LZ4 compressed data, legacy (.LZ4)"; break;
            case 0x04224D18: sName = "LZ4 compressed data (.LZ4)"; break;
            case 0x05224D18: sName = "LZ5 compressed data (.LZ5)"; break;
            case 0x06224D18: sName = "Lizard compressed data (.LIZ)"; break;
            default: bDetected = false;
        }

        if (bDetected) {
            var bFlags = Binary.read_uint8(0x04);
            if (bFlags & 64) { sVersion = "1.0"; }
            if (bFlags & 128) { sVersion = "2.0"; }
            if (bFlags & 64 && bFlags & 128) { sVersion = "3.0"; }
            if (Binary.isVerbose()) {
                if (bFlags & 1) { sOption("PresetDictionary"); }
                if (bFlags & 4) { sOption("ContentChecksum"); }
                if (bFlags & 8) { sOption("ContentSize"); }
                if (bFlags & 16) { sOption("BlockChecksum"); }
                if (bFlags & 32) { sOption("BlockIndependence"); }
            }
        }
    }

    return result();
}