int wordCnt = 0;
while(1){
- while(isspace(str[beginIndex])){
+ while(isspace((unsigned char)str[beginIndex])){
++beginIndex;
}
if(str[beginIndex] == '\0') {
break;
}
endIndex = beginIndex;
- while (str[endIndex] && !isspace(str[endIndex])){
+ while (str[endIndex] && !isspace((unsigned char)str[endIndex])){
++endIndex;
}
int len = endIndex - beginIndex;
#include <inttypes.h>
#include <string.h>
#include <unistd.h>
+#include <ctype.h>
#include "util.h"
#include "util_posix.h"
#include "iso14443crc.h"
static int CmdHelp(const char *Cmd);
static int waitCmd(uint8_t iLen);
+// structure and database for uid -> tagtype lookups
+typedef struct {
+ uint8_t uid;
+ char* desc;
+} manufactureName;
-const manufactureName manufactureMapping[] = {
+static const manufactureName manufactureMapping[] = {
// ID, "Vendor Country"
{ 0x01, "Motorola UK" },
{ 0x02, "ST Microelectronics SA France" },
break;
case 'x':
case 'X':
- cm = cm - ISO14A_CONNECT;
+ cm &= ~ISO14A_CONNECT;
break;
default:
PrintAndLog("Unknown command.");
PrintAndLog(" UID : %s", sprint_hex(card.uid, card.uidlen));
PrintAndLog("ATQA : %02x %02x", card.atqa[1], card.atqa[0]);
- PrintAndLog(" SAK : %02x [%d]", card.sak, resp.arg[0]);
+ PrintAndLog(" SAK : %02x [%" PRIu64 "]", card.sak, resp.arg[0]);
if(card.ats_len >= 3) { // a valid ATS consists of at least the length byte (TL) and 2 CRC bytes
PrintAndLog(" ATS : %s", sprint_hex(card.ats, card.ats_len));
}
PrintAndLog(" UID : %s", sprint_hex(card.uid, card.uidlen));
PrintAndLog("ATQA : %02x %02x", card.atqa[1], card.atqa[0]);
- PrintAndLog(" SAK : %02x [%d]", card.sak, resp.arg[0]);
+ PrintAndLog(" SAK : %02x [%" PRIu64 "]", card.sak, resp.arg[0]);
bool isMifareClassic = true;
switch (card.sak) {
return 1;
}
- if (isxdigit(c)) {
+ if (isxdigit((unsigned char)c)) {
// len = data + PCB(1b) + CRC(2b)
switch(param_gethex_to_eol(cmd, cmdp, data, sizeof(data) - 1 - 2, &datalen)) {
case 1:
#include <stdint.h>
#include <stdbool.h>
-// structure and database for uid -> tagtype lookups
-typedef struct {
- uint8_t uid;
- char* desc;
-} manufactureName;
-
int CmdHF14A(const char *Cmd);
int CmdHF14AList(const char *Cmd);
int CmdHF14AMifare(const char *Cmd);
int i, res;\r
int keycnt = 0;\r
char ctmp = 0x00;\r
+ int clen = 0;\r
char ctmp3[3] = {0x00};\r
uint8_t blockNo = 0;\r
uint8_t SectorsCnt = 0;\r
blockNo = param_get8(Cmd, 0);\r
\r
ctmp = param_getchar(Cmd, 1);\r
- switch (ctmp) {\r
- case 'a': case 'A':\r
- keyType = 0;\r
- break;\r
- case 'b': case 'B':\r
- keyType = 1;\r
- break;\r
- case '?':\r
- keyType = 2;\r
- break;\r
- default:\r
- PrintAndLog("Key type must be A , B or ?");\r
- free(keyBlock);\r
- return 1;\r
- };\r
+ clen = param_getlength(Cmd, 1);\r
+ if (clen == 1) {\r
+ switch (ctmp) {\r
+ case 'a': case 'A':\r
+ keyType = 0;\r
+ break;\r
+ case 'b': case 'B':\r
+ keyType = 1;\r
+ break;\r
+ case '?':\r
+ keyType = 2;\r
+ break;\r
+ default:\r
+ PrintAndLog("Key type must be A , B or ?");\r
+ free(keyBlock);\r
+ return 1;\r
+ };\r
+ }\r
\r
// transfer to emulator & create dump file\r
ctmp = param_getchar(Cmd, 2);\r
- if (ctmp == 't' || ctmp == 'T') transferToEml = 1;\r
- if (ctmp == 'd' || ctmp == 'D') createDumpFile = 1;\r
+ clen = param_getlength(Cmd, 2);\r
+ if (clen == 1 && (ctmp == 't' || ctmp == 'T')) transferToEml = 1;\r
+ if (clen == 1 && (ctmp == 'd' || ctmp == 'D')) createDumpFile = 1;\r
\r
param3InUse = transferToEml | createDumpFile;\r
\r
timeout14a = 500; // fast by default\r
// double parameters - ts, ds\r
- int clen = param_getlength(Cmd, 2);\r
+ clen = param_getlength(Cmd, 2);\r
if (clen == 2 || clen == 3){\r
param_getstr(Cmd, 2, ctmp3, sizeof(ctmp3));\r
ctmp = ctmp3[1];\r
\r
if( buf[0]=='#' ) continue; //The line start with # is comment, skip\r
\r
- if (!isxdigit(buf[0])){\r
+ if (!isxdigit((unsigned char)buf[0])){\r
PrintAndLog("File content error. '%s' must include 12 HEX symbols",buf);\r
continue;\r
}\r
//The line start with # is comment, skip\r
if( buf[0]=='#' ) continue;\r
\r
- if (!isxdigit(buf[0])) {\r
+ if (!isxdigit((unsigned char)buf[0])) {\r
PrintAndLog("File content error. '%s' must include 8 HEX symbols", buf);\r
continue;\r
}\r
// EMV commands
//-----------------------------------------------------------------------------
+#include <ctype.h>
#include "cmdemv.h"
#include "test/cryptotest.h"
return 1;
}
- if (isxdigit(c)) {
+ if (isxdigit((unsigned char)c)) {
switch(param_gethex_to_eol(cmd, cmdp, data, sizeof(data), &datalen)) {
case 1:
PrintAndLog("Invalid HEX value.");
res = rsa_public(&cp->ctx, buf, result);
if(res) {
- printf("RSA encrypt failed. Error: %x data len: %d key len: %d\n", res * -1, len, keylen);
+ printf("RSA encrypt failed. Error: %x data len: %zd key len: %zd\n", res * -1, len, keylen);
return NULL;
}
res = rsa_private(&cp->ctx, buf, result); // CHECK???
if(res) {
- printf("RSA decrypt failed. Error: %x data len: %d key len: %d\n", res * -1, len, keylen);
+ printf("RSA decrypt failed. Error: %x data len: %zd key len: %zd\n", res * -1, len, keylen);
return NULL;
}
}
if (cert_tlv->len != enc_pk->mlen) {
- printf("ERROR: Certificate length (%d) not equal key length (%d)\n", cert_tlv->len, enc_pk->mlen);
+ printf("ERROR: Certificate length (%zd) not equal key length (%zd)\n", cert_tlv->len, enc_pk->mlen);
return NULL;
}
kcp = crypto_pk_open(enc_pk->pk_algo,
un_tlv,
NULL);
if (!data || data_len < 3) {
- printf("ERROR: can't decode message. len %d\n", data_len);
+ printf("ERROR: can't decode message. len %zd\n", data_len);
return NULL;
}
tmp = crypto_pk_get_parameter(pubk, 0, &tmp_len);
if (tmp_len != sizeof(pk_N) || memcmp(tmp, pk_N, tmp_len)) {
- fprintf(stderr, "ERROR: crypto_pk_get_parameter(0) Modulus. param len %d len %d\n", tmp_len, sizeof(pk_N));
+ fprintf(stderr, "ERROR: crypto_pk_get_parameter(0) Modulus. param len %zd len %zd\n", tmp_len, sizeof(pk_N));
free(tmp);
goto close_pub;
}
tmp = crypto_pk_get_parameter(privk, 0, &tmp_len);
if (tmp_len != sizeof(pk_N) || memcmp(tmp, pk_N, tmp_len)) {
- fprintf(stderr, "ERROR: crypto_pk_get_parameter(0) Modulus. param len %d len %d\n", tmp_len, sizeof(pk_N));
+ fprintf(stderr, "ERROR: crypto_pk_get_parameter(0) Modulus. param len %zd len %zd\n", tmp_len, sizeof(pk_N));
free(tmp);
goto close;
}
FILE *f;
int retval = 1;
f = fopen("iclass_key.bin", "rb");
- if (f)
- {
- if(fread(key, sizeof(uint8_t), 8, f) == 1)
- {
- retval = 0;
- }
- fclose(f);
+ if (!f)
+ return retval;
+
+ if (fread(key, sizeof(uint8_t), 8, f) == 8) {
+ retval = 0;
}
+ fclose(f);
return retval;
}
-
int doKeyTests(uint8_t debuglevel)
{
debug_print = debuglevel;
sbyte = 0;
odd = 0;
}
- } else if (isspace(a[ii])) {
+ } else if (isspace((unsigned char)a[ii])) {
/* ignore */
} else {
/* err ... ignore too*/
uerror("cannot allocate memory for comparison string");
akey.name = uptr = ukey;
do
- *uptr++ = toupper(*key);
+ *uptr++ = toupper((unsigned char)*key);
while(*key++);
aptr = bsearch(&akey, aliases, NALIASES, sizeof(struct malias), (int (*)(const void *, const void *)) &acmp);
// UI utilities
//-----------------------------------------------------------------------------
-#include <stdarg.h>
+#include <stdbool.h>
+#ifndef EXTERNAL_PRINTANDLOG
#include <stdlib.h>
#include <stdio.h>
-#include <stdbool.h>
+#include <stdarg.h>
#include <readline/readline.h>
#include <pthread.h>
+#endif
#include "ui.h"
bool GridLocked = false;
bool showDemod = true;
-extern pthread_mutex_t print_lock;
-
static char *logfilename = "proxmark3.log";
+#ifndef EXTERNAL_PRINTANDLOG
+// Declared in proxmark3.c
+extern pthread_mutex_t print_lock;
+
void PrintAndLog(char *fmt, ...)
{
char *saved_line;
//release lock
pthread_mutex_unlock(&print_lock);
}
-
+#endif
void SetLogFilename(char *fn)
{
return 1;
for(i = 0; i < hexcnt; i += 2) {
- if (!(isxdigit(line[bg + i]) && isxdigit(line[bg + i + 1])) ) return 1;
+ if (!(isxdigit((unsigned char)line[bg + i]) && isxdigit((unsigned char)line[bg + i + 1])) ) return 1;
sscanf((char[]){line[bg + i], line[bg + i + 1], 0}, "%X", &temp);
data[i / 2] = temp & 0xff;
return 1;
for(i = 0; i < *hexcnt; i += 2) {
- if (!(isxdigit(line[bg + i]) && isxdigit(line[bg + i + 1])) ) return 1;
+ if (!(isxdigit((unsigned char)line[bg + i]) && isxdigit((unsigned char)line[bg + i + 1])) ) return 1;
sscanf((char[]){line[bg + i], line[bg + i + 1], 0}, "%X", &temp);
data[i / 2] = temp & 0xff;
continue;
}
- if (isxdigit(line[indx])) {
+ if (isxdigit((unsigned char)line[indx])) {
buf[strlen(buf) + 1] = 0x00;
buf[strlen(buf)] = line[indx];
} else {
else if (x >= 'A' && x <= 'F')
x -= 'A' - 10;
else {
- printf("Discovered unknown character %c %d at idx %d of %s\n", x, x, source - start, start);
+ printf("Discovered unknown character %c %d at idx %tu of %s\n", x, x, source - start, start);
return 0;
}
// output