FIX: introduced a bug in luascripts when adding the "safe ascii chars" to ConvertHexToAscii. Now its optional.

This commit is contained in:
iceman1001 2017-03-09 10:26:01 +01:00
commit b9534ca070
3 changed files with 16 additions and 12 deletions

View file

@ -285,14 +285,15 @@ local Utils =
return rev return rev
end, end,
ConvertHexToAscii = function(s) ConvertHexToAscii = function(s, useSafechars)
if s == nil then return '' end if s == nil then return '' end
if #s == 0 then return '' end if #s == 0 then return '' end
local t={} local t={}
for k in s:gmatch"(%x%x)" do for k in s:gmatch"(%x%x)" do
local n = tonumber(k,16)
local n = tonumber(k,16)
local c local c
if (n < 32) or (n == 127) then if useSafechars and ( (n < 32) or (n == 127) ) then
c = '.'; c = '.';
else else
c = string.char(n) c = string.char(n)

View file

@ -31,7 +31,7 @@ Arguments:
-o : filename for the saved dumps -o : filename for the saved dumps
]] ]]
local RANDOM = '20436F707972696768742028432920323031302041637469766973696F6E2E20416C6C205269676874732052657365727665642E20' local RANDOM = '20436F707972696768742028432920323031302041637469766973696F6E2E20416C6C205269676874732052657365727665642E20'
local TIMEOUT = 2000 -- Shouldn't take longer than 2 seconds local TIMEOUT = 2500 -- Shouldn't take longer than 2 seconds
local DEBUG = false -- the debug flag local DEBUG = false -- the debug flag
local numBlocks = 64 local numBlocks = 64
local numSectors = 16 local numSectors = 16
@ -80,17 +80,17 @@ local function readdumpkeys(infile)
end end
local function waitCmd() local function waitCmd()
local response = core.WaitForResponseTimeout(cmds.CMD_ACK,TIMEOUT) local response = core.WaitForResponseTimeout(cmds.CMD_ACK, TIMEOUT)
if response then if response then
local count,cmd,arg0 = bin.unpack('LL',response) local count, cmd, arg0 = bin.unpack('LL',response)
if(arg0==1) then if(arg0==1) then
local count,arg1,arg2,data = bin.unpack('LLH511',response,count) local count,arg1,arg2,data = bin.unpack('LLH511',response,count)
return data:sub(1,32) return data:sub(1,32)
else else
return nil, "Couldn't read block.." return nil, "Couldn't read block.. ["..arg0.."]"
end end
end end
return nil, "No response from device" return nil, 'No response from device'
end end
local function main(args) local function main(args)
@ -149,6 +149,7 @@ local function main(args)
if usePreCalc then if usePreCalc then
local pre = require('precalc') local pre = require('precalc')
akeys = pre.GetAll(result.uid) akeys = pre.GetAll(result.uid)
dbg(akeys)
else else
print('Loading dumpkeys.bin') print('Loading dumpkeys.bin')
local hex, err = utils.ReadDumpFile(input) local hex, err = utils.ReadDumpFile(input)
@ -159,7 +160,8 @@ local function main(args)
end end
-- Read block 0 -- Read block 0
cmd = Command:new{cmd = cmds.CMD_MIFARE_READBL, arg1 = 0,arg2 = 0,arg3 = 0, data = keyA} dbg('Reading block 0')
cmd = Command:new{cmd = cmds.CMD_MIFARE_READBL, arg1 = 0, arg2 = 0, arg3 = 0, data = keyA}
err = core.SendCommand(cmd:getBytes()) err = core.SendCommand(cmd:getBytes())
if err then return oops(err) end if err then return oops(err) end
local block0, err = waitCmd() local block0, err = waitCmd()
@ -168,7 +170,8 @@ local function main(args)
core.clearCommandBuffer() core.clearCommandBuffer()
-- Read block 1 -- Read block 1
cmd = Command:new{cmd = cmds.CMD_MIFARE_READBL, arg1 = 1,arg2 = 0,arg3 = 0, data = keyA} dbg('Reading block 1')
cmd = Command:new{cmd = cmds.CMD_MIFARE_READBL, arg1 = 1, arg2 = 0, arg3 = 0, data = keyA}
err = core.SendCommand(cmd:getBytes()) err = core.SendCommand(cmd:getBytes())
if err then return oops(err) end if err then return oops(err) end
local block1, err = waitCmd() local block1, err = waitCmd()
@ -187,6 +190,8 @@ local function main(args)
io.write('Reading blocks > ') io.write('Reading blocks > ')
for blockNo = 0, numBlocks-1, 1 do for blockNo = 0, numBlocks-1, 1 do
io.flush()
if core.ukbhit() then if core.ukbhit() then
print("aborted by user") print("aborted by user")
break break

View file

@ -71,7 +71,6 @@ end
-- @param usbpacket the data received from the device -- @param usbpacket the data received from the device
function showdata(blockno, data) function showdata(blockno, data)
local xorkey = '55AA55AA55AA55AA6262' local xorkey = '55AA55AA55AA55AA6262'
--local s = data.." | "..utils.ConvertHexToAscii(data).." | "
local s = data.." | " local s = data.." | "
local dex = '' local dex = ''
local rs local rs
@ -86,7 +85,6 @@ function showdata(blockno, data)
end end
dex = (dex..'%04X'):format(rs) dex = (dex..'%04X'):format(rs)
end end
--s = s..dex.." | "..utils.ConvertHexToAscii(dex)
s = s..dex.." | " s = s..dex.." | "
print( (" %02d | %s"):format(blockno,s)) print( (" %02d | %s"):format(blockno,s))
end end