// Author: DosX
// E-Mail: collab@kay-software.ru
// GitHub: https://github.com/DosX-dev
// Telegram: @DosX_dev

// https://github.com/DosX-dev/UPX-Patcher
init("tool", "UPX-Patcher");

function detect(bShowType, bShowVersion, bShowOptions) {
    if (PE.section[0].Name === ".dosx" &&
        PE.section[".fish"]) {
        bDetected = true;

        var is64 = PE.is64();

        if (!PE.isDll()) {
            if (PE.compareEP(is64 ?
                    "53" : // push rbx (x64)
                    "55" // push ebp (x86)
                ))
                sOptions = (is64 ? "x64" : "x86") + " mode"; // Custom EP
            else
                bDetected = false;

        }
    }

    return result(bShowType, bShowVersion, bShowOptions);
}