client should compile without warnings on linux, mac, windows

This commit is contained in:
roel@libnfc.org 2013-03-14 15:03:04 +00:00
parent 19d9a7b0ce
commit 759c16b31f
11 changed files with 106 additions and 35 deletions

View file

@ -12,7 +12,7 @@ CXX=g++
VPATH = ../common VPATH = ../common
OBJDIR = obj 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) LDFLAGS = $(COMMON_FLAGS)
CFLAGS = -std=c99 -I. -I../include -I../common -I/opt/local/include -Wall -Wno-unused-function $(COMMON_FLAGS) -g -O4 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 QTGUI = guidummy.o
endif endif
CMDSRCS = \ CORESRCS = uart.c \
nonce2key/crapto1.c\ util.c \
nonce2key/crypto1.c\ sleep.c
nonce2key/nonce2key.c\
CMDSRCS = nonce2key/crapto1.c\
nonce2key/crypto1.c\
nonce2key/nonce2key.c\
mifarehost.c\ mifarehost.c\
crc16.c \ crc16.c \
iso14443crc.c \ iso14443crc.c \
@ -50,8 +54,6 @@ CMDSRCS = \
data.c \ data.c \
graph.c \ graph.c \
ui.c \ ui.c \
uart.c \
util.c \
cmddata.c \ cmddata.c \
cmdhf.c \ cmdhf.c \
cmdhf14a.c \ cmdhf14a.c \
@ -72,6 +74,7 @@ CMDSRCS = \
cmdlft55xx.c \ cmdlft55xx.c \
cmdlfpcf7931.c cmdlfpcf7931.c
COREOBJS = $(CORESRCS:%.c=$(OBJDIR)/%.o)
CMDOBJS = $(CMDSRCS:%.c=$(OBJDIR)/%.o) CMDOBJS = $(CMDSRCS:%.c=$(OBJDIR)/%.o)
RM = rm -f RM = rm -f
@ -84,16 +87,16 @@ all-static: LDLIBS:=-static $(LDLIBS)
all-static: snooper cli flasher all-static: snooper cli flasher
proxmark3: LDLIBS+=$(QTLDLIBS) proxmark3: LDLIBS+=$(QTLDLIBS)
proxmark3: $(OBJDIR)/proxmark3.o $(CMDOBJS) $(OBJDIR)/uart.o $(QTGUI) proxmark3: $(OBJDIR)/proxmark3.o $(COREOBJS) $(CMDOBJS) $(QTGUI)
$(CXX) $(CXXFLAGS) $^ $(LDLIBS) -o $@ $(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 $@ $(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 $@ $(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 $@ $(CXX) $(CXXFLAGS) $^ $(LDLIBS) -o $@
$(OBJDIR)/%.o: %.c $(OBJDIR)/%.o: %.c

View file

@ -16,7 +16,6 @@
#include "common.h" #include "common.h"
#include "cmdmain.h" #include "cmdmain.h"
#include "sleep.h" #include "sleep.h"
#include "cmdhfepa.h" #include "cmdhfepa.h"
static int CmdHelp(const char *Cmd); static int CmdHelp(const char *Cmd);

View file

@ -287,10 +287,16 @@ int CmdHF14AMfDump(const char *Cmd)
// Read key file // Read key file
for (i=0 ; i<16 ; i++) { 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++) { 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 // Read access rights to sectors
@ -416,10 +422,16 @@ int CmdHF14AMfRestore(const char *Cmd)
} }
for (i=0 ; i<16 ; i++) { 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++) { 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"); 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}}; UsbCommand c = {CMD_MIFARE_WRITEBL, {i*4 + j, keyType, 0}};
memcpy(c.d.asBytes, key, 6); 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) { if (j == 3) {
bldata[0] = (keyA[i][0]); bldata[0] = (keyA[i][0]);
@ -816,8 +831,11 @@ int CmdHF14AMfChk(const char *Cmd)
if ( (f = fopen( filename , "r")) ) { if ( (f = fopen( filename , "r")) ) {
while( !feof(f) ){ while( !feof(f) ){
memset(buf, 0, sizeof(buf)); 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') if (strlen(buf) < 12 || buf[11] == '\n')
continue; continue;
@ -1077,7 +1095,10 @@ int CmdHF14AMfELoad(const char *Cmd)
blockNum = 0; blockNum = 0;
while(!feof(f)){ while(!feof(f)){
memset(buf, 0, sizeof(buf)); 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) < 32){
if(strlen(buf) && feof(f)) if(strlen(buf) && feof(f))
@ -1344,7 +1365,10 @@ int CmdHF14AMfCLoad(const char *Cmd)
flags = CSETBLOCK_INIT_FIELD + CSETBLOCK_WUPC; flags = CSETBLOCK_INIT_FIELD + CSETBLOCK_WUPC;
while(!feof(f)){ while(!feof(f)){
memset(buf, 0, sizeof(buf)); 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) < 32){
if(strlen(buf) && feof(f)) if(strlen(buf) && feof(f))

View file

@ -147,7 +147,10 @@ int CmdLFHitagSim(const char *Cmd) {
return 1; return 1;
} }
tag_mem_supplied = true; 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); fclose(pf);
} else { } else {
tag_mem_supplied = false; tag_mem_supplied = false;

View file

@ -326,7 +326,10 @@ int loadTraceCard(uint8_t *tuid) {
blockNum = 0; blockNum = 0;
while(!feof(f)){ while(!feof(f)){
memset(buf, 0, sizeof(buf)); 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) < 32){
if (feof(f)) break; if (feof(f)) break;

View file

@ -23,6 +23,7 @@
#include "uart.h" #include "uart.h"
#include "messages.h" #include "messages.h"
#include "ui.h" #include "ui.h"
#include "sleep.h"
static serial_port sp; static serial_port sp;
static UsbCommand txcmd; static UsbCommand txcmd;

View file

@ -18,7 +18,6 @@
#define lli PRIi64 #define lli PRIi64
#define hhu PRIu8 #define hhu PRIu8
#include <usb.h>
#include "usb_cmd.h" #include "usb_cmd.h"
#define PROXPROMPT "proxmark3> " #define PROXPROMPT "proxmark3> "

28
client/sleep.c Normal file
View file

@ -0,0 +1,28 @@
//-----------------------------------------------------------------------------
// Copyright (C) 2010 iZsh <izsh at fail0verflow.com>
//
// 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 <time.h>
#include <stdio.h>
#include <sys/time.h>
#include <errno.h>
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

View file

@ -12,13 +12,16 @@
#define SLEEP_H__ #define SLEEP_H__
#ifdef _WIN32 #ifdef _WIN32
#include <windows.h> # include <windows.h>
#define sleep(n) Sleep(1000 * n) # define sleep(n) Sleep(1000 * n)
#define msleep(n) Sleep(n) # define msleep(n) Sleep(n)
#else #else
#include <unistd.h> # include <inttypes.h>
#define msleep(n) usleep(1000 * n) # include <unistd.h>
#endif void nsleep(uint64_t n);
# define msleep(n) nsleep(1000000 * n)
# define usleep(n) nsleep(1000 * n)
#endif // _WIN32
#endif #endif // SLEEP_H__

View file

@ -16,8 +16,12 @@
#include <ctype.h> #include <ctype.h>
#include <time.h> #include <time.h>
#define MIN(a, b) (((a) < (b)) ? (a) : (b)) #ifndef MIN
#define MAX(a, b) (((a) > (b)) ? (a) : (b)) # define MIN(a, b) (((a) < (b)) ? (a) : (b))
#endif
#ifndef MAX
# define MAX(a, b) (((a) > (b)) ? (a) : (b))
#endif
int ukbhit(void); int ukbhit(void);

View file

@ -18,7 +18,11 @@
#include <at91sam7s512.h> #include <at91sam7s512.h>
typedef unsigned char byte_t; typedef unsigned char byte_t;
#define MIN(a, b) (((a) < (b)) ? (a) : (b)) #ifndef MIN
#define MAX(a, b) (((a) > (b)) ? (a) : (b)) # define MIN(a, b) (((a) < (b)) ? (a) : (b))
#endif
#ifndef MAX
# define MAX(a, b) (((a) > (b)) ? (a) : (b))
#endif
#endif #endif