X-Git-Url: http://cvs.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/aea4d76687f3aa3d5dcd0fc5cf3d36f8f753994c..e0c635d19c58423d88ae698788a31c865e5554ab:/client/util.c diff --git a/client/util.c b/client/util.c index ae213e43..0673f181 100644 --- a/client/util.c +++ b/client/util.c @@ -8,10 +8,6 @@ // utilities //----------------------------------------------------------------------------- -#include -#include -#include -#include #include "util.h" #ifndef WIN32 @@ -48,6 +44,52 @@ int ukbhit(void) { } #endif +// log files functions +void AddLogLine(char *fileName, char *extData, char *c) { + FILE *fLog = NULL; + + fLog = fopen(fileName, "a"); + if (!fLog) { + printf("Could not append log file %s", fileName); + return; + } + + fprintf(fLog, "%s", extData); + fprintf(fLog, "%s\n", c); + fclose(fLog); +} + +void AddLogHex(char *fileName, char *extData, const uint8_t * data, const size_t len){ + AddLogLine(fileName, extData, sprint_hex(data, len)); +} + +void AddLogUint64(char *fileName, char *extData, const uint64_t data) { + char buf[100] = {0}; + sprintf(buf, "%x%x", (unsigned int)((data & 0xFFFFFFFF00000000) >> 32), (unsigned int)(data & 0xFFFFFFFF)); + AddLogLine(fileName, extData, buf); +} + +void AddLogCurrentDT(char *fileName) { + char buff[20]; + struct tm *curTime; + + time_t now = time(0); + curTime = gmtime(&now); + + strftime (buff, sizeof(buff), "%Y-%m-%d %H:%M:%S", curTime); + AddLogLine(fileName, "\nanticollision: ", buff); +} + +void FillFileNameByUID(char *fileName, uint8_t * uid, char *ext, int byteCount) { + char * fnameptr = fileName; + memset(fileName, 0x00, 200); + + for (int j = 0; j < byteCount; j++, fnameptr += 2) + sprintf(fnameptr, "%02x", uid[j]); + sprintf(fnameptr, "%s", ext); +} + +// printing and converting functions void print_hex(const uint8_t * data, const size_t len) { @@ -166,7 +208,7 @@ uint64_t param_get64ex(const char *line, int paramnum, int deflt, int base) int bg, en; if (!param_getptr(line, &bg, &en, paramnum)) - return strtol(&line[bg], NULL, base); + return strtoll(&line[bg], NULL, base); else return deflt;