# $Id: Portfile 72624 2010-10-21 12:55:00Z michaelld@macports.org $

PortSystem          1.0

name                ophcrack
version             3.3.1
revision            2
categories          security
maintainers         gmail.com:cedric.luthi
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            http://ophcrack.sourceforge.net
platforms           darwin
master_sites        sourceforge

use_bzip2           yes
checksums           ${distname}${extract.suffix} md5 740eef54e9082f26851e15c1cb4ef55c \
                    ${distname}${extract.suffix} sha1 65982407f0b7738940d5444530492ce1d81899f9 \
                    ${distname}${extract.suffix} rmd160 3a4562e861eb90030c68b067a02cc41271ee8c66

configure.args      --disable-gui --disable-graph

set hasMoreThan512MBofRAM [expr [gets [open "|sysctl -n 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"
    }
}

pre-build {
    if {[variant_isset tables]} {
        reinplace "s|QString()|QString(\"${prefix}/share/${name}/tables\")|g" ${worksrcpath}/src/gui/tabledialog.cpp
    }
}

destroot {
    if {[variant_isset gui]} {
        xinstall -m 755 -d ${destroot}${applications_dir}
        copy ${worksrcpath}/src/${name}.app ${destroot}${applications_dir}
    } else {
        xinstall -m 755 -d ${destroot}${prefix}/bin
        copy ${worksrcpath}/src/${name} ${destroot}${prefix}/bin
    }
}

post-activate {
    if {[variant_isset tables]} {
        ui_msg "****************************************************"
        ui_msg ""
        ui_msg "  Free rainbow tables have been installed into"
        ui_msg "  ${prefix}/share/${name}/tables"
        ui_msg ""
        ui_msg "  Visit http://ophcrack.sourceforge.net/tables.php"
        ui_msg "  to get more (non-free) rainbow tables."
        ui_msg ""
        ui_msg "****************************************************"
    }
}

variant gui description {Builds the GUI version instead of the CLI version, requires the qt4-mac port} {
    PortGroup qt4 1.0
    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)} {
    if ${hasMoreThan512MBofRAM} {
        distfiles-append tables_xp_free_fast.zip
        checksums-append tables_xp_free_fast.zip sha1 141b8be045055068e8bae6542d484fffdd452641
    } else {
        distfiles-append tables_xp_free_small.zip
        checksums-append tables_xp_free_small.zip sha1 2933bc9e483f79966ee02569d3d91b4d0ecc5a8d
    }
    
    distfiles-append tables_vista_free.zip
    checksums-append tables_vista_free.zip sha1 31425c6b35679df53ba67cb1cc3807501eec3ced
    
    extract.only ${distname}${extract.suffix}
}

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