first batch of updated scripts to use sendMIX commands instead.

This commit is contained in:
iceman1001 2019-04-28 18:46:06 +02:00
commit 819896acf6
7 changed files with 223 additions and 194 deletions

View file

@ -2,17 +2,25 @@ local cmds = require('commands')
local getopt = require('getopt')
local lib14a = require('read14a')
local utils = require('utils')
example = [[
script run ufodump
script run ufodump -b 10
]]
author = "Iceman"
copyright = ''
author = 'Iceman'
version = 'v1.0.1'
desc =
[[
This is a script that reads AZTEK iso14443a tags.
It starts from block 0, and ends at default block 20. Use 'b' to say different endblock.
xor: the first three block (0,1,2) is not XORED. The rest seems to be xored.
]]
example = [[
-- default
script run ufodump
-- stop at block 10
script run ufodump -b 10
]]
usage = [[
script run ufudump -h -b
Arguments:
h this helptext
@ -20,43 +28,54 @@ Arguments:
]]
-- Some globals
local TIMEOUT = 2000 -- Shouldn't take longer than 2 seconds
local DEBUG = false -- the debug flag
---
-- A debug printout-function
local function dbg(args)
if DEBUG then
print("###", args)
if not DEBUG then return end
if type(args) == 'table' then
local i = 1
while args[i] do
dbg(args[i])
i = i+1
end
else
print('###', args)
end
end
---
-- This is only meant to be used when errors occur
local function oops(err)
print("ERROR: ",err)
print('ERROR:', err)
core.clearCommandBuffer()
return nil, err
end
---
-- Usage help
local function help()
print(copyright)
print(author)
print(version)
print(desc)
print("Example usage")
print('Example usage')
print(example)
print(usage)
end
--
-- writes data to ascii textfile.
function writeDumpFile(uid, blockData)
local destination = string.format("%s.eml", uid)
local file = io.open(destination, "w")
local destination = string.format('%s.eml', uid)
local file = io.open(destination, 'w')
if file == nil then
return nil, string.format("Could not write to file %s", destination)
return nil, string.format('Could not write to file %s', destination)
end
local rowlen = string.len(blockData[1])
for i,block in ipairs(blockData) do
if rowlen ~= string.len(block) then
print(string.format("WARNING: Dumpdata seems corrupted, line %d was not the same length as line 1",i))
print(string.format('WARNING: Dumpdata seems corrupted, line %d was not the same length as line 1',i))
end
file:write(block.."\n")
file:write(block..'\n')
end
file:close()
return destination
@ -91,24 +110,28 @@ end
--
-- Send a "raw" iso14443a package, ie "hf 14a raw" command
function sendRaw(rawdata, options)
--print(">> ", rawdata)
local flags = lib14a.ISO14A_COMMAND.ISO14A_NO_DISCONNECT + lib14a.ISO14A_COMMAND.ISO14A_RAW + lib14a.ISO14A_COMMAND.ISO14A_APPEND_CRC + lib14a.ISO14A_COMMAND.ISO14A_NO_RATS
local command = Command:new{cmd = cmds.CMD_READER_ISO_14443a,
local flags = lib14a.ISO14A_COMMAND.ISO14A_NO_DISCONNECT
+ lib14a.ISO14A_COMMAND.ISO14A_RAW
+ lib14a.ISO14A_COMMAND.ISO14A_APPEND_CRC
+ lib14a.ISO14A_COMMAND.ISO14A_NO_RATS
local command = Command:newMIX{cmd = cmds.CMD_READER_ISO_14443a,
arg1 = flags, -- Send raw
-- arg2 contains the length, which is half the length
-- of the ASCII-string rawdata
arg2 = string.len(rawdata)/2,
data = rawdata}
return lib14a.sendToDevice(command, options.ignore_response)
return command:sendMIX(options.ignore_response)
end
--
-- Sends an instruction to do nothing, only disconnect
function disconnect()
local command = Command:new{cmd = cmds.CMD_READER_ISO_14443a, arg1 = 0,}
local command = Command:newMIX{cmd = cmds.CMD_READER_ISO_14443a, arg1 = 0,}
-- We can ignore the response here, no ACK is returned for this command
-- Check /armsrc/iso14443a.c, ReaderIso14443a() for details
return lib14a.sendToDevice(command, true)
--core.console("hf 14a raw -r")
return command:sendMIX(true)
end
---
-- The main entry point
@ -119,8 +142,8 @@ function main(args)
-- Read the parameters
for o, a in getopt.getopt(args, 'hb:') do
if o == "h" then return help() end
if o == "b" then endblock = a end
if o == 'h' then return help() end
if o == 'b' then endblock = a end
end
endblock = endblock or 20
@ -132,12 +155,12 @@ function main(args)
local blockData = {}
-- Show tag info
print(("\nFound Card UID [%s]\n"):format(info.uid))
print(('\nFound Card UID [%s]\n'):format(info.uid))
print("blk | data | xored")
print("----+------------------+-------------------")
print('blk | data | xored')
print('----+------------------+-------------------')
for block = 00, endblock do
local cmd = string.format("10%02x00", block)
local cmd = string.format('10%02x00', block)
res, err = sendRaw(cmd , {ignore_response = ignore_response})
if err then disconnect() return oops(err) end
@ -154,7 +177,7 @@ function main(args)
local filename, err = writeDumpFile(info.uid, blockData)
if err then return oops(err) end
print(string.format("\nDumped data into %s", filename))
print(string.format('\nDumped data into %s', filename))
end
-------------------------
@ -162,13 +185,13 @@ end
-------------------------
function selftest()
DEBUG = true
dbg("Performing test")
dbg('Performing test')
main()
dbg("Tests done")
dbg('Tests done')
end
-- Flip the switch here to perform a sanity check.
-- It read a nonce in two different ways, as specified in the usage-section
if "--test"==args then
if '--test' == args then
selftest()
else
-- Call the main