From 91c38cf715f2bbd668cb13f4acfed0cb01293912 Mon Sep 17 00:00:00 2001 From: "izsh@fail0verflow.com" Date: Sat, 20 Feb 2010 00:36:48 +0000 Subject: [PATCH] Fix windows compilation issues. But still not final. We should move to pthread and factorize the code with *nix). Ideally we should move to libusb-1.0 too. --- client/Makefile | 10 +++++----- client/cmdmain.c | 14 +++++++------- client/flash.c | 3 --- client/flash.h | 2 ++ client/prox.c | 5 ++--- client/proxusb.h | 8 ++------ client/ui.c | 17 ++++++----------- client/wingui.c | 11 ++++++----- 8 files changed, 30 insertions(+), 40 deletions(-) diff --git a/client/Makefile b/client/Makefile index 65788beb..d0978a98 100644 --- a/client/Makefile +++ b/client/Makefile @@ -1,4 +1,4 @@ -WINCC=c:\mingw\bin\gcc +CC=gcc #COMMON_FLAGS = -m32 VPATH = ../common @@ -12,8 +12,8 @@ CXXFLAGS = $(shell pkg-config --cflags QtCore QtGui 2>/dev/null) -Wall QTLDLIBS = $(shell pkg-config --libs QtCore QtGui 2>/dev/null) CMDSRCS = \ - $(VPATH)\crc16.c \ - $(VPATH)\iso14443crc.c \ + crc16.c \ + iso14443crc.c \ data.c \ graph.c \ ui.c \ @@ -64,8 +64,8 @@ all: $(BINS) all-static: LDLIBS:=-static $(LDLIBS) all-static: snooper cli flasher -prox.exe: prox.c wingui.c $(CMDSRCS) flash.c - $(WINCC) $(CFLAGS) $(DEFINES) -o prox.exe prox.c wingui.c $(CMDSRCS) flash.c $(WINLIBS) +prox.exe: prox.o wingui.o $(CMDOBJS) flash.o + $(CC) $(CFLAGS) $(DEFINES) -o prox.exe prox.o wingui.o $(CMDOBJS) flash.c $(WINLIBS) proxmark3: LDLIBS+=$(QTLDLIBS) proxmark3: proxmark3.o $(CMDOBJS) proxusb.o $(QTGUI) diff --git a/client/cmdmain.c b/client/cmdmain.c index c6d59e2e..1e49e6cb 100644 --- a/client/cmdmain.c +++ b/client/cmdmain.c @@ -2,9 +2,7 @@ #include #include #include -#ifdef WIN32 -#include -#endif +#include "sleep.h" #include "cmdparser.h" #include "data.h" #include "usb_cmd.h" @@ -14,7 +12,6 @@ #include "cmdhw.h" #include "cmdlf.h" #include "cmdmain.h" -#include "proxusb.h" unsigned int current_command = CMD_UNKNOWN; unsigned int received_command = CMD_UNKNOWN; @@ -50,13 +47,16 @@ void WaitForResponse(uint32_t response_type) { while (received_command != response_type) { #ifdef WIN32 + // FIXME: Do we really need this under windows or is it + // just some historical code? + // pthread seems to be availabe for win32 nowadays + // so we should be able to port the code and get rid + // of this part. UsbCommand c; if (ReceiveCommandPoll(&c)) UsbCommandReceived(&c); - Sleep(0); -#else - usleep(10000); // XXX ugh #endif + msleep(10); // XXX ugh } received_command = CMD_UNKNOWN; } diff --git a/client/flash.c b/client/flash.c index ee66dbe1..b4e4c891 100644 --- a/client/flash.c +++ b/client/flash.c @@ -14,7 +14,6 @@ BOOL UsbConnect(void); static uint32_t ExpectedAddr; static uint8_t QueuedToSend[256]; -static bool AllWritten; #define PHYSICAL_FLASH_START 0x100000 #define PHYSICAL_FLASH_END 0x200000 @@ -63,8 +62,6 @@ void WriteBlock(unsigned int block_start, unsigned int len, unsigned char *buf) memcpy(c.d.asBytes, temp_buf+240, 16); SendCommand(&c); WaitForAck(); - - AllWritten = true; } void LoadFlashFromFile(const char *file, int start_addr, int end_addr) diff --git a/client/flash.h b/client/flash.h index ab4fca96..20090db7 100644 --- a/client/flash.h +++ b/client/flash.h @@ -1,6 +1,8 @@ #ifndef __FLASH_H__ #define __FLASH_H__ +#include + struct partition { int start; int end; diff --git a/client/prox.c b/client/prox.c index 190cfd70..d619c821 100644 --- a/client/prox.c +++ b/client/prox.c @@ -3,16 +3,15 @@ #include #include #include -#include //extern "C" { #include "include/hidusage.h" #include "include/hidpi.h" #include "include/hidsdi.h" //} -#include "ui.h" #include "flash.h" -#include "proxusb.h" +#include "usb_cmd.h" +#include "ui.h" #define OUR_VID 0x9ac4 #define OUR_PID 0x4b8f diff --git a/client/proxusb.h b/client/proxusb.h index 4ee00750..32a334c6 100644 --- a/client/proxusb.h +++ b/client/proxusb.h @@ -1,14 +1,10 @@ #ifndef PROXUSB_H__ #define PROXUSB_H__ -#ifdef _MSC_VER -typedef DWORD uint32_t; -typedef BYTE uint8_t; -typedef WORD uint16_t; -#define bool BOOL -#else #include #include +#ifndef WIN32 +#include #endif #include "usb_cmd.h" diff --git a/client/ui.c b/client/ui.c index 9f4377c8..99c9f170 100644 --- a/client/ui.c +++ b/client/ui.c @@ -10,6 +10,11 @@ int offline; static char *logfilename = "proxmark3.log"; +// FIXME: ifndef not really nice... +// We should eventually get rid of it once +// we fully factorize the code between *nix and windows +// (using pthread and alikes...) +#ifndef WIN32 void PrintAndLog(char *fmt, ...) { va_list argptr, argptr2; @@ -30,23 +35,13 @@ void PrintAndLog(char *fmt, ...) va_end(argptr); printf("\n"); if (logging && logfile) { -#if 0 - char zeit[25]; - time_t jetzt_t; - struct tm *jetzt; - - jetzt_t = time(NULL); - jetzt = localtime(&jetzt_t); - strftime(zeit, 25, "%b %e %T", jetzt); - - fprintf(logfile,"%s ", zeit); -#endif vfprintf(logfile, fmt, argptr2); fprintf(logfile,"\n"); fflush(logfile); } va_end(argptr2); } +#endif void SetLogFilename(char *fn) { diff --git a/client/wingui.c b/client/wingui.c index 6c7ef529..9fcf5ea6 100644 --- a/client/wingui.c +++ b/client/wingui.c @@ -10,10 +10,11 @@ #include #include #include -#include "graph.h" + #include "proxusb.h" -#include "cmdmain.h" +#include "graph.h" #include "ui.h" +#include "cmdmain.h" #define oops() do { \ char line[100]; \ @@ -354,7 +355,7 @@ nopaint: return 1; } -void PrintToScrollback(char *fmt, ...) +void PrintAndLog(char *fmt, ...) { va_list f; char str[1024]; @@ -450,8 +451,8 @@ void ShowGui() ResizeCommandWindow(); SetFocus(CommandEdit); - PrintToScrollback(">> Started prox, built " __DATE__ " " __TIME__); - PrintToScrollback(">> Connected to device"); + PrintAndLog(">> Started prox, built " __DATE__ " " __TIME__); + PrintAndLog(">> Connected to device"); GreyPenLite = CreatePen(PS_SOLID, 1, RGB(50, 50, 50)); GreyPen = CreatePen(PS_SOLID, 1, RGB(100, 100, 100)); -- 2.39.5