From 4b3a78538cb5e7344358308cb2a1371e9333c5af Mon Sep 17 00:00:00 2001 From: Bjoern Kerler Date: Fri, 17 Apr 2020 21:06:32 +0200 Subject: [PATCH 01/70] HF MFDES dump + chk commands added --- client/dictionaries/mfdes_default_keys.dic | 37 + client/src/cmdhfmfdes.c | 749 +++++++++++++++++++-- client/src/fileutils.c | 38 ++ client/src/fileutils.h | 1 + 4 files changed, 783 insertions(+), 42 deletions(-) create mode 100644 client/dictionaries/mfdes_default_keys.dic diff --git a/client/dictionaries/mfdes_default_keys.dic b/client/dictionaries/mfdes_default_keys.dic new file mode 100644 index 000000000..9766e127b --- /dev/null +++ b/client/dictionaries/mfdes_default_keys.dic @@ -0,0 +1,37 @@ +0000000000000000 +00000000000000000000000000000000 +000000000000000000000000000000000000000000000000 +404142434445464748494a4b4c4d4e4f +00112233445566778899aabbccddeeff +2b7e151628aed2a6abf7158809cf4f3c +fbeed618357133667c85e08f7236a8de +f7ddac306ae266ccf90bc11ee46d513b +54686973206973206D79206B65792020 +ffffffffffffffffffffffffffffffff +a0a1a2a3a4a5a6a7a0a1a2a3a4a5a6a7 +b0b1b2b3b4b5b6b7b0b1b2b3b4b5b6b7 +d3f7d3f7d3f7d3f7d3f7d3f7d3f7d3f7 +11111111111111111111111111111111 +22222222222222222222222222222222 +33333333333333333333333333333333 +44444444444444444444444444444444 +55555555555555555555555555555555 +66666666666666666666666666666666 +77777777777777777777777777777777 +88888888888888888888888888888888 +99999999999999999999999999999999 +aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb +cccccccccccccccccccccccccccccccc +dddddddddddddddddddddddddddddddd +eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee +000102030405060708090a0b0c0d0e0f +0102030405060708090a0b0c0d0e0f10 +00010203040506070809101112131415 +01020304050607080910111213141516 +16151413121110090807060504030201 +15141312111009080706050403020100 +0f0e0d0c0b0a09080706050403020100 +100f0e0d0c0b0a090807060504030201 +404142434445464748494a4b4c4d4e4f +303132333435363738393a3b3c3d3e3f diff --git a/client/src/cmdhfmfdes.c b/client/src/cmdhfmfdes.c index d02c1ddfa..159e319f8 100644 --- a/client/src/cmdhfmfdes.c +++ b/client/src/cmdhfmfdes.c @@ -16,21 +16,21 @@ #include "cmdparser.h" // command_t #include "comms.h" #include "ui.h" -#include "cmdhw.h" #include "cmdhf14a.h" -#include "mbedtls/des.h" #include "mbedtls/aes.h" #include "../crypto/libpcrypto.h" #include "protocols.h" -#include "mifare.h" // desfire raw command options #include "cmdtrace.h" #include "cliparser/cliparser.h" #include "emv/apduinfo.h" // APDU manipulation / errorcodes #include "emv/emvcore.h" // APDU logging #include "util_posix.h" // msleep -#include "mifare/mifare4.h" // MIFARE Authenticate / MAC #include "mifare/desfire_crypto.h" #include "crapto1/crapto1.h" +#include "fileutils.h" + +#define MAX_KEY_LEN 24 +#define MAX_KEYS_LIST_LEN 1024 struct desfire_key defaultkey = {0}; static desfirekey_t sessionkey = &defaultkey; @@ -175,17 +175,11 @@ static char *cluster_to_text(uint8_t cluster) { case CL_ADMIN: return "card administration"; case CL_MISC1: - return "miscellaneous applications"; case CL_MISC2: - return "miscellaneous applications"; case CL_MISC3: - return "miscellaneous applications"; case CL_MISC4: - return "miscellaneous applications"; case CL_MISC5: - return "miscellaneous applications"; case CL_MISC6: - return "miscellaneous applications"; case CL_MISC7: return "miscellaneous applications"; case CL_AIRLINES: @@ -219,7 +213,6 @@ static char *cluster_to_text(uint8_t cluster) { case CL_CITYCARD: return "city card services"; case CL_ACCESS_CONTROL_1: - return "access control & security"; case CL_ACCESS_CONTROL_2: return "access control & security"; case CL_VIGIK: @@ -289,19 +282,12 @@ static char *cluster_to_text(uint8_t cluster) { case CL_MAIL: return "mail"; case CL_AMISC: - return "miscellaneous applications"; case CL_AMISC1: - return "miscellaneous applications"; case CL_AMISC2: - return "miscellaneous applications"; case CL_AMISC3: - return "miscellaneous applications"; case CL_AMISC4: - return "miscellaneous applications"; case CL_AMISC5: - return "miscellaneous applications"; case CL_AMISC6: - return "miscellaneous applications"; case CL_AMISC7: return "miscellaneous applications"; default: @@ -311,7 +297,7 @@ static char *cluster_to_text(uint8_t cluster) { } typedef enum { - UNKNOWN = 0, + DESFIRE_UNKNOWN = 0, DESFIRE_MF3ICD40, DESFIRE_EV1, DESFIRE_EV2, @@ -736,8 +722,7 @@ int handler_desfire_auth(mfdes_authinput_t *payload, mfdes_auth_res_t *rpayload, sAPDU apdu = {0x90, subcommand, 0x00, 0x00, 0x01, data}; int res = send_desfire_cmd(&apdu, false, recv_data, &recv_len, &sw, 0, false); if (res != PM3_SUCCESS) { - PrintAndLogEx(SUCCESS, "Sending auth command %02X " _RED_("failed"), subcommand); - return PM3_ESOFT; + return 1; } } else if (payload->mode == MFDES_AUTH_PICC) { /*cmd[0] = AUTHENTICATE; @@ -747,13 +732,11 @@ int handler_desfire_auth(mfdes_authinput_t *payload, mfdes_auth_res_t *rpayload, } if (!recv_len) { - PrintAndLogEx(ERR, "Authentication failed. Card timeout."); - return PM3_ESOFT; + return 2; } if (sw != status(MFDES_ADDITIONAL_FRAME)) { - PrintAndLogEx(ERR, "Authentication failed. Invalid key number."); - return PM3_ESOFT; + return 3; } int expectedlen = 8; @@ -762,8 +745,7 @@ int handler_desfire_auth(mfdes_authinput_t *payload, mfdes_auth_res_t *rpayload, } if (recv_len != expectedlen) { - PrintAndLogEx(ERR, "Authentication failed. Length of answer %d doesn't match algo length %d.", recv_len, expectedlen); - return PM3_ESOFT; + return 4; } int rndlen = recv_len; @@ -778,8 +760,7 @@ int handler_desfire_auth(mfdes_authinput_t *payload, mfdes_auth_res_t *rpayload, // Part 3 if (payload->algo == MFDES_ALGO_AES) { if (mbedtls_aes_setkey_dec(&ctx, key->data, 128) != 0) { - PrintAndLogEx(ERR, "mbedtls_aes_setkey_dec failed"); - return PM3_ESOFT; + return 5; } mbedtls_aes_crypt_cbc(&ctx, MBEDTLS_AES_DECRYPT, rndlen, IV, encRndB, RndB); } else if (payload->algo == MFDES_ALGO_DES) @@ -848,8 +829,7 @@ int handler_desfire_auth(mfdes_authinput_t *payload, mfdes_auth_res_t *rpayload, } if (payload->algo == MFDES_ALGO_AES) { if (mbedtls_aes_setkey_enc(&ctx, key->data, 128) != 0) { - PrintAndLogEx(ERR, "mbedtls_aes_setkey_enc failed"); - return PM3_ESOFT; + return 6; } mbedtls_aes_crypt_cbc(&ctx, MBEDTLS_AES_ENCRYPT, 32, IV, tmp, both); if (g_debugMode > 1) { @@ -866,8 +846,7 @@ int handler_desfire_auth(mfdes_authinput_t *payload, mfdes_auth_res_t *rpayload, sAPDU apdu = {0x90, MFDES_ADDITIONAL_FRAME, 0x00, 0x00, bothlen, both}; int res = send_desfire_cmd(&apdu, false, recv_data, &recv_len, &sw, 0, false); if (res != PM3_SUCCESS) { - PrintAndLogEx(SUCCESS, "Sending auth command %02X " _RED_("failed"), subcommand); - return PM3_ESOFT; + return 7; } } else { /*cmd[0] = ADDITIONAL_FRAME; @@ -881,14 +860,12 @@ int handler_desfire_auth(mfdes_authinput_t *payload, mfdes_auth_res_t *rpayload, } if (!recv_len) { - PrintAndLogEx(ERR, "Authentication failed. Card timeout."); - return PM3_ESOFT; + return 8; } if (payload->mode != MFDES_AUTH_PICC) { if (sw != status(MFDES_S_OPERATION_OK)) { - PrintAndLogEx(ERR, "Authentication failed."); - return PM3_ESOFT; + return 9; } } else { /*if (resp[1] != 0x00) { @@ -915,8 +892,7 @@ int handler_desfire_auth(mfdes_authinput_t *payload, mfdes_auth_res_t *rpayload, tdes_nxp_receive(encRndA, encRndA, rndlen, key->data, IV, 3); } else if (payload->mode == MFDES_AUTH_AES) { if (mbedtls_aes_setkey_dec(&ctx, key->data, 128) != 0) { - PrintAndLogEx(ERR, "mbedtls_aes_setkey_dec failed"); - return PM3_ESOFT; + return 10; } mbedtls_aes_crypt_cbc(&ctx, MBEDTLS_AES_DECRYPT, rndlen, IV, encRndA, encRndA); } @@ -924,12 +900,11 @@ int handler_desfire_auth(mfdes_authinput_t *payload, mfdes_auth_res_t *rpayload, rol(RndA, rndlen); for (int x = 0; x < rndlen; x++) { if (RndA[x] != encRndA[x]) { - PrintAndLogEx(ERR, "Authentication failed. Cannot verify Session Key."); if (g_debugMode > 1) { PrintAndLogEx(INFO, "Expected_RndA : %s", sprint_hex(RndA, rndlen)); PrintAndLogEx(INFO, "Generated_RndA : %s", sprint_hex(encRndA, rndlen)); } - return PM3_ESOFT; + return 11; } } @@ -938,6 +913,45 @@ int handler_desfire_auth(mfdes_authinput_t *payload, mfdes_auth_res_t *rpayload, return PM3_SUCCESS; } +void AuthToError(int error) { + switch (error) { + case 1: + PrintAndLogEx(SUCCESS, "Sending auth command failed"); + break; + case 2: + PrintAndLogEx(ERR, "Authentication failed. No data received"); + break; + case 3: + PrintAndLogEx(ERR, "Authentication failed. Invalid key number."); + break; + case 4: + PrintAndLogEx(ERR, "Authentication failed. Length of answer %d doesn't match algo length %d."); + break; + case 5: + PrintAndLogEx(ERR, "mbedtls_aes_setkey_dec failed"); + break; + case 6: + PrintAndLogEx(ERR, "mbedtls_aes_setkey_enc failed"); + break; + case 7: + PrintAndLogEx(SUCCESS, "Sending auth command failed"); + break; + case 8: + PrintAndLogEx(ERR, "Authentication failed. Card timeout."); + break; + case 9: + PrintAndLogEx(ERR, "Authentication failed."); + break; + case 10: + PrintAndLogEx(ERR, "mbedtls_aes_setkey_dec failed"); + break; + case 11: + PrintAndLogEx(ERR, "Authentication failed. Cannot verify Session Key."); + break; + default: + break; + } +} // -- test if card supports 0x0A static int test_desfire_authenticate() { uint8_t data[] = {0x00}; @@ -3051,6 +3065,149 @@ static int DecodeFileSettings(uint8_t *src, int src_len, int maclen) { return PM3_ESOFT; } +static int CmdHF14ADesDump(const char *Cmd) { + (void)Cmd; // Cmd is not used so far + DropField(); + uint8_t aid[3] = {0}; + uint8_t app_ids[78] = {0}; + uint8_t app_ids_len = 0; + + uint8_t file_ids[33] = {0}; + uint8_t file_ids_len = 0; + + dfname_t dfnames[255]; + uint8_t dfname_count = 0; + + int res = 0; + + if (handler_desfire_appids(app_ids, &app_ids_len) != PM3_SUCCESS) { + PrintAndLogEx(ERR, "Can't get list of applications on tag"); + DropField(); + return PM3_ESOFT; + } + + if (handler_desfire_dfnames(dfnames, &dfname_count) != PM3_SUCCESS) { + PrintAndLogEx(WARNING, _RED_("Can't get DF Names")); + DropField(); + return PM3_ESOFT; + } + + PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(INFO, "-- Mifare DESFire Dump ----------------------"); + PrintAndLogEx(INFO, "-------------------------------------------------------------"); + + for (int i = 0; i < app_ids_len; i += 3) { + + aid[0] = app_ids[i]; + aid[1] = app_ids[i + 1]; + aid[2] = app_ids[i + 2]; + + PrintAndLogEx(SUCCESS, " AID : " _GREEN_("%02X%02X%02X"), aid[2], aid[1], aid[0]); + PrintAndLogEx(SUCCESS, " AID Function Cluster 0x%02X: " _YELLOW_("%s"), aid[2], cluster_to_text(aid[2])); + + for (int m = 0; m < dfname_count; m++) { + if (dfnames[m].aid[0] == aid[0] && dfnames[m].aid[1] == aid[1] && dfnames[m].aid[2] == aid[2]) { + PrintAndLogEx(SUCCESS, " - DF " _YELLOW_("%02X%02X") " Name : " _YELLOW_("%s"), dfnames[m].fid[1], dfnames[m].fid[0], dfnames[m].name); + } + } + + uint8_t num_keys = 0; + uint8_t key_setting = 0; + res = handler_desfire_keysettings(&key_setting, &num_keys); + if (res != PM3_SUCCESS) return res; + + res = handler_desfire_select_application(aid); + + if (handler_desfire_fileids(file_ids, &file_ids_len) == PM3_SUCCESS) { + for (int j = file_ids_len - 1; j >= 0; j--) { + PrintAndLogEx(SUCCESS, "\n\n Fileid %d (0x%02x)", file_ids[j], file_ids[j]); + + uint8_t filesettings[20] = {0}; + int fileset_len = 0; + int res = handler_desfire_filesettings(file_ids[j], filesettings, &fileset_len); + int maclen = 0; // To be implemented + if (res == PM3_SUCCESS) { + //if (DecodeFileSettings(filesettings, fileset_len, maclen) != PM3_SUCCESS) { + if (fileset_len == 1 + 1 + 2 + 3 + maclen) { + int filesize = (filesettings[6] << 16) + (filesettings[5] << 8) + filesettings[4]; + mfdes_data_t fdata; + fdata.fileno = file_ids[j]; + memset(fdata.offset, 0, 3); + //memcpy(fdata.length,&filesettings[4],3); + memset(fdata.length, 0, 3); + uint8_t *data = (uint8_t *)malloc(filesize); + fdata.data = data; + if (data) { + res = handler_desfire_readdata(&fdata, MFDES_DATA_FILE); + if (res == PM3_SUCCESS) { + PrintAndLogEx(NORMAL, "\nOffset | Data | Ascii"); + PrintAndLogEx(NORMAL, "----------------------------------------------------------------------------"); + int len = le24toh(fdata.length); + for (int i = 0; i < len; i += 16) { + PrintAndLogEx(NORMAL, "%02d/0x%02X | %s| %s", i, i, sprint_hex(&fdata.data[i], len > 16 ? 16 : len), sprint_ascii(&fdata.data[i], len > 16 ? 16 : len)); + } + free(data); + } else { + PrintAndLogEx(ERR, "Couldn't read value. Error %d", res); + res = handler_desfire_select_application(aid); + } + } + } else if (fileset_len == 1 + 1 + 2 + 4 + 4 + 4 + 1 + maclen) { + PrintAndLogEx(NORMAL, "\n\nValue file: 0x%0x", file_ids[j]); + mfdes_value_t value; + value.fileno = file_ids[j]; + int len = 0; + res = handler_desfire_getvalue(&value, &len); + if (res == PM3_SUCCESS) { + PrintAndLogEx(NORMAL, "\nOffset | Value | Ascii"); + PrintAndLogEx(NORMAL, "----------------------------------------------------------------------------"); + for (int i = 0; i < len; i += 16) { + PrintAndLogEx(NORMAL, "%02d/0x%02X | %s| %s", i, i, sprint_hex(&value.value[i], len > 16 ? 16 : len), sprint_ascii(&value.value[i], len > 16 ? 16 : len)); + } + } else { + PrintAndLogEx(ERR, "Couldn't read value. Error %d", res); + res = handler_desfire_select_application(aid); + } + } else if (fileset_len == 1 + 1 + 2 + 3 + 3 + 3 + maclen) { + int maxrecords = (filesettings[9] << 16) + (filesettings[8] << 8) + filesettings[7]; + int filesize = (filesettings[6] << 16) + (filesettings[5] << 8) + filesettings[4]; + mfdes_data_t fdata; + fdata.fileno = file_ids[j]; + memset(fdata.length, 0, 3); + //memcpy(fdata.length,&filesettings[4],3); + uint8_t *data = (uint8_t *)malloc(filesize); + fdata.data = data; + if (data) { + for (int offset = 0; offset < maxrecords; offset++) { + PrintAndLogEx(NORMAL, "\n\nRecord offset: %024x", offset); + memset(data, 0, filesize); + fdata.offset[0] = offset & 0xFF; + fdata.offset[1] = (offset >> 8) & 0xFF; + fdata.offset[2] = (offset >> 16) & 0xFF; + res = handler_desfire_readdata(&fdata, MFDES_RECORD_FILE); + if (res == PM3_SUCCESS) { + PrintAndLogEx(NORMAL, "\nOffset | Data | Ascii"); + PrintAndLogEx(NORMAL, "----------------------------------------------------------------------------"); + int len = le24toh(fdata.length); + for (int i = 0; i < len; i += 16) { + PrintAndLogEx(NORMAL, "%02d/0x%02X | %s| %s", i, i, sprint_hex(&fdata.data[i], len > 16 ? 16 : len), sprint_ascii(&fdata.data[i], len > 16 ? 16 : len)); + } + } else { + res = handler_desfire_select_application(aid); + } + } + free(data); + } + } + } + } + } + } + PrintAndLogEx(INFO, "-------------------------------------------------------------"); + DropField(); + return PM3_SUCCESS; +} + static int CmdHF14ADesEnumApplications(const char *Cmd) { (void)Cmd; // Cmd is not used so far DropField(); @@ -3305,17 +3462,523 @@ static int CmdHF14ADesAuth(const char *Cmd) { } */ mfdes_auth_res_t rpayload; - if (handler_desfire_auth(&payload, &rpayload, usedefaultkey) == PM3_SUCCESS) { + int error = handler_desfire_auth(&payload, &rpayload, usedefaultkey); + if (error == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, " Key : " _GREEN_("%s"), sprint_hex(key, keylength)); PrintAndLogEx(SUCCESS, " SESSION : " _GREEN_("%s"), sprint_hex(rpayload.sessionkey, keylength)); PrintAndLogEx(INFO, "-------------------------------------------------------------"); } else { + AuthToError(error); return PM3_ESOFT; } PrintAndLogEx(INFO, "-------------------------------------------------------------"); return PM3_SUCCESS; } +void DesFill2bPattern(uint8_t deskeyList[MAX_KEYS_LIST_LEN][8], size_t *deskeyListLen, uint8_t aeskeyList[MAX_KEYS_LIST_LEN][16], size_t *aeskeyListLen, uint8_t k3kkeyList[MAX_KEYS_LIST_LEN][24], size_t *k3kkeyListLen, uint32_t *startPattern) { + for (uint32_t pt = *startPattern; pt < 0x10000; pt++) { + if (*deskeyListLen != MAX_KEYS_LIST_LEN) { + deskeyList[*deskeyListLen][0] = (pt >> 8) & 0xff; + deskeyList[*deskeyListLen][1] = pt & 0xff; + memcpy(&deskeyList[*deskeyListLen][2], &deskeyList[*deskeyListLen][0], 2); + memcpy(&deskeyList[*deskeyListLen][4], &deskeyList[*deskeyListLen][0], 4); + (*deskeyListLen)++; + } + if (*aeskeyListLen != MAX_KEYS_LIST_LEN) { + aeskeyList[*aeskeyListLen][0] = (pt >> 8) & 0xff; + aeskeyList[*aeskeyListLen][1] = pt & 0xff; + memcpy(&aeskeyList[*aeskeyListLen][2], &aeskeyList[*aeskeyListLen][0], 2); + memcpy(&aeskeyList[*aeskeyListLen][4], &aeskeyList[*aeskeyListLen][0], 4); + memcpy(&aeskeyList[*aeskeyListLen][8], &aeskeyList[*aeskeyListLen][0], 8); + (*aeskeyListLen)++; + } + if (*k3kkeyListLen != MAX_KEYS_LIST_LEN) { + k3kkeyList[*k3kkeyListLen][0] = (pt >> 8) & 0xff; + k3kkeyList[*k3kkeyListLen][1] = pt & 0xff; + memcpy(&k3kkeyList[*k3kkeyListLen][2], &k3kkeyList[*k3kkeyListLen][0], 2); + memcpy(&k3kkeyList[*k3kkeyListLen][4], &k3kkeyList[*k3kkeyListLen][0], 4); + memcpy(&k3kkeyList[*k3kkeyListLen][8], &k3kkeyList[*k3kkeyListLen][0], 8); + memcpy(&k3kkeyList[*k3kkeyListLen][16], &k3kkeyList[*k3kkeyListLen][0], 4); + (*k3kkeyListLen)++; + } + + *startPattern = pt; + if ((*deskeyListLen == MAX_KEYS_LIST_LEN) && (*aeskeyListLen == MAX_KEYS_LIST_LEN) && (*k3kkeyListLen == MAX_KEYS_LIST_LEN)) + break; + } + (*startPattern)++; +} + +static int AuthCheckDesfire(uint8_t *aid, uint8_t deskeyList[MAX_KEYS_LIST_LEN][8], size_t deskeyListLen, uint8_t aeskeyList[MAX_KEYS_LIST_LEN][16], size_t aeskeyListLen, uint8_t k3kkeyList[MAX_KEYS_LIST_LEN][24], size_t k3kkeyListLen, uint8_t foundKeys[4][0xE][24 + 1], bool *result) { + int res = handler_desfire_select_application(aid); + if (res != PM3_SUCCESS) { + PrintAndLogEx(ERR, "AID %X does not exist."); + return res; + } + + int usedkeys[0xF] = {0}; + bool des = false; + bool tdes = false; + bool aes = false; + bool k3kdes = false; + + if (memcmp(aid, "\x00\x00\x00", 3) != 0) { + uint8_t file_ids[33] = {0}; + uint8_t file_ids_len = 0; + // Get File IDs + if (handler_desfire_fileids(file_ids, &file_ids_len) == PM3_SUCCESS) { + for (int j = file_ids_len - 1; j >= 0; j--) { + uint8_t filesettings[20] = {0}; + int fileset_len = 0; + res = handler_desfire_filesettings(file_ids[j], filesettings, &fileset_len); + if (res == PM3_SUCCESS) { + uint16_t accrights = (filesettings[3] << 8) + filesettings[2]; + int change_access_rights = accrights & 0xF; + int read_write_access = (accrights >> 4) & 0xF; + int write_access = (accrights >> 8) & 0xF; + int read_access = (accrights >> 12) & 0xF; + if (change_access_rights == 0xE) change_access_rights = 0x0; + if (read_write_access == 0xE) read_write_access = 0x0; + if (write_access == 0xE) write_access = 0x0; + if (read_access == 0xE) read_access = 0x0; + usedkeys[change_access_rights] = 1; + usedkeys[read_write_access] = 1; + usedkeys[write_access] = 1; + usedkeys[read_access] = 1; + if (res == PM3_SUCCESS) { + switch (fileset_len >> 6) { + case 0: + des = true; + tdes = true; + break; + case 1: + k3kdes = true; + break; + case 2: + aes = true; + break; + default: + break; + } + } + } + } + if (file_ids_len == 0) { + for (int z = 0; z < 0xE; z++) { + usedkeys[z] = 1; + des = true; + tdes = true; + aes = true; + k3kdes = true; + } + } + } + } else des = true; + int error = PM3_SUCCESS; + bool badlen = false; + mfdes_authinput_t payload; + uint32_t curaid = (aid[0] & 0xFF) + ((aid[1] & 0xFF) << 8) + ((aid[2] & 0xFF) << 16); + if (des) { + for (int keyno = 0; keyno < 0xE; keyno++) + if (usedkeys[keyno] == 1 && foundKeys[0][keyno][0] == 0) { + for (int curkey = 0; curkey < deskeyListLen; curkey++) { + payload.keylen = 8; + memcpy(payload.key, deskeyList[curkey], 8); + payload.mode = MFDES_AUTH_DES; + payload.algo = MFDES_ALGO_DES; + payload.keyno = keyno; + mfdes_auth_res_t rpayload; + error = handler_desfire_auth(&payload, &rpayload, false); + if (error == PM3_SUCCESS) { + PrintAndLogEx(SUCCESS, "AID 0x%06X, Found DES Key %d : " _GREEN_("%s"), curaid, keyno, sprint_hex(deskeyList[curkey], 8)); + foundKeys[0][keyno][0] = 0x01; + *result = true; + memcpy(&foundKeys[0][keyno][1], deskeyList[curkey], 8); + break; + } else if (error < 7) { + badlen = true; + DropField(); + res = handler_desfire_select_application(aid); + if (res != PM3_SUCCESS) { + PrintAndLogEx(ERR, "AID %X does not exist."); + return res; + } + break; + } + } + if (badlen == true) { + badlen = false; + break; + } + } + } + if (tdes) { + for (int keyno = 0; keyno < 0xE; keyno++) + if (usedkeys[keyno] == 1 && foundKeys[1][keyno][0] == 0) { + for (int curkey = 0; curkey < aeskeyListLen; curkey++) { + payload.keylen = 16; + memcpy(payload.key, aeskeyList[curkey], 16); + payload.mode = MFDES_AUTH_DES; + payload.algo = MFDES_ALGO_3DES; + payload.keyno = keyno; + mfdes_auth_res_t rpayload; + error = handler_desfire_auth(&payload, &rpayload, false); + if (error == PM3_SUCCESS) { + PrintAndLogEx(SUCCESS, "AID 0x%06X, Found 3DES Key %d : " _GREEN_("%s"), curaid, keyno, sprint_hex(aeskeyList[curkey], 16)); + foundKeys[1][keyno][0] = 0x01; + *result = true; + memcpy(&foundKeys[1][keyno][1], aeskeyList[curkey], 16); + break; + } else if (error < 7) { + badlen = true; + DropField(); + res = handler_desfire_select_application(aid); + if (res != PM3_SUCCESS) { + PrintAndLogEx(ERR, "AID %X does not exist."); + return res; + } + break; + } + } + if (badlen == true) { + badlen = false; + break; + } + } + } + + if (aes) { + for (int keyno = 0; keyno < 0xE; keyno++) + if (usedkeys[keyno] == 1 && foundKeys[2][keyno][0] == 0) { + for (int curkey = 0; curkey < aeskeyListLen; curkey++) { + payload.keylen = 16; + memcpy(payload.key, aeskeyList[curkey], 16); + payload.mode = MFDES_AUTH_AES; + payload.algo = MFDES_ALGO_AES; + payload.keyno = keyno; + mfdes_auth_res_t rpayload; + error = handler_desfire_auth(&payload, &rpayload, false); + if (error == PM3_SUCCESS) { + PrintAndLogEx(SUCCESS, "AID 0x%06X, Found AES Key %d : " _GREEN_("%s"), curaid, keyno, sprint_hex(aeskeyList[curkey], 16)); + foundKeys[2][keyno][0] = 0x01; + *result = true; + memcpy(&foundKeys[2][keyno][1], aeskeyList[curkey], 16); + break; + } else if (error < 7) { + badlen = true; + DropField(); + res = handler_desfire_select_application(aid); + if (res != PM3_SUCCESS) { + PrintAndLogEx(ERR, "AID %X does not exist."); + return res; + } + break; + } + } + if (badlen == true) { + badlen = false; + break; + } + } + } + + if (k3kdes) { + for (int keyno = 0; keyno < 0xE; keyno++) + if (usedkeys[keyno] == 1 && foundKeys[3][keyno][0] == 0) { + for (int curkey = 0; curkey < k3kkeyListLen; curkey++) { + payload.keylen = 24; + memcpy(payload.key, k3kkeyList[curkey], 24); + payload.mode = MFDES_AUTH_ISO; + payload.algo = MFDES_ALGO_3K3DES; + payload.keyno = keyno; + mfdes_auth_res_t rpayload; + error = handler_desfire_auth(&payload, &rpayload, false); + if (error == PM3_SUCCESS) { + PrintAndLogEx(SUCCESS, "AID 0x%06X, Found 3K3 Key %d : " _GREEN_("%s"), curaid, keyno, sprint_hex(k3kkeyList[curkey], 24)); + foundKeys[3][keyno][0] = 0x01; + *result = true; + memcpy(&foundKeys[3][keyno][1], k3kkeyList[curkey], 16); + break; + } else if (error < 7) { + badlen = true; + DropField(); + res = handler_desfire_select_application(aid); + if (res != PM3_SUCCESS) { + PrintAndLogEx(ERR, "AID %X does not exist."); + return res; + } + break; + } + } + if (badlen == true) { + badlen = false; + break; + } + } + } + DropField(); + return PM3_SUCCESS; +} + +static int CmdHF14aDesChk(const char *Cmd) { + int res; + uint8_t deskeyList[MAX_KEYS_LIST_LEN][8] = {{0}}; + uint8_t aeskeyList[MAX_KEYS_LIST_LEN][16] = {{0}}; + uint8_t k3kkeyList[MAX_KEYS_LIST_LEN][MAX_KEY_LEN] = {{0}}; + size_t deskeyListLen = 0; + size_t aeskeyListLen = 0; + size_t k3kkeyListLen = 0; + uint8_t foundKeys[4][0xE][24 + 1] = {{{0}}}; + + CLIParserInit("hf mfdes chk", + "Checks keys with Mifare Desfire card.", + "Usage:\n" + " hf mfdes chk -a 123456 -k 000102030405060708090a0b0c0d0e0f -> check key on aid 0x123456\n" + " hf mfdes chk -d mfdes_default_keys -> check keys from dictionary against all existing aid on card\n" + " hf mfdes chk -d mfdes_default_keys -a 123456 -> check keys from dictionary against aid 0x123456\n" + " hf mfdes chk -a 123456 --pattern1b -j keys -> check all 1-byte keys pattern on aid 0x123456 and save found keys to json\n" + " hf mfdes chk -a 123456 --pattern2b --startp2b FA00 -> check all 2-byte keys pattern on aid 0x123456. Start from key FA00FA00...FA00\n"); + + void *argtable[] = { + arg_param_begin, + arg_strx0("aA", "aid", "", "Use specific AID (3 hex bytes, big endian)"), + arg_str0("kK", "key", "", "Key for checking (HEX 16 bytes)"), + arg_str0("dD", "dict", "", "File with keys dictionary"), + arg_lit0(NULL, "pattern1b", "Check all 1-byte combinations of key (0000...0000, 0101...0101, 0202...0202, ...)"), + arg_lit0(NULL, "pattern2b", "Check all 2-byte combinations of key (0000...0000, 0001...0001, 0002...0002, ...)"), + arg_str0(NULL, "startp2b", "", "Start key (2-byte HEX) for 2-byte search (use with `--pattern2b`)"), + arg_str0("jJ", "json", "", "Json file to save keys"), + arg_lit0("vV", "verbose", "Verbose mode."), + arg_param_end + }; + CLIExecWithReturn(Cmd, argtable, false); + + int aidlength = 0; + uint8_t aid[3] = {0}; + CLIGetHexWithReturn(1, aid, &aidlength); + swap24(aid); + uint8_t vkey[16] = {0}; + int vkeylen = 0; + CLIGetHexWithReturn(2, vkey, &vkeylen); + + if (vkeylen > 0) { + if (vkeylen == 8) { + memcpy(&deskeyList[deskeyListLen], vkey, 8); + deskeyListLen++; + } else if (vkeylen == 16) { + memcpy(&aeskeyList[aeskeyListLen], vkey, 16); + aeskeyListLen++; + } else if (vkeylen == 24) { + memcpy(&k3kkeyList[k3kkeyListLen], vkey, 16); + k3kkeyListLen++; + } else { + PrintAndLogEx(ERR, "Specified key must have 8, 16 or 24 bytes length."); + CLIParserFree(); + return PM3_EINVARG; + } + } + + uint8_t dict_filename[FILE_PATH_SIZE + 2] = {0}; + int dict_filenamelen = 0; + if (CLIParamStrToBuf(arg_get_str(3), dict_filename, FILE_PATH_SIZE, &dict_filenamelen)) { + PrintAndLogEx(FAILED, "File name too long or invalid."); + CLIParserFree(); + return PM3_EINVARG; + } + + bool pattern1b = arg_get_lit(4); + bool pattern2b = arg_get_lit(5); + + if (pattern1b && pattern2b) { + PrintAndLogEx(ERR, "Pattern search mode must be 2-byte or 1-byte only."); + CLIParserFree(); + return PM3_EINVARG; + } + + if (dict_filenamelen && (pattern1b || pattern2b)) { + PrintAndLogEx(ERR, "Pattern search mode and dictionary mode can't be used in one command."); + CLIParserFree(); + return PM3_EINVARG; + } + + uint32_t startPattern = 0x0000; + uint8_t vpattern[2]; + int vpatternlen = 0; + CLIGetHexWithReturn(6, vpattern, &vpatternlen); + if (vpatternlen > 0) { + if (vpatternlen > 0 && vpatternlen <= 2) { + startPattern = (vpattern[0] << 8) + vpattern[1]; + } else { + PrintAndLogEx(ERR, "Pattern must be 2-byte length."); + CLIParserFree(); + return PM3_EINVARG; + } + if (!pattern2b) + PrintAndLogEx(WARNING, "Pattern entered, but search mode not is 2-byte search."); + } + + uint8_t jsonname[250] = {0}; + int jsonnamelen = 0; + if (CLIParamStrToBuf(arg_get_str(7), jsonname, sizeof(jsonname), &jsonnamelen)) { + PrintAndLogEx(ERR, "Invalid json name."); + CLIParserFree(); + return PM3_EINVARG; + } + jsonname[jsonnamelen] = 0; + + bool verbose = arg_get_lit(8); + + CLIParserFree(); + + // 1-byte pattern search mode + if (pattern1b) { + for (int i = 0; i < 0x100; i++) + memset(aeskeyList[i], i, 16); + for (int i = 0; i < 0x100; i++) + memset(deskeyList[i], i, 8); + for (int i = 0; i < 0x100; i++) + memset(k3kkeyList[i], i, 24); + aeskeyListLen = 0x100; + deskeyListLen = 0x100; + k3kkeyListLen = 0x100; + } + + // 2-byte pattern search mode + if (pattern2b) { + DesFill2bPattern(deskeyList, &deskeyListLen, aeskeyList, &aeskeyListLen, k3kkeyList, &k3kkeyListLen, &startPattern); + } + + // dictionary mode + size_t endFilePosition = 0; + if (dict_filenamelen) { + uint16_t keycnt = 0; + res = loadFileDICTIONARYEx((char *)dict_filename, deskeyList, sizeof(deskeyList), NULL, 8, &keycnt, 0, &endFilePosition, true); + deskeyListLen = keycnt; + if (endFilePosition) + PrintAndLogEx(SUCCESS, "First part of des dictionary successfully loaded."); + endFilePosition = 0; + res = loadFileDICTIONARYEx((char *)dict_filename, aeskeyList, sizeof(aeskeyList), NULL, 16, &keycnt, 0, &endFilePosition, true); + aeskeyListLen = keycnt; + if (endFilePosition) + PrintAndLogEx(SUCCESS, "First part of aes dictionary successfully loaded."); + endFilePosition = 0; + res = loadFileDICTIONARYEx((char *)dict_filename, k3kkeyList, sizeof(k3kkeyList), NULL, 24, &keycnt, 0, &endFilePosition, true); + k3kkeyListLen = keycnt; + if (endFilePosition) + PrintAndLogEx(SUCCESS, "First part of k3kdes dictionary successfully loaded."); + endFilePosition = 0; + + if (endFilePosition) + PrintAndLogEx(SUCCESS, "First part of dictionary successfully loaded."); + } + + if (aeskeyListLen == 0) { + PrintAndLogEx(ERR, "Aes key list is empty. Nothing to check."); + return PM3_EINVARG; + } else { + PrintAndLogEx(INFO, "Loaded " _YELLOW_("%zu") "aes keys", aeskeyListLen); + } + + if (deskeyListLen == 0) { + PrintAndLogEx(ERR, "Des key list is empty. Nothing to check."); + return PM3_EINVARG; + } else { + PrintAndLogEx(INFO, "Loaded " _YELLOW_("%zu") "des keys", deskeyListLen); + } + + if (k3kkeyListLen == 0) { + PrintAndLogEx(ERR, "K3k key list is empty. Nothing to check."); + return PM3_EINVARG; + } else { + PrintAndLogEx(INFO, "Loaded " _YELLOW_("%zu") "k3kdes keys", k3kkeyListLen); + } + + if (!verbose) + printf("Search keys:\n"); + + bool result = false; + uint8_t app_ids[78] = {0}; + uint8_t app_ids_len = 0; + + if (handler_desfire_appids(app_ids, &app_ids_len) != PM3_SUCCESS) { + PrintAndLogEx(ERR, "Can't get list of applications on tag"); + DropField(); + return PM3_ESOFT; + } + + if (aidlength != 0) { + memcpy(&app_ids[0], aid, 3); + app_ids_len = 1; + } + + for (int x = 0; x < app_ids_len / 3; x++) { + uint32_t curaid = (app_ids[x * 3] & 0xFF) + ((app_ids[(x * 3) + 1] & 0xFF) << 8) + ((app_ids[(x * 3) + 2] & 0xFF) << 16); + PrintAndLogEx(ERR, "Checking aid 0x%06X...", curaid); + res = AuthCheckDesfire(&app_ids[x * 3], deskeyList, deskeyListLen, aeskeyList, aeskeyListLen, k3kkeyList, k3kkeyListLen, foundKeys, &result); + if (res == PM3_EOPABORTED) { + break; + } + + if (pattern2b && startPattern < 0x10000) { + if (!verbose) + printf("p"); + aeskeyListLen = 0; + deskeyListLen = 0; + k3kkeyListLen = 0; + DesFill2bPattern(deskeyList, &deskeyListLen, aeskeyList, &aeskeyListLen, k3kkeyList, &k3kkeyListLen, &startPattern); + continue; + } + if (dict_filenamelen && endFilePosition) { + if (!verbose) + printf("d"); + uint16_t keycnt = 0; + res = loadFileDICTIONARYEx((char *)dict_filename, deskeyList, sizeof(deskeyList), NULL, 16, &keycnt, endFilePosition, &endFilePosition, false); + deskeyListLen = keycnt; + keycnt = 0; + res = loadFileDICTIONARYEx((char *)dict_filename, aeskeyList, sizeof(aeskeyList), NULL, 16, &keycnt, endFilePosition, &endFilePosition, false); + aeskeyListLen = keycnt; + keycnt = 0; + res = loadFileDICTIONARYEx((char *)dict_filename, k3kkeyList, sizeof(k3kkeyList), NULL, 16, &keycnt, endFilePosition, &endFilePosition, false); + k3kkeyListLen = keycnt; + continue; + } + } + if (!verbose) + printf("\n"); + + // save keys to json + if ((jsonnamelen > 0) && result) { + // Mifare Desfire info + SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_CONNECT, 0, 0, NULL, 0); + + PacketResponseNG resp; + WaitForResponse(CMD_ACK, &resp); + + iso14a_card_select_t card; + memcpy(&card, (iso14a_card_select_t *)resp.data.asBytes, sizeof(iso14a_card_select_t)); + + uint64_t select_status = resp.oldarg[0]; // 0: couldn't read, 1: OK, with ATS, 2: OK, no ATS, 3: proprietary Anticollision + + uint8_t data[10 + 1 + 2 + 1 + 256 + (4 * 0xE * (24 + 1))] = {0}; + uint8_t atslen = 0; + if (select_status == 1 || select_status == 2) { + memcpy(data, card.uid, card.uidlen); + data[10] = card.sak; + data[11] = card.atqa[1]; + data[12] = card.atqa[0]; + atslen = card.ats_len; + data[13] = atslen; + memcpy(&data[14], card.ats, atslen); + } + + // length: UID(10b)+SAK(1b)+ATQA(2b)+ATSlen(1b)+ATS(atslen)+foundKeys[2][64][AES_KEY_LEN + 1] + memcpy(&data[14 + atslen], foundKeys, 4 * 0xE * (24 + 1)); + saveFileJSON((char *)jsonname, jsfMfDesfireKeys, data, 0xE); + } + + return PM3_SUCCESS; +} + static int CmdHF14ADesList(const char *Cmd) { (void)Cmd; // Cmd is not used so far return CmdTraceList("des"); @@ -3364,6 +4027,8 @@ static command_t CommandTable[] = { {"getvalue", CmdHF14ADesGetValueData, IfPm3Iso14443a, "Get value of file"}, {"changevalue", CmdHF14ADesChangeValue, IfPm3Iso14443a, "Write value of a value file (credit/debit/clear)"}, {"formatpicc", CmdHF14ADesFormatPICC, IfPm3Iso14443a, "Format PICC"}, + {"dump", CmdHF14ADesDump, IfPm3Iso14443a, "Dump all files"}, + {"chk", CmdHF14aDesChk, IfPm3Iso14443a, "Check keys"}, /* ToDo: diff --git a/client/src/fileutils.c b/client/src/fileutils.c index 066a796b5..2e9ae43d6 100644 --- a/client/src/fileutils.c +++ b/client/src/fileutils.c @@ -426,6 +426,44 @@ int saveFileJSON(const char *preferredName, JSONFileType ftype, uint8_t *data, s } } break; + case jsfMfDesfireKeys: + JsonSaveStr(root, "FileType", "mfdes"); + JsonSaveBufAsHexCompact(root, "$.Card.UID", &data[0], 7); + JsonSaveBufAsHexCompact(root, "$.Card.SAK", &data[10], 1); + JsonSaveBufAsHexCompact(root, "$.Card.ATQA", &data[11], 2); + uint8_t datslen = data[13]; + if (datslen > 0) + JsonSaveBufAsHexCompact(root, "$.Card.ATS", &data[14], datslen); + + uint8_t dvdata[4][0xE][24 + 1] = {{{0}}}; + memcpy(dvdata, &data[14 + datslen], 4 * 0xE * (24 + 1)); + + for (int i = 0; i < (int)datalen; i++) { + char path[PATH_MAX_LENGTH] = {0}; + + if (dvdata[0][i][0]) { + memset(path, 0x00, sizeof(path)); + sprintf(path, "$.DES.%d.Key", i); + JsonSaveBufAsHexCompact(root, path, &dvdata[0][i][1], 8); + } + + if (dvdata[1][i][0]) { + memset(path, 0x00, sizeof(path)); + sprintf(path, "$.3DES.%d.Key", i); + JsonSaveBufAsHexCompact(root, path, &dvdata[1][i][1], 16); + } + if (dvdata[2][i][0]) { + memset(path, 0x00, sizeof(path)); + sprintf(path, "$.AES.%d.Key", i); + JsonSaveBufAsHexCompact(root, path, &dvdata[2][i][1], 16); + } + if (dvdata[3][i][0]) { + memset(path, 0x00, sizeof(path)); + sprintf(path, "$.K3KDES.%d.Key", i); + JsonSaveBufAsHexCompact(root, path, &dvdata[3][i][1], 24); + } + } + break; case jsfSettings: preferences_save_callback(root); break; diff --git a/client/src/fileutils.h b/client/src/fileutils.h index 06d3ff20a..ff43b3f7e 100644 --- a/client/src/fileutils.h +++ b/client/src/fileutils.h @@ -63,6 +63,7 @@ typedef enum { jsfT5555, jsfMfPlusKeys, jsfSettings, + jsfMfDesfireKeys, } JSONFileType; typedef enum { From 68747f5bbd1bd3488c456f2c5125694a1f468ab6 Mon Sep 17 00:00:00 2001 From: Bjoern Kerler Date: Fri, 17 Apr 2020 21:25:13 +0200 Subject: [PATCH 02/70] More keys --- client/dictionaries/mfdes_default_keys.dic | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/client/dictionaries/mfdes_default_keys.dic b/client/dictionaries/mfdes_default_keys.dic index 9766e127b..49b09dc9b 100644 --- a/client/dictionaries/mfdes_default_keys.dic +++ b/client/dictionaries/mfdes_default_keys.dic @@ -1,6 +1,12 @@ -0000000000000000 -00000000000000000000000000000000 -000000000000000000000000000000000000000000000000 +0000000000000000 #NXP Default DES +7544d1652bc9bd43 +00000000000000000000000000000000 #NXP Default 3DES/AES +000000000000000000000000000000000000000000000000 #NXP Default 3K3DES +00112233445566778899AABBCCDDEEFF #TI TRF7970A sloa213 +79702553797025537970255379702553 #TI TRF7970A sloa213 +4E617468616E2E4C6920546564647920 +43464F494D48504E4C4359454E528841 #NHIF +6AC292FAA1315B4D858AB3A3D7D5933A 404142434445464748494a4b4c4d4e4f 00112233445566778899aabbccddeeff 2b7e151628aed2a6abf7158809cf4f3c From 0762d29bb3818e7dd3925390f7be71ef184edda9 Mon Sep 17 00:00:00 2001 From: Bjoern Kerler Date: Fri, 17 Apr 2020 21:37:16 +0200 Subject: [PATCH 03/70] Another key --- client/dictionaries/mfdes_default_keys.dic | 1 + 1 file changed, 1 insertion(+) diff --git a/client/dictionaries/mfdes_default_keys.dic b/client/dictionaries/mfdes_default_keys.dic index 49b09dc9b..dac73fa04 100644 --- a/client/dictionaries/mfdes_default_keys.dic +++ b/client/dictionaries/mfdes_default_keys.dic @@ -16,6 +16,7 @@ f7ddac306ae266ccf90bc11ee46d513b ffffffffffffffffffffffffffffffff a0a1a2a3a4a5a6a7a0a1a2a3a4a5a6a7 b0b1b2b3b4b5b6b7b0b1b2b3b4b5b6b7 +b0b1b2b3b4b5b6b7b8b9babbbcbdbebf d3f7d3f7d3f7d3f7d3f7d3f7d3f7d3f7 11111111111111111111111111111111 22222222222222222222222222222222 From 7acc43fe9f970e70d6fc1d1331b52fcca7842a25 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 18 Apr 2020 12:07:54 +0200 Subject: [PATCH 04/70] Removing debug flag --- client/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/Makefile b/client/Makefile index 0be82d040..608445f55 100644 --- a/client/Makefile +++ b/client/Makefile @@ -51,7 +51,7 @@ ZLIB = $(OBJDIR)/libz.a LIBS = -I$(LUALIBPATH) -I$(MBEDTLSLIBPATH) -I$(JANSSONLIBPATH) -I$(CBORLIBPATH) -I$(ZLIBPATH) -I$(REVENGPATH) -I$(AMIIBOLIBPATH) INCLUDES_CLIENT = -I./src -I./deps -I../include -I../common -I./deps/cliparser -I./src/uart $(LIBS) -CFLAGS ?= -Wall -Werror -g -O3 +CFLAGS ?= -Wall -Werror -O3 # We cannot just use CFLAGS+=... because it has impact on sub-makes if CFLAGS is defined in env: PM3CFLAGS = $(CFLAGS) -std=c99 -D_ISOC99_SOURCE $(INCLUDES_CLIENT) PREFIX ?= /usr/local From edb96e75cf81a38dfa2a14951c809f57af3cfe8a Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 18 Apr 2020 12:20:42 +0200 Subject: [PATCH 05/70] Add QT_NO_DEBUG flag --- client/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/client/Makefile b/client/Makefile index 608445f55..892feadf7 100644 --- a/client/Makefile +++ b/client/Makefile @@ -112,6 +112,7 @@ ifneq ($(QTLDLIBS),) QTGUISRCS = proxgui.cpp proxguiqt.cpp proxguiqt.moc.cpp QTGUIOBJS = $(OBJDIR)/proxgui.o $(OBJDIR)/proxguiqt.o $(OBJDIR)/proxguiqt.moc.o PM3CFLAGS += -DHAVE_GUI + PM3CXXFLAGS += -DQT_NO_DEBUG else QTGUISRCS = guidummy.cpp QTGUIOBJS = $(OBJDIR)/guidummy.o From 6b1a8b8390a04b1e38bfb8aaf77b29f48440f783 Mon Sep 17 00:00:00 2001 From: Bjoern Kerler Date: Thu, 16 Apr 2020 10:57:53 +0200 Subject: [PATCH 06/70] Add cmake support --- client/CMakeLists.txt | 424 +++++++++++++++++++++++++++++++++++ client/cmake/FindSSE.cmake | 168 ++++++++++++++ client/deps/CMakeLists.txt | 8 + client/deps/amiibo.cmake | 28 +++ client/deps/hardnested.cmake | 115 ++++++++++ client/deps/jansson.cmake | 18 ++ client/deps/lua.cmake | 58 +++++ client/deps/mbedtls.cmake | 49 ++++ client/deps/reveng.cmake | 15 ++ client/deps/tinycbor.cmake | 10 + client/deps/zlib.cmake | 15 ++ 11 files changed, 908 insertions(+) create mode 100644 client/CMakeLists.txt create mode 100644 client/cmake/FindSSE.cmake create mode 100644 client/deps/CMakeLists.txt create mode 100644 client/deps/amiibo.cmake create mode 100644 client/deps/hardnested.cmake create mode 100644 client/deps/jansson.cmake create mode 100644 client/deps/lua.cmake create mode 100644 client/deps/mbedtls.cmake create mode 100644 client/deps/reveng.cmake create mode 100644 client/deps/tinycbor.cmake create mode 100644 client/deps/zlib.cmake diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt new file mode 100644 index 000000000..1d5b4baf5 --- /dev/null +++ b/client/CMakeLists.txt @@ -0,0 +1,424 @@ +cmake_minimum_required(VERSION 3.16) +project(proxmark3) + +set(CMAKE_CXX_STANDARD 14) + +find_package(Qt5 COMPONENTS Widgets Gui) + +SET (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake") + +INCLUDE(FindSSE) +#[[ +IF(SSE3_FOUND) + IF(SSSE3_FOUND) + SET(CXX_DFLAGS -msse3 -mssse3) + ENDIF(SSSE3_FOUND) +ENDIF(SSE3_FOUND) + +IF(SSE4_2_FOUND) + SET(CXX_DFLAGS -msse4.2 -mpopcnt) +ENDIF(SSE4_2_FOUND) +ADD_DEFINITIONS(${CXX_DFLAGS}) +]] +if(NOT SSE2_FOUND) + MESSAGE(STATUS "Could not find hardware support for SSE2 on this machine.") +endif(NOT SSE2_FOUND) +if(NOT SSE3_FOUND) + MESSAGE(STATUS "Could not find hardware support for SSE3 on this machine.") +endif(NOT SSE3_FOUND) +if(NOT SSSE3_FOUND) + MESSAGE(STATUS "Could not find hardware support for SSSE3 on this machine.") +endif(NOT SSSE3_FOUND) +if(NOT SSE4_1_FOUND) + MESSAGE(STATUS "Could not find hardware support for SSE4.1 on this machine.") +endif(NOT SSE4_1_FOUND) +if(NOT AVX_FOUND) + MESSAGE(STATUS "Could not find hardware support for AVX on this machine.") +endif(NOT AVX_FOUND) +if(NOT AVX2_FOUND) + MESSAGE(STATUS "Could not find hardware support for AVX2 on this machine.") +endif(NOT AVX2_FOUND) +if(NOT AVX512_FOUND) + MESSAGE(STATUS "Could not find hardware support for AVX512 on this machine.") +endif(NOT AVX512_FOUND) + +add_subdirectory(deps) + +include_directories( + .. + SYSTEM + deps + ../common + ../include + deps/jansson + deps/tinycbor + deps/liblua + client/deps/mbedtls/include + deps/amiitool + deps/cliparser + deps/reveng + ../common/zlib + src + src/uart +) + +#file(GLOB_RECURSE TARGET_HEADERS ${CMAKE_CURRENT_LIST_DIR}/src/*.h) +#file(GLOB_RECURSE TARGET_SOURCES ${CMAKE_CURRENT_LIST_DIR}/src/*.cpp) + +set (TARGET_SOURCES + src/proxmark3.c + src/proxmark3.h + ../common/commonutil.c + ../common/commonutil.h + ../common/util_posix.c + ../common/util_posix.h + ../common/parity.c + ../common/parity.h + ../common/bucketsort.c + ../common/bucketsort.h + ../common/crapto1/crapto1.c + ../common/crapto1/crapto1.h + ../common/crapto1/crypto1.c + ../common/crc.c + ../common/crc.h + ../common/crc16.c + ../common/crc16.h + ../common/crc32.c + ../common/crc32.h + ../common/crc64.c + ../common/crc64.h + ../common/lfdemod.c + ../common/lfdemod.h + ../common/legic_prng.c + ../common/legic_prng.h + ../common/iso15693tools.c + ../common/iso15693tools.h + ../common/cardhelper.c + ../common/cardhelper.h + ../common/generator.c + ../common/generator.h + deps/cliparser/argtable3.c + deps/cliparser/argtable3.h + deps/cliparser/cliparser.c + deps/cliparser/cliparser.h + deps/cliparser/getopt.h + deps/hardnested/hardnested_bruteforce.c + deps/hardnested/hardnested_bruteforce.h + src/crypto/asn1dump.c + src/crypto/asn1dump.h + src/crypto/asn1utils.c + src/crypto/asn1utils.h + src/crypto/libpcrypto.c + src/crypto/libpcrypto.h + src/emv/test/cda_test.c + src/emv/test/cda_test.h + src/emv/test/crypto_test.c + src/emv/test/crypto_test.h + src/emv/test/cryptotest.c + src/emv/test/cryptotest.h + src/emv/test/dda_test.c + src/emv/test/dda_test.h + src/emv/test/sda_test.c + src/emv/test/sda_test.h + src/emv/apduinfo.c + src/emv/apduinfo.h + src/emv/cmdemv.c + src/emv/cmdemv.h + src/emv/crypto.c + src/emv/crypto.h + src/emv/crypto_backend.h + src/emv/crypto_polarssl.c + src/emv/dol.c + src/emv/dol.h + src/emv/dump.c + src/emv/dump.h + src/emv/emv_pk.c + src/emv/emv_pk.h + src/emv/emv_pki.c + src/emv/emv_pki.h + src/emv/emv_pki_priv.c + src/emv/emv_pki_priv.h + src/emv/emv_roca.c + src/emv/emv_roca.h + src/emv/emv_tags.c + src/emv/emv_tags.h + src/emv/emvcore.c + src/emv/emvcore.h + src/emv/emvjson.c + src/emv/emvjson.h + src/emv/tlv.c + src/emv/tlv.h + src/fido/additional_ca.c + src/fido/additional_ca.h + src/fido/cbortools.c + src/fido/cbortools.h + src/fido/cose.c + src/fido/cose.h + src/fido/fidocore.c + src/fido/fidocore.h + src/loclass/cipher.c + src/loclass/cipher.h + src/loclass/cipherutils.c + src/loclass/cipherutils.h + src/loclass/elite_crack.c + src/loclass/elite_crack.h + src/loclass/hash1_brute.c + src/loclass/hash1_brute.h + src/loclass/ikeys.c + src/loclass/ikeys.h + src/mifare/mad.c + src/mifare/mad.h + src/mifare/mfkey.c + src/mifare/mfkey.h + src/mifare/mifare4.c + src/mifare/mifare4.h + src/mifare/mifaredefault.c + src/mifare/mifaredefault.h + src/mifare/mifarehost.c + src/mifare/mifarehost.h + src/mifare/ndef.c + src/mifare/ndef.h + src/mifare/desfire_crypto.c + src/mifare/desfire_crypto.h + src/uart/uart.h + src/uart/uart_posix.c + src/uart/uart_win32.c + src/ui/overlays.ui + src/aidsearch.c + src/aidsearch.h + src/cmdanalyse.c + src/cmdanalyse.h + src/cmdcrc.c + src/cmdcrc.h + src/cmddata.c + src/cmddata.h + src/cmdflashmem.c + src/cmdflashmem.h + src/cmdflashmemspiffs.c + src/cmdflashmemspiffs.h + src/cmdhf.c + src/cmdhf.h + src/cmdhf14a.c + src/cmdhf14a.h + src/cmdhf14b.c + src/cmdhf14b.h + src/cmdhf15.c + src/cmdhf15.h + src/cmdhfcryptorf.c + src/cmdhfcryptorf.h + src/cmdhfepa.c + src/cmdhfepa.h + src/cmdhffelica.c + src/cmdhffelica.h + src/cmdhffido.c + src/cmdhffido.h + src/cmdhficlass.c + src/cmdhficlass.h + src/cmdhflegic.c + src/cmdhflegic.h + src/cmdhflist.c + src/cmdhflist.h + src/cmdhflto.c + src/cmdhflto.h + src/cmdhfmf.c + src/cmdhfmf.h + src/cmdhfmfdes.c + src/cmdhfmfdes.h + src/cmdhfmfhard.c + src/cmdhfmfhard.h + src/cmdhfmfp.c + src/cmdhfmfp.h + src/cmdhfmfu.c + src/cmdhfmfu.h + src/cmdhfthinfilm.c + src/cmdhfthinfilm.h + src/cmdhftopaz.c + src/cmdhftopaz.h + src/cmdhw.c + src/cmdhw.h + src/cmdlf.c + src/cmdlf.h + src/cmdlfawid.c + src/cmdlfawid.h + src/cmdlfcotag.c + src/cmdlfcotag.h + src/cmdlfem4x.c + src/cmdlfem4x.h + src/cmdlffdx.c + src/cmdlffdx.h + src/cmdlfgallagher.c + src/cmdlfgallagher.h + src/cmdlfguard.c + src/cmdlfguard.h + src/cmdlfhid.c + src/cmdlfhid.h + src/cmdlfhitag.c + src/cmdlfhitag.h + src/cmdlfindala.c + src/cmdlfindala.h + src/cmdlfio.c + src/cmdlfio.h + src/cmdlfjablotron.c + src/cmdlfjablotron.h + src/cmdlfkeri.c + src/cmdlfkeri.h + src/cmdlfmotorola.c + src/cmdlfmotorola.h + src/cmdlfnedap.c + src/cmdlfnedap.h + src/cmdlfnexwatch.c + src/cmdlfnexwatch.h + src/cmdlfnoralsy.c + src/cmdlfnoralsy.h + src/cmdlfpac.c + src/cmdlfpac.h + src/cmdlfparadox.c + src/cmdlfparadox.h + src/cmdlfpcf7931.c + src/cmdlfpcf7931.h + src/cmdlfpresco.c + src/cmdlfpresco.h + src/cmdlfpyramid.c + src/cmdlfpyramid.h + src/cmdlfsecurakey.c + src/cmdlfsecurakey.h + src/cmdlft55xx.c + src/cmdlft55xx.h + src/cmdlfti.c + src/cmdlfti.h + src/cmdlfverichip.c + src/cmdlfverichip.h + src/cmdlfviking.c + src/cmdlfviking.h + src/cmdlfvisa2000.c + src/cmdlfvisa2000.h + src/cmdmain.c + src/cmdmain.h + src/cmdparser.c + src/cmdparser.h + src/cmdscript.c + src/cmdscript.h + src/cmdsmartcard.c + src/cmdsmartcard.h + src/cmdtrace.c + src/cmdtrace.h + src/cmdusart.c + src/cmdusart.h + src/cmdwiegand.c + src/cmdwiegand.h + src/comms.c + src/comms.h + src/elf.h + src/emojis.h + src/emojis_alt.h + src/fileutils.c + src/fileutils.h + src/flash.c + src/flash.h + src/graph.c + src/graph.h + src/guidummy.cpp + src/preferences.c + src/preferences.h + src/pm3_binlib.c + src/pm3_binlib.h + src/pm3_bit_limits.h + src/pm3_bitlib.c + src/pm3_bitlib.h + src/polarssl_config.h + src/prng.c + src/prng.h + src/proxendian.h + src/scandir.c + src/scandir.h + src/scripting.c + src/scripting.h + src/tea.c + src/tea.h + src/ui.c + src/ui.h + src/util.c + src/util.h + src/whereami.c + src/whereami.h + src/wiegand_formats.c + src/wiegand_formats.h + src/wiegand_formatutils.c + src/wiegand_formatutils.h + ) + +set(ADDITIONAL_SRC "") +set(ADDITIONAL_LNK "") + +set(X86_CPUS x86 x86_64 i686) + +message(STATUS "CMAKE_SYSTEM_PROCESSOR := ${CMAKE_SYSTEM_PROCESSOR}") + +if (APPLE) + message("Apple device detected.") + set(ADDITIONAL_SRC src/util_darwin.h src/util_darwin.m ${ADDITIONAL_SRC}) + set(ADDITIONAL_LNK "-framework Foundation" "-framework AppKit") + set_target_properties(proxmark3 PROPERTIES LINK_FLAGS "-Wl,-F/Library/Frameworks") +endif (APPLE) + +if (MINGW) + set(CMAKE_CXX_FLAGS "-mno-ms-bitfields -fexec-charset=cp850 ${CMAKE_CXX_FLAGS}") +endif (MINGW) + +set(CMAKE_CXX_FLAGS "-Wall -Werror -O3") + +add_executable( + proxmark3 + ${TARGET_SOURCES} +) + +if(NOT Qt5_LIB) + message("Qt5 library not found, not building gui") +endif() +if (Qt5_LIB) + add_executable(proxguiqt + src/proxgui.cpp + src/proxgui.h + src/proxguiqt.cpp + src/proxguiqt.h) +endif (Qt5_LIB) + + +find_library(jansson REQUIRED) +find_library(tinycbor REQUIRED) +find_library(lua REQUIRED) +find_library(mbedtls REQUIRED) +find_library(reveng REQUIRED) +find_library(z REQUIRED) +find_library(hardnested REQUIRED) + +target_include_directories(proxmark3 PUBLIC mbedtls jansson lua tinycbor amiibo reveng z hardnested) +target_link_libraries(proxmark3 readline pthread m mbedtls jansson lua tinycbor amiibo reveng z hardnested ${ADDITIONAL_LNK}) + +install(TARGETS proxmark3 DESTINATION "bin") +install(DIRECTORY cmdscripts lualibs luascripts resources dictionaries DESTINATION "share/proxmark3") + +add_custom_command(OUTPUT lualibs/pm3_cmd.lua + COMMAND "awk -f pm3_cmd_h2lua.awk ../include/pm3_cmd.h > lualibs/pm3_cmd.lua" + COMMENT "Creating lualibs/pm3_cmd.lua" + ) + +add_custom_command(OUTPUT lualibs/mfc_default_keys.lua + COMMAND "awk -f default_keys_dic2lua.awk mfc_default_keys.dic > lualibs/mfc_default_keys.lua" + COMMENT "Creating lualibs/mfc_default_keys.lua" + ) + +add_custom_command(OUTPUT src/proxguiqt.moc.cpp + COMMAND "$(MOC) -o src/proxguiqt.moc.cpp proxguiqt.h" + COMMENT "Creating src/proxguiqt.moc.cpp" + ) + +add_custom_command(OUTPUT src/ui/ui_overlays.h + COMMAND "$(UIC) src/ui/overlays.ui > src/ui/ui_overlays.h" + COMMENT "Creating ui/ui_overlays.h" + ) + +#"make package" will trigger this +SET(CPACK_GENERATOR "DEB") +SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "Iceman") +INCLUDE(CPack) \ No newline at end of file diff --git a/client/cmake/FindSSE.cmake b/client/cmake/FindSSE.cmake new file mode 100644 index 000000000..14021e1c1 --- /dev/null +++ b/client/cmake/FindSSE.cmake @@ -0,0 +1,168 @@ +# Check if SSE/AVX instructions are available on the machine where +# the project is compiled. + +IF(CMAKE_SYSTEM_NAME MATCHES "Linux") + EXEC_PROGRAM(cat ARGS "/proc/cpuinfo" OUTPUT_VARIABLE CPUINFO) + + STRING(REGEX REPLACE "^.*(sse2).*$" "\\1" SSE_THERE ${CPUINFO}) + STRING(COMPARE EQUAL "sse2" "${SSE_THERE}" SSE2_TRUE) + IF (SSE2_TRUE) + set(SSE2_FOUND true CACHE BOOL "SSE2 available on host") + ELSE (SSE2_TRUE) + set(SSE2_FOUND false CACHE BOOL "SSE2 available on host") + ENDIF (SSE2_TRUE) + + # /proc/cpuinfo apparently omits sse3 :( + STRING(REGEX REPLACE "^.*[^s](sse3).*$" "\\1" SSE_THERE ${CPUINFO}) + STRING(COMPARE EQUAL "sse3" "${SSE_THERE}" SSE3_TRUE) + IF (NOT SSE3_TRUE) + STRING(REGEX REPLACE "^.*(T2300).*$" "\\1" SSE_THERE ${CPUINFO}) + STRING(COMPARE EQUAL "T2300" "${SSE_THERE}" SSE3_TRUE) + ENDIF (NOT SSE3_TRUE) + + STRING(REGEX REPLACE "^.*(ssse3).*$" "\\1" SSE_THERE ${CPUINFO}) + STRING(COMPARE EQUAL "ssse3" "${SSE_THERE}" SSSE3_TRUE) + IF (SSE3_TRUE OR SSSE3_TRUE) + set(SSE3_FOUND true CACHE BOOL "SSE3 available on host") + ELSE (SSE3_TRUE OR SSSE3_TRUE) + set(SSE3_FOUND false CACHE BOOL "SSE3 available on host") + ENDIF (SSE3_TRUE OR SSSE3_TRUE) + IF (SSSE3_TRUE) + set(SSSE3_FOUND true CACHE BOOL "SSSE3 available on host") + ELSE (SSSE3_TRUE) + set(SSSE3_FOUND false CACHE BOOL "SSSE3 available on host") + ENDIF (SSSE3_TRUE) + + STRING(REGEX REPLACE "^.*(sse4_1).*$" "\\1" SSE_THERE ${CPUINFO}) + STRING(COMPARE EQUAL "sse4_1" "${SSE_THERE}" SSE41_TRUE) + IF (SSE41_TRUE) + set(SSE4_1_FOUND true CACHE BOOL "SSE4.1 available on host") + ELSE (SSE41_TRUE) + set(SSE4_1_FOUND false CACHE BOOL "SSE4.1 available on host") + ENDIF (SSE41_TRUE) + + STRING(REGEX REPLACE "^.*(avx).*$" "\\1" SSE_THERE ${CPUINFO}) + STRING(COMPARE EQUAL "avx" "${SSE_THERE}" AVX_TRUE) + IF (AVX_TRUE) + set(AVX_FOUND true CACHE BOOL "AVX available on host") + ELSE (AVX_TRUE) + set(AVX_FOUND false CACHE BOOL "AVX available on host") + ENDIF (AVX_TRUE) + + STRING(REGEX REPLACE "^.*(avx2).*$" "\\1" SSE_THERE ${CPUINFO}) + STRING(COMPARE EQUAL "avx2" "${SSE_THERE}" AVX2_TRUE) + IF (AVX2_TRUE) + set(AVX2_FOUND true CACHE BOOL "AVX2 available on host") + ELSE (AVX2_TRUE) + set(AVX2_FOUND false CACHE BOOL "AVX2 available on host") + ENDIF (AVX2_TRUE) + + STRING(REGEX REPLACE "^.*(avx512).*$" "\\1" SSE_THERE ${CPUINFO}) + STRING(COMPARE EQUAL "avx512" "${SSE_THERE}" AVX2_TRUE) + IF (AVX512_TRUE) + set(AVX512_FOUND true CACHE BOOL "AVX512 available on host") + ELSE (AVX2_TRUE) + set(AVX512_FOUND false CACHE BOOL "AVX512 available on host") + ENDIF (AVX512_TRUE) + +ELSEIF(CMAKE_SYSTEM_NAME MATCHES "Darwin") + EXEC_PROGRAM("/usr/sbin/sysctl -n machdep.cpu.features" OUTPUT_VARIABLE + CPUINFO) + + STRING(REGEX REPLACE "^.*[^S](SSE2).*$" "\\1" SSE_THERE ${CPUINFO}) + STRING(COMPARE EQUAL "SSE2" "${SSE_THERE}" SSE2_TRUE) + IF (SSE2_TRUE) + set(SSE2_FOUND true CACHE BOOL "SSE2 available on host") + ELSE (SSE2_TRUE) + set(SSE2_FOUND false CACHE BOOL "SSE2 available on host") + ENDIF (SSE2_TRUE) + + STRING(REGEX REPLACE "^.*[^S](SSE3).*$" "\\1" SSE_THERE ${CPUINFO}) + STRING(COMPARE EQUAL "SSE3" "${SSE_THERE}" SSE3_TRUE) + IF (SSE3_TRUE) + set(SSE3_FOUND true CACHE BOOL "SSE3 available on host") + ELSE (SSE3_TRUE) + set(SSE3_FOUND false CACHE BOOL "SSE3 available on host") + ENDIF (SSE3_TRUE) + + STRING(REGEX REPLACE "^.*(SSSE3).*$" "\\1" SSE_THERE ${CPUINFO}) + STRING(COMPARE EQUAL "SSSE3" "${SSE_THERE}" SSSE3_TRUE) + IF (SSSE3_TRUE) + set(SSSE3_FOUND true CACHE BOOL "SSSE3 available on host") + ELSE (SSSE3_TRUE) + set(SSSE3_FOUND false CACHE BOOL "SSSE3 available on host") + ENDIF (SSSE3_TRUE) + + STRING(REGEX REPLACE "^.*(SSE4.1).*$" "\\1" SSE_THERE ${CPUINFO}) + STRING(COMPARE EQUAL "SSE4.1" "${SSE_THERE}" SSE41_TRUE) + IF (SSE41_TRUE) + set(SSE4_1_FOUND true CACHE BOOL "SSE4.1 available on host") + ELSE (SSE41_TRUE) + set(SSE4_1_FOUND false CACHE BOOL "SSE4.1 available on host") + ENDIF (SSE41_TRUE) + + STRING(REGEX REPLACE "^.*(AVX).*$" "\\1" SSE_THERE ${CPUINFO}) + STRING(COMPARE EQUAL "AVX" "${SSE_THERE}" AVX_TRUE) + IF (AVX_TRUE) + set(AVX_FOUND true CACHE BOOL "AVX available on host") + ELSE (AVX_TRUE) + set(AVX_FOUND false CACHE BOOL "AVX available on host") + ENDIF (AVX_TRUE) + + STRING(REGEX REPLACE "^.*(AVX2).*$" "\\1" SSE_THERE ${CPUINFO}) + STRING(COMPARE EQUAL "AVX2" "${SSE_THERE}" AVX2_TRUE) + IF (AVX2_TRUE) + set(AVX2_FOUND true CACHE BOOL "AVX2 available on host") + ELSE (AVX2_TRUE) + set(AVX2_FOUND false CACHE BOOL "AVX2 available on host") + ENDIF (AVX2_TRUE) + + STRING(REGEX REPLACE "^.*(AVX512).*$" "\\1" SSE_THERE ${CPUINFO}) + STRING(COMPARE EQUAL "AVX512" "${SSE_THERE}" AVX2_TRUE) + IF (AVX2_TRUE) + set(AVX2_FOUND true CACHE BOOL "AVX512 available on host") + ELSE (AVX2_TRUE) + set(AVX2_FOUND false CACHE BOOL "AVX512 available on host") + ENDIF (AVX2_TRUE) + +ELSEIF(CMAKE_SYSTEM_NAME MATCHES "Windows") + # TODO + set(SSE2_FOUND true CACHE BOOL "SSE2 available on host") + set(SSE3_FOUND false CACHE BOOL "SSE3 available on host") + set(SSSE3_FOUND false CACHE BOOL "SSSE3 available on host") + set(SSE4_1_FOUND false CACHE BOOL "SSE4.1 available on host") + set(AVX_FOUND false CACHE BOOL "AVX available on host") + set(AVX2_FOUND false CACHE BOOL "AVX2 available on host") + set(AVX512_FOUND false CACHE BOOL "AVX512 available on host") +ELSE(CMAKE_SYSTEM_NAME MATCHES "Linux") + set(SSE2_FOUND true CACHE BOOL "SSE2 available on host") + set(SSE3_FOUND false CACHE BOOL "SSE3 available on host") + set(SSSE3_FOUND false CACHE BOOL "SSSE3 available on host") + set(SSE4_1_FOUND false CACHE BOOL "SSE4.1 available on host") + set(AVX_FOUND false CACHE BOOL "AVX available on host") + set(AVX2_FOUND false CACHE BOOL "AVX2 available on host") + set(AVX512_FOUND false CACHE BOOL "AVX512 available on host") +ENDIF(CMAKE_SYSTEM_NAME MATCHES "Linux") + +if(NOT SSE2_FOUND) + MESSAGE(STATUS "Could not find hardware support for SSE2 on this machine.") +endif(NOT SSE2_FOUND) +if(NOT SSE3_FOUND) + MESSAGE(STATUS "Could not find hardware support for SSE3 on this machine.") +endif(NOT SSE3_FOUND) +if(NOT SSSE3_FOUND) + MESSAGE(STATUS "Could not find hardware support for SSSE3 on this machine.") +endif(NOT SSSE3_FOUND) +if(NOT SSE4_1_FOUND) + MESSAGE(STATUS "Could not find hardware support for SSE4.1 on this machine.") +endif(NOT SSE4_1_FOUND) +if(NOT AVX_FOUND) + MESSAGE(STATUS "Could not find hardware support for AVX on this machine.") +endif(NOT AVX_FOUND) +if(NOT AVX2_FOUND) + MESSAGE(STATUS "Could not find hardware support for AVX2 on this machine.") +endif(NOT AVX2_FOUND) +if(NOT AVX512_FOUND) + MESSAGE(STATUS "Could not find hardware support for AVX512 on this machine.") +endif(NOT AVX512_FOUND) +mark_as_advanced(SSE2_FOUND SSE3_FOUND SSSE3_FOUND SSE4_1_FOUND, AVX_FOUND, AVX2_FOUND) diff --git a/client/deps/CMakeLists.txt b/client/deps/CMakeLists.txt new file mode 100644 index 000000000..f77a53305 --- /dev/null +++ b/client/deps/CMakeLists.txt @@ -0,0 +1,8 @@ +include(tinycbor.cmake) +include(jansson.cmake) +include(lua.cmake) +include(mbedtls.cmake) +include(amiibo.cmake) +include(reveng.cmake) +include(zlib.cmake) +include(hardnested.cmake) \ No newline at end of file diff --git a/client/deps/amiibo.cmake b/client/deps/amiibo.cmake new file mode 100644 index 000000000..8e21d1011 --- /dev/null +++ b/client/deps/amiibo.cmake @@ -0,0 +1,28 @@ +# just for testing amiitool before complete migration into a lib: + +#amiitool: +#gcc $(CFLAGS) \ +#amiitool.c $(MYSRCS) ../../../../common/../../commonutil.c ../ui.c -lreadline -lm ../../../../common/mbedtls/libmbedtls.a \ +#-o amiitool + +set_property(SOURCE PROPERTY C_STANDARD 99) +add_definitions(-D_ISOC99_SOURCE) +include_directories(jansson) +include_directories(../../common) +include_directories(../../common/include) +include_directories(amiitool) + +add_library(amiibo + jansson/dump.c + jansson/error.c + jansson/hashtable.c + jansson/hashtable_seed.c + jansson/load.c + jansson/memory.c + jansson/pack_unpack.c + jansson/strbuffer.c + jansson/strconv.c + jansson/utf.c + jansson/path.c + jansson/value.c +) diff --git a/client/deps/hardnested.cmake b/client/deps/hardnested.cmake new file mode 100644 index 000000000..b9e0bfa82 --- /dev/null +++ b/client/deps/hardnested.cmake @@ -0,0 +1,115 @@ +set_property(SOURCE PROPERTY C_STANDARD 99) +add_definitions(-DHAVE_STDINT_H) +include_directories(hardnested) + +## CPU-specific code +## These are mostly for x86-based architectures, which is not useful for many Android devices. +add_library(hardnested_nosimd OBJECT + hardnested/hardnested_bf_core.c + hardnested/hardnested_bitarray_core.c) + +target_include_directories(hardnested_nosimd PRIVATE + ../../common + ../../include + hardnested) + +set(X86_CPUS x86 x86_64 i686) + +message(STATUS "CMAKE_SYSTEM_PROCESSOR := ${CMAKE_SYSTEM_PROCESSOR}") + +if ("${CMAKE_SYSTEM_PROCESSOR}" IN_LIST X86_CPUS) + message(STATUS "Building optimised x86/x86_64 binaries") + target_compile_options(hardnested_nosimd BEFORE PRIVATE + -mno-mmx -mno-sse2 -mno-avx -mno-avx2 -mno-avx512f) + + set_property(TARGET hardnested_nosimd PROPERTY POSITION_INDEPENDENT_CODE ON) + + ## x86 / MMX + add_library(hardnested_mmx OBJECT + hardnested/hardnested_bf_core.c + hardnested/hardnested_bitarray_core.c) + + target_compile_options(hardnested_mmx BEFORE PRIVATE + -mmmx -mno-sse2 -mno-avx -mno-avx2 -mno-avx512f) + + target_include_directories(hardnested_mmx PRIVATE + ../../common + ../../include + hardnested) + + set_property(TARGET hardnested_mmx PROPERTY POSITION_INDEPENDENT_CODE ON) + + ## x86 / SSE2 + add_library(hardnested_sse2 OBJECT + hardnested/hardnested_bf_core.c + hardnested/hardnested_bitarray_core.c) + + target_compile_options(hardnested_sse2 BEFORE PRIVATE + -mmmx -msse2 -mno-avx -mno-avx2 -mno-avx512f) + + target_include_directories(hardnested_sse2 PRIVATE + ../../common + ../../include + hardnested) + + set_property(TARGET hardnested_sse2 PROPERTY POSITION_INDEPENDENT_CODE ON) + + ## x86 / AVX + add_library(hardnested_avx OBJECT + hardnested/hardnested_bf_core.c + hardnested/hardnested_bitarray_core.c) + + target_compile_options(hardnested_avx BEFORE PRIVATE + -mmmx -msse2 -mavx -mno-avx2 -mno-avx512f) + + target_include_directories(hardnested_avx PRIVATE + ../../common + ../../include + hardnested) + + set_property(TARGET hardnested_avx PROPERTY POSITION_INDEPENDENT_CODE ON) + + ## x86 / AVX2 + add_library(hardnested_avx2 OBJECT + hardnested/hardnested_bf_core.c + hardnested/hardnested_bitarray_core.c) + + target_compile_options(hardnested_avx2 BEFORE PRIVATE + -mmmx -msse2 -mavx -mavx2 -mno-avx512f) + + target_include_directories(hardnested_avx2 PRIVATE + ../../common + ../../include + hardnested) + + set_property(TARGET hardnested_avx2 PROPERTY POSITION_INDEPENDENT_CODE ON) + + ## x86 / AVX512 + add_library(hardnested_avx512 OBJECT + hardnested/hardnested_bf_core.c + hardnested/hardnested_bitarray_core.c) + + target_compile_options(hardnested_avx512 BEFORE PRIVATE + -mmmx -msse2 -mavx -mavx2 -mavx512f) + + target_include_directories(hardnested_avx512 PRIVATE + ../../common + ../../include + hardnested) + + set_property(TARGET hardnested_avx512 PROPERTY POSITION_INDEPENDENT_CODE ON) + + set(SIMD_TARGETS + $ + $ + $ + $ + $) +else () + message(STATUS "Not building optimised targets") + set(SIMD_TARGETS) +endif () + +add_library(hardnested STATIC + $ + ${SIMD_TARGETS}) diff --git a/client/deps/jansson.cmake b/client/deps/jansson.cmake new file mode 100644 index 000000000..f35d7dbc9 --- /dev/null +++ b/client/deps/jansson.cmake @@ -0,0 +1,18 @@ +set_property(SOURCE PROPERTY C_STANDARD 99) +add_definitions(-DHAVE_STDINT_H) +include_directories(jansson) + +add_library(jansson + jansson/dump.c + jansson/error.c + jansson/hashtable.c + jansson/hashtable_seed.c + jansson/load.c + jansson/memory.c + jansson/pack_unpack.c + jansson/strbuffer.c + jansson/strconv.c + jansson/utf.c + jansson/path.c + jansson/value.c +) diff --git a/client/deps/lua.cmake b/client/deps/lua.cmake new file mode 100644 index 000000000..916d79c6f --- /dev/null +++ b/client/deps/lua.cmake @@ -0,0 +1,58 @@ +add_definitions(-DLUA_COMPAT_ALL $(SYSCFLAGS)) +include_directories(liblua) + +set(SYSCFLAGS "-DLUA_COMPAT_ALL") + +if (UNIX) + set(SYSCFLAGS "-DLUA_USE_LINUX") +endif (UNIX) + +if (WIN32) + set(SYSCFLAGS "-DLUA_USE_LINUX") +endif (WIN32) + +if (MINGW) + set(SYSCFLAGS "-DLUA_COMPAT_ALL $(SYSCFLAGS)") +endif (MINGW) + +if (APPLE) + set(SYSCFLAGS "-DLUA_USE_MACOSX") +endif (APPLE) + +add_definitions($(SYSCFLAGS)) + +add_library(lua + liblua/lapi.c + liblua/lcode.c + liblua/lctype.c + liblua/ldebug.c + liblua/ldo.c + liblua/ldump.c + liblua/lfunc.c + liblua/lgc.c + liblua/llex.c + liblua/lmem.c + liblua/lobject.c + liblua/lopcodes.c + liblua/lparser.c + liblua/lstate.c + liblua/lstring.c + liblua/ltable.c + liblua/ltm.c + liblua/lundump.c + liblua/lvm.c + liblua/lzio.c + liblua/lauxlib.c + liblua/lbaselib.c + liblua/lbitlib.c + liblua/lcorolib.c + liblua/ldblib.c + liblua/liolib.c + liblua/lmathlib.c + liblua/loslib.c + liblua/lstrlib.c + liblua/ltablib.c + liblua/loadlib.c + liblua/linit.c +) + diff --git a/client/deps/mbedtls.cmake b/client/deps/mbedtls.cmake new file mode 100644 index 000000000..0b4c04e62 --- /dev/null +++ b/client/deps/mbedtls.cmake @@ -0,0 +1,49 @@ +set_property(SOURCE PROPERTY C_STANDARD 99) +add_definitions(-DHAVE_STDINT_H) +include_directories(../../common) + +add_library(mbedtls + ../../common/mbedtls/aes.c + ../../common/mbedtls/asn1parse.c + ../../common/mbedtls/asn1write.c + ../../common/mbedtls/base64.c + ../../common/mbedtls/bignum.c + ../../common/mbedtls/ctr_drbg.c + ../../common/mbedtls/entropy_poll.c + ../../common/mbedtls/entropy.c + ../../common/mbedtls/error.c + ../../common/mbedtls/timing.c + ../../common/mbedtls/ecp.c + ../../common/mbedtls/ecp_curves.c + ../../common/mbedtls/certs.c + ../../common/mbedtls/camellia.c + ../../common/mbedtls/blowfish.c + ../../common/mbedtls/cipher_wrap.c + ../../common/mbedtls/cipher.c + ../../common/mbedtls/cmac.c + ../../common/mbedtls/des.c + ../../common/mbedtls/ecdsa.c + ../../common/mbedtls/md.c + ../../common/mbedtls/md_wrap.c + ../../common/mbedtls/md5.c + ../../common/mbedtls/oid.c + ../../common/mbedtls/pem.c + ../../common/mbedtls/arc4.c + ../../common/mbedtls/pk.c + ../../common/mbedtls/pk_wrap.c + ../../common/mbedtls/pkwrite.c + ../../common/mbedtls/pkcs5.c + ../../common/mbedtls/pkcs12.c + ../../common/mbedtls/pkparse.c + ../../common/mbedtls/platform.c + ../../common/mbedtls/platform_util.c + ../../common/mbedtls/rsa.c + ../../common/mbedtls/rsa_internal.c + ../../common/mbedtls/sha1.c + ../../common/mbedtls/sha256.c + ../../common/mbedtls/sha512.c + ../../common/mbedtls/threading.c + ../../common/mbedtls/x509.c + ../../common/mbedtls/x509_crl.c + ../../common/mbedtls/x509_crt.c + ) diff --git a/client/deps/reveng.cmake b/client/deps/reveng.cmake new file mode 100644 index 000000000..5df1e85f2 --- /dev/null +++ b/client/deps/reveng.cmake @@ -0,0 +1,15 @@ +set_property(SOURCE PROPERTY C_STANDARD 99) +add_definitions(-DPRESETS) +include_directories(reveng) +include_directories(.) + +add_library(reveng + reveng/bmpbit.c + reveng/cli.c + reveng/getopt.c + reveng/model.c + reveng/poly.c + reveng/preset.c + reveng/reveng.c +) + diff --git a/client/deps/tinycbor.cmake b/client/deps/tinycbor.cmake new file mode 100644 index 000000000..f58011e93 --- /dev/null +++ b/client/deps/tinycbor.cmake @@ -0,0 +1,10 @@ +add_library(tinycbor + tinycbor/cborencoder.c + tinycbor/cborencoder_close_container_checked.c + tinycbor/cborerrorstrings.c + tinycbor/cborparser.c + tinycbor/cborparser_dup_string.c + tinycbor/cborpretty.c + tinycbor/cbortojson.c + tinycbor/cborvalidation.c + ) \ No newline at end of file diff --git a/client/deps/zlib.cmake b/client/deps/zlib.cmake new file mode 100644 index 000000000..28b42d74c --- /dev/null +++ b/client/deps/zlib.cmake @@ -0,0 +1,15 @@ +set_property(SOURCE PROPERTY C_STANDARD 99) +add_definitions(-D_ISOC99_SOURCE -DZ_SOLO -DNO_GZIP -DZLIB_PM3_TUNED) +include_directories(../../common/zlib) + +add_library(z + ../../common/zlib/deflate.c + ../../common/zlib/adler32.c + ../../common/zlib/trees.c + ../../common/zlib/zutil.c + ../../common/zlib/inflate.c + ../../common/zlib/inffast.c + ../../common/zlib/inftrees.c +) + + From 78a5e666bbb61f7b05db11842eeda6eaa16a54e3 Mon Sep 17 00:00:00 2001 From: Bjoern Kerler Date: Thu, 16 Apr 2020 16:44:15 +0200 Subject: [PATCH 07/70] Fix QT5 GUI CMake --- client/CMakeLists.txt | 65 ++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 31 deletions(-) diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 1d5b4baf5..cd7230976 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -1,25 +1,23 @@ cmake_minimum_required(VERSION 3.16) project(proxmark3) +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) +set(CMAKE_AUTOUIC ON) + +if(CMAKE_VERSION VERSION_LESS "3.7.0") + set(CMAKE_INCLUDE_CURRENT_DIR ON) +endif() + set(CMAKE_CXX_STANDARD 14) -find_package(Qt5 COMPONENTS Widgets Gui) +#set(Qt5_DIR "/opt/Qt/5.13.0/gcc_64/lib/cmake/Qt5") + +find_package(Qt5 COMPONENTS Core Widgets Gui) SET (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake") INCLUDE(FindSSE) -#[[ -IF(SSE3_FOUND) - IF(SSSE3_FOUND) - SET(CXX_DFLAGS -msse3 -mssse3) - ENDIF(SSSE3_FOUND) -ENDIF(SSE3_FOUND) - -IF(SSE4_2_FOUND) - SET(CXX_DFLAGS -msse4.2 -mpopcnt) -ENDIF(SSE4_2_FOUND) -ADD_DEFINITIONS(${CXX_DFLAGS}) -]] if(NOT SSE2_FOUND) MESSAGE(STATUS "Could not find hardware support for SSE2 on this machine.") endif(NOT SSE2_FOUND) @@ -317,7 +315,6 @@ set (TARGET_SOURCES src/flash.h src/graph.c src/graph.h - src/guidummy.cpp src/preferences.c src/preferences.h src/pm3_binlib.c @@ -367,23 +364,34 @@ endif (MINGW) set(CMAKE_CXX_FLAGS "-Wall -Werror -O3") + +if(NOT Qt5_FOUND) + message("Qt5 library not found, not building gui") + set(TARGET_SOURCES + src/guidummy.cpp + ${TARGET_SOURCES}) +endif(NOT Qt5_FOUND) +if (Qt5_FOUND) + message("Qt5 library found, building gui :)") + set (TARGET_SOURCES + src/proxgui.cpp + src/proxgui.h + src/proxguiqt.cpp + src/proxguiqt.h + ${TARGET_SOURCES}) + add_custom_command(OUTPUT src/proxguiqt.moc.cpp + COMMAND "$(MOC) -o src/proxguiqt.moc.cpp proxguiqt.h" + COMMENT "Creating src/proxguiqt.moc.cpp" + ) + add_definitions("-DHAVE_GUI") + set(ADDITIONAL_LNK Qt5::Core Qt5::Widgets Qt5::Gui ${ADDITIONAL_LNK}) +endif (Qt5_FOUND) + add_executable( proxmark3 ${TARGET_SOURCES} ) -if(NOT Qt5_LIB) - message("Qt5 library not found, not building gui") -endif() -if (Qt5_LIB) - add_executable(proxguiqt - src/proxgui.cpp - src/proxgui.h - src/proxguiqt.cpp - src/proxguiqt.h) -endif (Qt5_LIB) - - find_library(jansson REQUIRED) find_library(tinycbor REQUIRED) find_library(lua REQUIRED) @@ -408,11 +416,6 @@ add_custom_command(OUTPUT lualibs/mfc_default_keys.lua COMMENT "Creating lualibs/mfc_default_keys.lua" ) -add_custom_command(OUTPUT src/proxguiqt.moc.cpp - COMMAND "$(MOC) -o src/proxguiqt.moc.cpp proxguiqt.h" - COMMENT "Creating src/proxguiqt.moc.cpp" - ) - add_custom_command(OUTPUT src/ui/ui_overlays.h COMMAND "$(UIC) src/ui/overlays.ui > src/ui/ui_overlays.h" COMMENT "Creating ui/ui_overlays.h" From fdccfb2b8831293842a94aa3ef6ad89ad4bd96a4 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 16 Apr 2020 23:56:32 +0200 Subject: [PATCH 08/70] add cmake build in Travis --- .travis.yml | 49 +++++++++++------------- client/CMakeLists.txt | 2 +- pm3test.sh | 86 +++++++++++++++++++++++++------------------ 3 files changed, 72 insertions(+), 65 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5aee2a918..d136892a4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,29 +4,23 @@ language: c #default linux build env is: xenial compiler: gcc +os: + - linux + - osx + +dist: xenial + +osx_image: xcode11 + # move some env variables to homebrew env env: global: - HOMEBREW_TRAVIS_BRANCH=$TRAVIS_BRANCH - HOMEBREW_TRAVIS_COMMIT=$TRAVIS_COMMIT - -# Test on Linux and MacOS -matrix: - include: - - os: osx - osx_image: xcode11 - env: MAKE_PARAMS='PLATFORM_EXTRAS=' - - os: osx - osx_image: xcode11 - env: MAKE_PARAMS='PLATFORM_EXTRAS=BTADDON' - - os: linux - dist: xenial - sudo: required - env: MAKE_PARAMS='PLATFORM_EXTRAS=' - - os: linux - dist: xenial - sudo: required - env: MAKE_PARAMS='PLATFORM_EXTRAS=BTADDON' + jobs: + - TO_TEST=MAKEFILE MAKE_PARAMS='PLATFORM_EXTRAS=' + - TO_TEST=MAKEFILE MAKE_PARAMS='PLATFORM_EXTRAS=BTADDON' + - TO_TEST=CMAKE addons: apt: @@ -53,18 +47,17 @@ before_install: fi install: - if ! arm-none-eabi-gcc -v; then + if ! arm-none-eabi-gcc -v; then echo "arm-none-eabi-gcc [ERROR]"; travis_terminate 1; fi - - make clean; - make all V=1 "$MAKE_PARAMS"; script: -## start and run a test script - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then - ./pm3test.sh; - elif [[ "$TRAVIS_OS_NAME" == "linux" ]]; then - ./pm3test.sh; - fi + - if [ "$TO_TEST" = "MAKEFILE" ]; then + make clean && make V=1 "$MAKE_PARAMS"; + ./pm3test.sh; + fi + - if [ "$TO_TEST" = "CMAKE" ]; then + mkdir -p client/build && ( cd client/build && cmake .. && make VERBOSE=1 ); + PM3BIN=./client/build/proxmark3 ./pm3test.sh client; + fi diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index cd7230976..7fdba41d8 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.16) +cmake_minimum_required(VERSION 3.12.4) project(proxmark3) set(CMAKE_AUTOMOC ON) diff --git a/pm3test.sh b/pm3test.sh index 11b459ab4..202849f60 100755 --- a/pm3test.sh +++ b/pm3test.sh @@ -3,7 +3,16 @@ PM3PATH=$(dirname "$0") cd "$PM3PATH" || exit 1 +if [ "$1" == "client" ]; then + shift + TESTDEVICE=false + TESTTOOLS=false +else + TESTDEVICE=true + TESTTOOLS=true +fi if [ "$1" == "long" ]; then + shift SLOWTESTS=true else SLOWTESTS=false @@ -66,6 +75,7 @@ printf "\n${C_BLUE}RRG/Iceman Proxmark3 test tool ${C_NC}\n\n" printf "work directory: " pwd +printf "client ${PM3BIN:="./client/proxmark3"}\n" if [ "$TRAVIS_COMMIT" ]; then if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then @@ -83,45 +93,49 @@ echo "" while true; do printf "\n${C_BLUE}Testing files:${C_NC}\n" - if ! CheckFileExist "proxmark3 exists" "./client/proxmark3"; then break; fi - if ! CheckFileExist "arm image exists" "./armsrc/obj/fullimage.elf"; then break; fi - if ! CheckFileExist "bootrom exists" "./bootrom/obj/bootrom.elf"; then break; fi - if ! CheckFileExist "hardnested tables exists" "./client/resources/hardnested_tables/*.z"; then break; fi - - printf "\n${C_BLUE}Testing basic help:${C_NC}\n" - if ! CheckExecute "proxmark help" "./client/proxmark3 -h" "wait"; then break; fi - if ! CheckExecute "proxmark help text ISO7816" "./client/proxmark3 -t 2>&1" "ISO7816"; then break; fi - if ! CheckExecute "proxmark help text hardnested" "./client/proxmark3 -t 2>&1" "hardnested"; then break; fi - - printf "\n${C_BLUE}Testing data manipulation:${C_NC}\n" - if ! CheckExecute "reveng test" "./client/proxmark3 -c 'reveng -w 8 -s 01020304e3 010204039d'" "CRC-8/SMBUS"; then break; fi - if ! CheckExecute "mfu pwdgen test" "./client/proxmark3 -c 'hf mfu pwdgen t'" "Selftest OK"; then break; fi - - printf "\n${C_BLUE}Testing LF:${C_NC}\n" - if ! CheckExecute "lf em4x05 test" "./client/proxmark3 -c 'data load traces/em4x05.pm3;lf search'" "FDX-B ID found"; then break; fi - - printf "\n${C_BLUE}Testing HF:${C_NC}\n" - if ! CheckExecute "hf mf offline text" "./client/proxmark3 -c 'hf mf'" "at_enc"; then break; fi - if $SLOWTESTS; then - if ! CheckExecute "hf mf hardnested test" "./client/proxmark3 -c 'hf mf hardnested t 1 000000000000'" "found:" "repeat" "ignore"; then break; fi - if ! CheckExecute "hf iclass test" "./client/proxmark3 -c 'hf iclass loclass t l'" "verified ok"; then break; fi - if ! CheckExecute "emv test" "./client/proxmark3 -c 'emv test -l'" "Test(s) \[ OK"; then break; fi - else - if ! CheckExecute "hf iclass test" "./client/proxmark3 -c 'hf iclass loclass t'" "OK!"; then break; fi - if ! CheckExecute "emv test" "./client/proxmark3 -c 'emv test'" "Test(s) \[ OK"; then break; fi + if ! CheckFileExist "proxmark3 exists" "$PM3BIN"; then break; fi + if ! CheckFileExist "hardnested tables exists" "./client/resources/hardnested_tables/*.z"; then break; fi + if $TESTDEVICE; then + if ! CheckFileExist "arm image exists" "./armsrc/obj/fullimage.elf"; then break; fi + if ! CheckFileExist "bootrom exists" "./bootrom/obj/bootrom.elf"; then break; fi fi - printf "\n${C_BLUE}Testing tools:${C_NC}\n" - # Need a decent example for mfkey32... - if ! CheckExecute "mfkey32v2 test" "tools/mfkey/mfkey32v2 12345678 1AD8DF2B 1D316024 620EF048 30D6CB07 C52077E2 837AC61A" "Found Key: \[a0a1a2a3a4a5\]"; then break; fi - if ! CheckExecute "mfkey64 test" "tools/mfkey/mfkey64 9c599b32 82a4166c a1e458ce 6eea41e0 5cadf439" "Found Key: \[ffffffffffff\]"; then break; fi - if ! CheckExecute "mfkey64 long trace test" "tools/mfkey/./mfkey64 14579f69 ce844261 f8049ccb 0525c84f 9431cc40 7093df99 9972428ce2e8523f456b99c831e769dced09 8ca6827b ab797fd369e8b93a86776b40dae3ef686efd c3c381ba 49e2c9def4868d1777670e584c27230286f4 fbdcd7c1 4abd964b07d3563aa066ed0a2eac7f6312bf 9f9149ea" "Found Key: \[091e639cb715\]"; then break; fi - if ! CheckExecute "nonce2key test" "tools/nonce2key/nonce2key e9cadd9c a8bf4a12 a020a8285858b090 050f010607060e07 5693be6c00000000" "key recovered: fc00018778f7"; then break; fi - if ! CheckExecute "xorcheck test" "tools/xorcheck.py 04 00 80 64 ba" "final LRC XOR byte value: 5A"; then break; fi - if ! CheckExecute "findbits test" "tools/findbits.py 73 0110010101110011" "Match at bit 9: 011001010"; then break; fi - if ! CheckExecute "findbits_test test" "tools/findbits_test.py 2>&1" "OK"; then break; fi - if ! CheckExecute "pm3_eml_mfd test" "tools/pm3_eml_mfd_test.py 2>&1" "OK"; then break; fi + printf "\n${C_BLUE}Testing basic help:${C_NC}\n" + if ! CheckExecute "proxmark help" "$PM3BIN -h" "wait"; then break; fi + if ! CheckExecute "proxmark help text ISO7816" "$PM3BIN -t 2>&1" "ISO7816"; then break; fi + if ! CheckExecute "proxmark help text hardnested" "$PM3BIN -t 2>&1" "hardnested"; then break; fi + + printf "\n${C_BLUE}Testing data manipulation:${C_NC}\n" + if ! CheckExecute "reveng test" "$PM3BIN -c 'reveng -w 8 -s 01020304e3 010204039d'" "CRC-8/SMBUS"; then break; fi + if ! CheckExecute "mfu pwdgen test" "$PM3BIN -c 'hf mfu pwdgen t'" "Selftest OK"; then break; fi + printf "\n${C_BLUE}Testing LF:${C_NC}\n" + if ! CheckExecute "lf em4x05 test" "$PM3BIN -c 'data load traces/em4x05.pm3;lf search'" "FDX-B ID found"; then break; fi + + printf "\n${C_BLUE}Testing HF:${C_NC}\n" + if ! CheckExecute "hf mf offline text" "$PM3BIN -c 'hf mf'" "at_enc"; then break; fi + if $SLOWTESTS; then + if ! CheckExecute "hf mf hardnested test" "$PM3BIN -c 'hf mf hardnested t 1 000000000000'" "found:" "repeat" "ignore"; then break; fi + if ! CheckExecute "hf iclass test" "$PM3BIN -c 'hf iclass loclass t l'" "verified ok"; then break; fi + if ! CheckExecute "emv test" "$PM3BIN -c 'emv test -l'" "Test(s) \[ OK"; then break; fi + else + if ! CheckExecute "hf iclass test" "$PM3BIN -c 'hf iclass loclass t'" "OK!"; then break; fi + if ! CheckExecute "emv test" "$PM3BIN -c 'emv test'" "Test(s) \[ OK"; then break; fi + fi + + if $TESTTOOLS; then + printf "\n${C_BLUE}Testing tools:${C_NC}\n" + # Need a decent example for mfkey32... + if ! CheckExecute "mfkey32v2 test" "tools/mfkey/mfkey32v2 12345678 1AD8DF2B 1D316024 620EF048 30D6CB07 C52077E2 837AC61A" "Found Key: \[a0a1a2a3a4a5\]"; then break; fi + if ! CheckExecute "mfkey64 test" "tools/mfkey/mfkey64 9c599b32 82a4166c a1e458ce 6eea41e0 5cadf439" "Found Key: \[ffffffffffff\]"; then break; fi + if ! CheckExecute "mfkey64 long trace test" "tools/mfkey/./mfkey64 14579f69 ce844261 f8049ccb 0525c84f 9431cc40 7093df99 9972428ce2e8523f456b99c831e769dced09 8ca6827b ab797fd369e8b93a86776b40dae3ef686efd c3c381ba 49e2c9def4868d1777670e584c27230286f4 fbdcd7c1 4abd964b07d3563aa066ed0a2eac7f6312bf 9f9149ea" "Found Key: \[091e639cb715\]"; then break; fi + if ! CheckExecute "nonce2key test" "tools/nonce2key/nonce2key e9cadd9c a8bf4a12 a020a8285858b090 050f010607060e07 5693be6c00000000" "key recovered: fc00018778f7"; then break; fi + if ! CheckExecute "xorcheck test" "tools/xorcheck.py 04 00 80 64 ba" "final LRC XOR byte value: 5A"; then break; fi + if ! CheckExecute "findbits test" "tools/findbits.py 73 0110010101110011" "Match at bit 9: 011001010"; then break; fi + if ! CheckExecute "findbits_test test" "tools/findbits_test.py 2>&1" "OK"; then break; fi + if ! CheckExecute "pm3_eml_mfd test" "tools/pm3_eml_mfd_test.py 2>&1" "OK"; then break; fi + fi + printf "\n${C_GREEN}Tests [OK]${C_NC}\n\n" exit 0 done From ad28dc1fa0c85a450c5b822329e1197440a4e62f Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 17 Apr 2020 01:13:52 +0200 Subject: [PATCH 09/70] cmake: remove custom rule for .ui, we already have AUTOUIC --- client/CMakeLists.txt | 5 ----- 1 file changed, 5 deletions(-) diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 7fdba41d8..dbfc62cf0 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -416,11 +416,6 @@ add_custom_command(OUTPUT lualibs/mfc_default_keys.lua COMMENT "Creating lualibs/mfc_default_keys.lua" ) -add_custom_command(OUTPUT src/ui/ui_overlays.h - COMMAND "$(UIC) src/ui/overlays.ui > src/ui/ui_overlays.h" - COMMENT "Creating ui/ui_overlays.h" - ) - #"make package" will trigger this SET(CPACK_GENERATOR "DEB") SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "Iceman") From 4e233c682de543508bb8b41be39056bdceb69f4a Mon Sep 17 00:00:00 2001 From: Iceman Date: Fri, 17 Apr 2020 06:43:16 +0200 Subject: [PATCH 10/70] Update CMakeLists.txt --- client/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index dbfc62cf0..76b280fe1 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -390,6 +390,7 @@ endif (Qt5_FOUND) add_executable( proxmark3 ${TARGET_SOURCES} + ${ADDITIONAL_SRC} ) find_library(jansson REQUIRED) @@ -419,4 +420,4 @@ add_custom_command(OUTPUT lualibs/mfc_default_keys.lua #"make package" will trigger this SET(CPACK_GENERATOR "DEB") SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "Iceman") -INCLUDE(CPack) \ No newline at end of file +INCLUDE(CPack) From 64e7aa4c468b90770d18f318d2139bf66a9411ba Mon Sep 17 00:00:00 2001 From: Uli Heilmeier Date: Fri, 17 Apr 2020 08:47:10 +0200 Subject: [PATCH 11/70] cmake: fix qt handling for macos This is like we find qt in the Wireshark project. Tested it with macOS. Not tested with Linux, Windows etc. --- client/CMakeLists.txt | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 76b280fe1..47eea50da 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -11,9 +11,24 @@ endif() set(CMAKE_CXX_STANDARD 14) -#set(Qt5_DIR "/opt/Qt/5.13.0/gcc_64/lib/cmake/Qt5") - -find_package(Qt5 COMPONENTS Core Widgets Gui) +if(APPLE AND EXISTS /usr/local/opt/qt5) + # Homebrew installs Qt5 (up to at least 5.11.0) in + # /usr/local/qt5. Ensure that it can be found by CMake + # since it is not in the default /usr/local prefix. + # Add it to PATHS so that it doesn't override the + # CMAKE_PREFIX_PATH environment variable. + # QT_FIND_PACKAGE_OPTIONS should be passed to find_package, + # e.g. find_package(Qt5Core ${QT_FIND_PACKAGE_OPTIONS}) + list(APPEND QT_FIND_PACKAGE_OPTIONS PATHS /usr/local/opt/qt5) +endif() +set(QT_PACKAGELIST + Qt5Core + Qt5Widgets + Qt5Gui +) +foreach(_qt_package IN LISTS QT_PACKAGELIST) + find_package(${_qt_package} REQUIRED ${QT_FIND_PACKAGE_OPTIONS}) +endforeach() SET (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake") From 6562c22029a49afa2c2b2d30f100a876768cf79a Mon Sep 17 00:00:00 2001 From: Uli Heilmeier Date: Fri, 17 Apr 2020 09:15:06 +0200 Subject: [PATCH 12/70] Fix qt5_found handling --- client/CMakeLists.txt | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 47eea50da..229457852 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -12,22 +12,29 @@ endif() set(CMAKE_CXX_STANDARD 14) if(APPLE AND EXISTS /usr/local/opt/qt5) - # Homebrew installs Qt5 (up to at least 5.11.0) in - # /usr/local/qt5. Ensure that it can be found by CMake - # since it is not in the default /usr/local prefix. - # Add it to PATHS so that it doesn't override the - # CMAKE_PREFIX_PATH environment variable. - # QT_FIND_PACKAGE_OPTIONS should be passed to find_package, - # e.g. find_package(Qt5Core ${QT_FIND_PACKAGE_OPTIONS}) - list(APPEND QT_FIND_PACKAGE_OPTIONS PATHS /usr/local/opt/qt5) + # Homebrew installs Qt5 (up to at least 5.11.0) in + # /usr/local/qt5. Ensure that it can be found by CMake + # since it is not in the default /usr/local prefix. + # Add it to PATHS so that it doesn't override the + # CMAKE_PREFIX_PATH environment variable. + # QT_FIND_PACKAGE_OPTIONS should be passed to find_package, + # e.g. find_package(Qt5Core ${QT_FIND_PACKAGE_OPTIONS}) + list(APPEND QT_FIND_PACKAGE_OPTIONS PATHS /usr/local/opt/qt5) endif() set(QT_PACKAGELIST - Qt5Core - Qt5Widgets - Qt5Gui + Qt5Core + Qt5Widgets + Qt5Gui ) foreach(_qt_package IN LISTS QT_PACKAGELIST) - find_package(${_qt_package} REQUIRED ${QT_FIND_PACKAGE_OPTIONS}) + find_package(${_qt_package} REQUIRED ${QT_FIND_PACKAGE_OPTIONS}) +endforeach() + +set(Qt5_FOUND ON) +foreach(_qt_package IN LISTS QT_PACKAGELIST) + if(NOT ${_qt_package}_FOUND) + set(Qt5_FOUND OFF) + endif(NOT ${_qt_package}_FOUND) endforeach() SET (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake") From 500343488513464b7d5afee1e234e86c921e7b4b Mon Sep 17 00:00:00 2001 From: TrustedUser Date: Fri, 17 Apr 2020 01:59:01 -0700 Subject: [PATCH 13/70] =?UTF-8?q?=C2=A8fix:=20osc=20cmake?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/CMakeLists.txt | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 229457852..3da7093b1 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -377,7 +377,6 @@ if (APPLE) message("Apple device detected.") set(ADDITIONAL_SRC src/util_darwin.h src/util_darwin.m ${ADDITIONAL_SRC}) set(ADDITIONAL_LNK "-framework Foundation" "-framework AppKit") - set_target_properties(proxmark3 PROPERTIES LINK_FLAGS "-Wl,-F/Library/Frameworks") endif (APPLE) if (MINGW) @@ -395,16 +394,19 @@ if(NOT Qt5_FOUND) endif(NOT Qt5_FOUND) if (Qt5_FOUND) message("Qt5 library found, building gui :)") + + add_custom_command(OUTPUT src/proxguiqt.moc.cpp + COMMAND "$(MOC) -o src/proxguiqt.moc.cpp proxguiqt.h" + COMMENT "Creating src/proxguiqt.moc.cpp" + ) + set (TARGET_SOURCES src/proxgui.cpp src/proxgui.h src/proxguiqt.cpp src/proxguiqt.h ${TARGET_SOURCES}) - add_custom_command(OUTPUT src/proxguiqt.moc.cpp - COMMAND "$(MOC) -o src/proxguiqt.moc.cpp proxguiqt.h" - COMMENT "Creating src/proxguiqt.moc.cpp" - ) + add_definitions("-DHAVE_GUI") set(ADDITIONAL_LNK Qt5::Core Qt5::Widgets Qt5::Gui ${ADDITIONAL_LNK}) endif (Qt5_FOUND) @@ -415,6 +417,11 @@ add_executable( ${ADDITIONAL_SRC} ) +if (APPLE) + set_target_properties(proxmark3 PROPERTIES LINK_FLAGS "-Wl,-F/Library/Frameworks") +endif (APPLE) + + find_library(jansson REQUIRED) find_library(tinycbor REQUIRED) find_library(lua REQUIRED) From c888fcdb7e978a9617c65270f528912771b6a198 Mon Sep 17 00:00:00 2001 From: Uli Heilmeier Date: Fri, 17 Apr 2020 12:40:34 +0200 Subject: [PATCH 14/70] Fix cmake qt: remove REQUIRED --- client/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 3da7093b1..14cbbf47d 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -27,7 +27,7 @@ set(QT_PACKAGELIST Qt5Gui ) foreach(_qt_package IN LISTS QT_PACKAGELIST) - find_package(${_qt_package} REQUIRED ${QT_FIND_PACKAGE_OPTIONS}) + find_package(${_qt_package} ${QT_FIND_PACKAGE_OPTIONS}) endforeach() set(Qt5_FOUND ON) From 18f875cb84bf20a1aa9a7c411b143168d930bc06 Mon Sep 17 00:00:00 2001 From: Uli Heilmeier Date: Fri, 17 Apr 2020 13:08:52 +0200 Subject: [PATCH 15/70] cmake macOS: use brew installed readline --- client/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 14cbbf47d..f3ac5427e 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -418,7 +418,8 @@ add_executable( ) if (APPLE) - set_target_properties(proxmark3 PROPERTIES LINK_FLAGS "-Wl,-F/Library/Frameworks") + set_target_properties(proxmark3 PROPERTIES LINK_FLAGS "-Wl,-F/Library/Frameworks, -L/usr/local/opt/readline/lib") + set_target_properties(proxmark3 PROPERTIES COMPILE_FLAGS "-I/usr/local/opt/readline/include") endif (APPLE) From 1a344a933d8d7e6d7e1e5c6ce86644ca1298d39e Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 17 Apr 2020 13:46:12 +0200 Subject: [PATCH 16/70] Remove header files from CMakeLists --- client/CMakeLists.txt | 143 ------------------------------------------ 1 file changed, 143 deletions(-) diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index f3ac5427e..973385c7a 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -87,283 +87,142 @@ include_directories( set (TARGET_SOURCES src/proxmark3.c - src/proxmark3.h ../common/commonutil.c - ../common/commonutil.h ../common/util_posix.c - ../common/util_posix.h ../common/parity.c - ../common/parity.h ../common/bucketsort.c - ../common/bucketsort.h ../common/crapto1/crapto1.c - ../common/crapto1/crapto1.h ../common/crapto1/crypto1.c ../common/crc.c - ../common/crc.h ../common/crc16.c - ../common/crc16.h ../common/crc32.c - ../common/crc32.h ../common/crc64.c - ../common/crc64.h ../common/lfdemod.c - ../common/lfdemod.h ../common/legic_prng.c - ../common/legic_prng.h ../common/iso15693tools.c - ../common/iso15693tools.h ../common/cardhelper.c - ../common/cardhelper.h ../common/generator.c - ../common/generator.h deps/cliparser/argtable3.c - deps/cliparser/argtable3.h deps/cliparser/cliparser.c - deps/cliparser/cliparser.h - deps/cliparser/getopt.h deps/hardnested/hardnested_bruteforce.c - deps/hardnested/hardnested_bruteforce.h src/crypto/asn1dump.c - src/crypto/asn1dump.h src/crypto/asn1utils.c - src/crypto/asn1utils.h src/crypto/libpcrypto.c - src/crypto/libpcrypto.h src/emv/test/cda_test.c - src/emv/test/cda_test.h src/emv/test/crypto_test.c - src/emv/test/crypto_test.h src/emv/test/cryptotest.c - src/emv/test/cryptotest.h src/emv/test/dda_test.c - src/emv/test/dda_test.h src/emv/test/sda_test.c - src/emv/test/sda_test.h src/emv/apduinfo.c - src/emv/apduinfo.h src/emv/cmdemv.c - src/emv/cmdemv.h src/emv/crypto.c - src/emv/crypto.h - src/emv/crypto_backend.h src/emv/crypto_polarssl.c src/emv/dol.c - src/emv/dol.h src/emv/dump.c - src/emv/dump.h src/emv/emv_pk.c - src/emv/emv_pk.h src/emv/emv_pki.c - src/emv/emv_pki.h src/emv/emv_pki_priv.c - src/emv/emv_pki_priv.h src/emv/emv_roca.c - src/emv/emv_roca.h src/emv/emv_tags.c - src/emv/emv_tags.h src/emv/emvcore.c - src/emv/emvcore.h src/emv/emvjson.c - src/emv/emvjson.h src/emv/tlv.c - src/emv/tlv.h src/fido/additional_ca.c - src/fido/additional_ca.h src/fido/cbortools.c - src/fido/cbortools.h src/fido/cose.c - src/fido/cose.h src/fido/fidocore.c - src/fido/fidocore.h src/loclass/cipher.c - src/loclass/cipher.h src/loclass/cipherutils.c - src/loclass/cipherutils.h src/loclass/elite_crack.c - src/loclass/elite_crack.h src/loclass/hash1_brute.c - src/loclass/hash1_brute.h src/loclass/ikeys.c - src/loclass/ikeys.h src/mifare/mad.c - src/mifare/mad.h src/mifare/mfkey.c - src/mifare/mfkey.h src/mifare/mifare4.c - src/mifare/mifare4.h src/mifare/mifaredefault.c - src/mifare/mifaredefault.h src/mifare/mifarehost.c - src/mifare/mifarehost.h src/mifare/ndef.c - src/mifare/ndef.h src/mifare/desfire_crypto.c - src/mifare/desfire_crypto.h - src/uart/uart.h src/uart/uart_posix.c src/uart/uart_win32.c src/ui/overlays.ui src/aidsearch.c - src/aidsearch.h src/cmdanalyse.c - src/cmdanalyse.h src/cmdcrc.c - src/cmdcrc.h src/cmddata.c - src/cmddata.h src/cmdflashmem.c - src/cmdflashmem.h src/cmdflashmemspiffs.c - src/cmdflashmemspiffs.h src/cmdhf.c - src/cmdhf.h src/cmdhf14a.c - src/cmdhf14a.h src/cmdhf14b.c - src/cmdhf14b.h src/cmdhf15.c - src/cmdhf15.h src/cmdhfcryptorf.c - src/cmdhfcryptorf.h src/cmdhfepa.c - src/cmdhfepa.h src/cmdhffelica.c - src/cmdhffelica.h src/cmdhffido.c - src/cmdhffido.h src/cmdhficlass.c - src/cmdhficlass.h src/cmdhflegic.c - src/cmdhflegic.h src/cmdhflist.c - src/cmdhflist.h src/cmdhflto.c - src/cmdhflto.h src/cmdhfmf.c - src/cmdhfmf.h src/cmdhfmfdes.c - src/cmdhfmfdes.h src/cmdhfmfhard.c - src/cmdhfmfhard.h src/cmdhfmfp.c - src/cmdhfmfp.h src/cmdhfmfu.c - src/cmdhfmfu.h src/cmdhfthinfilm.c - src/cmdhfthinfilm.h src/cmdhftopaz.c - src/cmdhftopaz.h src/cmdhw.c - src/cmdhw.h src/cmdlf.c - src/cmdlf.h src/cmdlfawid.c - src/cmdlfawid.h src/cmdlfcotag.c - src/cmdlfcotag.h src/cmdlfem4x.c - src/cmdlfem4x.h src/cmdlffdx.c - src/cmdlffdx.h src/cmdlfgallagher.c - src/cmdlfgallagher.h src/cmdlfguard.c - src/cmdlfguard.h src/cmdlfhid.c - src/cmdlfhid.h src/cmdlfhitag.c - src/cmdlfhitag.h src/cmdlfindala.c - src/cmdlfindala.h src/cmdlfio.c - src/cmdlfio.h src/cmdlfjablotron.c - src/cmdlfjablotron.h src/cmdlfkeri.c - src/cmdlfkeri.h src/cmdlfmotorola.c - src/cmdlfmotorola.h src/cmdlfnedap.c - src/cmdlfnedap.h src/cmdlfnexwatch.c - src/cmdlfnexwatch.h src/cmdlfnoralsy.c - src/cmdlfnoralsy.h src/cmdlfpac.c - src/cmdlfpac.h src/cmdlfparadox.c - src/cmdlfparadox.h src/cmdlfpcf7931.c - src/cmdlfpcf7931.h src/cmdlfpresco.c - src/cmdlfpresco.h src/cmdlfpyramid.c - src/cmdlfpyramid.h src/cmdlfsecurakey.c - src/cmdlfsecurakey.h src/cmdlft55xx.c - src/cmdlft55xx.h src/cmdlfti.c - src/cmdlfti.h src/cmdlfverichip.c - src/cmdlfverichip.h src/cmdlfviking.c - src/cmdlfviking.h src/cmdlfvisa2000.c - src/cmdlfvisa2000.h src/cmdmain.c - src/cmdmain.h src/cmdparser.c - src/cmdparser.h src/cmdscript.c - src/cmdscript.h src/cmdsmartcard.c - src/cmdsmartcard.h src/cmdtrace.c - src/cmdtrace.h src/cmdusart.c - src/cmdusart.h src/cmdwiegand.c - src/cmdwiegand.h src/comms.c - src/comms.h - src/elf.h - src/emojis.h - src/emojis_alt.h src/fileutils.c - src/fileutils.h src/flash.c - src/flash.h src/graph.c - src/graph.h src/preferences.c - src/preferences.h src/pm3_binlib.c - src/pm3_binlib.h - src/pm3_bit_limits.h src/pm3_bitlib.c - src/pm3_bitlib.h - src/polarssl_config.h src/prng.c - src/prng.h - src/proxendian.h src/scandir.c - src/scandir.h src/scripting.c - src/scripting.h src/tea.c - src/tea.h src/ui.c - src/ui.h src/util.c - src/util.h src/whereami.c - src/whereami.h src/wiegand_formats.c - src/wiegand_formats.h src/wiegand_formatutils.c - src/wiegand_formatutils.h ) set(ADDITIONAL_SRC "") @@ -402,9 +261,7 @@ if (Qt5_FOUND) set (TARGET_SOURCES src/proxgui.cpp - src/proxgui.h src/proxguiqt.cpp - src/proxguiqt.h ${TARGET_SOURCES}) add_definitions("-DHAVE_GUI") From 01432fd84b93c7fd9374565fc44cba2c2b7186e0 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 17 Apr 2020 14:31:29 +0200 Subject: [PATCH 17/70] Lower cmake min version to 3.10 for WSL --- client/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 973385c7a..b46e250fc 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.12.4) +cmake_minimum_required(VERSION 3.10) project(proxmark3) set(CMAKE_AUTOMOC ON) From 7d1ef452b9a5f958643baa7c1200fa721b7976af Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 17 Apr 2020 14:50:30 +0200 Subject: [PATCH 18/70] update gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 7bbad2e87..25c3117dd 100644 --- a/.gitignore +++ b/.gitignore @@ -37,6 +37,9 @@ Makefile.platform # Cache for detecting platform def changes .Makefile.options.cache +# cmake +client/build/ + !client/resources/hardnested/*.bin !client/resources/hardnested_tables/*.z client/src/ui/ui_overlays.h From 397f46c0efad7579fbdb598c0b8747c8a65d9b16 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 18 Apr 2020 11:39:15 +0200 Subject: [PATCH 19/70] cmake: Fix the (not yet used) amiibo srcs --- client/deps/amiibo.cmake | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/client/deps/amiibo.cmake b/client/deps/amiibo.cmake index 8e21d1011..615a344b3 100644 --- a/client/deps/amiibo.cmake +++ b/client/deps/amiibo.cmake @@ -6,23 +6,11 @@ #-o amiitool set_property(SOURCE PROPERTY C_STANDARD 99) -add_definitions(-D_ISOC99_SOURCE) -include_directories(jansson) -include_directories(../../common) -include_directories(../../common/include) -include_directories(amiitool) add_library(amiibo - jansson/dump.c - jansson/error.c - jansson/hashtable.c - jansson/hashtable_seed.c - jansson/load.c - jansson/memory.c - jansson/pack_unpack.c - jansson/strbuffer.c - jansson/strconv.c - jansson/utf.c - jansson/path.c - jansson/value.c + amiitool/amiibo.c + amiitool/drbg.c + amiitool/keygen.c ) + +target_include_directories(amiibo PRIVATE ../../include ../../common) From 0fc5c41a4925fee1b621d8298fa5ce65daa393ef Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 18 Apr 2020 13:46:42 +0200 Subject: [PATCH 20/70] cmake: fix liblua platform definitions to match regular Makefile --- client/deps/lua.cmake | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/client/deps/lua.cmake b/client/deps/lua.cmake index 916d79c6f..b148d3795 100644 --- a/client/deps/lua.cmake +++ b/client/deps/lua.cmake @@ -1,26 +1,3 @@ -add_definitions(-DLUA_COMPAT_ALL $(SYSCFLAGS)) -include_directories(liblua) - -set(SYSCFLAGS "-DLUA_COMPAT_ALL") - -if (UNIX) - set(SYSCFLAGS "-DLUA_USE_LINUX") -endif (UNIX) - -if (WIN32) - set(SYSCFLAGS "-DLUA_USE_LINUX") -endif (WIN32) - -if (MINGW) - set(SYSCFLAGS "-DLUA_COMPAT_ALL $(SYSCFLAGS)") -endif (MINGW) - -if (APPLE) - set(SYSCFLAGS "-DLUA_USE_MACOSX") -endif (APPLE) - -add_definitions($(SYSCFLAGS)) - add_library(lua liblua/lapi.c liblua/lcode.c @@ -56,3 +33,13 @@ add_library(lua liblua/linit.c ) +target_compile_definitions(lua PRIVATE LUA_COMPAT_ALL) + +if (NOT MINGW) + if (APPLE) + target_compile_definitions(lua PRIVATE LUA_USE_MACOSX) + else (APPLE) + target_compile_definitions(lua PRIVATE LUA_USE_LINUX) + target_link_libraries(lua INTERFACE dl) + endif (APPLE) +endif (NOT MINGW) From b7fb3b074657a81cfc89ea2b18c2dd53379d0d1b Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 18 Apr 2020 13:50:53 +0200 Subject: [PATCH 21/70] cmake: fix jansson defines, keep them local --- client/deps/hardnested.cmake | 1 - client/deps/jansson.cmake | 4 ++-- client/deps/mbedtls.cmake | 1 - 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/client/deps/hardnested.cmake b/client/deps/hardnested.cmake index b9e0bfa82..fb4fd881a 100644 --- a/client/deps/hardnested.cmake +++ b/client/deps/hardnested.cmake @@ -1,5 +1,4 @@ set_property(SOURCE PROPERTY C_STANDARD 99) -add_definitions(-DHAVE_STDINT_H) include_directories(hardnested) ## CPU-specific code diff --git a/client/deps/jansson.cmake b/client/deps/jansson.cmake index f35d7dbc9..bb004d155 100644 --- a/client/deps/jansson.cmake +++ b/client/deps/jansson.cmake @@ -1,6 +1,4 @@ set_property(SOURCE PROPERTY C_STANDARD 99) -add_definitions(-DHAVE_STDINT_H) -include_directories(jansson) add_library(jansson jansson/dump.c @@ -16,3 +14,5 @@ add_library(jansson jansson/path.c jansson/value.c ) + +target_compile_definitions(jansson PRIVATE HAVE_STDINT_H) diff --git a/client/deps/mbedtls.cmake b/client/deps/mbedtls.cmake index 0b4c04e62..9e3d0f8a6 100644 --- a/client/deps/mbedtls.cmake +++ b/client/deps/mbedtls.cmake @@ -1,5 +1,4 @@ set_property(SOURCE PROPERTY C_STANDARD 99) -add_definitions(-DHAVE_STDINT_H) include_directories(../../common) add_library(mbedtls From 0b68f3b81e70a489686e2ea3c4d1cb31be26209e Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 18 Apr 2020 13:56:26 +0200 Subject: [PATCH 22/70] cmake: fix zlib defines, keep them local --- client/deps/zlib.cmake | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/client/deps/zlib.cmake b/client/deps/zlib.cmake index 28b42d74c..bb1b63561 100644 --- a/client/deps/zlib.cmake +++ b/client/deps/zlib.cmake @@ -1,6 +1,4 @@ set_property(SOURCE PROPERTY C_STANDARD 99) -add_definitions(-D_ISOC99_SOURCE -DZ_SOLO -DNO_GZIP -DZLIB_PM3_TUNED) -include_directories(../../common/zlib) add_library(z ../../common/zlib/deflate.c @@ -12,4 +10,4 @@ add_library(z ../../common/zlib/inftrees.c ) - +target_compile_definitions(z PRIVATE Z_SOLO NO_GZIP ZLIB_PM3_TUNED) From c5d2655ebe91553d6dd13f306b02dd5b3468c677 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 18 Apr 2020 13:57:56 +0200 Subject: [PATCH 23/70] cmake: fix reveng defines, keep them local --- client/deps/reveng.cmake | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/client/deps/reveng.cmake b/client/deps/reveng.cmake index 5df1e85f2..c1243f192 100644 --- a/client/deps/reveng.cmake +++ b/client/deps/reveng.cmake @@ -1,6 +1,4 @@ set_property(SOURCE PROPERTY C_STANDARD 99) -add_definitions(-DPRESETS) -include_directories(reveng) include_directories(.) add_library(reveng @@ -13,3 +11,4 @@ add_library(reveng reveng/reveng.c ) +target_compile_definitions(reveng PRIVATE PRESETS) From 1ccd7648377cd0794c5441403e954c27a2921fef Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 18 Apr 2020 14:08:25 +0200 Subject: [PATCH 24/70] cmake: hardnested --- client/deps/hardnested.cmake | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/client/deps/hardnested.cmake b/client/deps/hardnested.cmake index fb4fd881a..76ae3b53b 100644 --- a/client/deps/hardnested.cmake +++ b/client/deps/hardnested.cmake @@ -1,5 +1,4 @@ set_property(SOURCE PROPERTY C_STANDARD 99) -include_directories(hardnested) ## CPU-specific code ## These are mostly for x86-based architectures, which is not useful for many Android devices. @@ -9,8 +8,7 @@ add_library(hardnested_nosimd OBJECT target_include_directories(hardnested_nosimd PRIVATE ../../common - ../../include - hardnested) + ../../include) set(X86_CPUS x86 x86_64 i686) @@ -33,8 +31,7 @@ if ("${CMAKE_SYSTEM_PROCESSOR}" IN_LIST X86_CPUS) target_include_directories(hardnested_mmx PRIVATE ../../common - ../../include - hardnested) + ../../include) set_property(TARGET hardnested_mmx PROPERTY POSITION_INDEPENDENT_CODE ON) @@ -48,8 +45,7 @@ if ("${CMAKE_SYSTEM_PROCESSOR}" IN_LIST X86_CPUS) target_include_directories(hardnested_sse2 PRIVATE ../../common - ../../include - hardnested) + ../../include) set_property(TARGET hardnested_sse2 PROPERTY POSITION_INDEPENDENT_CODE ON) @@ -63,8 +59,7 @@ if ("${CMAKE_SYSTEM_PROCESSOR}" IN_LIST X86_CPUS) target_include_directories(hardnested_avx PRIVATE ../../common - ../../include - hardnested) + ../../include) set_property(TARGET hardnested_avx PROPERTY POSITION_INDEPENDENT_CODE ON) @@ -78,8 +73,7 @@ if ("${CMAKE_SYSTEM_PROCESSOR}" IN_LIST X86_CPUS) target_include_directories(hardnested_avx2 PRIVATE ../../common - ../../include - hardnested) + ../../include) set_property(TARGET hardnested_avx2 PROPERTY POSITION_INDEPENDENT_CODE ON) @@ -93,8 +87,7 @@ if ("${CMAKE_SYSTEM_PROCESSOR}" IN_LIST X86_CPUS) target_include_directories(hardnested_avx512 PRIVATE ../../common - ../../include - hardnested) + ../../include) set_property(TARGET hardnested_avx512 PROPERTY POSITION_INDEPENDENT_CODE ON) From b5ce5c1d99d15a5b196d97badef93322c27b8f3b Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 18 Apr 2020 14:15:40 +0200 Subject: [PATCH 25/70] cmake: mbedtls keep includes local --- client/deps/mbedtls.cmake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/deps/mbedtls.cmake b/client/deps/mbedtls.cmake index 9e3d0f8a6..8a76f4b0d 100644 --- a/client/deps/mbedtls.cmake +++ b/client/deps/mbedtls.cmake @@ -1,5 +1,4 @@ set_property(SOURCE PROPERTY C_STANDARD 99) -include_directories(../../common) add_library(mbedtls ../../common/mbedtls/aes.c @@ -46,3 +45,5 @@ add_library(mbedtls ../../common/mbedtls/x509_crl.c ../../common/mbedtls/x509_crt.c ) + +target_include_directories(mbedtls PRIVATE ../../common) From 2aa587f35feb77899bbb5f99a0abfa906f07c504 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 18 Apr 2020 14:16:57 +0200 Subject: [PATCH 26/70] cmake: reveng keep includes local --- client/deps/reveng.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/deps/reveng.cmake b/client/deps/reveng.cmake index c1243f192..77b078d13 100644 --- a/client/deps/reveng.cmake +++ b/client/deps/reveng.cmake @@ -1,5 +1,4 @@ set_property(SOURCE PROPERTY C_STANDARD 99) -include_directories(.) add_library(reveng reveng/bmpbit.c @@ -12,3 +11,4 @@ add_library(reveng ) target_compile_definitions(reveng PRIVATE PRESETS) +target_include_directories(reveng PRIVATE .) From f32974bb07022aab62ff49bca4e69fc53a8a529c Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 18 Apr 2020 14:19:43 +0200 Subject: [PATCH 27/70] cmake libs static --- client/deps/amiibo.cmake | 2 +- client/deps/jansson.cmake | 2 +- client/deps/lua.cmake | 2 +- client/deps/mbedtls.cmake | 2 +- client/deps/reveng.cmake | 2 +- client/deps/tinycbor.cmake | 2 +- client/deps/zlib.cmake | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/client/deps/amiibo.cmake b/client/deps/amiibo.cmake index 615a344b3..0374cb5d3 100644 --- a/client/deps/amiibo.cmake +++ b/client/deps/amiibo.cmake @@ -7,7 +7,7 @@ set_property(SOURCE PROPERTY C_STANDARD 99) -add_library(amiibo +add_library(amiibo STATIC amiitool/amiibo.c amiitool/drbg.c amiitool/keygen.c diff --git a/client/deps/jansson.cmake b/client/deps/jansson.cmake index bb004d155..c82694a21 100644 --- a/client/deps/jansson.cmake +++ b/client/deps/jansson.cmake @@ -1,6 +1,6 @@ set_property(SOURCE PROPERTY C_STANDARD 99) -add_library(jansson +add_library(jansson STATIC jansson/dump.c jansson/error.c jansson/hashtable.c diff --git a/client/deps/lua.cmake b/client/deps/lua.cmake index b148d3795..d0ea7fd12 100644 --- a/client/deps/lua.cmake +++ b/client/deps/lua.cmake @@ -1,4 +1,4 @@ -add_library(lua +add_library(lua STATIC liblua/lapi.c liblua/lcode.c liblua/lctype.c diff --git a/client/deps/mbedtls.cmake b/client/deps/mbedtls.cmake index 8a76f4b0d..e0cc2d91f 100644 --- a/client/deps/mbedtls.cmake +++ b/client/deps/mbedtls.cmake @@ -1,6 +1,6 @@ set_property(SOURCE PROPERTY C_STANDARD 99) -add_library(mbedtls +add_library(mbedtls STATIC ../../common/mbedtls/aes.c ../../common/mbedtls/asn1parse.c ../../common/mbedtls/asn1write.c diff --git a/client/deps/reveng.cmake b/client/deps/reveng.cmake index 77b078d13..425f98331 100644 --- a/client/deps/reveng.cmake +++ b/client/deps/reveng.cmake @@ -1,6 +1,6 @@ set_property(SOURCE PROPERTY C_STANDARD 99) -add_library(reveng +add_library(reveng STATIC reveng/bmpbit.c reveng/cli.c reveng/getopt.c diff --git a/client/deps/tinycbor.cmake b/client/deps/tinycbor.cmake index f58011e93..a78d428f5 100644 --- a/client/deps/tinycbor.cmake +++ b/client/deps/tinycbor.cmake @@ -1,4 +1,4 @@ -add_library(tinycbor +add_library(tinycbor STATIC tinycbor/cborencoder.c tinycbor/cborencoder_close_container_checked.c tinycbor/cborerrorstrings.c diff --git a/client/deps/zlib.cmake b/client/deps/zlib.cmake index bb1b63561..c78522a66 100644 --- a/client/deps/zlib.cmake +++ b/client/deps/zlib.cmake @@ -1,6 +1,6 @@ set_property(SOURCE PROPERTY C_STANDARD 99) -add_library(z +add_library(z STATIC ../../common/zlib/deflate.c ../../common/zlib/adler32.c ../../common/zlib/trees.c From dc6b751ea3ec6bd09396183dc970656c39d99db1 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 18 Apr 2020 15:09:35 +0200 Subject: [PATCH 28/70] cmake: rework includes, wip, need to modify more src after merge --- client/CMakeLists.txt | 27 +++++++++------------------ client/deps/amiibo.cmake | 1 + client/deps/jansson.cmake | 1 + client/deps/lua.cmake | 2 ++ client/deps/tinycbor.cmake | 5 ++++- client/src/emv/emvjson.h | 2 +- 6 files changed, 18 insertions(+), 20 deletions(-) diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index b46e250fc..5f566e35e 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -64,24 +64,6 @@ endif(NOT AVX512_FOUND) add_subdirectory(deps) -include_directories( - .. - SYSTEM - deps - ../common - ../include - deps/jansson - deps/tinycbor - deps/liblua - client/deps/mbedtls/include - deps/amiitool - deps/cliparser - deps/reveng - ../common/zlib - src - src/uart -) - #file(GLOB_RECURSE TARGET_HEADERS ${CMAKE_CURRENT_LIST_DIR}/src/*.h) #file(GLOB_RECURSE TARGET_SOURCES ${CMAKE_CURRENT_LIST_DIR}/src/*.cpp) @@ -274,6 +256,15 @@ add_executable( ${ADDITIONAL_SRC} ) +target_include_directories(proxmark3 PRIVATE + .. + ../common + ../include + deps + src + src/uart +) + if (APPLE) set_target_properties(proxmark3 PROPERTIES LINK_FLAGS "-Wl,-F/Library/Frameworks, -L/usr/local/opt/readline/lib") set_target_properties(proxmark3 PROPERTIES COMPILE_FLAGS "-I/usr/local/opt/readline/include") diff --git a/client/deps/amiibo.cmake b/client/deps/amiibo.cmake index 0374cb5d3..75501ca0a 100644 --- a/client/deps/amiibo.cmake +++ b/client/deps/amiibo.cmake @@ -14,3 +14,4 @@ add_library(amiibo STATIC ) target_include_directories(amiibo PRIVATE ../../include ../../common) +target_include_directories(amiibo INTERFACE amiitool) diff --git a/client/deps/jansson.cmake b/client/deps/jansson.cmake index c82694a21..49e059eff 100644 --- a/client/deps/jansson.cmake +++ b/client/deps/jansson.cmake @@ -16,3 +16,4 @@ add_library(jansson STATIC ) target_compile_definitions(jansson PRIVATE HAVE_STDINT_H) +target_include_directories(jansson INTERFACE jansson) diff --git a/client/deps/lua.cmake b/client/deps/lua.cmake index d0ea7fd12..1863297da 100644 --- a/client/deps/lua.cmake +++ b/client/deps/lua.cmake @@ -43,3 +43,5 @@ if (NOT MINGW) target_link_libraries(lua INTERFACE dl) endif (APPLE) endif (NOT MINGW) + +target_include_directories(lua INTERFACE liblua) diff --git a/client/deps/tinycbor.cmake b/client/deps/tinycbor.cmake index a78d428f5..7e4f78501 100644 --- a/client/deps/tinycbor.cmake +++ b/client/deps/tinycbor.cmake @@ -7,4 +7,7 @@ add_library(tinycbor STATIC tinycbor/cborpretty.c tinycbor/cbortojson.c tinycbor/cborvalidation.c - ) \ No newline at end of file + ) + +target_include_directories(tinycbor INTERFACE tinycbor) + diff --git a/client/src/emv/emvjson.h b/client/src/emv/emvjson.h index 9b1efb034..f4f3d4fb4 100644 --- a/client/src/emv/emvjson.h +++ b/client/src/emv/emvjson.h @@ -12,7 +12,7 @@ #include "common.h" -#include +#include "jansson.h" #include "tlv.h" typedef struct { From f9857a8b0c2ba4a0e6eecc8e83e65645bb2b3cb9 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 18 Apr 2020 17:37:11 +0200 Subject: [PATCH 29/70] cmake: add cflags --- client/CMakeLists.txt | 5 ++--- client/deps/amiibo.cmake | 1 + client/deps/hardnested.cmake | 6 ++++++ client/deps/jansson.cmake | 1 + client/deps/lua.cmake | 1 + client/deps/mbedtls.cmake | 1 + client/deps/reveng.cmake | 1 + client/deps/tinycbor.cmake | 2 +- client/deps/zlib.cmake | 1 + 9 files changed, 15 insertions(+), 4 deletions(-) diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 5f566e35e..3c6c44767 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -224,9 +224,6 @@ if (MINGW) set(CMAKE_CXX_FLAGS "-mno-ms-bitfields -fexec-charset=cp850 ${CMAKE_CXX_FLAGS}") endif (MINGW) -set(CMAKE_CXX_FLAGS "-Wall -Werror -O3") - - if(NOT Qt5_FOUND) message("Qt5 library not found, not building gui") set(TARGET_SOURCES @@ -256,6 +253,8 @@ add_executable( ${ADDITIONAL_SRC} ) +target_compile_options(proxmark3 PUBLIC -Wall -Werror -O3) + target_include_directories(proxmark3 PRIVATE .. ../common diff --git a/client/deps/amiibo.cmake b/client/deps/amiibo.cmake index 75501ca0a..dd185fc91 100644 --- a/client/deps/amiibo.cmake +++ b/client/deps/amiibo.cmake @@ -15,3 +15,4 @@ add_library(amiibo STATIC target_include_directories(amiibo PRIVATE ../../include ../../common) target_include_directories(amiibo INTERFACE amiitool) +target_compile_options(amiibo PRIVATE -Wall -Werror -O3) diff --git a/client/deps/hardnested.cmake b/client/deps/hardnested.cmake index 76ae3b53b..708203eb7 100644 --- a/client/deps/hardnested.cmake +++ b/client/deps/hardnested.cmake @@ -9,6 +9,7 @@ add_library(hardnested_nosimd OBJECT target_include_directories(hardnested_nosimd PRIVATE ../../common ../../include) +target_compile_options(hardnested_nosimd PRIVATE -Wall -Werror -O3) set(X86_CPUS x86 x86_64 i686) @@ -26,6 +27,7 @@ if ("${CMAKE_SYSTEM_PROCESSOR}" IN_LIST X86_CPUS) hardnested/hardnested_bf_core.c hardnested/hardnested_bitarray_core.c) + target_compile_options(hardnested_mmx PRIVATE -Wall -Werror -O3) target_compile_options(hardnested_mmx BEFORE PRIVATE -mmmx -mno-sse2 -mno-avx -mno-avx2 -mno-avx512f) @@ -40,6 +42,7 @@ if ("${CMAKE_SYSTEM_PROCESSOR}" IN_LIST X86_CPUS) hardnested/hardnested_bf_core.c hardnested/hardnested_bitarray_core.c) + target_compile_options(hardnested_sse2 PRIVATE -Wall -Werror -O3) target_compile_options(hardnested_sse2 BEFORE PRIVATE -mmmx -msse2 -mno-avx -mno-avx2 -mno-avx512f) @@ -54,6 +57,7 @@ if ("${CMAKE_SYSTEM_PROCESSOR}" IN_LIST X86_CPUS) hardnested/hardnested_bf_core.c hardnested/hardnested_bitarray_core.c) + target_compile_options(hardnested_avx PRIVATE -Wall -Werror -O3) target_compile_options(hardnested_avx BEFORE PRIVATE -mmmx -msse2 -mavx -mno-avx2 -mno-avx512f) @@ -68,6 +72,7 @@ if ("${CMAKE_SYSTEM_PROCESSOR}" IN_LIST X86_CPUS) hardnested/hardnested_bf_core.c hardnested/hardnested_bitarray_core.c) + target_compile_options(hardnested_avx2 PRIVATE -Wall -Werror -O3) target_compile_options(hardnested_avx2 BEFORE PRIVATE -mmmx -msse2 -mavx -mavx2 -mno-avx512f) @@ -82,6 +87,7 @@ if ("${CMAKE_SYSTEM_PROCESSOR}" IN_LIST X86_CPUS) hardnested/hardnested_bf_core.c hardnested/hardnested_bitarray_core.c) + target_compile_options(hardnested_avx512 PRIVATE -Wall -Werror -O3) target_compile_options(hardnested_avx512 BEFORE PRIVATE -mmmx -msse2 -mavx -mavx2 -mavx512f) diff --git a/client/deps/jansson.cmake b/client/deps/jansson.cmake index 49e059eff..b2042c6b4 100644 --- a/client/deps/jansson.cmake +++ b/client/deps/jansson.cmake @@ -17,3 +17,4 @@ add_library(jansson STATIC target_compile_definitions(jansson PRIVATE HAVE_STDINT_H) target_include_directories(jansson INTERFACE jansson) +target_compile_options(jansson PRIVATE -Wall -Werror -Wno-unused-function -O3) diff --git a/client/deps/lua.cmake b/client/deps/lua.cmake index 1863297da..3850863b5 100644 --- a/client/deps/lua.cmake +++ b/client/deps/lua.cmake @@ -45,3 +45,4 @@ if (NOT MINGW) endif (NOT MINGW) target_include_directories(lua INTERFACE liblua) +target_compile_options(lua PRIVATE -Wall -Werror -O3) diff --git a/client/deps/mbedtls.cmake b/client/deps/mbedtls.cmake index e0cc2d91f..13b08bec0 100644 --- a/client/deps/mbedtls.cmake +++ b/client/deps/mbedtls.cmake @@ -47,3 +47,4 @@ add_library(mbedtls STATIC ) target_include_directories(mbedtls PRIVATE ../../common) +target_compile_options(mbedtls PRIVATE -Wall -Werror -O3) diff --git a/client/deps/reveng.cmake b/client/deps/reveng.cmake index 425f98331..80fd2930b 100644 --- a/client/deps/reveng.cmake +++ b/client/deps/reveng.cmake @@ -12,3 +12,4 @@ add_library(reveng STATIC target_compile_definitions(reveng PRIVATE PRESETS) target_include_directories(reveng PRIVATE .) +target_compile_options(reveng PRIVATE -Wall -Werror -O3) diff --git a/client/deps/tinycbor.cmake b/client/deps/tinycbor.cmake index 7e4f78501..b3247d1e7 100644 --- a/client/deps/tinycbor.cmake +++ b/client/deps/tinycbor.cmake @@ -10,4 +10,4 @@ add_library(tinycbor STATIC ) target_include_directories(tinycbor INTERFACE tinycbor) - +target_compile_options(tinycbor PRIVATE -Wall -Werror -O2) diff --git a/client/deps/zlib.cmake b/client/deps/zlib.cmake index c78522a66..882022ab5 100644 --- a/client/deps/zlib.cmake +++ b/client/deps/zlib.cmake @@ -11,3 +11,4 @@ add_library(z STATIC ) target_compile_definitions(z PRIVATE Z_SOLO NO_GZIP ZLIB_PM3_TUNED) +target_compile_options(z PRIVATE -Wall -Werror -O3) From 26c28c188a9e3c04bd004e09c1439c8e6a25d170 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 18 Apr 2020 18:20:19 +0200 Subject: [PATCH 30/70] minor --- client/Makefile | 2 ++ client/src/emv/emvjson.c | 4 ++-- client/src/fido/cbortools.c | 10 +++++----- client/src/mifare/mad.c | 4 ++-- client/src/mifare/mifare4.c | 2 +- client/src/mifare/ndef.c | 4 ++-- client/src/util.c | 2 +- 7 files changed, 15 insertions(+), 13 deletions(-) diff --git a/client/Makefile b/client/Makefile index 892feadf7..ebc7f3676 100644 --- a/client/Makefile +++ b/client/Makefile @@ -54,6 +54,8 @@ INCLUDES_CLIENT = -I./src -I./deps -I../include -I../common -I./deps/cliparser - CFLAGS ?= -Wall -Werror -O3 # We cannot just use CFLAGS+=... because it has impact on sub-makes if CFLAGS is defined in env: PM3CFLAGS = $(CFLAGS) -std=c99 -D_ISOC99_SOURCE $(INCLUDES_CLIENT) +# WIP Testing +#PM3CFLAGS = $(CFLAGS) -std=c11 -pedantic $(INCLUDES_CLIENT) PREFIX ?= /usr/local ifneq (,$(findstring MINGW,$(platform))) PM3CFLAGS += -mno-ms-bitfields -fexec-charset=cp850 diff --git a/client/src/emv/emvjson.c b/client/src/emv/emvjson.c index 968b51d51..ebf42704f 100644 --- a/client/src/emv/emvjson.c +++ b/client/src/emv/emvjson.c @@ -92,7 +92,7 @@ int JsonSaveInt(json_t *root, const char *path, int value) { int JsonSaveStr(json_t *root, const char *path, const char *value) { return JsonSaveJsonObject(root, path, json_string(value)); -}; +} int JsonSaveBoolean(json_t *root, const char *path, bool value) { return JsonSaveJsonObject(root, path, json_boolean(value)); @@ -298,7 +298,7 @@ int JsonLoadBufAsHex(json_t *elm, const char *path, uint8_t *data, size_t maxbuf return 2; return 0; -}; +} bool ParamLoadFromJson(struct tlvdb *tlv) { json_t *root; diff --git a/client/src/fido/cbortools.c b/client/src/fido/cbortools.c index 911244806..d58b11145 100644 --- a/client/src/fido/cbortools.c +++ b/client/src/fido/cbortools.c @@ -387,7 +387,7 @@ CborError CborGetArrayBinStringValueEx(CborValue *elm, uint8_t *data, size_t max *datalen = totallen; return CborNoError; -}; +} CborError CborGetBinStringValue(CborValue *elm, uint8_t *data, size_t maxdatalen, size_t *datalen) { if (datalen) @@ -402,7 +402,7 @@ CborError CborGetBinStringValue(CborValue *elm, uint8_t *data, size_t maxdatalen *datalen = slen; return CborNoError; -}; +} CborError CborGetArrayStringValue(CborValue *elm, char *data, size_t maxdatalen, size_t *datalen, char *delimiter) { CborValue array; @@ -435,7 +435,7 @@ CborError CborGetArrayStringValue(CborValue *elm, char *data, size_t maxdatalen, *datalen = totallen; return CborNoError; -}; +} CborError CborGetStringValue(CborValue *elm, char *data, size_t maxdatalen, size_t *datalen) { if (datalen) @@ -450,14 +450,14 @@ CborError CborGetStringValue(CborValue *elm, char *data, size_t maxdatalen, size *datalen = slen; return CborNoError; -}; +} CborError CborGetStringValueBuf(CborValue *elm) { static char stringBuf[2048]; memset(stringBuf, 0x00, sizeof(stringBuf)); return CborGetStringValue(elm, stringBuf, sizeof(stringBuf), NULL); -}; +} int CBOREncodeElm(json_t *root, const char *rootElmId, CborEncoder *encoder) { json_t *elm = NULL; diff --git a/client/src/mifare/mad.c b/client/src/mifare/mad.c index fe41ac032..ffacba3a7 100644 --- a/client/src/mifare/mad.c +++ b/client/src/mifare/mad.c @@ -236,7 +236,7 @@ int MAD1DecodeAndPrint(uint8_t *sector, bool verbose, bool *haveMAD2) { }; return 0; -}; +} int MAD2DecodeAndPrint(uint8_t *sector, bool verbose) { PrintAndLogEx(NORMAL, "16 MAD2"); @@ -255,4 +255,4 @@ int MAD2DecodeAndPrint(uint8_t *sector, bool verbose) { }; return 0; -}; +} diff --git a/client/src/mifare/mifare4.c b/client/src/mifare/mifare4.c index 67c6f3932..09f10d321 100644 --- a/client/src/mifare/mifare4.c +++ b/client/src/mifare/mifare4.c @@ -88,7 +88,7 @@ const char *mfGetAccessConditionsDesc(uint8_t blockn, uint8_t *data) { }; return StaticNone; -}; +} /* static int CalculateEncIVCommand(mf4Session_t *session, uint8_t *iv, bool verbose) { memcpy(&iv[0], &session->TI, 4); diff --git a/client/src/mifare/ndef.c b/client/src/mifare/ndef.c index 990221c5c..45ad2e081 100644 --- a/client/src/mifare/ndef.c +++ b/client/src/mifare/ndef.c @@ -219,7 +219,7 @@ static int ndefDecodeSig1(uint8_t *sig, size_t siglen) { } return PM3_SUCCESS; -}; +} // https://github.com/nfcpy/ndeflib/blob/master/src/ndef/signature.py#L292 static int ndefDecodeSig2(uint8_t *sig, size_t siglen) { @@ -283,7 +283,7 @@ static int ndefDecodeSig2(uint8_t *sig, size_t siglen) { } return PM3_SUCCESS; -}; +} static int ndefDecodeSig(uint8_t *sig, size_t siglen) { PrintAndLogEx(SUCCESS, "\tsignature version : \t" _GREEN_("0x%02x"), sig[0]); diff --git a/client/src/util.c b/client/src/util.c index 654a87cc3..3d0c6bd87 100644 --- a/client/src/util.c +++ b/client/src/util.c @@ -941,7 +941,7 @@ char *str_ndup(const char *src, size_t len) { * Returns the number of nibbles (4 bits) entered. */ int hexstring_to_u96(uint32_t *hi2, uint32_t *hi, uint32_t *lo, const char *str) { - int n = 0, i = 0; + unsigned int n = 0, i = 0; while (sscanf(&str[i++], "%1x", &n) == 1) { *hi2 = (*hi2 << 4) | (*hi >> 28); From b41c5769e7736936ac0611c591e82a1a6e376ac2 Mon Sep 17 00:00:00 2001 From: Bjoern Kerler Date: Sat, 18 Apr 2020 18:35:50 +0200 Subject: [PATCH 31/70] Fix DESFIRE_UNKNOWN --- client/src/cmdhfmfdes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/cmdhfmfdes.c b/client/src/cmdhfmfdes.c index 159e319f8..814c9ebd2 100644 --- a/client/src/cmdhfmfdes.c +++ b/client/src/cmdhfmfdes.c @@ -639,7 +639,7 @@ static nxp_cardtype_t getCardType(uint8_t major, uint8_t minor) { if (major == 0x11 && minor == 0x00) return PLUS_EV1; - return UNKNOWN; + return DESFIRE_UNKNOWN; } int handler_desfire_auth(mfdes_authinput_t *payload, mfdes_auth_res_t *rpayload, bool defaultkey) { From c2ff11f32142304c7832198e3db912f3e4539a82 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 18 Apr 2020 19:39:55 +0200 Subject: [PATCH 32/70] hardnested compilation reorganized to be similar with cmake approach --- Makefile.host | 2 +- client/Makefile | 85 +++++---------------------------- client/deps/hardnested.cmake | 6 +++ client/deps/hardnested/Makefile | 83 ++++++++++++++++++++++++++++++++ client/deps/tinycbor.cmake | 1 + 5 files changed, 102 insertions(+), 75 deletions(-) create mode 100644 client/deps/hardnested/Makefile diff --git a/Makefile.host b/Makefile.host index 6d405ee14..896c9b361 100644 --- a/Makefile.host +++ b/Makefile.host @@ -28,7 +28,7 @@ POSTCOMPILE = $(MV) -f $(OBJDIR)/$*.Td $(OBJDIR)/$*.d && $(TOUCH) $@ BINDIR := . OBJDIR := obj -MYOBJS = $(MYSRCS:%.c=$(OBJDIR)/%.o) +MYOBJS ?= $(MYSRCS:%.c=$(OBJDIR)/%.o) CLEAN = $(foreach bin,$(MYLIBS) $(BINS) $(LIB_A),$(BINDIR)/$(bin)) all: $(foreach bin,$(MYLIBS) $(BINS) $(LIB_A),$(BINDIR)/$(bin)) diff --git a/client/Makefile b/client/Makefile index ebc7f3676..1b128b562 100644 --- a/client/Makefile +++ b/client/Makefile @@ -42,6 +42,8 @@ REVENGPATH = ./deps/reveng REVENGLIB = $(REVENGPATH)/libreveng.a AMIIBOLIBPATH = ./deps/amiitool AMIIBOLIB = $(AMIIBOLIBPATH)/libamiibo.a +HARDNESTEDPATH = ./deps/hardnested +HARDNESTEDLIB = $(HARDNESTEDPATH)/libhardnested.a # common libraries MBEDTLSLIBPATH = ../common/mbedtls @@ -49,7 +51,7 @@ MBEDTLSLIB = $(OBJDIR)/libmbedtls.a ZLIBPATH = ../common/zlib ZLIB = $(OBJDIR)/libz.a -LIBS = -I$(LUALIBPATH) -I$(MBEDTLSLIBPATH) -I$(JANSSONLIBPATH) -I$(CBORLIBPATH) -I$(ZLIBPATH) -I$(REVENGPATH) -I$(AMIIBOLIBPATH) +LIBS = -I$(LUALIBPATH) -I$(MBEDTLSLIBPATH) -I$(JANSSONLIBPATH) -I$(CBORLIBPATH) -I$(ZLIBPATH) -I$(REVENGPATH) -I$(AMIIBOLIBPATH) -I$(HARDNESTEDPATH) INCLUDES_CLIENT = -I./src -I./deps -I../include -I../common -I./deps/cliparser -I./src/uart $(LIBS) CFLAGS ?= -Wall -Werror -O3 # We cannot just use CFLAGS+=... because it has impact on sub-makes if CFLAGS is defined in env: @@ -204,7 +206,6 @@ CMDSRCS = crapto1/crapto1.c \ cmdhfmfu.c \ cmdhfmfp.c \ cmdhfmfhard.c \ - deps/hardnested/hardnested_bruteforce.c \ cmdhfmfdes.c \ cmdhftopaz.c \ cmdhffido.c \ @@ -260,43 +261,11 @@ CMDSRCS = crapto1/crapto1.c \ cardhelper.c \ preferences.c -cpu_arch = $(shell uname -m) -ifneq ($(findstring 86, $(cpu_arch)), ) - MULTIARCHSRCS = deps/hardnested/hardnested_bf_core.c deps/hardnested/hardnested_bitarray_core.c -endif -ifneq ($(findstring amd64, $(cpu_arch)), ) - MULTIARCHSRCS = deps/hardnested/hardnested_bf_core.c deps/hardnested/hardnested_bitarray_core.c -endif -ifeq ($(MULTIARCHSRCS), ) - CMDSRCS += deps/hardnested/hardnested_bf_core.c deps/hardnested/hardnested_bitarray_core.c -endif COREOBJS = $(CORESRCS:%.c=$(OBJDIR)/%.o) CMDOBJS = $(CMDSRCS:%.c=$(OBJDIR)/%.o) OBJCOBJS = $(OBJCSRCS:%.m=$(OBJDIR)/%.o) -MULTIARCHOBJS = $(MULTIARCHSRCS:%.c=$(OBJDIR)/%_NOSIMD.o) \ - $(MULTIARCHSRCS:%.c=$(OBJDIR)/%_MMX.o) \ - $(MULTIARCHSRCS:%.c=$(OBJDIR)/%_SSE2.o) \ - $(MULTIARCHSRCS:%.c=$(OBJDIR)/%_AVX.o) \ - $(MULTIARCHSRCS:%.c=$(OBJDIR)/%_AVX2.o) - -SUPPORTS_AVX512 := $(shell echo | gcc -E -mavx512f - > /dev/null 2>&1 && echo "True" ) - -HARD_SWITCH_NOSIMD = -mno-mmx -mno-sse2 -mno-avx -mno-avx2 -HARD_SWITCH_MMX = -mmmx -mno-sse2 -mno-avx -mno-avx2 -HARD_SWITCH_SSE2 = -mmmx -msse2 -mno-avx -mno-avx2 -HARD_SWITCH_AVX = -mmmx -msse2 -mavx -mno-avx2 -HARD_SWITCH_AVX2 = -mmmx -msse2 -mavx -mavx2 -HARD_SWITCH_AVX512 = -mmmx -msse2 -mavx -mavx2 -mavx512f -ifeq "$(SUPPORTS_AVX512)" "True" - HARD_SWITCH_NOSIMD += -mno-avx512f - HARD_SWITCH_MMX += -mno-avx512f - HARD_SWITCH_SSE2 += -mno-avx512f - HARD_SWITCH_AVX += -mno-avx512f - HARD_SWITCH_AVX2 += -mno-avx512f - MULTIARCHOBJS += $(MULTIARCHSRCS:%.c=$(OBJDIR)/%_AVX512.o) -endif BINS = proxmark3 CLEAN = $(BINS) *.moc.cpp ui/ui_overlays.h lualibs/pm3_cmd.lua lualibs/mfc_default_keys.lua @@ -309,10 +278,10 @@ all: $(BINS) all-static: LDLIBS:=-static $(LDLIBS) all-static: $(BINS) -proxmark3: LDLIBS+=$(LUALIB) $(JANSSONLIB) $(MBEDTLSLIB) $(CBORLIB) $(ZLIB) $(REVENGLIB) $(AMIIBOLIB) $(QTLDLIBS) -proxmark3: $(OBJDIR)/proxmark3.o $(COREOBJS) $(CMDOBJS) $(OBJCOBJS) $(QTGUIOBJS) $(MULTIARCHOBJS) $(LUALIB) $(JANSSONLIB) $(CBORLIB) $(REVENGLIB) $(MBEDTLSLIB) $(ZLIB) $(AMIIBOLIB) lualibs/pm3_cmd.lua lualibs/mfc_default_keys.lua +proxmark3: LDLIBS+=$(LUALIB) $(JANSSONLIB) $(MBEDTLSLIB) $(CBORLIB) $(ZLIB) $(REVENGLIB) $(AMIIBOLIB) $(HARDNESTEDLIB) $(QTLDLIBS) +proxmark3: $(OBJDIR)/proxmark3.o $(COREOBJS) $(CMDOBJS) $(OBJCOBJS) $(QTGUIOBJS) $(LUALIB) $(JANSSONLIB) $(CBORLIB) $(REVENGLIB) $(MBEDTLSLIB) $(ZLIB) $(AMIIBOLIB) $(HARDNESTEDLIB) lualibs/pm3_cmd.lua lualibs/mfc_default_keys.lua $(info [=] LD $@) - $(Q)$(LD) $(LDFLAGS) $(OBJDIR)/proxmark3.o $(COREOBJS) $(CMDOBJS) $(OBJCOBJS) $(QTGUIOBJS) $(MULTIARCHOBJS) $(LDLIBS) -o $@ + $(Q)$(LD) $(LDFLAGS) $(OBJDIR)/proxmark3.o $(COREOBJS) $(CMDOBJS) $(OBJCOBJS) $(QTGUIOBJS) $(LDLIBS) -o $@ src/proxgui.cpp: src/ui/ui_overlays.h @@ -340,6 +309,7 @@ clean: $(Q)$(MAKE) --no-print-directory -C $(CBORLIBPATH) clean $(Q)$(MAKE) --no-print-directory -C $(REVENGPATH) clean $(Q)$(MAKE) --no-print-directory -C $(AMIIBOLIBPATH) clean + $(Q)$(MAKE) --no-print-directory -C $(HARDNESTEDPATH) clean install: all $(info [@] Installing client to $(DESTDIR)$(PREFIX)...) @@ -384,6 +354,10 @@ $(REVENGLIB): $(info [*] MAKE reveng) $(Q)$(MAKE) --no-print-directory -C $(REVENGPATH) all +$(HARDNESTEDLIB): + $(info [*] MAKE hardnested) + $(Q)$(MAKE) --no-print-directory -C $(HARDNESTEDPATH) all + $(AMIIBOLIB): $(info [*] MAKE amiibo) $(Q)$(MAKE) --no-print-directory -C $(AMIIBOLIBPATH) all @@ -402,42 +376,6 @@ $(ZLIB): # easy printing of MAKE VARIABLES print-%: ; @echo $* = $($*) -$(OBJDIR)/%_NOSIMD.o : %.c $(OBJDIR)/%_NOSIMD.d - $(info [-] CC(NOSIMD) $<) - $(Q)$(MKDIR) $(dir $@) - $(Q)$(CC) $(DEPFLAGS:%.Td=%_NOSIMD.Td) $(PM3CFLAGS) $(HARD_SWITCH_NOSIMD) -c -o $@ $< - $(Q)$(MV) -f $(OBJDIR)/$*_NOSIMD.Td $(OBJDIR)/$*_NOSIMD.d && $(TOUCH) $@ - -$(OBJDIR)/%_MMX.o : %.c $(OBJDIR)/%_MMX.d - $(info [-] CC(MMX) $<) - $(Q)$(MKDIR) $(dir $@) - $(Q)$(CC) $(DEPFLAGS:%.Td=%_MMX.Td) $(PM3CFLAGS) $(HARD_SWITCH_MMX) -c -o $@ $< - $(Q)$(MV) -f $(OBJDIR)/$*_MMX.Td $(OBJDIR)/$*_MMX.d && $(TOUCH) $@ - -$(OBJDIR)/%_SSE2.o : %.c $(OBJDIR)/%_SSE2.d - $(info [-] CC(SSE2) $<) - $(Q)$(MKDIR) $(dir $@) - $(Q)$(CC) $(DEPFLAGS:%.Td=%_SSE2.Td) $(PM3CFLAGS) $(HARD_SWITCH_SSE2) -c -o $@ $< - $(Q)$(MV) -f $(OBJDIR)/$*_SSE2.Td $(OBJDIR)/$*_SSE2.d && $(TOUCH) $@ - -$(OBJDIR)/%_AVX.o : %.c $(OBJDIR)/%_AVX.d - $(info [-] CC(AVX) $<) - $(Q)$(MKDIR) $(dir $@) - $(Q)$(CC) $(DEPFLAGS:%.Td=%_AVX.Td) $(PM3CFLAGS) $(HARD_SWITCH_AVX) -c -o $@ $< - $(Q)$(MV) -f $(OBJDIR)/$*_AVX.Td $(OBJDIR)/$*_AVX.d && $(TOUCH) $@ - -$(OBJDIR)/%_AVX2.o : %.c $(OBJDIR)/%_AVX2.d - $(info [-] CC(AVX2) $<) - $(Q)$(MKDIR) $(dir $@) - $(Q)$(CC) $(DEPFLAGS:%.Td=%_AVX2.Td) $(PM3CFLAGS) $(HARD_SWITCH_AVX2) -c -o $@ $< - $(Q)$(MV) -f $(OBJDIR)/$*_AVX2.Td $(OBJDIR)/$*_AVX2.d && $(TOUCH) $@ - -$(OBJDIR)/%_AVX512.o : %.c $(OBJDIR)/%_AVX512.d - $(info [-] CC(AVX512) $<) - $(Q)$(MKDIR) $(dir $@) - $(Q)$(CC) $(DEPFLAGS:%.Td=%_AVX512.Td) $(PM3CFLAGS) $(HARD_SWITCH_AVX512) -c -o $@ $< - $(Q)$(MV) -f $(OBJDIR)/$*_AVX512.Td $(OBJDIR)/$*_AVX512.d && $(TOUCH) $@ - %.o: %.c $(OBJDIR)/%.o : %.c $(OBJDIR)/%.d $(info [-] CC $<) @@ -460,7 +398,6 @@ $(OBJDIR)/%.o : %.m $(OBJDIR)/%.d $(Q)$(POSTCOMPILE) DEPENDENCY_FILES = $(patsubst %.c, $(OBJDIR)/%.d, $(CORESRCS) $(CMDSRCS) $(REVENGSRCS)) \ - $(patsubst %.o, %.d, $(MULTIARCHOBJS)) \ $(patsubst %.cpp, $(OBJDIR)/%.d, $(QTGUISRCS)) \ $(patsubst %.m, $(OBJDIR)/%.d, $(OBJCSRCS)) \ $(OBJDIR)/proxmark3.d diff --git a/client/deps/hardnested.cmake b/client/deps/hardnested.cmake index 708203eb7..4e19740c1 100644 --- a/client/deps/hardnested.cmake +++ b/client/deps/hardnested.cmake @@ -109,5 +109,11 @@ else () endif () add_library(hardnested STATIC + hardnested/hardnested_bruteforce.c $ ${SIMD_TARGETS}) +target_include_directories(hardnested PRIVATE + ../../common + ../../include + ../src + jansson) diff --git a/client/deps/hardnested/Makefile b/client/deps/hardnested/Makefile new file mode 100644 index 000000000..84c4ce842 --- /dev/null +++ b/client/deps/hardnested/Makefile @@ -0,0 +1,83 @@ +MYSRCPATHS = +MYINCLUDES = -I../../../common -I../../../include -I../../src -I../jansson +MYCFLAGS = -std=c99 -D_ISOC99_SOURCE +MYDEFS = +MYSRCS = hardnested_bruteforce.c + +cpu_arch = $(shell uname -m) +ifneq ($(findstring 86, $(cpu_arch)), ) + MULTIARCHSRCS = hardnested_bf_core.c hardnested_bitarray_core.c +endif +ifneq ($(findstring amd64, $(cpu_arch)), ) + MULTIARCHSRCS = hardnested_bf_core.c hardnested_bitarray_core.c +endif +ifeq ($(MULTIARCHSRCS), ) + MYSRCS += hardnested_bf_core.c hardnested_bitarray_core.c +endif + +LIB_A = libhardnested.a + +MYOBJS = $(MYSRCS:%.c=$(OBJDIR)/%.o) +MYOBJS += $(MULTIARCHSRCS:%.c=$(OBJDIR)/%_NOSIMD.o) \ + $(MULTIARCHSRCS:%.c=$(OBJDIR)/%_MMX.o) \ + $(MULTIARCHSRCS:%.c=$(OBJDIR)/%_SSE2.o) \ + $(MULTIARCHSRCS:%.c=$(OBJDIR)/%_AVX.o) \ + $(MULTIARCHSRCS:%.c=$(OBJDIR)/%_AVX2.o) + +SUPPORTS_AVX512 := $(shell echo | gcc -E -mavx512f - > /dev/null 2>&1 && echo "True" ) + +HARD_SWITCH_NOSIMD = -mno-mmx -mno-sse2 -mno-avx -mno-avx2 +HARD_SWITCH_MMX = -mmmx -mno-sse2 -mno-avx -mno-avx2 +HARD_SWITCH_SSE2 = -mmmx -msse2 -mno-avx -mno-avx2 +HARD_SWITCH_AVX = -mmmx -msse2 -mavx -mno-avx2 +HARD_SWITCH_AVX2 = -mmmx -msse2 -mavx -mavx2 +HARD_SWITCH_AVX512 = -mmmx -msse2 -mavx -mavx2 -mavx512f +ifeq "$(SUPPORTS_AVX512)" "True" + HARD_SWITCH_NOSIMD += -mno-avx512f + HARD_SWITCH_MMX += -mno-avx512f + HARD_SWITCH_SSE2 += -mno-avx512f + HARD_SWITCH_AVX += -mno-avx512f + HARD_SWITCH_AVX2 += -mno-avx512f + MYOBJS += $(MULTIARCHSRCS:%.c=$(OBJDIR)/%_AVX512.o) +endif + +include ../../../Makefile.host + +$(OBJDIR)/%_NOSIMD.o : %.c $(OBJDIR)/%_NOSIMD.d + $(info DEBUG $<) + +$(OBJDIR)/%_NOSIMD.o : %.c $(OBJDIR)/%_NOSIMD.d + $(info [-] CC(NOSIMD) $<) + $(Q)$(MKDIR) $(dir $@) + $(Q)$(CC) $(DEPFLAGS:%.Td=%_NOSIMD.Td) $(CFLAGS) $(HARD_SWITCH_NOSIMD) -c -o $@ $< + $(Q)$(MV) -f $(OBJDIR)/$*_NOSIMD.Td $(OBJDIR)/$*_NOSIMD.d && $(TOUCH) $@ + +$(OBJDIR)/%_MMX.o : %.c $(OBJDIR)/%_MMX.d + $(info [-] CC(MMX) $<) + $(Q)$(MKDIR) $(dir $@) + $(Q)$(CC) $(DEPFLAGS:%.Td=%_MMX.Td) $(CFLAGS) $(HARD_SWITCH_MMX) -c -o $@ $< + $(Q)$(MV) -f $(OBJDIR)/$*_MMX.Td $(OBJDIR)/$*_MMX.d && $(TOUCH) $@ + +$(OBJDIR)/%_SSE2.o : %.c $(OBJDIR)/%_SSE2.d + $(info [-] CC(SSE2) $<) + $(Q)$(MKDIR) $(dir $@) + $(Q)$(CC) $(DEPFLAGS:%.Td=%_SSE2.Td) $(CFLAGS) $(HARD_SWITCH_SSE2) -c -o $@ $< + $(Q)$(MV) -f $(OBJDIR)/$*_SSE2.Td $(OBJDIR)/$*_SSE2.d && $(TOUCH) $@ + +$(OBJDIR)/%_AVX.o : %.c $(OBJDIR)/%_AVX.d + $(info [-] CC(AVX) $<) + $(Q)$(MKDIR) $(dir $@) + $(Q)$(CC) $(DEPFLAGS:%.Td=%_AVX.Td) $(CFLAGS) $(HARD_SWITCH_AVX) -c -o $@ $< + $(Q)$(MV) -f $(OBJDIR)/$*_AVX.Td $(OBJDIR)/$*_AVX.d && $(TOUCH) $@ + +$(OBJDIR)/%_AVX2.o : %.c $(OBJDIR)/%_AVX2.d + $(info [-] CC(AVX2) $<) + $(Q)$(MKDIR) $(dir $@) + $(Q)$(CC) $(DEPFLAGS:%.Td=%_AVX2.Td) $(CFLAGS) $(HARD_SWITCH_AVX2) -c -o $@ $< + $(Q)$(MV) -f $(OBJDIR)/$*_AVX2.Td $(OBJDIR)/$*_AVX2.d && $(TOUCH) $@ + +$(OBJDIR)/%_AVX512.o : %.c $(OBJDIR)/%_AVX512.d + $(info [-] CC(AVX512) $<) + $(Q)$(MKDIR) $(dir $@) + $(Q)$(CC) $(DEPFLAGS:%.Td=%_AVX512.Td) $(CFLAGS) $(HARD_SWITCH_AVX512) -c -o $@ $< + $(Q)$(MV) -f $(OBJDIR)/$*_AVX512.Td $(OBJDIR)/$*_AVX512.d && $(TOUCH) $@ diff --git a/client/deps/tinycbor.cmake b/client/deps/tinycbor.cmake index b3247d1e7..14ebb5326 100644 --- a/client/deps/tinycbor.cmake +++ b/client/deps/tinycbor.cmake @@ -10,4 +10,5 @@ add_library(tinycbor STATIC ) target_include_directories(tinycbor INTERFACE tinycbor) +# Strange errors on Mingw when compiling with -O3 target_compile_options(tinycbor PRIVATE -Wall -Werror -O2) From 45134859cfb1e0db2dbe2fab52acdcea5faac21f Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 18 Apr 2020 20:01:51 +0200 Subject: [PATCH 33/70] cmake: remove unneeded PIC in hardnested lib --- client/deps/hardnested.cmake | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/client/deps/hardnested.cmake b/client/deps/hardnested.cmake index 4e19740c1..facb804fa 100644 --- a/client/deps/hardnested.cmake +++ b/client/deps/hardnested.cmake @@ -20,8 +20,6 @@ if ("${CMAKE_SYSTEM_PROCESSOR}" IN_LIST X86_CPUS) target_compile_options(hardnested_nosimd BEFORE PRIVATE -mno-mmx -mno-sse2 -mno-avx -mno-avx2 -mno-avx512f) - set_property(TARGET hardnested_nosimd PROPERTY POSITION_INDEPENDENT_CODE ON) - ## x86 / MMX add_library(hardnested_mmx OBJECT hardnested/hardnested_bf_core.c @@ -35,8 +33,6 @@ if ("${CMAKE_SYSTEM_PROCESSOR}" IN_LIST X86_CPUS) ../../common ../../include) - set_property(TARGET hardnested_mmx PROPERTY POSITION_INDEPENDENT_CODE ON) - ## x86 / SSE2 add_library(hardnested_sse2 OBJECT hardnested/hardnested_bf_core.c @@ -50,8 +46,6 @@ if ("${CMAKE_SYSTEM_PROCESSOR}" IN_LIST X86_CPUS) ../../common ../../include) - set_property(TARGET hardnested_sse2 PROPERTY POSITION_INDEPENDENT_CODE ON) - ## x86 / AVX add_library(hardnested_avx OBJECT hardnested/hardnested_bf_core.c @@ -65,8 +59,6 @@ if ("${CMAKE_SYSTEM_PROCESSOR}" IN_LIST X86_CPUS) ../../common ../../include) - set_property(TARGET hardnested_avx PROPERTY POSITION_INDEPENDENT_CODE ON) - ## x86 / AVX2 add_library(hardnested_avx2 OBJECT hardnested/hardnested_bf_core.c @@ -80,8 +72,6 @@ if ("${CMAKE_SYSTEM_PROCESSOR}" IN_LIST X86_CPUS) ../../common ../../include) - set_property(TARGET hardnested_avx2 PROPERTY POSITION_INDEPENDENT_CODE ON) - ## x86 / AVX512 add_library(hardnested_avx512 OBJECT hardnested/hardnested_bf_core.c @@ -95,8 +85,6 @@ if ("${CMAKE_SYSTEM_PROCESSOR}" IN_LIST X86_CPUS) ../../common ../../include) - set_property(TARGET hardnested_avx512 PROPERTY POSITION_INDEPENDENT_CODE ON) - set(SIMD_TARGETS $ $ From 17aacae8d38f6d024ee0afaa83cd74c5333116a3 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 18 Apr 2020 20:13:46 +0200 Subject: [PATCH 34/70] fix clean path after src reorg --- client/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/Makefile b/client/Makefile index 1b128b562..fa9dd281f 100644 --- a/client/Makefile +++ b/client/Makefile @@ -268,7 +268,7 @@ CMDOBJS = $(CMDSRCS:%.c=$(OBJDIR)/%.o) OBJCOBJS = $(OBJCSRCS:%.m=$(OBJDIR)/%.o) BINS = proxmark3 -CLEAN = $(BINS) *.moc.cpp ui/ui_overlays.h lualibs/pm3_cmd.lua lualibs/mfc_default_keys.lua +CLEAN = $(BINS) src/*.moc.cpp src/ui/ui_overlays.h lualibs/pm3_cmd.lua lualibs/mfc_default_keys.lua # transition: make sure old flasher is gone too CLEAN += flasher From f94a98b9c6fb0d2f0353272ba10dffd80bbc9a39 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 18 Apr 2020 20:14:18 +0200 Subject: [PATCH 35/70] cmake qt5: no need for custom command if AUTOMOC? --- client/CMakeLists.txt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 3c6c44767..ee7f6c7ad 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -232,12 +232,6 @@ if(NOT Qt5_FOUND) endif(NOT Qt5_FOUND) if (Qt5_FOUND) message("Qt5 library found, building gui :)") - - add_custom_command(OUTPUT src/proxguiqt.moc.cpp - COMMAND "$(MOC) -o src/proxguiqt.moc.cpp proxguiqt.h" - COMMENT "Creating src/proxguiqt.moc.cpp" - ) - set (TARGET_SOURCES src/proxgui.cpp src/proxguiqt.cpp From a04c8cb41cc24adfe0903863973da66686b5fbae Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 18 Apr 2020 20:42:38 +0200 Subject: [PATCH 36/70] cosmetic --- client/CMakeLists.txt | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index ee7f6c7ad..43529809e 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -224,12 +224,6 @@ if (MINGW) set(CMAKE_CXX_FLAGS "-mno-ms-bitfields -fexec-charset=cp850 ${CMAKE_CXX_FLAGS}") endif (MINGW) -if(NOT Qt5_FOUND) - message("Qt5 library not found, not building gui") - set(TARGET_SOURCES - src/guidummy.cpp - ${TARGET_SOURCES}) -endif(NOT Qt5_FOUND) if (Qt5_FOUND) message("Qt5 library found, building gui :)") set (TARGET_SOURCES @@ -239,6 +233,11 @@ if (Qt5_FOUND) add_definitions("-DHAVE_GUI") set(ADDITIONAL_LNK Qt5::Core Qt5::Widgets Qt5::Gui ${ADDITIONAL_LNK}) +else (Qt5_FOUND) + message("Qt5 library not found, not building gui") + set(TARGET_SOURCES + src/guidummy.cpp + ${TARGET_SOURCES}) endif (Qt5_FOUND) add_executable( From da814243480376d2baf172d184c2b260fa383ea6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nahuel=20Grisol=C3=ADa?= Date: Sat, 18 Apr 2020 21:34:48 +0200 Subject: [PATCH 37/70] OTP-TEAR --- armsrc/appmain.c | 2 +- armsrc/mifarecmd.c | 38 +++--------- armsrc/mifarecmd.h | 2 +- client/src/cmdhfmfu.c | 138 ++++++++++++++++++++++++++++++++++++++---- 4 files changed, 137 insertions(+), 43 deletions(-) diff --git a/armsrc/appmain.c b/armsrc/appmain.c index b44dbc5c5..587347390 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -1295,7 +1295,7 @@ static void PacketReceived(PacketCommandNG *packet) { break; } case CMD_HF_MFU_OTP_TEAROFF: { - MifareU_Otp_Tearoff(); + MifareU_Otp_Tearoff(packet->oldarg[0], packet->oldarg[1], packet->data.asBytes); break; } case CMD_HF_MIFARE_STATIC_NONCE: { diff --git a/armsrc/mifarecmd.c b/armsrc/mifarecmd.c index a8f829144..0266af633 100644 --- a/armsrc/mifarecmd.c +++ b/armsrc/mifarecmd.c @@ -2423,12 +2423,14 @@ void Mifare_DES_Auth2(uint32_t arg0, uint8_t *datain) { // // Tear-off attack against MFU. // - Moebius et al -void MifareU_Otp_Tearoff() { - -// should the -// optional time be configurable via client side? +void MifareU_Otp_Tearoff(uint8_t arg0, uint32_t arg1, uint8_t *datain) { + uint8_t blockNo = arg0; + uint32_t tearOffTime = arg1; + uint8_t data_fullwrite[4] = {0x00}; + uint8_t data_testwrite[4] = {0x00}; + memcpy(data_fullwrite, datain, 4); + memcpy(data_testwrite, datain + 4, 4); // optional authentication before? -// optional data to be written? if (DBGLEVEL >= DBG_ERROR) DbpString("Preparing OTP tear-off"); @@ -2439,46 +2441,26 @@ void MifareU_Otp_Tearoff() { StartTicks(); -#define OTP_TEAR_OFF_TIME 1000 -#define OTP_BLK_NO 3 - // write cmd to send, include CRC // 1b write, 1b block, 4b data, 2 crc - uint8_t cmd[] = {MIFARE_ULC_WRITE, OTP_BLK_NO, 0xFF, 0xFF, 0xFF, 0xFF, 0, 0}; + uint8_t cmd[] = {MIFARE_ULC_WRITE, blockNo, data_testwrite[0], data_testwrite[1], data_testwrite[2], data_testwrite[3], 0, 0}; -// User specific data to write? -// memcpy(block + 2, blockData, 4); + MifareUWriteBlock(blockNo, 0, data_fullwrite); AddCrc14A(cmd, sizeof(cmd) - 2); - if (DBGLEVEL >= DBG_ERROR) DbpString("Transmitting"); - // anticollision / select card if (!iso14443a_select_card(NULL, NULL, NULL, true, 0, true)) { if (DBGLEVEL >= DBG_ERROR) Dbprintf("Can't select card"); OnError(1); return; }; - - /* - // UL-EV1 / NTAG authentication - if (usePwd) { - uint8_t pwd[4] = {0x00}; - memcpy(pwd, datain + 4, 4); - uint8_t pack[4] = {0, 0, 0, 0}; - if (!mifare_ul_ev1_auth(pwd, pack)) { - OnError(1); - return; - } - } - */ - // send ReaderTransmit(cmd, sizeof(cmd), NULL); // Wait before cutting power. aka tear-off LED_D_ON(); - WaitUS(OTP_TEAR_OFF_TIME); + WaitUS(tearOffTime); switch_off(); reply_ng(CMD_HF_MFU_OTP_TEAROFF, PM3_SUCCESS, NULL, 0); diff --git a/armsrc/mifarecmd.h b/armsrc/mifarecmd.h index 91adba3b1..a4bf2b30b 100644 --- a/armsrc/mifarecmd.h +++ b/armsrc/mifarecmd.h @@ -59,6 +59,6 @@ void Mifare_DES_Auth1(uint8_t arg0, uint8_t *datain); void Mifare_DES_Auth2(uint32_t arg0, uint8_t *datain); // Tear-off test for MFU -void MifareU_Otp_Tearoff(); +void MifareU_Otp_Tearoff(uint8_t arg0, uint32_t arg1, uint8_t *datain); #endif diff --git a/client/src/cmdhfmfu.c b/client/src/cmdhfmfu.c index fcac8d137..a3e256cff 100644 --- a/client/src/cmdhfmfu.c +++ b/client/src/cmdhfmfu.c @@ -235,13 +235,21 @@ static int usage_hf_mfu_pwdgen(void) { } static int usage_hf_mfu_otp_tearoff(void) { - PrintAndLogEx(NORMAL, "Tear-off test against OTP block on MFU tags."); - PrintAndLogEx(NORMAL, "Usage: hf mfu otptear [h]"); + PrintAndLogEx(NORMAL, "Tear-off test against OTP block (no 3) on MFU tags - More help sooner or later\n"); + PrintAndLogEx(NORMAL, "Usage: hf mfu otptear b i l s \n"); PrintAndLogEx(NORMAL, "Options:"); - PrintAndLogEx(NORMAL, " h : this help"); - PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, _YELLOW_(" hf mfu otptear")); + PrintAndLogEx(NORMAL, " b : (optional) block to run the test - default block: 8 (not OTP for safety)"); + PrintAndLogEx(NORMAL, " i