]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/util.c
Merge branch 'master' of https://github.com/Proxmark/proxmark3
[proxmark3-svn] / client / util.c
index 8a62e361aec8f9ba8452c12887627d13eabe70b5..1ebfebea2ce452870ebccfaecaf95faeb6bc31ad 100644 (file)
 
 #include "util.h"
 
-#ifndef WIN32
+#ifndef _WIN32
 #include <termios.h>
 #include <sys/ioctl.h> 
+
 int ukbhit(void)
 {
   int cnt = 0;
@@ -80,15 +81,13 @@ void AddLogCurrentDT(char *fileName) {
        AddLogLine(fileName, "\nanticollision: ", buff);
 }
 
-void FillFileNameByUID(char *fileName, uint8_t * uid, char *ext) {
+void FillFileNameByUID(char *fileName, uint8_t * uid, char *ext, int byteCount) {
        char * fnameptr = fileName;
        memset(fileName, 0x00, 200);
        
-       for (int j = 0; j < 7; j++, fnameptr += 2)
+       for (int j = 0; j < byteCount; j++, fnameptr += 2)
                sprintf(fnameptr, "%02x", uid[j]); 
        sprintf(fnameptr, "%s", ext); 
-       
-       printf("fname:%s", fileName);
 }
 
 // printing and converting functions
@@ -114,6 +113,17 @@ char * sprint_hex(const uint8_t * data, const size_t len) {
        return buf;
 }
 
+char * sprint_bin(const uint8_t * data, const size_t len) {
+       static char buf[1024];
+       char * tmp = buf;
+       size_t i;
+
+       for (i=0; i < len && i < 1024; i++, tmp++)
+               sprintf(tmp, "%u", data[i]);
+
+       return buf;
+}
+
 void num_to_bytes(uint64_t n, size_t len, uint8_t* dest)
 {
        while (len--) {
@@ -133,6 +143,28 @@ uint64_t bytes_to_num(uint8_t* src, size_t len)
        return num;
 }
 
+//assumes little endian
+char * printBits(size_t const size, void const * const ptr)
+{
+    unsigned char *b = (unsigned char*) ptr;   
+    unsigned char byte;
+       static char buf[1024];
+       char * tmp = buf;
+    int i, j;
+
+    for (i=size-1;i>=0;i--)
+    {
+        for (j=7;j>=0;j--)
+        {
+            byte = b[i] & (1<<j);
+            byte >>= j;
+            sprintf(tmp, "%u", byte);
+                       tmp++;
+        }
+    }
+       return buf;
+}
+
 //  -------------------------------------------------------------------------
 //  string parameters lib
 //  -------------------------------------------------------------------------
@@ -190,7 +222,7 @@ uint8_t param_get8ex(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) & 0xff;
+               return strtoul(&line[bg], NULL, base) & 0xff;
        else
                return deflt;
 }
@@ -200,7 +232,7 @@ uint32_t param_get32ex(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 strtoul(&line[bg], NULL, base);
        else
                return deflt;
 }
@@ -210,7 +242,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 strtoll(&line[bg], NULL, base);
+               return strtoull(&line[bg], NULL, base);
        else
                return deflt;
 
Impressum, Datenschutz