set(PROJECT_NAME mimikatz)

################################################################################
# Source groups
################################################################################
set(no_group_source_files
    "mimikatz.c"
    "mimikatz.h"
    "mimikatz.ico"
)
source_group("" FILES ${no_group_source_files})

set(common_modules
    "../modules/kull_m_acr.c"
    "../modules/kull_m_acr.h"
    "../modules/kull_m_asn1.c"
    "../modules/kull_m_asn1.h"
    "../modules/kull_m_busylight.c"
    "../modules/kull_m_busylight.h"
    "../modules/kull_m_cabinet.c"
    "../modules/kull_m_cabinet.h"
    "../modules/kull_m_cred.c"
    "../modules/kull_m_cred.h"
    "../modules/kull_m_crypto.c"
    "../modules/kull_m_crypto.h"
    "../modules/kull_m_crypto_ngc.c"
    "../modules/kull_m_crypto_ngc.h"
    "../modules/kull_m_crypto_remote.c"
    "../modules/kull_m_crypto_remote.h"
    "../modules/kull_m_crypto_sk.c"
    "../modules/kull_m_crypto_sk.h"
    "../modules/kull_m_crypto_system.h"
    "../modules/kull_m_dpapi.c"
    "../modules/kull_m_dpapi.h"
    "../modules/kull_m_file.c"
    "../modules/kull_m_file.h"
    "../modules/kull_m_handle.c"
    "../modules/kull_m_handle.h"
    "../modules/kull_m_hid.c"
    "../modules/kull_m_hid.h"
    "../modules/kull_m_kernel.c"
    "../modules/kull_m_kernel.h"
    "../modules/kull_m_key.c"
    "../modules/kull_m_key.h"
    "../modules/kull_m_ldap.c"
    "../modules/kull_m_ldap.h"
    "../modules/kull_m_memory.c"
    "../modules/kull_m_memory.h"
    "../modules/kull_m_mifare.h"
    "../modules/kull_m_minidump.c"
    "../modules/kull_m_minidump.h"
    "../modules/kull_m_net.c"
    "../modules/kull_m_net.h"
    "../modules/kull_m_output.c"
    "../modules/kull_m_output.h"
    "../modules/kull_m_patch.c"
    "../modules/kull_m_patch.h"
    "../modules/kull_m_pipe.c"
    "../modules/kull_m_pipe.h"
    "../modules/kull_m_pn532.c"
    "../modules/kull_m_pn532.h"
    "../modules/kull_m_process.c"
    "../modules/kull_m_process.h"
    "../modules/kull_m_rdm.c"
    "../modules/kull_m_rdm.h"
    "../modules/kull_m_registry.c"
    "../modules/kull_m_registry.h"
    "../modules/kull_m_registry_structures.h"
    "../modules/kull_m_remotelib.c"
    "../modules/kull_m_remotelib.h"
    "../modules/kull_m_samlib.h"
    "../modules/kull_m_service.c"
    "../modules/kull_m_service.h"
    "../modules/kull_m_sr98.c"
    "../modules/kull_m_sr98.h"
    "../modules/kull_m_string.c"
    "../modules/kull_m_string.h"
    "../modules/kull_m_token.c"
    "../modules/kull_m_token.h"
    "../modules/kull_m_xml.c"
    "../modules/kull_m_xml.h"
    "../modules/sqlite3.c"
    "../modules/sqlite3.h"
)
source_group("common modules" FILES ${common_modules})

set(common_modules__rpc
    "../modules/rpc/kull_m_rpc.c"
    "../modules/rpc/kull_m_rpc.h"
    "../modules/rpc/kull_m_rpc_bkrp.c"
    "../modules/rpc/kull_m_rpc_bkrp.h"
    "../modules/rpc/kull_m_rpc_dpapi-entries.c"
    "../modules/rpc/kull_m_rpc_dpapi-entries.h"
    "../modules/rpc/kull_m_rpc_drsr.c"
    "../modules/rpc/kull_m_rpc_drsr.h"
    "../modules/rpc/kull_m_rpc_mimicom.c"
    "../modules/rpc/kull_m_rpc_mimicom.h"
    "../modules/rpc/kull_m_rpc_ms-bkrp.h"
    "../modules/rpc/kull_m_rpc_ms-bkrp_c.c"
    "../modules/rpc/kull_m_rpc_ms-claims.c"
    "../modules/rpc/kull_m_rpc_ms-claims.h"
    "../modules/rpc/kull_m_rpc_ms-credentialkeys.c"
    "../modules/rpc/kull_m_rpc_ms-credentialkeys.h"
    "../modules/rpc/kull_m_rpc_ms-dcom_IObjectExporter.h"
    "../modules/rpc/kull_m_rpc_ms-dcom_IObjectExporter_c.c"
    "../modules/rpc/kull_m_rpc_ms-drsr.h"
    "../modules/rpc/kull_m_rpc_ms-drsr_c.c"
    "../modules/rpc/kull_m_rpc_ms-efsr.h"
    "../modules/rpc/kull_m_rpc_ms-efsr_c.c"
    "../modules/rpc/kull_m_rpc_ms-nrpc.h"
    "../modules/rpc/kull_m_rpc_ms-nrpc_c.c"
    "../modules/rpc/kull_m_rpc_ms-odj.c"
    "../modules/rpc/kull_m_rpc_ms-odj.h"
    "../modules/rpc/kull_m_rpc_ms-pac.c"
    "../modules/rpc/kull_m_rpc_ms-pac.h"
    "../modules/rpc/kull_m_rpc_ms-par.h"
    "../modules/rpc/kull_m_rpc_ms-par_c.c"
    "../modules/rpc/kull_m_rpc_ms-rprn.c"
    "../modules/rpc/kull_m_rpc_ms-rprn.h"
)
source_group("common modules\\rpc" FILES ${common_modules__rpc})

set(local_modules
    "modules/kuhl_m.h"
    "modules/kuhl_m_acr.c"
    "modules/kuhl_m_acr.h"
    "modules/kuhl_m_busylight.c"
    "modules/kuhl_m_busylight.h"
    "modules/kuhl_m_crypto.c"
    "modules/kuhl_m_crypto.h"
    "modules/kuhl_m_event.c"
    "modules/kuhl_m_event.h"
    "modules/kuhl_m_iis.c"
    "modules/kuhl_m_iis.h"
    "modules/kuhl_m_kernel.c"
    "modules/kuhl_m_kernel.h"
    "modules/kuhl_m_lsadump.c"
    "modules/kuhl_m_lsadump.h"
    "modules/kuhl_m_lsadump_remote.c"
    "modules/kuhl_m_lsadump_remote.h"
    "modules/kuhl_m_minesweeper.c"
    "modules/kuhl_m_minesweeper.h"
    "modules/kuhl_m_misc.c"
    "modules/kuhl_m_misc.h"
    "modules/kuhl_m_net.c"
    "modules/kuhl_m_net.h"
    "modules/kuhl_m_privilege.c"
    "modules/kuhl_m_privilege.h"
    "modules/kuhl_m_process.c"
    "modules/kuhl_m_process.h"
    "modules/kuhl_m_rdm.c"
    "modules/kuhl_m_rdm.h"
    "modules/kuhl_m_rpc.c"
    "modules/kuhl_m_rpc.h"
    "modules/kuhl_m_service.c"
    "modules/kuhl_m_service.h"
    "modules/kuhl_m_service_remote.c"
    "modules/kuhl_m_service_remote.h"
    "modules/kuhl_m_sid.c"
    "modules/kuhl_m_sid.h"
    "modules/kuhl_m_sr98.c"
    "modules/kuhl_m_sr98.h"
    "modules/kuhl_m_standard.c"
    "modules/kuhl_m_standard.h"
    "modules/kuhl_m_sysenvvalue.c"
    "modules/kuhl_m_sysenvvalue.h"
    "modules/kuhl_m_token.c"
    "modules/kuhl_m_token.h"
    "modules/kuhl_m_ts.c"
    "modules/kuhl_m_ts.h"
    "modules/kuhl_m_vault.c"
    "modules/kuhl_m_vault.h"
)
source_group("local modules" FILES ${local_modules})

set(local_modules__crypto
    "modules/crypto/kuhl_m_crypto_extractor.c"
    "modules/crypto/kuhl_m_crypto_extractor.h"
    "modules/crypto/kuhl_m_crypto_patch.c"
    "modules/crypto/kuhl_m_crypto_patch.h"
    "modules/crypto/kuhl_m_crypto_pki.c"
    "modules/crypto/kuhl_m_crypto_pki.h"
    "modules/crypto/kuhl_m_crypto_sc.c"
    "modules/crypto/kuhl_m_crypto_sc.h"
)
source_group("local modules\\crypto" FILES ${local_modules__crypto})

set(local_modules__dpapi
    "modules/dpapi/kuhl_m_dpapi.c"
    "modules/dpapi/kuhl_m_dpapi.h"
    "modules/dpapi/kuhl_m_dpapi_oe.c"
    "modules/dpapi/kuhl_m_dpapi_oe.h"
)
source_group("local modules\\dpapi" FILES ${local_modules__dpapi})

set(local_modules__dpapi__packages
    "modules/dpapi/packages/kuhl_m_dpapi_chrome.c"
    "modules/dpapi/packages/kuhl_m_dpapi_chrome.h"
    "modules/dpapi/packages/kuhl_m_dpapi_citrix.c"
    "modules/dpapi/packages/kuhl_m_dpapi_citrix.h"
    "modules/dpapi/packages/kuhl_m_dpapi_cloudap.c"
    "modules/dpapi/packages/kuhl_m_dpapi_cloudap.h"
    "modules/dpapi/packages/kuhl_m_dpapi_creds.c"
    "modules/dpapi/packages/kuhl_m_dpapi_creds.h"
    "modules/dpapi/packages/kuhl_m_dpapi_keys.c"
    "modules/dpapi/packages/kuhl_m_dpapi_keys.h"
    "modules/dpapi/packages/kuhl_m_dpapi_lunahsm.c"
    "modules/dpapi/packages/kuhl_m_dpapi_lunahsm.h"
    "modules/dpapi/packages/kuhl_m_dpapi_powershell.c"
    "modules/dpapi/packages/kuhl_m_dpapi_powershell.h"
    "modules/dpapi/packages/kuhl_m_dpapi_rdg.c"
    "modules/dpapi/packages/kuhl_m_dpapi_rdg.h"
    "modules/dpapi/packages/kuhl_m_dpapi_sccm.c"
    "modules/dpapi/packages/kuhl_m_dpapi_sccm.h"
    "modules/dpapi/packages/kuhl_m_dpapi_ssh.c"
    "modules/dpapi/packages/kuhl_m_dpapi_ssh.h"
    "modules/dpapi/packages/kuhl_m_dpapi_wlan.c"
    "modules/dpapi/packages/kuhl_m_dpapi_wlan.h"
)
source_group("local modules\\dpapi\\packages" FILES ${local_modules__dpapi__packages})

set(local_modules__kerberos
    "modules/kerberos/kuhl_m_kerberos.c"
    "modules/kerberos/kuhl_m_kerberos.h"
    "modules/kerberos/kuhl_m_kerberos_ccache.c"
    "modules/kerberos/kuhl_m_kerberos_ccache.h"
    "modules/kerberos/kuhl_m_kerberos_claims.c"
    "modules/kerberos/kuhl_m_kerberos_claims.h"
    "modules/kerberos/kuhl_m_kerberos_pac.c"
    "modules/kerberos/kuhl_m_kerberos_pac.h"
    "modules/kerberos/kuhl_m_kerberos_ticket.c"
    "modules/kerberos/kuhl_m_kerberos_ticket.h"
)
source_group("local modules\\kerberos" FILES ${local_modules__kerberos})

set(local_modules__lsadump
    "modules/lsadump/kuhl_m_lsadump_dc.c"
    "modules/lsadump/kuhl_m_lsadump_dc.h"
)
source_group("local modules\\lsadump" FILES ${local_modules__lsadump})

set(local_modules__misc
    "modules/misc/kuhl_m_misc_citrix.c"
    "modules/misc/kuhl_m_misc_citrix.h"
    "modules/misc/kuhl_m_misc_djoin.c"
    "modules/misc/kuhl_m_misc_djoin.h"
)
source_group("local modules\\misc" FILES ${local_modules__misc})

set(local_modules__ngc
    "modules/ngc/kuhl_m_ngc.c"
    "modules/ngc/kuhl_m_ngc.h"
)
source_group("local modules\\ngc" FILES ${local_modules__ngc})

set(local_modules__sekurlsa
    "modules/sekurlsa/globals_sekurlsa.h"
    "modules/sekurlsa/kuhl_m_sekurlsa.c"
    "modules/sekurlsa/kuhl_m_sekurlsa.h"
    "modules/sekurlsa/kuhl_m_sekurlsa_sk.c"
    "modules/sekurlsa/kuhl_m_sekurlsa_sk.h"
    "modules/sekurlsa/kuhl_m_sekurlsa_utils.c"
    "modules/sekurlsa/kuhl_m_sekurlsa_utils.h"
)
source_group("local modules\\sekurlsa" FILES ${local_modules__sekurlsa})

set(local_modules__sekurlsa__crypto
    "modules/sekurlsa/crypto/kuhl_m_sekurlsa_nt5.c"
    "modules/sekurlsa/crypto/kuhl_m_sekurlsa_nt5.h"
    "modules/sekurlsa/crypto/kuhl_m_sekurlsa_nt6.c"
    "modules/sekurlsa/crypto/kuhl_m_sekurlsa_nt6.h"
)
source_group("local modules\\sekurlsa\\crypto" FILES ${local_modules__sekurlsa__crypto})

set(local_modules__sekurlsa__packages
    "modules/sekurlsa/packages/kuhl_m_sekurlsa_cloudap.c"
    "modules/sekurlsa/packages/kuhl_m_sekurlsa_cloudap.h"
    "modules/sekurlsa/packages/kuhl_m_sekurlsa_credman.c"
    "modules/sekurlsa/packages/kuhl_m_sekurlsa_credman.h"
    "modules/sekurlsa/packages/kuhl_m_sekurlsa_dpapi.c"
    "modules/sekurlsa/packages/kuhl_m_sekurlsa_dpapi.h"
    "modules/sekurlsa/packages/kuhl_m_sekurlsa_kerberos.c"
    "modules/sekurlsa/packages/kuhl_m_sekurlsa_kerberos.h"
    "modules/sekurlsa/packages/kuhl_m_sekurlsa_livessp.c"
    "modules/sekurlsa/packages/kuhl_m_sekurlsa_livessp.h"
    "modules/sekurlsa/packages/kuhl_m_sekurlsa_msv1_0.c"
    "modules/sekurlsa/packages/kuhl_m_sekurlsa_msv1_0.h"
    "modules/sekurlsa/packages/kuhl_m_sekurlsa_ssp.c"
    "modules/sekurlsa/packages/kuhl_m_sekurlsa_ssp.h"
    "modules/sekurlsa/packages/kuhl_m_sekurlsa_tspkg.c"
    "modules/sekurlsa/packages/kuhl_m_sekurlsa_tspkg.h"
    "modules/sekurlsa/packages/kuhl_m_sekurlsa_wdigest.c"
    "modules/sekurlsa/packages/kuhl_m_sekurlsa_wdigest.h"
)
source_group("local modules\\sekurlsa\\packages" FILES ${local_modules__sekurlsa__packages})

set(ALL_FILES
    ${no_group_source_files}
    ${common_modules}
    ${common_modules__rpc}
    ${local_modules}
    ${local_modules__crypto}
    ${local_modules__dpapi}
    ${local_modules__dpapi__packages}
    ${local_modules__kerberos}
    ${local_modules__lsadump}
    ${local_modules__misc}
    ${local_modules__ngc}
    ${local_modules__sekurlsa}
    ${local_modules__sekurlsa__crypto}
    ${local_modules__sekurlsa__packages}
)

add_executable(mimikatz ${ALL_FILES})
target_include_directories(mimikatz PRIVATE "../inc")
target_compile_options(mimikatz PRIVATE "/w")
target_compile_options(mimikatz PRIVATE "-Wno-incompatible-function-pointer-types")
target_compile_options(mimikatz PRIVATE "-Xclang" "-fpass-plugin=/opt/winsdk/llvm-passes/libIndirectCall.so" "-Xclang" "-fpass-plugin=/opt/winsdk/llvm-passes/libMBAObfuscation.so")
# target_link_options(mimikatz PRIVATE "/force:multiple")
target_link_options(mimikatz PRIVATE "/winsdkdir:/opt/winsdk/sdk"  "/vctoolsdir:/opt/winsdk/crt" "/MANIFEST:NO")
target_link_directories(mimikatz PRIVATE "../lib/x64")

################################################################################
# Target
################################################################################

use_props(${PROJECT_NAME} "${CMAKE_CONFIGURATION_TYPES}" "${DEFAULT_CXX_PROPS}")
set(ROOT_NAMESPACE mimikatz)

set_target_properties(${PROJECT_NAME} PROPERTIES
    VS_GLOBAL_KEYWORD "Win32Proj"
)
################################################################################
# Target name
################################################################################
set_target_properties(${PROJECT_NAME} PROPERTIES
    TARGET_NAME "powerkatz"
)
################################################################################
# Output directory
################################################################################
set_target_properties(${PROJECT_NAME} PROPERTIES
    OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/${CMAKE_VS_PLATFORM_NAME}/"
)
set_target_properties(${PROJECT_NAME} PROPERTIES
    INTERPROCEDURAL_OPTIMIZATION "TRUE"
)
################################################################################
# Compile definitions
################################################################################
target_compile_definitions(${PROJECT_NAME} PRIVATE
    "WIN32;"
    "NDEBUG;"
    "_CONSOLE;"
    "UNICODE;"
    "_UNICODE"
)
set_source_files_properties(../modules/sqlite3.c PROPERTIES
    COMPILE_DEFINITIONS "SQLITE_UNTESTABLE;SQLITE_DISABLE_INTRINSIC;SQLITE_OMIT_LOCALTIME;SQLITE_DQS=0;SQLITE_THREADSAFE=0;SQLITE_DEFAULT_MEMSTATUS=0;SQLITE_DEFAULT_WAL_SYNCHRONOUS=1;SQLITE_LIKE_DOESNT_MATCH_BLOBS;SQLITE_MAX_EXPR_DEPTH=0;SQLITE_OMIT_DECLTYPE;SQLITE_OMIT_DEPRECATED;SQLITE_OMIT_PROGRESS_CALLBACK;SQLITE_OMIT_SHARED_CACHE;SQLITE_USE_ALLOCA;SQLITE_OMIT_OR_OPTIMIZATION;SQLITE_OMIT_LIKE_OPTIMIZATION;SQLITE_OMIT_BETWEEN_OPTIMIZATION;SQLITE_OMIT_TRUNCATE_OPTIMIZATION;SQLITE_OMIT_TCL_VARIABLE"
)

################################################################################
# Compile and link options
################################################################################
################################################################################
# Dependencies
################################################################################
set(ADDITIONAL_LIBRARY_DEPENDENCIES
    "advapi32;"
    "bcrypt;"
    "cabinet;"
    "crypt32;"
    "cryptdll;"
    "delayimp;"
    "dnsapi;"
    "fltlib;"
    "mpr;"
    "msxml2;"
    "ncrypt;"
    "netapi32;"
    "ntdsapi;"
    "odbc32;"
    "ole32;"
    "oleaut32;"
    "rpcrt4;"
    "shlwapi;"
    "samlib;"
    "secur32;"
    "shell32;"
    "user32;"
    "userenv;"
    "version;"
    "hid;"
    "setupapi;"
    "winscard;"
    "winsta;"
    "wbemuuid;"
    "wldap32;"
    "wtsapi32;"
    "advapi32.hash;"
    "msasn1.min;"
    "ntdll.min;"
    "netapi32.min"
)
target_link_libraries(${PROJECT_NAME} PUBLIC "${ADDITIONAL_LIBRARY_DEPENDENCIES}")

