From 7f76fea21a7434aabf633c9b6cc28c8a576a1d30 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Wed, 10 Apr 2019 10:21:42 +0200 Subject: [PATCH] good const, bad const, fixing -Wincompatible-pointer-types-discards-qualifiers --- client/cliparser/argtable3.c | 12 +++++----- client/cliparser/cliparser.c | 8 +++---- client/cliparser/cliparser.h | 2 +- client/cliparser/getopt.h | 2 +- client/cmdhf14a.c | 4 ++-- client/cmdhf14a.h | 4 ++-- client/cmdhf15.c | 10 ++++---- client/cmdhffido.c | 2 +- client/cmdhfmfdes.c | 2 +- client/cmdhfmfhard.c | 2 +- client/cmdhfmfhard.h | 2 +- client/cmdlfti.c | 2 +- client/cmdparser.c | 2 +- client/cmdscript.c | 4 ++-- client/cmdtrace.c | 2 +- client/crypto/asn1dump.c | 2 +- client/crypto/asn1utils.c | 2 +- client/crypto/asn1utils.h | 2 +- client/crypto/libpcrypto.c | 6 ++--- client/emv/apduinfo.c | 2 +- client/emv/apduinfo.h | 2 +- client/emv/cmdemv.c | 2 +- client/emv/emv_tags.c | 6 ++--- client/emv/emv_tags.h | 2 +- client/emv/emvcore.c | 4 ++-- client/emv/emvcore.h | 2 +- client/emv/emvjson.c | 32 +++++++++++++------------- client/emv/emvjson.h | 28 +++++++++++----------- client/fido/cbortools.c | 4 ++-- client/fido/cbortools.h | 2 +- client/fido/cose.c | 10 ++++---- client/fido/fidocore.c | 10 ++++---- client/fido/fidocore.h | 4 ++-- client/hardnested/hardnested_bf_core.c | 8 +++---- client/hardnested/hardnested_bf_core.h | 2 +- client/loclass/cipherutils.c | 6 ++--- client/loclass/cipherutils.h | 6 ++--- client/loclass/ikeys.c | 4 ++-- client/mifare/mifare4.c | 2 +- client/mifare/mifare4.h | 4 ++-- client/ui.c | 8 +++---- client/ui.h | 4 ++-- client/util.c | 10 ++++---- client/util.h | 10 ++++---- uart/uart_posix.c | 2 +- 45 files changed, 124 insertions(+), 124 deletions(-) diff --git a/client/cliparser/argtable3.c b/client/cliparser/argtable3.c index 1d5c2d055..019603f50 100644 --- a/client/cliparser/argtable3.c +++ b/client/cliparser/argtable3.c @@ -236,7 +236,7 @@ int opterr = 1; /* if error message should be printed */ int optind = 1; /* index into parent argv vector */ int optopt = '?'; /* character checked for validity */ int optreset; /* reset getopt */ -char *optarg; /* argument associated with option */ +const char *optarg; /* argument associated with option */ #endif #define PRINT_ERROR ((opterr) && (*options != ':')) @@ -259,7 +259,7 @@ static int parse_long_options(char *const *, const char *, static int gcd(int, int); static void permute_args(int, int, int, char *const *); -static char *place = EMSG; /* option letter processing */ +static const char *place = EMSG; /* option letter processing */ /* XXX: set optreset to 1 rather than these two */ static int nonopt_start = -1; /* first non option argument (for permute) */ @@ -377,7 +377,7 @@ permute_args(int panonopt_start, int panonopt_end, int opt_end, static int parse_long_options(char *const *nargv, const char *options, const struct option *long_options, int *idx, int short_too) { - char *current_argv, *has_equal; + const char *current_argv, *has_equal; size_t current_argv_len; int i, match; @@ -4325,9 +4325,9 @@ void arg_print_option(FILE *fp, static void arg_print_gnuswitch(FILE *fp, struct arg_hdr * *table) { int tabindex; - char *format1 = " -%c"; - char *format2 = " [-%c"; - char *suffix = ""; + const char *format1 = " -%c"; + const char *format2 = " [-%c"; + const char *suffix = ""; /* print all mandatory switches that are without argument values */ for (tabindex = 0; diff --git a/client/cliparser/cliparser.c b/client/cliparser/cliparser.c index 6bba6f58b..ae2124085 100644 --- a/client/cliparser/cliparser.c +++ b/client/cliparser/cliparser.c @@ -14,12 +14,12 @@ void **argtable = NULL; size_t argtableLen = 0; -char *programName = NULL; -char *programHint = NULL; -char *programHelp = NULL; +const char *programName = NULL; +const char *programHint = NULL; +const char *programHelp = NULL; char buf[500] = {0}; -int CLIParserInit(char *vprogramName, char *vprogramHint, char *vprogramHelp) { +int CLIParserInit(const char *vprogramName, const char *vprogramHint, const char *vprogramHelp) { argtable = NULL; argtableLen = 0; programName = vprogramName; diff --git a/client/cliparser/cliparser.h b/client/cliparser/cliparser.h index a7c8480f4..44d9cc12c 100644 --- a/client/cliparser/cliparser.h +++ b/client/cliparser/cliparser.h @@ -31,7 +31,7 @@ #define CLIGetHexWithReturn(paramnum, data, datalen) if (CLIParamHexToBuf(arg_get_str(paramnum), data, sizeof(data), datalen)) {CLIParserFree();return 1;} #define CLIGetStrWithReturn(paramnum, data, datalen) if (CLIParamStrToBuf(arg_get_str(paramnum), data, sizeof(data), datalen)) {CLIParserFree();return 1;} -int CLIParserInit(char *vprogramName, char *vprogramHint, char *vprogramHelp); +int CLIParserInit(const char *vprogramName, const char *vprogramHint, const char *vprogramHelp); int CLIParserParseString(const char *str, void *vargtable[], size_t vargtableLen, bool allowEmptyExec); int CLIParserParseStringEx(const char *str, void *vargtable[], size_t vargtableLen, bool allowEmptyExec, bool clueData); int CLIParserParseArg(int argc, char **argv, void *vargtable[], size_t vargtableLen, bool allowEmptyExec); diff --git a/client/cliparser/getopt.h b/client/cliparser/getopt.h index 308acf3ce..bf645feb5 100644 --- a/client/cliparser/getopt.h +++ b/client/cliparser/getopt.h @@ -68,7 +68,7 @@ int getopt_long_only(int, char *const *, const char *, #define _GETOPT_DECLARED int getopt(int, char *const [], const char *); -extern char *optarg; /* getopt(3) external variables */ +extern const char *optarg; /* getopt(3) external variables */ extern int optind, opterr, optopt; #endif #ifndef _OPTRESET_DECLARED diff --git a/client/cmdhf14a.c b/client/cmdhf14a.c index a8fe2e40b..ede90f7fb 100644 --- a/client/cmdhf14a.c +++ b/client/cmdhf14a.c @@ -136,7 +136,7 @@ static const manufactureName manufactureMapping[] = { // get a product description based on the UID // uid[8] tag uid // returns description of the best match -char *getTagInfo(uint8_t uid) { +const char *getTagInfo(uint8_t uid) { int i; int len = sizeof(manufactureMapping) / sizeof(manufactureName); @@ -566,7 +566,7 @@ int CmdHF14AInfo(const char *Cmd) { pos++; } if (card.ats[0] > pos && card.ats[0] < card.ats_len - 2) { - char *tip = ""; + const char *tip = ""; if (card.ats[0] - pos >= 7) { if (memcmp(card.ats + pos, "\xC1\x05\x2F\x2F\x01\xBC\xD6", 7) == 0) { tip = "-> MIFARE Plus X 2K or 4K"; diff --git a/client/cmdhf14a.h b/client/cmdhf14a.h index 263bb7e9f..cababc217 100644 --- a/client/cmdhf14a.h +++ b/client/cmdhf14a.h @@ -35,7 +35,7 @@ // structure and database for uid -> tagtype lookups typedef struct { uint8_t uid; - char *desc; + const char *desc; } manufactureName; int CmdHF14A(const char *Cmd); @@ -48,7 +48,7 @@ int CmdHF14ACmdRaw(const char *Cmd); int CmdHF14ACUIDs(const char *Cmd); int CmdHF14AAntiFuzz(const char *Cmd); -char *getTagInfo(uint8_t uid); +const char *getTagInfo(uint8_t uid); int Hf14443_4aGetCardData(iso14a_card_select_t *card); int ExchangeAPDU14a(uint8_t *datain, int datainlen, bool activateField, bool leaveSignalON, uint8_t *dataout, int maxdataoutlen, int *dataoutlen); int ExchangeRAW14a(uint8_t *datain, int datainlen, bool activateField, bool leaveSignalON, uint8_t *dataout, int maxdataoutlen, int *dataoutlen); diff --git a/client/cmdhf15.c b/client/cmdhf15.c index 2b9751c33..bc03b0883 100644 --- a/client/cmdhf15.c +++ b/client/cmdhf15.c @@ -46,7 +46,7 @@ typedef struct { uint64_t uid; int mask; // how many MSB bits used - char *desc; + const char *desc; } productName; const productName uidmapping[] = { @@ -235,7 +235,7 @@ int getUID(uint8_t *buf) { // get a product description based on the UID // uid[8] tag uid // returns description of the best match -static char *getTagInfo_15(uint8_t *uid) { +static const char *getTagInfo_15(uint8_t *uid) { uint64_t myuid, mask; int i = 0, best = -1; memcpy(&myuid, uid, sizeof(uint64_t)); @@ -259,7 +259,7 @@ static char *getTagInfo_15(uint8_t *uid) { } // return a clear-text message to an errorcode -static char *TagErrorStr(uint8_t error) { +static const char *TagErrorStr(uint8_t error) { switch (error) { case 0x01: return "The command is not supported"; @@ -350,7 +350,7 @@ int usage_15_dump(void) { return 0; } int usage_15_restore(void) { - char *options[][2] = { + const char *options[][2] = { {"h", "this help"}, {"-2", "use slower '1 out of 256' mode"}, {"-o", "set OPTION Flag (needed for TI)"}, @@ -364,7 +364,7 @@ int usage_15_restore(void) { return 0; } int usage_15_raw(void) { - char *options[][2] = { + const char *options[][2] = { {"-r", "do not read response" }, {"-2", "use slower '1 out of 256' mode" }, {"-c", "calculate and append CRC" }, diff --git a/client/cmdhffido.c b/client/cmdhffido.c index 496ae5427..cb9694584 100644 --- a/client/cmdhffido.c +++ b/client/cmdhffido.c @@ -621,7 +621,7 @@ void CheckSlash(char *fileName) { strcat(fileName, "/"); } -int GetExistsFileNameJson(char *prefixDir, char *reqestedFileName, char *fileName) { +int GetExistsFileNameJson(const char *prefixDir, const char *reqestedFileName, char *fileName) { fileName[0] = 0x00; strcpy(fileName, get_my_executable_directory()); CheckSlash(fileName); diff --git a/client/cmdhfmfdes.c b/client/cmdhfmfdes.c index 801e07ced..1294f98c7 100644 --- a/client/cmdhfmfdes.c +++ b/client/cmdhfmfdes.c @@ -253,7 +253,7 @@ char *GetVersionStr(uint8_t major, uint8_t minor) { void GetKeySettings(uint8_t *aid) { char messStr[512] = {0x00}; - char *str = messStr; + const char *str = messStr; uint8_t isOK = 0; uint32_t options; UsbCommand c = {CMD_MIFARE_DESFIRE}; diff --git a/client/cmdhfmfhard.c b/client/cmdhfmfhard.c index 683879fec..dae915700 100644 --- a/client/cmdhfmfhard.c +++ b/client/cmdhfmfhard.c @@ -109,7 +109,7 @@ static void print_progress_header(void) { } -void hardnested_print_progress(uint32_t nonces, char *activity, float brute_force, uint64_t min_diff_print_time) { +void hardnested_print_progress(uint32_t nonces, const char *activity, float brute_force, uint64_t min_diff_print_time) { static uint64_t last_print_time = 0; if (msclock() - last_print_time > min_diff_print_time) { last_print_time = msclock(); diff --git a/client/cmdhfmfhard.h b/client/cmdhfmfhard.h index 7d3e4fa0b..2f20986e2 100644 --- a/client/cmdhfmfhard.h +++ b/client/cmdhfmfhard.h @@ -42,7 +42,7 @@ typedef struct noncelist { } noncelist_t; int mfnestedhard(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint8_t trgBlockNo, uint8_t trgKeyType, uint8_t *trgkey, bool nonce_file_read, bool nonce_file_write, bool slow, int tests, uint64_t *foundkey, char *filename); -void hardnested_print_progress(uint32_t nonces, char *activity, float brute_force, uint64_t min_diff_print_time); +void hardnested_print_progress(uint32_t nonces, const char *activity, float brute_force, uint64_t min_diff_print_time); #endif diff --git a/client/cmdlfti.c b/client/cmdlfti.c index db87a2d14..223629786 100644 --- a/client/cmdlfti.c +++ b/client/cmdlfti.c @@ -251,7 +251,7 @@ int CmdTIDemod(const char *Cmd) { //crc = crc16_ccitt(message, sizeof(message); - char *crcStr = (crc == (shift2 & 0xFFFF)) ? _GREEN_("Passed") : _RED_("Failed"); + const char *crcStr = (crc == (shift2 & 0xFFFF)) ? _GREEN_("Passed") : _RED_("Failed"); PrintAndLogEx(INFO, "Tag data = %08X%08X [Crc %04X %s]", shift1, shift0, crc, crcStr); diff --git a/client/cmdparser.c b/client/cmdparser.c index a819cedcf..5ff0c9255 100644 --- a/client/cmdparser.c +++ b/client/cmdparser.c @@ -93,7 +93,7 @@ void dumpCommandsRecursive(const command_t cmds[], int markdown) { } while (cmds[i].Name) { - char *cmd_offline = "N"; + const char *cmd_offline = "N"; if (cmds[i].Help[0] == '{' && ++i) continue; if (cmds[i].Offline) diff --git a/client/cmdscript.c b/client/cmdscript.c index e1a21ffc4..d71a9285b 100644 --- a/client/cmdscript.c +++ b/client/cmdscript.c @@ -56,7 +56,7 @@ int str_ends_with(const char *str, const char *suffix) { /** * Utility to check the ending of a string (used to check file suffix) */ -bool endsWith(char *base, char *str) { +bool endsWith(const char *base, const char *str) { int blen = strlen(base); int slen = strlen(str); return (blen >= slen) && (0 == strcmp(base + blen - slen, str)); @@ -125,7 +125,7 @@ int CmdScriptRun(const char *Cmd) { int arg_len = 0; sscanf(Cmd, "%127s%n %255[^\n\r]%n", script_name, &name_len, arguments, &arg_len); - char *suffix = ""; + const char *suffix = ""; if (!endsWith(script_name, ".lua")) { suffix = ".lua"; } diff --git a/client/cmdtrace.c b/client/cmdtrace.c index bb98e6919..1f10ab214 100644 --- a/client/cmdtrace.c +++ b/client/cmdtrace.c @@ -221,7 +221,7 @@ uint16_t printTraceLine(uint16_t tracepos, uint16_t traceLen, uint8_t *trace, ui } // Draw the CRC column - char *crc = (crcStatus == 0 ? "!crc" : (crcStatus == 1 ? " ok " : " ")); + const char *crc = (crcStatus == 0 ? "!crc" : (crcStatus == 1 ? " ok " : " ")); EndOfTransmissionTimestamp = timestamp + duration; diff --git a/client/crypto/asn1dump.c b/client/crypto/asn1dump.c index 8453d0f13..47fe791d4 100644 --- a/client/crypto/asn1dump.c +++ b/client/crypto/asn1dump.c @@ -41,7 +41,7 @@ enum asn1_tag_t { struct asn1_tag { tlv_tag_t tag; - char *name; + const char *name; enum asn1_tag_t type; const void *data; }; diff --git a/client/crypto/asn1utils.c b/client/crypto/asn1utils.c index 87fdd8c9d..c82f4aac8 100644 --- a/client/crypto/asn1utils.c +++ b/client/crypto/asn1utils.c @@ -71,7 +71,7 @@ static bool print_cb(void *data, const struct tlv *tlv, int level, bool is_leaf) return true; } -int asn1_print(uint8_t *asn1buf, size_t asn1buflen, char *indent) { +int asn1_print(uint8_t *asn1buf, size_t asn1buflen, const char *indent) { struct tlvdb *t = tlvdb_parse_multi(asn1buf, asn1buflen); if (t) { diff --git a/client/crypto/asn1utils.h b/client/crypto/asn1utils.h index 60c94e34a..029741bc6 100644 --- a/client/crypto/asn1utils.h +++ b/client/crypto/asn1utils.h @@ -15,7 +15,7 @@ #include #include -int asn1_print(uint8_t *asn1buf, size_t asn1buflen, char *indent); +int asn1_print(uint8_t *asn1buf, size_t asn1buflen, const char *indent); int ecdsa_asn1_get_signature(uint8_t *signature, size_t signaturelen, uint8_t *rval, uint8_t *sval); #endif /* asn1utils.h */ diff --git a/client/crypto/libpcrypto.c b/client/crypto/libpcrypto.c index 7ea667e7e..f1f6e782d 100644 --- a/client/crypto/libpcrypto.c +++ b/client/crypto/libpcrypto.c @@ -121,7 +121,7 @@ int sha512hash(uint8_t *input, int length, uint8_t *hash) { return 0; } -int ecdsa_init_str(mbedtls_ecdsa_context *ctx, char *key_d, char *key_x, char *key_y) { +int ecdsa_init_str(mbedtls_ecdsa_context *ctx, const char *key_d, const char *key_x, const char *key_y) { if (!ctx) return 1; @@ -279,7 +279,7 @@ exit: return res; } -int ecdsa_signature_create_test(char *key_d, char *key_x, char *key_y, char *random, uint8_t *input, int length, uint8_t *signature, size_t *signaturelen) { +int ecdsa_signature_create_test(const char *key_d, const char *key_x, const char *key_y, const char *random, uint8_t *input, int length, uint8_t *signature, size_t *signaturelen) { int res; *signaturelen = 0; @@ -299,7 +299,7 @@ int ecdsa_signature_create_test(char *key_d, char *key_x, char *key_y, char *ran return res; } -int ecdsa_signature_verify_keystr(char *key_x, char *key_y, uint8_t *input, int length, uint8_t *signature, size_t signaturelen) { +int ecdsa_signature_verify_keystr(const char *key_x, const char *key_y, uint8_t *input, int length, uint8_t *signature, size_t signaturelen) { int res; uint8_t shahash[32] = {0}; res = sha256hash(input, length, shahash); diff --git a/client/emv/apduinfo.c b/client/emv/apduinfo.c index 23da3e1a2..8d0d3bf89 100644 --- a/client/emv/apduinfo.c +++ b/client/emv/apduinfo.c @@ -277,7 +277,7 @@ int CodeCmp(const char *code1, const char *code2) { return -1; } -const APDUCode *const GetAPDUCode(uint8_t sw1, uint8_t sw2) { +const APDUCode * GetAPDUCode(uint8_t sw1, uint8_t sw2) { char buf[6] = {0}; int res; int mineq = APDUCodeTableLen; diff --git a/client/emv/apduinfo.h b/client/emv/apduinfo.h index d7811dbc6..317d661ff 100644 --- a/client/emv/apduinfo.h +++ b/client/emv/apduinfo.h @@ -28,7 +28,7 @@ typedef struct { const char *Description; } APDUCode; -const APDUCode *const GetAPDUCode(uint8_t sw1, uint8_t sw2); +const APDUCode *GetAPDUCode(uint8_t sw1, uint8_t sw2); const char *GetAPDUCodeDescription(uint8_t sw1, uint8_t sw2); #endif diff --git a/client/emv/cmdemv.c b/client/emv/cmdemv.c index b5edfa81c..8e3b1ff83 100644 --- a/client/emv/cmdemv.c +++ b/client/emv/cmdemv.c @@ -652,7 +652,7 @@ void InitTransactionParameters(struct tlvdb *tlvRoot, bool paramLoadJSON, enum T } //9F66:(Terminal Transaction Qualifiers (TTQ)) len:4 - char *qVSDC = "\x26\x00\x00\x00"; + const char *qVSDC = "\x26\x00\x00\x00"; if (GenACGPO) { qVSDC = "\x26\x80\x00\x00"; } diff --git a/client/emv/emv_tags.c b/client/emv/emv_tags.c index f51442183..2ebe78009 100644 --- a/client/emv/emv_tags.c +++ b/client/emv/emv_tags.c @@ -42,7 +42,7 @@ enum emv_tag_t { struct emv_tag { tlv_tag_t tag; - char *name; + const char *name; enum emv_tag_t type; const void *data; }; @@ -819,8 +819,8 @@ bool emv_tag_dump(const struct tlv *tlv, FILE *f, int level) { return true; } -char *emv_get_tag_name(const struct tlv *tlv) { - static char *defstr = ""; +const char *emv_get_tag_name(const struct tlv *tlv) { + static const char *defstr = ""; if (!tlv) return defstr; diff --git a/client/emv/emv_tags.h b/client/emv/emv_tags.h index f7d9a8476..51905e75e 100644 --- a/client/emv/emv_tags.h +++ b/client/emv/emv_tags.h @@ -35,6 +35,6 @@ # define EMVCID_REASON_MASK 0x07 bool emv_tag_dump(const struct tlv *tlv, FILE *f, int level); -char *emv_get_tag_name(const struct tlv *tlv); +const char *emv_get_tag_name(const struct tlv *tlv); #endif diff --git a/client/emv/emvcore.c b/client/emv/emvcore.c index 086c72674..7e0174baa 100644 --- a/client/emv/emvcore.c +++ b/client/emv/emvcore.c @@ -20,7 +20,7 @@ static const char *PSElist [] = { }; //static const size_t PSElistLen = sizeof(PSElist)/sizeof(char*); -char *TransactionTypeStr[] = { +const char *TransactionTypeStr[] = { "MSD", "VSDC", "qVCDCMCHIP", @@ -434,7 +434,7 @@ int EMVSearchPSE(EMVCommandChannel channel, bool ActivateField, bool LeaveFieldO int res; bool fileFound = false; - char *PSE_or_PPSE = PSENum == 1 ? "PSE" : "PPSE"; + const char *PSE_or_PPSE = PSENum == 1 ? "PSE" : "PPSE"; // select PPSE res = EMVSelectPSE(channel, ActivateField, true, PSENum, data, sizeof(data), &datalen, &sw); diff --git a/client/emv/emvcore.h b/client/emv/emvcore.h index 94d929f06..219c3f9b5 100644 --- a/client/emv/emvcore.h +++ b/client/emv/emvcore.h @@ -43,7 +43,7 @@ enum TransactionType { TT_QVSDCMCHIP, TT_CDA, }; -extern char *TransactionTypeStr[]; +extern const char *TransactionTypeStr[]; typedef struct { uint8_t CLA; diff --git a/client/emv/emvjson.c b/client/emv/emvjson.c index 717f806d9..dadff33fc 100644 --- a/client/emv/emvjson.c +++ b/client/emv/emvjson.c @@ -60,7 +60,7 @@ static const ApplicationDataElm ApplicationData[] = { }; int ApplicationDataLen = sizeof(ApplicationData) / sizeof(ApplicationDataElm); -char *GetApplicationDataName(tlv_tag_t tag) { +const char *GetApplicationDataName(tlv_tag_t tag) { for (int i = 0; i < ApplicationDataLen; i++) if (ApplicationData[i].Tag == tag) return ApplicationData[i].Name; @@ -68,7 +68,7 @@ char *GetApplicationDataName(tlv_tag_t tag) { return NULL; } -int JsonSaveJsonObject(json_t *root, char *path, json_t *value) { +int JsonSaveJsonObject(json_t *root, const char *path, json_t *value) { json_error_t error; if (strlen(path) < 1) @@ -86,15 +86,15 @@ int JsonSaveJsonObject(json_t *root, char *path, json_t *value) { } } -int JsonSaveInt(json_t *root, char *path, int value) { +int JsonSaveInt(json_t *root, const char *path, int value) { return JsonSaveJsonObject(root, path, json_integer(value)); } -int JsonSaveStr(json_t *root, char *path, char *value) { +int JsonSaveStr(json_t *root, const char *path, const char *value) { return JsonSaveJsonObject(root, path, json_string(value)); }; -int JsonSaveBufAsHexCompact(json_t *elm, char *path, uint8_t *data, size_t datalen) { +int JsonSaveBufAsHexCompact(json_t *elm, const char *path, uint8_t *data, size_t datalen) { char *msg = sprint_hex_inrow(data, datalen); if (msg && strlen(msg) && msg[strlen(msg) - 1] == ' ') msg[strlen(msg) - 1] = '\0'; @@ -102,7 +102,7 @@ int JsonSaveBufAsHexCompact(json_t *elm, char *path, uint8_t *data, size_t datal return JsonSaveStr(elm, path, msg); } -int JsonSaveBufAsHex(json_t *elm, char *path, uint8_t *data, size_t datalen) { +int JsonSaveBufAsHex(json_t *elm, const char *path, uint8_t *data, size_t datalen) { char *msg = sprint_hex(data, datalen); if (msg && strlen(msg) && msg[strlen(msg) - 1] == ' ') msg[strlen(msg) - 1] = '\0'; @@ -110,7 +110,7 @@ int JsonSaveBufAsHex(json_t *elm, char *path, uint8_t *data, size_t datalen) { return JsonSaveStr(elm, path, msg); } -int JsonSaveHex(json_t *elm, char *path, uint64_t data, int datalen) { +int JsonSaveHex(json_t *elm, const char *path, uint64_t data, int datalen) { uint8_t bdata[8] = {0}; int len = 0; if (!datalen) { @@ -130,7 +130,7 @@ int JsonSaveHex(json_t *elm, char *path, uint64_t data, int datalen) { return JsonSaveBufAsHex(elm, path, bdata, len); } -int JsonSaveTLVValue(json_t *root, char *path, struct tlvdb *tlvdbelm) { +int JsonSaveTLVValue(json_t *root, const char *path, struct tlvdb *tlvdbelm) { const struct tlv *tlvelm = tlvdb_get_tlv(tlvdbelm); if (tlvelm) return JsonSaveBufAsHex(root, path, (uint8_t *)tlvelm->value, tlvelm->len); @@ -138,7 +138,7 @@ int JsonSaveTLVValue(json_t *root, char *path, struct tlvdb *tlvdbelm) { return 1; } -int JsonSaveTLVElm(json_t *elm, char *path, struct tlv *tlvelm, bool saveName, bool saveValue, bool saveAppDataLink) { +int JsonSaveTLVElm(json_t *elm, const char *path, struct tlv *tlvelm, bool saveName, bool saveValue, bool saveAppDataLink) { json_error_t error; if (strlen(path) < 1 || !tlvelm) @@ -164,11 +164,11 @@ int JsonSaveTLVElm(json_t *elm, char *path, struct tlv *tlvelm, bool saveName, b } if (saveAppDataLink) { - char *AppDataName = GetApplicationDataName(tlvelm->tag); + const char *AppDataName = GetApplicationDataName(tlvelm->tag); if (AppDataName) JsonSaveStr(obj, "appdata", AppDataName); } else { - char *name = emv_get_tag_name(tlvelm); + const char *name = emv_get_tag_name(tlvelm); if (saveName && name && strlen(name) > 0 && strncmp(name, "Unknown", 7)) JsonSaveStr(obj, "name", emv_get_tag_name(tlvelm)); JsonSaveHex(obj, "tag", tlvelm->tag, 0); @@ -182,15 +182,15 @@ int JsonSaveTLVElm(json_t *elm, char *path, struct tlv *tlvelm, bool saveName, b return 0; } -int JsonSaveTLVTreeElm(json_t *elm, char *path, struct tlvdb *tlvdbelm, bool saveName, bool saveValue, bool saveAppDataLink) { +int JsonSaveTLVTreeElm(json_t *elm, const char *path, struct tlvdb *tlvdbelm, bool saveName, bool saveValue, bool saveAppDataLink) { return JsonSaveTLVElm(elm, path, (struct tlv *)tlvdb_get_tlv(tlvdbelm), saveName, saveValue, saveAppDataLink); } -int JsonSaveTLVTree(json_t *root, json_t *elm, char *path, struct tlvdb *tlvdbelm) { +int JsonSaveTLVTree(json_t *root, json_t *elm, const char *path, struct tlvdb *tlvdbelm) { struct tlvdb *tlvp = tlvdbelm; while (tlvp) { const struct tlv *tlvpelm = tlvdb_get_tlv(tlvp); - char *AppDataName = NULL; + const char *AppDataName = NULL; if (tlvpelm) AppDataName = GetApplicationDataName(tlvpelm->tag); @@ -265,7 +265,7 @@ bool HexToBuffer(const char *errormsg, const char *hexvalue, uint8_t *buffer, si return true; } -int JsonLoadStr(json_t *root, char *path, char *value) { +int JsonLoadStr(json_t *root, const char *path, char *value) { if (!value) return 1; @@ -282,7 +282,7 @@ int JsonLoadStr(json_t *root, char *path, char *value) { return 0; } -int JsonLoadBufAsHex(json_t *elm, char *path, uint8_t *data, size_t maxbufferlen, size_t *datalen) { +int JsonLoadBufAsHex(json_t *elm, const char *path, uint8_t *data, size_t maxbufferlen, size_t *datalen) { if (datalen) *datalen = 0; diff --git a/client/emv/emvjson.h b/client/emv/emvjson.h index 23cfba545..6bcf8243d 100644 --- a/client/emv/emvjson.h +++ b/client/emv/emvjson.h @@ -15,26 +15,26 @@ typedef struct { tlv_tag_t Tag; - char *Name; + const char *Name; } ApplicationDataElm; -char *GetApplicationDataName(tlv_tag_t tag); +const char *GetApplicationDataName(tlv_tag_t tag); -int JsonSaveJsonObject(json_t *root, char *path, json_t *value); -int JsonSaveStr(json_t *root, char *path, char *value); -int JsonSaveInt(json_t *root, char *path, int value); -int JsonSaveBufAsHexCompact(json_t *elm, char *path, uint8_t *data, size_t datalen); -int JsonSaveBufAsHex(json_t *elm, char *path, uint8_t *data, size_t datalen); -int JsonSaveHex(json_t *elm, char *path, uint64_t data, int datalen); +int JsonSaveJsonObject(json_t *root, const char *path, json_t *value); +int JsonSaveStr(json_t *root, const char *path, const char *value); +int JsonSaveInt(json_t *root, const char *path, int value); +int JsonSaveBufAsHexCompact(json_t *elm, const char *path, uint8_t *data, size_t datalen); +int JsonSaveBufAsHex(json_t *elm, const char *path, uint8_t *data, size_t datalen); +int JsonSaveHex(json_t *elm, const char *path, uint64_t data, int datalen); -int JsonSaveTLVValue(json_t *root, char *path, struct tlvdb *tlvdbelm); -int JsonSaveTLVElm(json_t *elm, char *path, struct tlv *tlvelm, bool saveName, bool saveValue, bool saveAppDataLink); -int JsonSaveTLVTreeElm(json_t *elm, char *path, struct tlvdb *tlvdbelm, bool saveName, bool saveValue, bool saveAppDataLink); +int JsonSaveTLVValue(json_t *root, const char *path, struct tlvdb *tlvdbelm); +int JsonSaveTLVElm(json_t *elm, const char *path, struct tlv *tlvelm, bool saveName, bool saveValue, bool saveAppDataLink); +int JsonSaveTLVTreeElm(json_t *elm, const char *path, struct tlvdb *tlvdbelm, bool saveName, bool saveValue, bool saveAppDataLink); -int JsonSaveTLVTree(json_t *root, json_t *elm, char *path, struct tlvdb *tlvdbelm); +int JsonSaveTLVTree(json_t *root, json_t *elm, const char *path, struct tlvdb *tlvdbelm); -int JsonLoadStr(json_t *root, char *path, char *value); -int JsonLoadBufAsHex(json_t *elm, char *path, uint8_t *data, size_t maxbufferlen, size_t *datalen); +int JsonLoadStr(json_t *root, const char *path, char *value); +int JsonLoadBufAsHex(json_t *elm, const char *path, uint8_t *data, size_t maxbufferlen, size_t *datalen); bool ParamLoadFromJson(struct tlvdb *tlv); diff --git a/client/fido/cbortools.c b/client/fido/cbortools.c index b12571538..78055cc9e 100644 --- a/client/fido/cbortools.c +++ b/client/fido/cbortools.c @@ -161,7 +161,7 @@ static CborError dumprecursive(uint8_t cmdCode, bool isResponse, CborValue *it, if (cmdCode > 0 && nestingLevel == 1 && isMapType && !(elmCount % 2)) { int64_t val; cbor_value_get_int64(it, &val); - char *desc = fido2GetCmdMemberDescription(cmdCode, isResponse, val); + const char *desc = fido2GetCmdMemberDescription(cmdCode, isResponse, val); if (desc) printf(" (%s)", desc); } @@ -459,7 +459,7 @@ CborError CborGetStringValueBuf(CborValue *elm) { return CborGetStringValue(elm, stringBuf, sizeof(stringBuf), NULL); }; -int CBOREncodeElm(json_t *root, char *rootElmId, CborEncoder *encoder) { +int CBOREncodeElm(json_t *root, const char *rootElmId, CborEncoder *encoder) { json_t *elm = NULL; if (rootElmId && strlen(rootElmId) && rootElmId[0] == '$') elm = json_path_get(root, rootElmId); diff --git a/client/fido/cbortools.h b/client/fido/cbortools.h index d42506658..99b3536c1 100644 --- a/client/fido/cbortools.h +++ b/client/fido/cbortools.h @@ -32,7 +32,7 @@ CborError CborGetArrayStringValue(CborValue *elm, char *data, size_t maxdatalen, CborError CborGetStringValue(CborValue *elm, char *data, size_t maxdatalen, size_t *datalen); CborError CborGetStringValueBuf(CborValue *elm); -int CBOREncodeElm(json_t *root, char *rootElmId, CborEncoder *encoder); +int CBOREncodeElm(json_t *root, const char *rootElmId, CborEncoder *encoder); CborError CBOREncodeClientDataHash(json_t *root, CborEncoder *encoder); #endif /* __CBORTOOLS_H__ */ diff --git a/client/fido/cose.c b/client/fido/cose.c index 48fa6d4d1..134c29772 100644 --- a/client/fido/cose.c +++ b/client/fido/cose.c @@ -19,15 +19,15 @@ static const char COSEEmptyStr[] = ""; typedef struct { int Value; - char *Name; - char *Description; + const char *Name; + const char *Description; } COSEValueNameDesc_t; typedef struct { int Value; - char *Type; - char *Name; - char *Description; + const char *Type; + const char *Name; + const char *Description; } COSEValueTypeNameDesc_t; // kty - Key Type Values diff --git a/client/fido/fidocore.c b/client/fido/fidocore.c index 2b0aa7b94..915617244 100644 --- a/client/fido/fidocore.c +++ b/client/fido/fidocore.c @@ -25,8 +25,8 @@ typedef struct { uint8_t ErrorCode; - char *ShortDescription; - char *Description; + const char *ShortDescription; + const char *Description; } fido2Error_t; fido2Error_t fido2Errors[] = { @@ -84,7 +84,7 @@ typedef struct { fido2Commands Command; fido2PacketType PckType; int MemberNumber; - char *Description; + const char *Description; } fido2Desc_t; fido2Desc_t fido2CmdGetInfoRespDesc[] = { @@ -149,7 +149,7 @@ fido2Desc_t fido2CmdGetInfoRespDesc[] = { {fido2COSEKey, ptResponse, -4, "d - private key"}, }; -char *fido2GetCmdErrorDescription(uint8_t errorCode) { +const char *fido2GetCmdErrorDescription(uint8_t errorCode) { for (int i = 0; i < sizeof(fido2Errors) / sizeof(fido2Error_t); i++) if (fido2Errors[i].ErrorCode == errorCode) return fido2Errors[i].Description; @@ -157,7 +157,7 @@ char *fido2GetCmdErrorDescription(uint8_t errorCode) { return fido2Errors[0].Description; } -char *fido2GetCmdMemberDescription(uint8_t cmdCode, bool isResponse, int memberNum) { +const char *fido2GetCmdMemberDescription(uint8_t cmdCode, bool isResponse, int memberNum) { for (int i = 0; i < sizeof(fido2CmdGetInfoRespDesc) / sizeof(fido2Desc_t); i++) if (fido2CmdGetInfoRespDesc[i].Command == cmdCode && fido2CmdGetInfoRespDesc[i].PckType == (isResponse ? ptResponse : ptQuery) && diff --git a/client/fido/fidocore.h b/client/fido/fidocore.h index 676dd2646..d54dc5b88 100644 --- a/client/fido/fidocore.h +++ b/client/fido/fidocore.h @@ -45,8 +45,8 @@ int FIDO2GetAssertion(uint8_t *params, uint8_t paramslen, uint8_t *Result, size_ int FIDOCheckDERAndGetKey(uint8_t *der, size_t derLen, bool verbose, uint8_t *publicKey, size_t publicKeyMaxLen); -char *fido2GetCmdMemberDescription(uint8_t cmdCode, bool isResponse, int memberNum); -char *fido2GetCmdErrorDescription(uint8_t errorCode); +const char *fido2GetCmdMemberDescription(uint8_t cmdCode, bool isResponse, int memberNum); +const char *fido2GetCmdErrorDescription(uint8_t errorCode); bool CheckrpIdHash(json_t *json, uint8_t *hash); int FIDO2CreateMakeCredentionalReq(json_t *root, uint8_t *data, size_t maxdatalen, size_t *datalen); diff --git a/client/hardnested/hardnested_bf_core.c b/client/hardnested/hardnested_bf_core.c index c180b353a..494e13328 100644 --- a/client/hardnested/hardnested_bf_core.c +++ b/client/hardnested/hardnested_bf_core.c @@ -123,7 +123,7 @@ typedef union { #endif // typedefs and declaration of functions: -typedef const uint64_t crack_states_bitsliced_t(uint32_t, uint8_t *, statelist_t *, uint32_t *, uint64_t *, uint32_t, uint8_t *, noncelist_t *); +typedef uint64_t crack_states_bitsliced_t(uint32_t, uint8_t *, statelist_t *, uint32_t *, uint64_t *, uint32_t, uint8_t *, noncelist_t *); crack_states_bitsliced_t crack_states_bitsliced_AVX512; crack_states_bitsliced_t crack_states_bitsliced_AVX2; crack_states_bitsliced_t crack_states_bitsliced_AVX; @@ -205,7 +205,7 @@ void BITSLICE_TEST_NONCES(uint32_t nonces_to_bruteforce, uint32_t *bf_test_nonce } -const uint64_t CRACK_STATES_BITSLICED(uint32_t cuid, uint8_t *best_first_bytes, statelist_t *p, uint32_t *keys_found, uint64_t *num_keys_tested, uint32_t nonces_to_bruteforce, uint8_t *bf_test_nonce_2nd_byte, noncelist_t *nonces) { +uint64_t CRACK_STATES_BITSLICED(uint32_t cuid, uint8_t *best_first_bytes, statelist_t *p, uint32_t *keys_found, uint64_t *num_keys_tested, uint32_t nonces_to_bruteforce, uint8_t *bf_test_nonce_2nd_byte, noncelist_t *nonces) { // Unlike aczid's implementation this doesn't roll back at all when performing bitsliced bruteforce. // We know that the best first byte is already shifted in. Testing with the remaining three bytes of @@ -586,7 +586,7 @@ SIMDExecInstr GetSIMDInstrAuto() { } // determine the available instruction set at runtime and call the correct function -const uint64_t crack_states_bitsliced_dispatch(uint32_t cuid, uint8_t *best_first_bytes, statelist_t *p, uint32_t *keys_found, uint64_t *num_keys_tested, uint32_t nonces_to_bruteforce, uint8_t *bf_test_nonce_2nd_byte, noncelist_t *nonces) { +uint64_t crack_states_bitsliced_dispatch(uint32_t cuid, uint8_t *best_first_bytes, statelist_t *p, uint32_t *keys_found, uint64_t *num_keys_tested, uint32_t nonces_to_bruteforce, uint8_t *bf_test_nonce_2nd_byte, noncelist_t *nonces) { switch (GetSIMDInstrAuto()) { #if defined (__i386__) || defined (__x86_64__) #if !defined(__APPLE__) || (defined(__APPLE__) && (__clang_major__ > 8 || __clang_major__ == 8 && __clang_minor__ >= 1)) @@ -651,7 +651,7 @@ void bitslice_test_nonces_dispatch(uint32_t nonces_to_bruteforce, uint32_t *bf_t } // Entries to dispatched function calls -const uint64_t crack_states_bitsliced(uint32_t cuid, uint8_t *best_first_bytes, statelist_t *p, uint32_t *keys_found, uint64_t *num_keys_tested, uint32_t nonces_to_bruteforce, uint8_t *bf_test_nonce_2nd_byte, noncelist_t *nonces) { +uint64_t crack_states_bitsliced(uint32_t cuid, uint8_t *best_first_bytes, statelist_t *p, uint32_t *keys_found, uint64_t *num_keys_tested, uint32_t nonces_to_bruteforce, uint8_t *bf_test_nonce_2nd_byte, noncelist_t *nonces) { return (*crack_states_bitsliced_function_p)(cuid, best_first_bytes, p, keys_found, num_keys_tested, nonces_to_bruteforce, bf_test_nonce_2nd_byte, nonces); } diff --git a/client/hardnested/hardnested_bf_core.h b/client/hardnested/hardnested_bf_core.h index 9dc10961a..00b20b786 100644 --- a/client/hardnested/hardnested_bf_core.h +++ b/client/hardnested/hardnested_bf_core.h @@ -64,7 +64,7 @@ typedef enum { void SetSIMDInstr(SIMDExecInstr instr); SIMDExecInstr GetSIMDInstrAuto(void); -const uint64_t crack_states_bitsliced(uint32_t cuid, uint8_t *best_first_bytes, statelist_t *p, uint32_t *keys_found, uint64_t *num_keys_tested, uint32_t nonces_to_bruteforce, uint8_t *bf_test_nonce_2nd_byte, noncelist_t *nonces); +uint64_t crack_states_bitsliced(uint32_t cuid, uint8_t *best_first_bytes, statelist_t *p, uint32_t *keys_found, uint64_t *num_keys_tested, uint32_t nonces_to_bruteforce, uint8_t *bf_test_nonce_2nd_byte, noncelist_t *nonces); void bitslice_test_nonces(uint32_t nonces_to_bruteforce, uint32_t *bf_test_nonce, uint8_t *bf_test_nonce_par); #endif diff --git a/client/loclass/cipherutils.c b/client/loclass/cipherutils.c index d48863f98..bb457e371 100644 --- a/client/loclass/cipherutils.c +++ b/client/loclass/cipherutils.c @@ -142,7 +142,7 @@ void reverse_arraycopy(uint8_t *arr, uint8_t *dest, size_t len) { } } -void printarr(char *name, uint8_t *arr, int len) { +void printarr(const char *name, uint8_t *arr, int len) { int cx, i; size_t outsize = 40 + strlen(name) + len * 5; char *output = calloc(outsize, sizeof(char)); @@ -155,7 +155,7 @@ void printarr(char *name, uint8_t *arr, int len) { free(output); } -void printvar(char *name, uint8_t *arr, int len) { +void printvar(const char *name, uint8_t *arr, int len) { int cx, i; size_t outsize = 40 + strlen(name) + len * 2; char *output = calloc(outsize, sizeof(char)); @@ -168,7 +168,7 @@ void printvar(char *name, uint8_t *arr, int len) { free(output); } -void printarr_human_readable(char *title, uint8_t *arr, int len) { +void printarr_human_readable(const char *title, uint8_t *arr, int len) { int cx, i; size_t outsize = 100 + strlen(title) + len * 4; char *output = calloc(outsize, sizeof(char)); diff --git a/client/loclass/cipherutils.h b/client/loclass/cipherutils.h index 161e09e48..70438d33b 100644 --- a/client/loclass/cipherutils.h +++ b/client/loclass/cipherutils.h @@ -69,7 +69,7 @@ uint64_t x_bytes_to_num(uint8_t *src, size_t len); uint8_t reversebytes(uint8_t b); void reverse_arraybytes(uint8_t *arr, size_t len); void reverse_arraycopy(uint8_t *arr, uint8_t *dest, size_t len); -void printarr(char *name, uint8_t *arr, int len); -void printvar(char *name, uint8_t *arr, int len); -void printarr_human_readable(char *title, uint8_t *arr, int len); +void printarr(const char *name, uint8_t *arr, int len); +void printvar(const char *name, uint8_t *arr, int len); +void printarr_human_readable(const char *title, uint8_t *arr, int len); #endif // CIPHERUTILS_H diff --git a/client/loclass/ikeys.c b/client/loclass/ikeys.c index d7c965421..43959b421 100644 --- a/client/loclass/ikeys.c +++ b/client/loclass/ikeys.c @@ -221,7 +221,7 @@ void printbegin() { PrintAndLogDevice(NORMAL, " | x| y|z0|z1|z2|z3|z4|z5|z6|z7|"); } -void printState(char *desc, uint64_t c) { +void printState(const char *desc, uint64_t c) { if (debug_print < 2) return; @@ -569,7 +569,7 @@ int testKeyDiversificationWithMasterkeyTestcases() { return error; } -void print64bits(char *name, uint64_t val) { +void print64bits(const char *name, uint64_t val) { printf("%s%08x%08x\n", name, (uint32_t)(val >> 32), (uint32_t)(val & 0xFFFFFFFF)); } diff --git a/client/mifare/mifare4.c b/client/mifare/mifare4.c index f3189f37f..757865564 100644 --- a/client/mifare/mifare4.c +++ b/client/mifare/mifare4.c @@ -72,7 +72,7 @@ AccessConditions_t MFAccessConditionsTrailer[] = { {0x07, "rdCbyAB"} }; -char *mfGetAccessConditionsDesc(uint8_t blockn, uint8_t *data) { +const char *mfGetAccessConditionsDesc(uint8_t blockn, uint8_t *data) { static char StaticNone[] = "none"; uint8_t data1 = ((data[1] >> 4) & 0x0f) >> blockn; diff --git a/client/mifare/mifare4.h b/client/mifare/mifare4.h index d403bdd94..330c6d9f9 100644 --- a/client/mifare/mifare4.h +++ b/client/mifare/mifare4.h @@ -40,7 +40,7 @@ typedef enum { typedef struct { uint8_t cond; - char *description; + const char *description; } AccessConditions_t; void mfpSetVerboseMode(bool verbose); @@ -55,7 +55,7 @@ int MFPReadBlock(mf4Session *session, bool plain, uint8_t blockNum, uint8_t bloc int MFPWriteBlock(mf4Session *session, uint8_t blockNum, uint8_t *data, bool activateField, bool leaveSignalON, uint8_t *dataout, int maxdataoutlen, int *dataoutlen, uint8_t *mac); int mfpReadSector(uint8_t sectorNo, uint8_t keyType, uint8_t *key, uint8_t *dataout, bool verbose); -char *mfGetAccessConditionsDesc(uint8_t blockn, uint8_t *data); +const char *mfGetAccessConditionsDesc(uint8_t blockn, uint8_t *data); uint8_t mfNumBlocksPerSector(uint8_t sectorNo); uint8_t mfFirstBlockOfSector(uint8_t sectorNo); diff --git a/client/ui.c b/client/ui.c index 1e5c145be..d22790b9a 100644 --- a/client/ui.c +++ b/client/ui.c @@ -19,11 +19,11 @@ bool GridLocked = false; bool showDemod = true; pthread_mutex_t print_lock = PTHREAD_MUTEX_INITIALIZER; -static char *logfilename = "proxmark3.log"; +static const char *logfilename = "proxmark3.log"; float complex cexpf(float complex Z); -void PrintAndLogOptions(char *str[][2], size_t size, size_t space) { +void PrintAndLogOptions(const char *str[][2], size_t size, size_t space) { char buff[2000] = "Options:\n"; char format[2000] = ""; size_t counts[2] = {0, 0}; @@ -56,7 +56,7 @@ void PrintAndLogEx(logLevel_t level, const char *fmt, ...) { char buffer2[MAX_PRINT_BUFFER + 20] = {0}; char *token = NULL; // {NORMAL, SUCCESS, INFO, FAILED, WARNING, ERR, DEBUG} - static char *prefixes[7] = { "", "[+] ", "[=] ", "[-] ", "[!] ", "[!!] ", "[#] "}; + static const char *prefixes[7] = { "", "[+] ", "[=] ", "[-] ", "[!] ", "[!!] ", "[#] "}; switch (level) { case ERR: @@ -118,7 +118,7 @@ void PrintAndLogEx(logLevel_t level, const char *fmt, ...) { } } -void PrintAndLog(char *fmt, ...) { +void PrintAndLog(const char *fmt, ...) { char *saved_line; int saved_point; va_list argptr, argptr2; diff --git a/client/ui.h b/client/ui.h index 774579725..14af52fcb 100644 --- a/client/ui.h +++ b/client/ui.h @@ -33,8 +33,8 @@ void ShowGui(void); void HideGraphWindow(void); void ShowGraphWindow(void); void RepaintGraphWindow(void); -void PrintAndLog(char *fmt, ...); -void PrintAndLogOptions(char *str[][2], size_t size, size_t space); +void PrintAndLog(const char *fmt, ...); +void PrintAndLogOptions(const char *str[][2], size_t size, size_t space); void PrintAndLogEx(logLevel_t level, const char *fmt, ...); void SetLogFilename(char *fn); void SetFlushAfterWrite(bool value); diff --git a/client/util.c b/client/util.c index f69138947..f64e9f342 100644 --- a/client/util.c +++ b/client/util.c @@ -58,7 +58,7 @@ int ukbhit(void) { // log files functions // open, appped and close logfile -void AddLogLine(char *fn, char *data, char *c) { +void AddLogLine(const char *fn, const char *data, const char *c) { FILE *f = NULL; char filename[FILE_PATH_SIZE] = {0x00}; int len = 0; @@ -80,18 +80,18 @@ void AddLogLine(char *fn, char *data, char *c) { fclose(f); } -void AddLogHex(char *fn, char *extData, const uint8_t *data, const size_t len) { +void AddLogHex(const char *fn, const char *extData, const uint8_t *data, const size_t len) { AddLogLine(fn, extData, sprint_hex(data, len)); } -void AddLogUint64(char *fn, char *data, const uint64_t value) { +void AddLogUint64(const char *fn, const char *data, const uint64_t value) { char buf[20] = {0}; memset(buf, 0x00, sizeof(buf)); sprintf(buf, "%016" PRIx64 "", value); AddLogLine(fn, data, buf); } -void AddLogCurrentDT(char *fn) { +void AddLogCurrentDT(const char *fn) { char buf[20]; memset(buf, 0x00, sizeof(buf)); struct tm *curTime; @@ -106,7 +106,7 @@ void AddLogCurrentDT(char *fn) { // param *uid - pointer to uid byte array // param *ext - ".log" // param uidlen - length of uid array. -void FillFileNameByUID(char *filenamePrefix, uint8_t *uid, const char *ext, int uidlen) { +void FillFileNameByUID(char *filenamePrefix, const uint8_t *uid, const char *ext, const int uidlen) { if (filenamePrefix == NULL || uid == NULL || ext == NULL) { printf("[!] error parameter is NULL\n"); return; diff --git a/client/util.h b/client/util.h index dcd702fb0..5d6643c73 100644 --- a/client/util.h +++ b/client/util.h @@ -189,11 +189,11 @@ uint8_t g_debugMode; int ukbhit(void); -void AddLogLine(char *fn, char *data, char *c); -void AddLogHex(char *fn, char *extData, const uint8_t *data, const size_t len); -void AddLogUint64(char *fn, char *data, const uint64_t value); -void AddLogCurrentDT(char *fn); -void FillFileNameByUID(char *filenamePrefix, uint8_t *uid, const char *ext, int uidlen); +void AddLogLine(const char *fn, const char *data, const char *c); +void AddLogHex(const char *fn, const char *extData, const uint8_t *data, const size_t len); +void AddLogUint64(const char *fn, const char *data, const uint64_t value); +void AddLogCurrentDT(const char *fn); +void FillFileNameByUID(char *filenamePrefix, const uint8_t *uid, const char *ext, const int uidlen); // fill buffer from structure [{uint8_t data, size_t length},...] int FillBuffer(uint8_t *data, size_t maxDataLength, size_t *dataLength, ...); diff --git a/uart/uart_posix.c b/uart/uart_posix.c index fc5eced7f..2c1dc1b3b 100644 --- a/uart/uart_posix.c +++ b/uart/uart_posix.c @@ -90,7 +90,7 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) { timeout.tv_usec = 300000; // 300 000 micro seconds char *colon = strrchr(addrstr, ':'); - char *portstr; + const char *portstr; if (colon) { portstr = colon + 1; *colon = '\0';