From: roel@libnfc.org Date: Thu, 14 Mar 2013 15:03:04 +0000 (+0000) Subject: client should compile without warnings on linux, mac, windows X-Git-Tag: v1.0.0~125 X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/commitdiff_plain/759c16b31f8dcec37458dd6a5973ce0cfce58015?ds=inline client should compile without warnings on linux, mac, windows --- diff --git a/client/Makefile b/client/Makefile index d314427c..79e6eb2e 100644 --- a/client/Makefile +++ b/client/Makefile @@ -12,7 +12,7 @@ CXX=g++ VPATH = ../common OBJDIR = obj -LDLIBS = -L/opt/local/lib -L/usr/local/lib -lusb -lreadline -lpthread +LDLIBS = -L/opt/local/lib -L/usr/local/lib -lreadline -lpthread LDFLAGS = $(COMMON_FLAGS) CFLAGS = -std=c99 -I. -I../include -I../common -I/opt/local/include -Wall -Wno-unused-function $(COMMON_FLAGS) -g -O4 @@ -39,10 +39,14 @@ else QTGUI = guidummy.o endif -CMDSRCS = \ - nonce2key/crapto1.c\ - nonce2key/crypto1.c\ - nonce2key/nonce2key.c\ +CORESRCS = uart.c \ + util.c \ + sleep.c + + +CMDSRCS = nonce2key/crapto1.c\ + nonce2key/crypto1.c\ + nonce2key/nonce2key.c\ mifarehost.c\ crc16.c \ iso14443crc.c \ @@ -50,8 +54,6 @@ CMDSRCS = \ data.c \ graph.c \ ui.c \ - uart.c \ - util.c \ cmddata.c \ cmdhf.c \ cmdhf14a.c \ @@ -72,6 +74,7 @@ CMDSRCS = \ cmdlft55xx.c \ cmdlfpcf7931.c +COREOBJS = $(CORESRCS:%.c=$(OBJDIR)/%.o) CMDOBJS = $(CMDSRCS:%.c=$(OBJDIR)/%.o) RM = rm -f @@ -84,16 +87,16 @@ all-static: LDLIBS:=-static $(LDLIBS) all-static: snooper cli flasher proxmark3: LDLIBS+=$(QTLDLIBS) -proxmark3: $(OBJDIR)/proxmark3.o $(CMDOBJS) $(OBJDIR)/uart.o $(QTGUI) +proxmark3: $(OBJDIR)/proxmark3.o $(COREOBJS) $(CMDOBJS) $(QTGUI) $(CXX) $(CXXFLAGS) $^ $(LDLIBS) -o $@ -snooper: $(OBJDIR)/snooper.o $(CMDOBJS) $(OBJDIR)/uart.o $(OBJDIR)/guidummy.o +snooper: $(OBJDIR)/snooper.o $(COREOBJS) $(CMDOBJS) $(OBJDIR)/guidummy.o $(CXX) $(CXXFLAGS) $^ $(LDLIBS) -o $@ -cli: $(OBJDIR)/cli.o $(CMDOBJS) $(OBJDIR)/uart.o $(OBJDIR)/guidummy.o +cli: $(OBJDIR)/cli.o $(COREOBJS) $(CMDOBJS) $(OBJDIR)/guidummy.o $(CXX) $(CXXFLAGS) $^ $(LDLIBS) -o $@ -flasher: $(OBJDIR)/flash.o $(OBJDIR)/flasher.o $(OBJDIR)/uart.o +flasher: $(OBJDIR)/flash.o $(OBJDIR)/flasher.o $(COREOBJS) $(CXX) $(CXXFLAGS) $^ $(LDLIBS) -o $@ $(OBJDIR)/%.o: %.c diff --git a/client/cmdhfepa.c b/client/cmdhfepa.c index a89c448a..8a36d6ae 100644 --- a/client/cmdhfepa.c +++ b/client/cmdhfepa.c @@ -16,7 +16,6 @@ #include "common.h" #include "cmdmain.h" #include "sleep.h" - #include "cmdhfepa.h" static int CmdHelp(const char *Cmd); diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index 11288085..597841e1 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -287,10 +287,16 @@ int CmdHF14AMfDump(const char *Cmd) // Read key file for (i=0 ; i<16 ; i++) { - fread ( keyA[i], 1, 6, fin ); + if (fread( keyA[i], 1, 6, fin ) == 0) { + PrintAndLog("File reading error."); + return 2; + } } for (i=0 ; i<16 ; i++) { - fread ( keyB[i], 1, 6, fin ); + if (fread( keyB[i], 1, 6, fin ) == 0) { + PrintAndLog("File reading error."); + return 2; + } } // Read access rights to sectors @@ -416,10 +422,16 @@ int CmdHF14AMfRestore(const char *Cmd) } for (i=0 ; i<16 ; i++) { - fread(keyA[i], 1, 6, fkeys); + if (fread(keyA[i], 1, 6, fkeys) == 0) { + PrintAndLog("File reading error."); + return 2; + } } for (i=0 ; i<16 ; i++) { - fread(keyB[i], 1, 6, fkeys); + if (fread(keyB[i], 1, 6, fkeys) == 0) { + PrintAndLog("File reading error."); + return 2; + } } PrintAndLog("Restoring dumpdata.bin to card"); @@ -429,7 +441,10 @@ int CmdHF14AMfRestore(const char *Cmd) UsbCommand c = {CMD_MIFARE_WRITEBL, {i*4 + j, keyType, 0}}; memcpy(c.d.asBytes, key, 6); - fread(bldata, 1, 16, fdump); + if (fread(bldata, 1, 16, fdump) == 0) { + PrintAndLog("File reading error."); + return 2; + } if (j == 3) { bldata[0] = (keyA[i][0]); @@ -816,8 +831,11 @@ int CmdHF14AMfChk(const char *Cmd) if ( (f = fopen( filename , "r")) ) { while( !feof(f) ){ memset(buf, 0, sizeof(buf)); - fgets(buf, sizeof(buf), f); - + if (fgets(buf, sizeof(buf), f) == NULL) { + PrintAndLog("File reading error."); + return 2; + } + if (strlen(buf) < 12 || buf[11] == '\n') continue; @@ -1077,7 +1095,10 @@ int CmdHF14AMfELoad(const char *Cmd) blockNum = 0; while(!feof(f)){ memset(buf, 0, sizeof(buf)); - fgets(buf, sizeof(buf), f); + if (fgets(buf, sizeof(buf), f) == NULL) { + PrintAndLog("File reading error."); + return 2; + } if (strlen(buf) < 32){ if(strlen(buf) && feof(f)) @@ -1344,7 +1365,10 @@ int CmdHF14AMfCLoad(const char *Cmd) flags = CSETBLOCK_INIT_FIELD + CSETBLOCK_WUPC; while(!feof(f)){ memset(buf, 0, sizeof(buf)); - fgets(buf, sizeof(buf), f); + if (fgets(buf, sizeof(buf), f) == NULL) { + PrintAndLog("File reading error."); + return 2; + } if (strlen(buf) < 32){ if(strlen(buf) && feof(f)) diff --git a/client/cmdlfhitag.c b/client/cmdlfhitag.c index ab279dcb..af61bd36 100644 --- a/client/cmdlfhitag.c +++ b/client/cmdlfhitag.c @@ -147,7 +147,10 @@ int CmdLFHitagSim(const char *Cmd) { return 1; } tag_mem_supplied = true; - fread(c.d.asBytes,48,1,pf); + if (fread(c.d.asBytes,48,1,pf) == 0) { + PrintAndLog("Error: File reading error"); + return 1; + } fclose(pf); } else { tag_mem_supplied = false; diff --git a/client/mifarehost.c b/client/mifarehost.c index 14674b16..9676e6f7 100644 --- a/client/mifarehost.c +++ b/client/mifarehost.c @@ -326,7 +326,10 @@ int loadTraceCard(uint8_t *tuid) { blockNum = 0; while(!feof(f)){ memset(buf, 0, sizeof(buf)); - fgets(buf, sizeof(buf), f); + if (fgets(buf, sizeof(buf), f) == NULL) { + PrintAndLog("File reading error."); + return 2; + } if (strlen(buf) < 32){ if (feof(f)) break; diff --git a/client/proxmark3.c b/client/proxmark3.c index ae4ad7c0..32e6320a 100644 --- a/client/proxmark3.c +++ b/client/proxmark3.c @@ -23,6 +23,7 @@ #include "uart.h" #include "messages.h" #include "ui.h" +#include "sleep.h" static serial_port sp; static UsbCommand txcmd; diff --git a/client/proxmark3.h b/client/proxmark3.h index eebaa495..8236bfe7 100644 --- a/client/proxmark3.h +++ b/client/proxmark3.h @@ -18,7 +18,6 @@ #define lli PRIi64 #define hhu PRIu8 -#include #include "usb_cmd.h" #define PROXPROMPT "proxmark3> " diff --git a/client/sleep.c b/client/sleep.c new file mode 100644 index 00000000..fe397da9 --- /dev/null +++ b/client/sleep.c @@ -0,0 +1,28 @@ +//----------------------------------------------------------------------------- +// Copyright (C) 2010 iZsh +// +// This code is licensed to you under the terms of the GNU GPL, version 2 or, +// at your option, any later version. See the LICENSE.txt file for the text of +// the license. +//----------------------------------------------------------------------------- +// platform-independant sleep macros +//----------------------------------------------------------------------------- + +#ifndef _WIN32 + +#define _POSIX_C_SOURCE 199309L +#include "sleep.h" +#include +#include +#include +#include + +void nsleep(uint64_t n) { + struct timespec timeout; + timeout.tv_sec = n/1000000000; + timeout.tv_nsec = n%1000000000; + while (nanosleep(&timeout, &timeout) && errno == EINTR); +} + +#endif // _WIN32 + diff --git a/client/sleep.h b/client/sleep.h index 62d9f4d1..81e1dea0 100644 --- a/client/sleep.h +++ b/client/sleep.h @@ -12,13 +12,16 @@ #define SLEEP_H__ #ifdef _WIN32 -#include -#define sleep(n) Sleep(1000 * n) -#define msleep(n) Sleep(n) +# include +# define sleep(n) Sleep(1000 * n) +# define msleep(n) Sleep(n) #else -#include -#define msleep(n) usleep(1000 * n) -#endif +# include +# include + void nsleep(uint64_t n); +# define msleep(n) nsleep(1000000 * n) +# define usleep(n) nsleep(1000 * n) +#endif // _WIN32 -#endif +#endif // SLEEP_H__ diff --git a/client/util.h b/client/util.h index 1d410592..ce8876ed 100644 --- a/client/util.h +++ b/client/util.h @@ -16,8 +16,12 @@ #include #include -#define MIN(a, b) (((a) < (b)) ? (a) : (b)) -#define MAX(a, b) (((a) > (b)) ? (a) : (b)) +#ifndef MIN +# define MIN(a, b) (((a) < (b)) ? (a) : (b)) +#endif +#ifndef MAX +# define MAX(a, b) (((a) > (b)) ? (a) : (b)) +#endif int ukbhit(void); diff --git a/include/common.h b/include/common.h index ba286377..71787b4f 100644 --- a/include/common.h +++ b/include/common.h @@ -18,7 +18,11 @@ #include typedef unsigned char byte_t; -#define MIN(a, b) (((a) < (b)) ? (a) : (b)) -#define MAX(a, b) (((a) > (b)) ? (a) : (b)) +#ifndef MIN +# define MIN(a, b) (((a) < (b)) ? (a) : (b)) +#endif +#ifndef MAX +# define MAX(a, b) (((a) > (b)) ? (a) : (b)) +#endif #endif