// DIE's signature file
// Author: Jason Hood <jadoxa@yahoo.com.au>

includeScript("cab");

function cab_resource(bShowOptions) {
    for (var i = 0; i < PE.resource.length; i++) {
        if (detect_Cab(PE.resource[i].Offset, PE.resource[i].Size, bShowOptions)) {
            return 1;
        }
    }
    return 0;
}

function detect(bShowType, bShowVersion, bShowOptions) {
    if (!detect_Cab(PE.getOverlayOffset(), PE.getOverlaySize(), bShowOptions) &&
        !cab_resource(bShowOptions)) {
        if (PE.section[".rsrc"]) {
            var nFileSize = PE.section[".rsrc"].FileSize;
            var nVirtSize = PE.section[".rsrc"].VirtualSize;
            if (nFileSize > nVirtSize) {
                var nOffset = PE.section[".rsrc"].FileOffset + nVirtSize;
                nOffset = (nOffset + 0x1ff) & -0x200;
                while ((!detect_Cab(nOffset, nFileSize, bShowOptions)) &&
                    (nOffset > PE.section[".rsrc"].FileOffset) && (!_isStop())) {
                    nOffset -= 0x200;
                }
            }
        }
    }

    return result(bShowType, bShowVersion, bShowOptions);
}