This commit is contained in:
iceman1001 2019-04-28 19:45:00 +02:00
parent 25dd7c9a1c
commit 79bfe892d6

View file

@ -3,12 +3,12 @@ local getopt = require('getopt')
local bin = require('bin') local bin = require('bin')
local utils = require('utils') local utils = require('utils')
local format=string.format local format = string.format
local floor=math.floor local floor = math.floor
copyright = '' copyright = ''
author = "Iceman" author = "Iceman"
version = '' version = 'v1.0.1'
desc =[[ desc =[[
This script will program a T55x7 TAG with a configuration and four blocks of data. This script will program a T55x7 TAG with a configuration and four blocks of data.
It will then try to detect and read back those block data and compare if read data matches the expected data. It will then try to detect and read back those block data and compare if read data matches the expected data.
@ -39,7 +39,6 @@ Arguments:
-h this help -h this help
]] ]]
local TIMEOUT = 2000 -- Shouldn't take longer than 2 seconds
local DEBUG = false -- the debug flag local DEBUG = false -- the debug flag
local total_tests = 0 local total_tests = 0
local total_pass = 0 local total_pass = 0
@ -54,24 +53,23 @@ local data_blocks_cmds = {
--- ---
-- A debug printout-function -- A debug printout-function
local function dbg(args) local function dbg(args)
if not DEBUG then if not DEBUG then return end
return if type(args) == 'table' then
end
if type(args) == "table" then
local i = 1 local i = 1
while args[i] do while args[i] do
dbg(args[i]) dbg(args[i])
i = i+1 i = i+1
end end
else else
print("###", args) print('###', args)
end end
end end
--- ---
-- This is only meant to be used when errors occur -- This is only meant to be used when errors occur
local function oops(err) local function oops(err)
print("ERROR: ",err) print('ERROR:', err)
core.clearCommandBuffer()
return nil, err
end end
--- ---
-- Usage help -- Usage help
@ -82,6 +80,7 @@ local function help()
print(desc) print(desc)
print("Example usage") print("Example usage")
print(example) print(example)
print(usage)
end end
--- ---
-- Exit message -- Exit message
@ -210,10 +209,10 @@ local function WipeCard()
local res, msg = core.t55xx_detect() local res, msg = core.t55xx_detect()
if not res then if not res then
oops("Can't detect modulation. Test failed.") oops("Can't detect modulation. Test failed.")
core.console("rem [ERR:DETECT:WIPED] Failed to detect after wipe") core.console('rem [ERR:DETECT:WIPED] Failed to detect after wipe')
return false return false
else else
local wipe_data_cmd = "lf t55xx write b %s d %s" local wipe_data_cmd = 'lf t55xx write b %s d %s'
for _ = 1, #data_blocks_cmds do for _ = 1, #data_blocks_cmds do
local val = data_blocks_cmds[_] local val = data_blocks_cmds[_]
local c = string.format(wipe_data_cmd, _, val) local c = string.format(wipe_data_cmd, _, val)
@ -227,9 +226,9 @@ end
local function CheckReadBlock(block) local function CheckReadBlock(block)
local data, msg local data, msg
-- blockno, page1, override, pwd -- blockno, page1, override, pwd
data, msg = core.t55xx_readblock(block, "0", "0", "") data, msg = core.t55xx_readblock(block, '0', '0', '')
if not data then if not data then
return "" return ''
end end
return ('%08X'):format(data) return ('%08X'):format(data)
end end
@ -238,7 +237,7 @@ local function test(modulation)
local process_block0_cmds = {} local process_block0_cmds = {}
local y local y
local block = "00" local block = '00'
local s = ('Start test of %s'):format(modulation) local s = ('Start test of %s'):format(modulation)
print(s) print(s)
@ -256,16 +255,19 @@ local function test(modulation)
-- Write Config block -- Write Config block
dbg(('lf t55xx write b 0 d %s'):format(p_config_cmd)) dbg(('lf t55xx write b 0 d %s'):format(p_config_cmd))
local config = tonumber(p_config_cmd, 16) local config = tonumber(p_config_cmd, 16)
local writecmd = Command:new{cmd = cmds.CMD_T55XX_WRITE_BLOCK,arg1 = config, arg2 = block, arg3 = '00', data = '00'} local wc = Command:newMIX{
local err = core.SendCommand(writecmd:getBytes()) cmd = cmds.CMD_T55XX_WRITE_BLOCK
if err then return oops(err) end , arg1 = config
local response = core.WaitForResponseTimeout(cmds.CMD_ACK,TIMEOUT) , arg2 = block
}
local response, err = wc:sendMIX(false)
if not response then return oops(err) end
-- Detect -- Detect
local res, msg = core.t55xx_detect() local res, msg = core.t55xx_detect()
if not res then if not res then
print("can't detect modulation, skip to next config") print("can't detect modulation, skip to next config")
core.console(format("rem [ERR:DETECT:%s] Failed to detect modulation", p_config_cmd)) core.console(format('rem [ERR:DETECT:%s] Failed to detect modulation', p_config_cmd))
core.console(format('rem [SUMMARY:%s] FAIL detection', p_config_cmd)) core.console(format('rem [SUMMARY:%s] FAIL detection', p_config_cmd))
total_tests = total_tests + #data_blocks_cmds total_tests = total_tests + #data_blocks_cmds
else else
@ -299,7 +301,7 @@ local function main(args)
-- Arguments for the script -- Arguments for the script
for o, arg in getopt.getopt(args, 'h') do for o, arg in getopt.getopt(args, 'h') do
if o == "h" then return help() end if o == 'h' then return help() end
end end
core.clearCommandBuffer() core.clearCommandBuffer()
@ -321,7 +323,12 @@ local function main(args)
end end
exitMsg('Tests finished') exitMsg('Tests finished')
core.console( format('rem [SUMMARY] Success rate: %d/%d tests passed%s', total_pass, total_tests, total_pass < total_tests and ", help me improving that number!" or " \\o/")) core.console(
format('rem [SUMMARY] Success rate: %d/%d tests passed%s'
, total_pass
, total_tests
, total_pass < total_tests and ', help me improving that number!' or ' \\o/'
)
)
end end
main(args) main(args)