mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-03-18 03:00:58 +08:00
FIX: minor parseing bug when loading dumpkeys.bin file.
ADD: added some useful helperfunctions to utils.lua
This commit is contained in:
parent
1a5ff2c2a7
commit
9b989c45b9
2 changed files with 58 additions and 4 deletions
|
@ -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
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue