]> git.zerfleddert.de Git - proxmark3-svn/commitdiff
FIX: minor parseing bug when loading dumpkeys.bin file.
authoriceman1001 <iceman@iuse.se>
Wed, 5 Nov 2014 18:16:54 +0000 (19:16 +0100)
committericeman1001 <iceman@iuse.se>
Wed, 5 Nov 2014 18:16:54 +0000 (19:16 +0100)
ADD:  added some useful helperfunctions to utils.lua

client/lualibs/utils.lua
client/scripts/tnp3.lua

index 3d27d5b68350d1b913536c56c3f3befff15946d3..6b3777dbd7232ce5ab4303dca9d622d559a49359 100644 (file)
@@ -47,11 +47,65 @@ local Utils =
        ---\r
        -- Convert Byte array to string of hex\r
        ConvertBytes2String = function(bytes)\r
-               s = {}\r
+               local s = {}\r
                for i = 1, #(bytes) do\r
-                       s[i] =   string.format("%02X",bytes[i]) \r
+                       s[i] = string.format("%02X",bytes[i]) \r
                end\r
                return table.concat(s)\r
        end,    \r
+\r
+       ConvertStringToBytes = function(s)\r
+               local t={}\r
+               for k in s:gmatch"(%x%x)" do\r
+                       table.insert(t,tonumber(k,16))\r
+               end\r
+               return t\r
+       end,\r
+       \r
+       -- function convertStringToBytes(str)\r
+       -- local bytes = {}\r
+       -- local strLength = string.len(str)\r
+       -- for i=1,strLength do\r
+               -- table.insert(bytes, string.byte(str, i))\r
+       -- end\r
+\r
+       -- return bytes\r
+-- end\r
+\r
+-- function convertBytesToString(bytes)\r
+       -- local bytesLength = table.getn(bytes)\r
+       -- local str = ""\r
+       -- for i=1,bytesLength do\r
+               -- str = str .. string.char(bytes[i])\r
+       -- end\r
+\r
+       -- return str\r
+-- end\r
+\r
+-- function convertHexStringToBytes(str)\r
+       -- local bytes = {}\r
+       -- local strLength = string.len(str)\r
+       -- for k=2,strLength,2 do\r
+               -- local hexString = "0x" .. string.sub(str, (k - 1), k)\r
+               -- table.insert(bytes, hex.to_dec(hexString))\r
+       -- end\r
+\r
+       -- return bytes\r
+-- end\r
+\r
+-- function convertBytesToHexString(bytes)\r
+       -- local str = ""\r
+       -- local bytesLength = table.getn(bytes)\r
+       -- for i=1,bytesLength do\r
+               -- local hexString = string.sub(hex.to_hex(bytes[i]), 3)\r
+               -- if string.len(hexString) == 1 then\r
+                       -- hexString = "0" .. hexString\r
+               -- end\r
+               -- str = str .. hexString\r
+       -- end\r
+\r
+       -- return str\r
+-- end\r
+\r
 }\r
 return Utils
\ No newline at end of file
index 5b3da98f0b7111b815fb8a770f1a9fc6ad935a8a..4e8ca77b3d24f290ec4405a5d45f171457a5011b 100644 (file)
@@ -145,7 +145,7 @@ local function main(args)
                return oops('Could not read file ', input)
        end
        local akeys = readdumpkeys(infile):sub(0,12*16)
-
+       
        -- Read block 0
        cmd = Command:new{cmd = cmds.CMD_MIFARE_READBL, arg1 = 0,arg2 = 0,arg3 = 0, data = keyA}
        err = core.SendCommand(cmd:getBytes())
@@ -174,7 +174,7 @@ local function main(args)
                end
        
                pos = (math.floor( blockNo / 4 ) * 12)+1
-               key = akeys:sub(pos, pos + 12 )
+               key = akeys:sub(pos, pos + 11 )
                cmd = Command:new{cmd = cmds.CMD_MIFARE_READBL, arg1 = blockNo ,arg2 = 0,arg3 = 0, data = key}
                local err = core.SendCommand(cmd:getBytes())
                if err then return oops(err) end
Impressum, Datenschutz