]> cvs.zerfleddert.de Git - proxmark3-svn/commitdiff
FIX: I think the dumping of data is correct now in tnp3.lua. MD5 string vs bytearra...
authoriceman1001 <iceman@iuse.se>
Sun, 9 Nov 2014 18:29:47 +0000 (19:29 +0100)
committericeman1001 <iceman@iuse.se>
Sun, 9 Nov 2014 18:29:47 +0000 (19:29 +0100)
ADD: utils.lua some functions to convert between ascii, bytes and strings.

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

index 6b3777dbd7232ce5ab4303dca9d622d559a49359..bff89c5f9fbcac168a07d6646d3187a9edcaf5f5 100644 (file)
@@ -46,21 +46,46 @@ local Utils =
        end,\r
        ---\r
        -- Convert Byte array to string of hex\r
-       ConvertBytes2String = function(bytes)\r
-               local s = {}\r
+       ConvertBytes2HexString = function(bytes)\r
+               if #bytes == 0 then\r
+                       return ''\r
+               end\r
+               local s={}\r
                for i = 1, #(bytes) do\r
                        s[i] = string.format("%02X",bytes[i]) \r
                end\r
                return table.concat(s)\r
        end,    \r
-\r
-       ConvertStringToBytes = function(s)\r
+       -- Convert byte array to string with ascii\r
+    ConvertBytesToAsciiString = function(bytes)\r
+               if #bytes == 0 then\r
+                       return ''\r
+               end\r
+               local s={}\r
+               for i = 1, #(bytes) do\r
+                       s[i] = string.char(bytes[i]) \r
+               end\r
+               return table.concat(s)          \r
+       end,     \r
+       ConvertHexStringToBytes = function(s)\r
                local t={}\r
+               if s == nil then return t end\r
+               if #s == 0 then return t end\r
                for k in s:gmatch"(%x%x)" do\r
                        table.insert(t,tonumber(k,16))\r
                end\r
                return t\r
        end,\r
+       ConvertAsciiStringToBytes = function(s)\r
+               local t={}\r
+               if s == nil then return t end\r
+               if #s == 0 then return t end\r
+               \r
+               for k in s:gmatch"(.)" do\r
+                       table.insert(t, string.byte(k))\r
+               end\r
+               return t\r
+       end,\r
        \r
        -- function convertStringToBytes(str)\r
        -- local bytes = {}\r
index 56d0b48694971ebef6c3bb58b2e89c0ca66a448e..303963ba9b1d02177735d24060b6142a0f545106 100644 (file)
@@ -93,7 +93,7 @@ end
 local function main(args)
 
        print( string.rep('--',20) )
-    --print( string.rep('--',20) )
+       print( string.rep('--',20) )
        --print()
        
        local keyA
@@ -187,35 +187,30 @@ local function main(args)
                local blockdata, err = waitCmd()
                if err then return oops(err) end                
 
-               local b = blockNo%4
-
-               if b ~= 3 then
+               if  blockNo%4 ~= 3 then
                        if blockNo < 8 then
                                -- Block 0-7 not encrypted
-                               blocks[blockNo+1] = ('%02d  :: %s :: %s'):format(blockNo,blockdata,blockdata) 
+                               blocks[blockNo+1] = ('%02d  :: %s'):format(blockNo,blockdata) 
                        else
-                               local base = ('%s%s%d%s'):format(block0, block1, blockNo, hashconstant)         local md5hash = md5.sumhexa(base)
+                               local base = ('%s%s%02d%s'):format(block0, block1, blockNo, hashconstant)       
+                               local baseArr = utils.ConvertHexStringToBytes(base)
+                               local baseStr = utils.ConvertBytesToAsciiString(baseArr)
+                               local md5hash = md5.sumhexa(baseStr)
                                local aestest = core.aes(md5hash, blockdata)
-                       
-                               local _,hex = bin.unpack(("H%d"):format(16),aestest)
-                       
-                               -- local hexascii = string.gsub(hex, '(%x%x)', 
-                                                               -- function(value) 
-                                                                       -- return string.char(tonumber(value, 16)) 
-                                                               -- end
-                                                       -- )
+                               --print(aestest, type(aestest))
+                               local hex = utils.ConvertAsciiStringToBytes(aestest)
+                               hex = utils.ConvertBytes2HexString(hex)
+                               --local _,hex = bin.unpack(("H%d"):format(16),aestest)
 
                                if string.find(blockdata, '^0+$') then
-                                       blocks[blockNo+1] = ('%02d  :: %s :: %s'):format(blockNo,blockdata,blockdata) 
+                                       blocks[blockNo+1] = ('%02d  :: %s'):format(blockNo,blockdata) 
                                else
-                                       --blocks[blockNo+1] = ('%02d :: %s :: %s :: %s '):format(blockNo,key,md5hash,hex)
-                                       blocks[blockNo+1] = ('%02d  :: %s :: %s'):format(blockNo,blockdata,hex) 
+                                       blocks[blockNo+1] = ('%02d  :: %s'):format(blockNo,hex) 
                                end             
                        end
-
                else
                        -- Sectorblocks, not encrypted
-                       blocks[blockNo+1] = ('%02d  :: %s :: %s'):format(blockNo,blockdata,blockdata) 
+                       blocks[blockNo+1] = ('%02d  :: %s'):format(blockNo,blockdata) 
                end
        end
        
@@ -226,10 +221,11 @@ local function main(args)
        print( ('        UID : %s'):format(uid) )
        print( ('  ITEM TYPE : %s - %s'):format(itemtype, toyNames[itemtype]) )
        print( ('     CARDID : %s'):format(cardid ) )   
-       print('BLK :: DATA                                DECRYPTED' )
+       print('BLK :: Decrypted                        Ascii' )
        print( string.rep('--',36) )
        for _,s in pairs(blocks) do
-               print( s )
+               local arr = utils.ConvertHexStringToBytes(s:sub(7,#s))
+               print( s, utils.ConvertBytesToAsciiString(arr) )
        end 
 end
 
Impressum, Datenschutz