From: iceman1001 Date: Wed, 5 Nov 2014 18:16:54 +0000 (+0100) Subject: FIX: minor parseing bug when loading dumpkeys.bin file. X-Git-Url: http://cvs.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/commitdiff_plain/9b989c45b942356410416b10e96bc4ca624e4563?hp=1a5ff2c2a7feaaf2ba6dc83bee611d1cab5f4527 FIX: minor parseing bug when loading dumpkeys.bin file. ADD: added some useful helperfunctions to utils.lua --- diff --git a/client/lualibs/utils.lua b/client/lualibs/utils.lua index 3d27d5b6..6b3777db 100644 --- a/client/lualibs/utils.lua +++ b/client/lualibs/utils.lua @@ -47,11 +47,65 @@ local Utils = --- -- Convert Byte array to string of hex ConvertBytes2String = function(bytes) - s = {} + local s = {} for i = 1, #(bytes) do - s[i] = string.format("%02X",bytes[i]) + s[i] = string.format("%02X",bytes[i]) end return table.concat(s) end, + + ConvertStringToBytes = function(s) + local t={} + for k in s:gmatch"(%x%x)" do + table.insert(t,tonumber(k,16)) + end + return t + end, + + -- function convertStringToBytes(str) + -- local bytes = {} + -- local strLength = string.len(str) + -- for i=1,strLength do + -- table.insert(bytes, string.byte(str, i)) + -- end + + -- return bytes +-- end + +-- function convertBytesToString(bytes) + -- local bytesLength = table.getn(bytes) + -- local str = "" + -- for i=1,bytesLength do + -- str = str .. string.char(bytes[i]) + -- end + + -- return str +-- end + +-- function convertHexStringToBytes(str) + -- local bytes = {} + -- local strLength = string.len(str) + -- for k=2,strLength,2 do + -- local hexString = "0x" .. string.sub(str, (k - 1), k) + -- table.insert(bytes, hex.to_dec(hexString)) + -- end + + -- return bytes +-- end + +-- function convertBytesToHexString(bytes) + -- local str = "" + -- local bytesLength = table.getn(bytes) + -- for i=1,bytesLength do + -- local hexString = string.sub(hex.to_hex(bytes[i]), 3) + -- if string.len(hexString) == 1 then + -- hexString = "0" .. hexString + -- end + -- str = str .. hexString + -- end + + -- return str +-- end + } return Utils \ No newline at end of file diff --git a/client/scripts/tnp3.lua b/client/scripts/tnp3.lua index 5b3da98f..4e8ca77b 100644 --- a/client/scripts/tnp3.lua +++ b/client/scripts/tnp3.lua @@ -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