X-Git-Url: http://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/79544b28adc44792888788eac3d58a03003860c5..6306ff4bacd74eff46d44f4b62240277ecb4c670:/client/util.c diff --git a/client/util.c b/client/util.c index a077aae9..edd9aebc 100644 --- a/client/util.c +++ b/client/util.c @@ -46,12 +46,18 @@ int ukbhit(void) { #endif // log files functions -void AddLogLine(char *fileName, char *extData, char *c) { +void AddLogLine(char *file, char *extData, char *c) { FILE *fLog = NULL; - - fLog = fopen(fileName, "a"); + char filename[FILE_PATH_SIZE] = {0x00}; + int len = 0; + + len = strlen(file); + if (len > FILE_PATH_SIZE) len = FILE_PATH_SIZE; + memcpy(filename, file, len); + + fLog = fopen(filename, "a"); if (!fLog) { - printf("Could not append log file %s", fileName); + printf("Could not append log file %s", filename); return; } @@ -103,11 +109,13 @@ void print_hex(const uint8_t * data, const size_t len) } char * sprint_hex(const uint8_t * data, const size_t len) { + + int maxLen = ( len > 1024/3) ? 1024/3 : len; static char buf[1024]; char * tmp = buf; size_t i; - for (i=0; i < len && i < 1024/3; i++, tmp += 3) + for (i=0; i < maxLen; ++i, tmp += 3) sprintf(tmp, "%02x ", data[i]); return buf; @@ -205,6 +213,7 @@ int param_getptr(const char *line, int *bg, int *en, int paramnum) return 0; } + char param_getchar(const char *line, int paramnum) { int bg, en; @@ -219,6 +228,35 @@ uint8_t param_get8(const char *line, int paramnum) return param_get8ex(line, paramnum, 10, 0); } +/** + * @brief Reads a decimal integer (actually, 0-254, not 255) + * @param line + * @param paramnum + * @return -1 if error + */ +uint8_t param_getdec(const char *line, int paramnum, uint8_t *destination) +{ + uint8_t val = param_get8ex(line, paramnum, 255, 10); + if( (int8_t) val == -1) return 1; + (*destination) = val; + return 0; +} +/** + * @brief Checks if param is decimal + * @param line + * @param paramnum + * @return + */ +uint8_t param_isdec(const char *line, int paramnum) +{ + int bg, en; + //TODO, check more thorougly + if (!param_getptr(line, &bg, &en, paramnum)) return 1; + // return strtoul(&line[bg], NULL, 10) & 0xff; + + return 0; +} + uint8_t param_get8ex(const char *line, int paramnum, int deflt, int base) { int bg, en;