X-Git-Url: http://cvs.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/6cb08550c40e94e1662ca8351dcca5139615ee66..a82c1ac827376ea6eef2487d33a3047b4fc594b1:/client/util.c diff --git a/client/util.c b/client/util.c index 9f2142c6..797a9392 100644 --- a/client/util.c +++ b/client/util.c @@ -113,11 +113,11 @@ char *sprint_hex(const uint8_t *data, const size_t len) { int maxLen = ( len > 1024/3) ? 1024/3 : len; static char buf[1024]; memset(buf, 0x00, 1024); - char *tmp = buf; + char * tmp = buf; size_t i; for (i=0; i < maxLen; ++i, tmp += 3) - sprintf(tmp, "%02x ", data[i]); + sprintf(tmp, "%02X ", data[i]); return buf; } @@ -248,7 +248,7 @@ char param_getchar(const char *line, int paramnum) uint8_t param_get8(const char *line, int paramnum) { - return param_get8ex(line, paramnum, 10, 0); + return param_get8ex(line, paramnum, 0, 10); } /** @@ -394,7 +394,7 @@ int hextobinstring(char *target, char *source) // convert binary array of 0x00/0x01 values to hex (safe to do in place as target will always be shorter than source) // return number of bits converted -int binarraytohex(char *target,char *source, int length) +int binarraytohex(char *target, char *source, int length) { unsigned char i, x; int j = length; @@ -445,7 +445,7 @@ void wiegand_add_parity(char *target, char *source, char length) *(target)= GetParity(source + length / 2, ODD, length / 2); } -void xor(unsigned char *dst, unsigned char *src, size_t len) { +void xor(unsigned char * dst, unsigned char * src, size_t len) { for( ; len > 0; len--,dst++,src++) *dst ^= *src; } @@ -453,3 +453,18 @@ void xor(unsigned char *dst, unsigned char *src, size_t len) { int32_t le24toh (uint8_t data[3]) { return (data[2] << 16) | (data[1] << 8) | data[0]; } + + +uint32_t PackBits(uint8_t start, uint8_t len, uint8_t* bits) { + + int i = start; + int j = len-1; + + if (len > 32) return 0; + + uint32_t tmp = 0; + for (; j >= 0; --j, ++i) + tmp |= bits[i] << j; + + return tmp; +}