]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/pm3_binlib.c
FIX: 'iclass write'
[proxmark3-svn] / client / pm3_binlib.c
index e3af7b47e66ee05c55e47a9d55229f0067d0c1e5..06fd39d24ce120ffb6c13ea9e0ff94fc75270684 100644 (file)
@@ -35,7 +35,7 @@
 #include <lua.h>
 #include <lualib.h>
 #include <lauxlib.h>
-
+#include <stdint.h>
 #include "pm3_binlib.h"
 
 
@@ -48,8 +48,8 @@ static void badcode(lua_State *L, int c)
 
 static int doendian(int c)
 {
- int x=1;
- int e=*(char*)&x;
+ int x = 1;
+ int e = *(char*)&x;
  if (c==OP_LITTLEENDIAN) return !e;
  if (c==OP_BIGENDIAN) return e;
  if (c==OP_NATIVE) return 0;
@@ -60,7 +60,7 @@ static void doswap(int swap, void *p, size_t n)
 {
  if (swap)
  {
-  char *a=(char*)p;
+  char *a = (char*)p;
   int i,j;
   for (i=0, j=n-1, n=n/2; n--; i++, j--)
   {
@@ -87,14 +87,14 @@ static void doswap(int swap, void *p, size_t n)
    case OP:                            \
    {                                   \
     T l;                               \
-    int m=sizeof(l);                   \
-    if (i+m>len) { done = 1;   break; }        \
-    memcpy(&l,s+i,m);                  \
+    int m = sizeof(l);                 \
+    if (i + m > len) { done = 1;       break; }        \
+    memcpy(&l, s+i, m);                        \
     doswap(swap,&l,m);                 \
-    if (i+m+l>len) { done = 1; break;}         \
-    i+=m;                              \
+    if (i + m + l > len) { done = 1; break;}           \
+    i += m;                            \
     lua_pushlstring(L,s+i,l);          \
-    i+=l;                              \
+    i += l;                            \
     ++n;                               \
     break;                             \
    }
@@ -107,7 +107,7 @@ static int l_unpack(lua_State *L)           /** unpack(f,s, [init]) */
  size_t len;
  const char *s=luaL_checklstring(L,2,&len); /* switched s and f */
  const char *f=luaL_checkstring(L,1);
- int i_read = luaL_optint(L,3,1)-1;
+ int i_read = (int)luaL_optint(L,(3),(1))-1;
  unsigned int i;
  if (i_read >= 0) {
    i = i_read;
@@ -120,8 +120,8 @@ static int l_unpack(lua_State *L)           /** unpack(f,s, [init]) */
  lua_pushnil(L);
  while (*f && done == 0)
  {
-  int c=*f++;
-  int N=1;
+  int c = *f++;
+  int N = 1;
   if (isdigit((int) (unsigned char) *f))
   {
    N=0;
@@ -158,20 +158,21 @@ static int l_unpack(lua_State *L)                 /** unpack(f,s, [init]) */
     ++n;
     break;
    }
-   UNPACKSTRING(OP_BSTRING, unsigned char)
-   UNPACKSTRING(OP_WSTRING, unsigned short)
-   UNPACKSTRING(OP_SSTRING, size_t)
+
+   UNPACKSTRING(OP_BSTRING, uint8_t)
+   UNPACKSTRING(OP_WSTRING, uint16_t)
+   UNPACKSTRING(OP_SSTRING, uint32_t)
    UNPACKNUMBER(OP_NUMBER, lua_Number)
    UNPACKNUMBER(OP_DOUBLE, double)
    UNPACKNUMBER(OP_FLOAT, float)
-   UNPACKNUMBER(OP_CHAR, char)
-   UNPACKNUMBER(OP_BYTE, unsigned char)
-   UNPACKNUMBER(OP_SHORT, short)
-   UNPACKNUMBER(OP_USHORT, unsigned short)
-   UNPACKNUMBER(OP_INT, int)
-   UNPACKNUMBER(OP_UINT, unsigned int)
-   UNPACKNUMBER(OP_LONG, long)
-   UNPACKNUMBER(OP_ULONG, unsigned long)
+   UNPACKNUMBER(OP_CHAR, int8_t)
+   UNPACKNUMBER(OP_BYTE, uint8_t)
+   UNPACKNUMBER(OP_SHORT, int16_t)
+   UNPACKNUMBER(OP_USHORT, uint16_t)
+   UNPACKNUMBER(OP_INT, int32_t)
+   UNPACKNUMBER(OP_UINT, uint32_t)
+   UNPACKNUMBER(OP_LONG, int64_t)
+   UNPACKNUMBER(OP_ULONG, uint64_t)
   case OP_HEX:
     {
       luaL_Buffer buf;
@@ -232,15 +233,15 @@ static int l_unpack(lua_State *L)                 /** unpack(f,s, [init]) */
 
 static int l_pack(lua_State *L)                /** pack(f,...) */
 {
- int i=2;
- const char *f=luaL_checkstring(L,1);
- int swap=0;
+ int i = 2;
+ const char *f = luaL_checkstring(L,1);
+ int swap = 0;
  luaL_Buffer b;
  luaL_buffinit(L,&b);
  while (*f)
  {
-  int c=*f++;
-  int N=1;
+  int c = *f++;
+  int N = 1;
   if (isdigit((int) (unsigned char) *f))
   {
    N=0;
@@ -264,20 +265,20 @@ static int l_pack(lua_State *L)           /** pack(f,...) */
     luaL_addlstring(&b,a,l+(c==OP_ZSTRING));
     break;
    }
-   PACKSTRING(OP_BSTRING, unsigned char)
-   PACKSTRING(OP_WSTRING, unsigned short)
-   PACKSTRING(OP_SSTRING, size_t)
+   PACKSTRING(OP_BSTRING, uint8_t)
+   PACKSTRING(OP_WSTRING, uint16_t)
+   PACKSTRING(OP_SSTRING, uint32_t)
    PACKNUMBER(OP_NUMBER, lua_Number)
    PACKNUMBER(OP_DOUBLE, double)
    PACKNUMBER(OP_FLOAT, float)
-   PACKNUMBER(OP_CHAR, char)
-   PACKNUMBER(OP_BYTE, unsigned char)
-   PACKNUMBER(OP_SHORT, short)
-   PACKNUMBER(OP_USHORT, unsigned short)
-   PACKNUMBER(OP_INT, int)
-   PACKNUMBER(OP_UINT, unsigned int)
-   PACKNUMBER(OP_LONG, long)
-   PACKNUMBER(OP_ULONG, unsigned long)
+   PACKNUMBER(OP_CHAR, int8_t)
+   PACKNUMBER(OP_BYTE, uint8_t)
+   PACKNUMBER(OP_SHORT, int16_t)
+   PACKNUMBER(OP_USHORT, uint16_t)
+   PACKNUMBER(OP_INT, int32_t)
+   PACKNUMBER(OP_UINT, uint32_t)
+   PACKNUMBER(OP_LONG, int64_t)
+   PACKNUMBER(OP_ULONG, uint64_t)
   case OP_HEX:
     { // doing digit parsing the lpack way
       unsigned char sbyte = 0;
Impressum, Datenschutz