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
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

View file

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

View file

@ -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,7 +831,10 @@ 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))

View file

@ -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;

View file

@ -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;

View file

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

View file

@ -18,7 +18,6 @@
#define lli PRIi64
#define hhu PRIu8
#include <usb.h>
#include "usb_cmd.h"
#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__
#ifdef _WIN32
#include <windows.h>
#define sleep(n) Sleep(1000 * n)
#define msleep(n) Sleep(n)
# include <windows.h>
# define sleep(n) Sleep(1000 * n)
# define msleep(n) Sleep(n)
#else
#include <unistd.h>
#define msleep(n) usleep(1000 * n)
#endif
# include <inttypes.h>
# include <unistd.h>
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 <time.h>
#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);

View file

@ -18,7 +18,11 @@
#include <at91sam7s512.h>
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