# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem              1.0
PortGroup               github 1.0
PortGroup               makefile 1.0

github.setup            hashcat hashcat 8.0.0 v
github.tarball_from     archive
revision                0

categories              security
platforms               {darwin >= 19}
license                 MIT
maintainers             @gaming-hacker {i0ntempest @i0ntempest} openmaintainer

description             World's fastest and most advanced password recovery utility.
long_description        hashcat is the world's fastest and most advanced \
                        password recovery utility, supporting CPUs, GPUs, and \
                        other hardware accelerators on Linux, Windows, and macOS, \
                        with facilities to enable distributed password cracking.

homepage                https://hashcat.net/hashcat/

checksums               ${distname}${extract.suffix} \
                        rmd160  ad227eaf8427f8ac680cd79739849c98d2597a58 \
                        sha256  6281721ef2bc57aed1ffa1a186aa39d01cee09899741cb58e027733a373c2ae3 \
                        size    24663871

supported_archs         arm64 x86_64
universal_variant       no
build.target            {}

# Upstream consumes CFLAGS but not CPPFLAGS. Prefer its event.h to libevent's.
configure.cppflags-prepend \
                        -Iinclude
configure.cflags-append {*}${configure.cppflags}
makefile.override-append \
                        MACOSX_DEPLOYMENT_TARGET

set python_branch       3.14
set python_version      [string map {. ""} ${python_branch}]
set perl_version        5.34
set clang_version       23

# These libraries are loaded at runtime, without their development headers.
depends_run-append      port:libiconv \
                        port:openssl3 \
                        port:xz \
                        port:zlib \
                        port:zstd \
                        port:python${python_version} \
                        port:py${python_version}-python-snappy \
                        port:py${python_version}-plyvel \
                        port:py${python_version}-cryptography \
                        port:py${python_version}-pycryptodome \
                        port:py${python_version}-protobuf3 \
                        port:py${python_version}-asn1 \
                        port:py${python_version}-asn1crypto \
                        port:perl${perl_version} \
                        port:p${perl_version}-dbd-sqlite

patchfiles-append       patch-makefile.diff \
                        patch-runtime-libraries.diff \
                        patch-bitwarden-plyvel.diff

post-patch {
    reinplace "s|@PREFIX@|${prefix}|g" \
        ${worksrcpath}/src/ext_iconv.c \
        ${worksrcpath}/src/ext_lzma.c \
        ${worksrcpath}/src/ext_zstd.c \
        ${worksrcpath}/src/ext_zlib.c \
        ${worksrcpath}/src/ext_openssl.c
    reinplace "s|#define DEFAULT_PYTHON \"python3\"|#define DEFAULT_PYTHON \"${prefix}/bin/python${python_branch}\"|" \
        ${worksrcpath}/src/bridges/bridge_python_generic_hash.c
    reinplace "1s|^#!.*|#!${prefix}/bin/python${python_branch}|" \
        {*}[glob ${worksrcpath}/tools/*hashcat.py ${worksrcpath}/Python/*.py]
    reinplace "1s|^#!.*|#!${prefix}/bin/perl${perl_version}|" \
        {*}[glob ${worksrcpath}/tools/*hashcat.pl]
}

set build_args          {SHARED=1 USE_SYSTEM_OPENCL=1 MAINTAINER_MODE=1 MACOS_UNIVERSAL_BINARY=0}
build.args-append       {*}${build_args}
destroot.args-append    {*}${build_args}

# Keep Intel builds usable on CPUs without AVX unless +native is selected.
if {${configure.build_arch} eq "x86_64"} {
    configure.cflags-append \
                        -mno-avx -mno-avx2 -mno-avx512f
}

variant native description {Optimize for the build machine's CPU} {
    build.args-replace  MAINTAINER_MODE=1 MAINTAINER_MODE=0
    destroot.args-replace \
                        MAINTAINER_MODE=1 MAINTAINER_MODE=0

    if {${configure.build_arch} eq "x86_64"} {
        configure.cflags-delete \
                        -mno-avx -mno-avx2 -mno-avx512f
        # Use the compiler's detected CPU features, not upstream's fixed -mavx2.
        set native_args {SIMD_NATIVE='$(MARCH_NATIVE)'}
    } elseif {${configure.build_arch} eq "arm64"} {
        set native_args {MCPU=native}
    } else {
        return -code error "+native supports only arm64 and x86_64"
    }
    build.args-append   {*}${native_args}
    destroot.args-append \
                        {*}${native_args}

    pre-build {
        if {(${configure.build_arch} eq "arm64" && ${os.arch} ne "arm")
            || (${configure.build_arch} eq "x86_64" && ${os.arch} ne "i386")} {
            return -code error "+native requires building for the host CPU architecture"
        }
    }
}

variant rust description {Build the Rust bridge plugins and random feed} {}
default_variants        +rust

if {[variant_isset rust]} {
    PortGroup           cargo_fetch 1.0

    # Bindgen needs libclang to generate the bridge ABI bindings.
    depends_build-append \
                        port:clang-${clang_version}
    patchfiles-append   patch-rust-build.diff
    build.args-append   RUST_CARGO=${cargo.bin} RUST_RUSTUP=false
    destroot.args-append \
                        RUST_CARGO=${cargo.bin} RUST_RUSTUP=false
    build.env-append    LIBCLANG_PATH=${prefix}/libexec/llvm-${clang_version}/lib
    destroot.env-append LIBCLANG_PATH=${prefix}/libexec/llvm-${clang_version}/lib
} else {
    # Avoid opportunistically building plugins with an undeclared toolchain.
    build.args-append   RUST_CARGO=false RUST_RUSTUP=false
    destroot.args-append \
                        RUST_CARGO=false RUST_RUSTUP=false
}

post-destroot {
    xinstall -d ${destroot}${prefix}/share/bash-completion/completions
    xinstall -m 0644 ${worksrcpath}/extra/tab_completion/${name}.sh \
        ${destroot}${prefix}/share/bash-completion/completions/${name}

    # bisq2hashcat.py imports this companion package from the script directory.
    xinstall -d ${destroot}${prefix}/share/${name}/tools/protobuf
    xinstall -m 0644 {*}[glob ${worksrcpath}/tools/protobuf/*.py] \
        ${destroot}${prefix}/share/${name}/tools/protobuf
    reinplace "s|from protobuf.wallet_pb2 import|import sys; sys.path.insert(0, '${prefix}/share/${name}/tools'); from protobuf.wallet_pb2 import|" \
        ${destroot}${prefix}/bin/bisq2hashcat.py
}

if {[variant_isset rust]} {
    # Crates from the Rust bridge and feed Cargo.lock files in hashcat v8.0.0.
    cargo.crates \
        aho-corasick               1.1.3          8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916 \
        base64                     0.22.1         72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6 \
        bcrypt                     0.17.1         abaf6da45c74385272ddf00e1ac074c7d8a6c1a1dda376902bd6a427522a8b2c \
        bindgen                    0.72.1         993776b509cfb49c750f11b8f07a46fa23e0a1386ffc01fb1e7d343efc387895 \
        bitflags                   2.9.2          6a65b545ab31d687cff52899d4890855fec459eb6afe0da6417b8a18da87aa29 \
        bitflags                   2.9.3          34efbcccd345379ca2868b2b2c9d3782e9cc58ba87bc7d79d5b53d9c9ae6f25d \
        block-buffer               0.10.4         3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71 \
        blowfish                   0.9.1          e412e2cd0f2b2d93e02543ceae7917b3c70331573df19ee046bcbc35e45e87d7 \
        byteorder                  1.5.0          1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b \
        cexpr                      0.6.0          6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766 \
        cfg-if                     1.0.1          9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268 \
        cfg-if                     1.0.3          2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9 \
        cipher                     0.4.4          773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad \
        clang-sys                  1.8.1          0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4 \
        cpufeatures                0.2.17         59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280 \
        crypto-common              0.1.6          1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3 \
        digest                     0.10.7         9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292 \
        either                     1.15.0         48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719 \
        equivalent                 1.0.2          877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f \
        generic-array              0.14.7         85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a \
        getrandom                  0.3.3          26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4 \
        glob                       0.3.3          0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280 \
        hashbrown                  0.17.1         ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a \
        hex                        0.4.3          7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70 \
        hmac                       0.12.1         6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e \
        indexmap                   2.14.0         d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9 \
        inout                      0.1.4          879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01 \
        itertools                  0.13.0         413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186 \
        keccak                     0.1.6          cb26cec98cce3a3d96cbb7bced3c4b16e3d13f27ec56dbd62cbc8f39cfb9d653 \
        libc                       0.2.175        6a82ae493e598baaea5209805c49bbf2ea7de956d50d7da0da1164f9c6d28543 \
        libloading                 0.8.8          07033963ba89ebaf1584d767badaa2e8fcec21aedea6b8c0346d487d49c28667 \
        log                        0.4.27         13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94 \
        md-5                       0.10.6         d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf \
        md2                        0.10.2         1f4f0f3ed25ff4f8d8d102288d92f900efc202661c884cf67dfe4f0d07c43d1f \
        md4                        0.10.2         7da5ac363534dce5fabf69949225e174fbf111a498bf0ff794c8ea1fba9f3dda \
        memchr                     2.7.5          32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0 \
        minimal-lexical            0.2.1          68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a \
        nom                        7.1.3          d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a \
        pbkdf2                     0.12.2         f8ed6a7761f76e3b9f92dfb0a60a6a6477c61024b775147ff0973a02653abaf2 \
        prettyplease               0.2.37         479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b \
        proc-macro2                1.0.101        89ae43fd86e4158d6db51ad8e2b80f313af9cc74f5c0e03ccb87de09998732de \
        proc-macro2                1.0.107        985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9 \
        quote                      1.0.40         1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d \
        quote                      1.0.47         1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001 \
        r-efi                      5.3.0          69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f \
        regex                      1.11.1         b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191 \
        regex                      1.11.2         23d7fd106d8c02486a8d64e778353d1cffe08ce79ac2e82f540c86d0facf6912 \
        regex-automata             0.4.10         6b9458fa0bfeeac22b5ca447c63aaf45f28439a709ccd244698632f9aa6394d6 \
        regex-automata             0.4.9          809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908 \
        regex-syntax               0.8.5          2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c \
        regex-syntax               0.8.6          caf4aa5b0f434c91fe5c7f1ecb6a5ece2130b02ad2a590589dda5146df959001 \
        rustc-hash                 2.1.1          357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d \
        serde_core                 1.0.229        67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48 \
        serde_derive               1.0.229        e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348 \
        serde_spanned              1.1.1          6662b5879511e06e8999a8a235d848113e942c9124f211511b16466ee2995f26 \
        sha1                       0.10.6         e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba \
        sha2                       0.10.9         a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283 \
        sha3                       0.10.8         75872d278a8f37ef87fa0ddbda7802605cb18344497949862c0d4dcb291eba60 \
        shlex                      1.3.0          0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64 \
        subtle                     2.6.1          13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292 \
        syn                        2.0.106        ede7c438028d4436d71104916910f5bb611972c5cfd7f89b8300a8186e6fada6 \
        syn                        3.0.3          53e9bae58849f64dfa4f5d5ae372c8341f7305f82a3868709269343628b659a3 \
        thread_local               1.1.9          f60246a4944f24f6e018aa17cdeffb7818b76356965d03b07d6a9886e8962185 \
        toml                       1.1.4+spec-1.1.0 3aace63f4bbcdfc2c965b059de67119c89c4017a70d633be6c104910f67056f5 \
        toml_datetime              1.1.1+spec-1.1.0 3165f65f62e28e0115a00b2ebdd37eb6f3b641855f9d636d3cd4103767159ad7 \
        toml_parser                1.1.3+spec-1.1.0 1d38ac1cf9b95face32296c0a3ede1fdc270627c9d9c02a7274dd6d960dc4d56 \
        toml_writer                1.1.2+spec-1.1.0 7d56353a2a665ad0f41a421187180aab746c8c325620617ad883a99a1cbe66d2 \
        typenum                    1.18.0         1dccffe3ce07af9386bfd29e80c0ab1a8205a2fc34e4bcd40364df902cfa8f3f \
        unicode-ident              1.0.18         5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512 \
        unicode-ident              1.0.24         e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75 \
        version_check              0.9.5          0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a \
        wasi                       0.14.2+wasi-0.2.4 9683f9a5a998d873c0d21fcbe3c083009670149a8fab228644b8bd36b2c48cb3 \
        windows-link               0.1.3          5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a \
        windows-targets            0.53.3         d5fe6031c4041849d7c496a8ded650796e7b6ecc19df1a431c1a363342e5dc91 \
        windows_aarch64_gnullvm    0.53.0         86b8d5f90ddd19cb4a147a5fa63ca848db3df085e25fee3cc10b39b6eebae764 \
        windows_aarch64_msvc       0.53.0         c7651a1f62a11b8cbd5e0d42526e55f2c99886c77e007179efff86c2b137e66c \
        windows_i686_gnu           0.53.0         c1dc67659d35f387f5f6c479dc4e28f1d4bb90ddd1a5d3da2e5d97b42d6272c3 \
        windows_i686_gnullvm       0.53.0         9ce6ccbdedbf6d6354471319e781c0dfef054c81fbc7cf83f338a4296c0cae11 \
        windows_i686_msvc          0.53.0         581fee95406bb13382d2f65cd4a908ca7b1e4c2f1917f143ba16efe98a589b5d \
        windows_x86_64_gnu         0.53.0         2e55b5ac9ea33f2fc1716d1742db15574fd6fc8dadc51caab1c16a3d3b4190ba \
        windows_x86_64_gnullvm     0.53.0         0a6e035dd0599267ce1ee132e51c27dd29437f63325753051e71dd9e42406c57 \
        windows_x86_64_msvc        0.53.0         271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486 \
        winnow                     1.0.4          23b97319f7b8343df12cc98938e5c3eb436064524c8d2b4e30a1d3a36eecdf81 \
        winresource                0.1.31         0986a8b1d586b7d3e4fe3d9ea39fb451ae22869dcea4aa109d287a374d866087 \
        wit-bindgen-rt             0.39.0         6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1 \
        zeroize                    1.8.1          ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde
}
