PortSystem          1.0

name                ophcrack
version             3.8.0
revision            1
categories          security
license             {GPL-2+ OpenSSLException}
maintainers         nomaintainer
description         Microsoft Windows password cracker
long_description    Ophcrack is a free Windows password cracker based on \
                    rainbow tables. It is a very efficient implementation \
                    of rainbow tables done by the inventors of the method.

homepage            https://ophcrack.sourceforge.io
platforms           darwin
master_sites        sourceforge:project/${name}/${name}/${version}

use_bzip2           yes

checksums           ${distname}${extract.suffix} md5 d4449e15f65b1f0f82abfd963ceff452 \
                    ${distname}${extract.suffix} sha1 5dea7466f17ab2d50e1c8e5533f0dc66c36a4fc0 \
                    ${distname}${extract.suffix} rmd160 ed635704144b5d2613615a4c7e9d720680a281bc \
                    ${distname}${extract.suffix} sha256 048a6df57983a3a5a31ac7c4ec12df16aa49e652a29676d93d4ef959d50aeee0

depends_lib         port:expat \
                    port:openssl

configure.args      --disable-gui \
                    --with-libexpat=${prefix} \
                    --with-libssl=${prefix}

set hasMoreThan512MBofRAM 0
catch {set hasMoreThan512MBofRAM [expr [sysctl hw.memsize] >= 536870912]}

post-extract {
    if {[variant_isset tables]} {
        set tables_dir ${destroot}${prefix}/share/${name}/tables

        if {${hasMoreThan512MBofRAM}} {
            xinstall -m 755 -d ${tables_dir}/xp_free_fast
            system "unzip ${distpath}/tables_xp_free_fast.zip -d ${tables_dir}/xp_free_fast"
        } else {
            xinstall -m 755 -d ${tables_dir}/xp_free_small
            system "unzip ${distpath}/tables_xp_free_small.zip -d ${tables_dir}/xp_free_small"
        }

        xinstall -m 755 -d ${tables_dir}/vista_free
        system "unzip ${distpath}/tables_vista_free.zip -d ${tables_dir}/vista_free"
    }
}

destroot {
    if {[variant_isset gui]} {
        xinstall -d ${destroot}${applications_dir}
        copy ${worksrcpath}/src/${name}.app ${destroot}${applications_dir}
    } else {
        xinstall -d ${destroot}${prefix}/bin
        xinstall ${worksrcpath}/src/${name} ${destroot}${prefix}/bin
    }
    xinstall -d ${destroot}${prefix}/share/doc/${name}
    xinstall -W ${worksrcpath} -m 644 AUTHORS COPYING ChangeLog LICENSE \
        README.md ${destroot}${prefix}/share/doc/${name}
}

notes "
  Visit https://ophcrack.sourceforge.io/tables.php
  to get rainbow tables."

variant gui description {Builds the GUI version instead of the CLI version, requires Qt 5 port} {
    PortGroup qt5 1.0
    qt5.depends_component   qtcharts
    configure.args-delete --disable-gui
    configure.args-append --with-libqt4=${qt_dir}
}

variant tables description {Installs the free rainbow tables for Windows XP and Vista (700+ MB)} {
    master_sites-append sourceforge:project/${name}/tables/XP%20free:xptables
    if {$hasMoreThan512MBofRAM} {
        distfiles-append tables_xp_free_fast.zip:xptables
        checksums-append tables_xp_free_fast.zip sha1 141b8be045055068e8bae6542d484fffdd452641
    } else {
        distfiles-append tables_xp_free_small.zip:xptables
        checksums-append tables_xp_free_small.zip sha1 2933bc9e483f79966ee02569d3d91b4d0ecc5a8d
    }

    master_sites-append sourceforge:project/${name}/tables/Vista%20free:vistatables
    distfiles-append tables_vista_free.zip:vistatables
    checksums-append tables_vista_free.zip sha1 31425c6b35679df53ba67cb1cc3807501eec3ced

    extract.only ${distname}${extract.suffix}

    patchfiles-append patch-src-gui-tabledialog.cpp.diff

    post-patch {
        reinplace "s|@TABLES_DIR@|${prefix}/share/${name}/tables|g" ${worksrcpath}/src/gui/tabledialog.cpp
    }

    notes-append "
  Free rainbow tables are installed into
  ${prefix}/share/${name}/tables"
}

livecheck.type  regex
livecheck.url   ${homepage}/download.php?type=ophcrack
livecheck.regex The latest version of ophcrack is (\\d(\\.\\d+)*)