xmake.lua 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. package("hashcat")
  2. set_homepage("https://hashcat.net/hashcat/")
  3. set_description("World's fastest and most advanced password recovery utility.")
  4. set_license("MIT")
  5. set_urls("https://github.com/hashcat/hashcat/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/hashcat/hashcat.git")
  7. add_versions("v7.1.2", "9546a6326d747530b44fcc079babad40304a87f32d3c9080016d58b39cfc8b96")
  8. -- if shared=false is specified, the library will not be built.
  9. add_configs("shared", {description = "Build shared library.", default = true, type = "boolean", readonly = true})
  10. add_configs("frontend", {description = "Build the hashcat frontend executable.", default = true, type = "boolean"})
  11. add_configs("bridge", {description = "Build the cross-language bridges.", default = false, type = "boolean"})
  12. if is_plat("linux") then
  13. add_syslinks("pthread", "dl", "rt", "m")
  14. elseif is_plat("bsd") then
  15. add_syslinks("pthread", "m")
  16. elseif is_plat("macosx") then
  17. add_syslinks("pthread", "IOReport")
  18. add_frameworks("CoreFoundation", "CoreGraphics", "Foundation", "IOKit", "Metal")
  19. elseif is_plat("cygwin") then
  20. add_syslinks("psapi")
  21. elseif is_plat("msys") then
  22. add_syslinks("psapi", "ws2_32", "powrprof")
  23. end
  24. add_deps("python >=3.12")
  25. add_deps("lzma", "zlib", "opencl-headers", "xxhash", "minizip", "libiconv")
  26. on_load(function (package)
  27. package:add("includedirs", "include", "include/OpenCL")
  28. end)
  29. -- unsupported mingw on macosx: gendef tool is missing.
  30. on_install("linux", "bsd", "macosx", "msys", "mingw@windows,linux", "cygwin", function (package)
  31. import("package.tools.make")
  32. local configs = {
  33. "PRODUCTION=1",
  34. "USE_SYSTEM_LZMA=1",
  35. "USE_SYSTEM_ZLIB=1",
  36. "USE_SYSTEM_OPENCL=1",
  37. "USE_SYSTEM_XXHASH=1"
  38. }
  39. table.insert(configs, "DEBUG=" .. (package:is_debug() and "1" or "0"))
  40. table.insert(configs, "SHARED=" .. (package:config("shared") and "1" or "0"))
  41. table.insert(configs, "PREFIX=" .. package:installdir():gsub("\\", "/"))
  42. local envs = make.buildenvs(package)
  43. local cflags = {}
  44. local ldflags = {}
  45. for _, dep in ipairs(package:orderdeps()) do
  46. local fetchinfo = dep:fetch()
  47. if fetchinfo then
  48. for _, includedir in ipairs(fetchinfo.includedirs or fetchinfo.sysincludedirs) do
  49. table.insert(cflags, "-I" .. includedir)
  50. end
  51. for _, linkdir in ipairs(fetchinfo.linkdirs) do
  52. table.insert(ldflags, "-L" .. linkdir)
  53. end
  54. end
  55. end
  56. table.insert(ldflags, "-liconv")
  57. envs.CFLAGS = envs.CFLAGS .. " " .. table.concat(cflags, " ")
  58. envs.LDFLAGS = envs.LDFLAGS .. " " .. table.concat(ldflags, " ")
  59. if not package:config("frontend") then
  60. io.replace("src/Makefile", "default: $(HASHCAT_FRONTEND)", "default: $(HASHCAT_LIBRARY)", {plain = true})
  61. io.replace("src/Makefile", "install_bridges install_hashcat", "install_bridges", {plain = true})
  62. end
  63. io.replace("src/Makefile", "-llzmasdk", "-llzma", {plain = true})
  64. io.replace("src/Makefile", "install: install_docs", "install: ", {plain = true})
  65. io.replace("src/Makefile", ".$(VERSION_PURE)", "", {plain = true})
  66. if package:is_plat("macosx") and not package:is_arch("x86_64") then
  67. io.replace("src/Makefile", "CFLAGS_NATIVE += -arch x86_64", "", {plain = true})
  68. io.replace("src/Makefile", "LFLAGS_NATIVE += -arch x86_64", "", {plain = true})
  69. end
  70. if not package:config("bridge") then
  71. io.replace("src/Makefile", "modules bridges", "modules", {plain = true})
  72. io.replace("src/Makefile", "modules_linux bridges_linux", "modules_linux", {plain = true})
  73. io.replace("src/Makefile", "modules_win bridges_win", "modules_win", {plain = true})
  74. io.replace("src/Makefile", "install_modules install_bridges", "install_modules", {plain = true})
  75. io.replace("src/Makefile", "include $(wildcard src/bridges/bridge_*.mk)", "", {plain = true})
  76. end
  77. -- sometimes hashcat will misjudge the platform.
  78. if package:is_plat("msys", "mingw") then
  79. table.insert(configs, "UNAME=MSYS2")
  80. table.insert(configs, "CC=" .. package:build_getenv("cc"))
  81. table.insert(configs, "CXX=" .. package:build_getenv("cxx"))
  82. table.insert(configs, "AR=" .. package:build_getenv("ar"))
  83. end
  84. make.build(package, configs, {envs = envs})
  85. if package:is_plat("msys", "mingw", "cygwin") then
  86. -- enable installation in msys, since we defined PREFIX.
  87. io.replace("src/Makefile", "$(error $(ERROR_INSTALL_DISALLOWED))", "", {plain = true})
  88. end
  89. table.insert(configs, "install")
  90. make.make(package, configs, {envs = envs})
  91. os.cp("OpenCL", package:installdir("include"))
  92. -- fix hashcat import library on msys.
  93. if package:is_plat("msys", "mingw", "cygwin") then
  94. os.cd(package:installdir("lib"))
  95. os.vrun("gendef hashcat.dll")
  96. os.vrun("dlltool -d hashcat.def -l libhashcat.a -D hashcat.dll")
  97. os.mv("hashcat.dll", "../bin")
  98. end
  99. end)
  100. on_test(function (package)
  101. if package:config("frontend") then
  102. local prefix = is_host("windows") and ".exe" or ""
  103. assert(os.isexec(package:installdir("bin/hashcat" .. prefix)), "hashcat executable not found!")
  104. end
  105. assert(package:has_cfuncs("hashcat_init", {includes = {"hashcat/types.h", "hashcat/hashcat.h"}}))
  106. end)