X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/1686e4d1db2a7ebaa1f6126e53e91b6db46b2029..01aa068b6ff34d86dd5d9d9e962aba20cd490050:/client/scripts/ndef_dump.lua diff --git a/client/scripts/ndef_dump.lua b/client/scripts/ndef_dump.lua index bfb4e341..3b27cac3 100644 --- a/client/scripts/ndef_dump.lua +++ b/client/scripts/ndef_dump.lua @@ -7,6 +7,14 @@ local taglib = require('taglib') local desc = [[This script will automatically recognize and dump full content of a NFC NDEF Initialized tag; non-initialized tags will be ignored. +It also write the dump to an eml-file .eml. + +(The difference between an .eml-file and a .bin-file is that the eml file contains +ASCII representation of the hex-data, with linebreaks between 'rows'. A .bin-file contains the +raw data, but when saving into that for, we lose the infromation about how the memory is structured. +For example: 24 bytes could be 6 blocks of 4 bytes, or vice versa. +Therefore, the .eml is better to use file when saving dumps.) + Arguments: -d debug logging on -h this help @@ -14,16 +22,52 @@ Arguments: ]] local example = "script run xxx" local author = "Martin Holst Swende & Asper" - - - - --- -- PrintAndLog function prlog(...) -- TODO; replace this with a call to the proper PrintAndLog print(...) end +--- +-- This is only meant to be used when errors occur +function oops(err) + prlog("ERROR: ",err) + return nil,err +end + + +-- Perhaps this will be moved to a separate library at one point +local utils = { + --- Writes an eml-file. + -- @param uid - the uid of the tag. Used in filename + -- @param blockData. Assumed to be on the format {'\0\1\2\3,'\b\e\e\f' ..., + -- that is, blockData[row] contains a string with the actual data, not ascii hex representation + -- return filename if all went well, + -- @reurn nil, error message if unsuccessfull + writeDumpFile = function(uid, blockData) + 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) + end + local rowlen = string.len(blockData[1]) + + for i,block in ipairs(blockData) do + if rowlen ~= string.len(block) then + prlog(string.format("WARNING: Dumpdata seems corrupted, line %d was not the same length as line 1",i)) + end + + local formatString = string.format("H%d", string.len(block)) + local _,hex = bin.unpack(formatString,block) + file:write(hex.."\n") + end + file:close() + return destination + end, +} + + + --- -- Usage help function help() @@ -38,12 +82,6 @@ function debug(...) end end ---- --- This is only meant to be used when errors occur -function oops(err) - prlog("ERROR: ",err) - return nil,err -end local function show(data) if DEBUG then @@ -105,7 +143,7 @@ local function getBlock(block) show(data) if string.len(data) < 18 then - return nil, ("Error, expected at least 18 bytes, got %d"):format(string.len(data)) + return nil, ("Expected at least 18 bytes, got %d - this tag is not NDEF-compliant"):format(string.len(data)) end -- Now, parse out the block data -- 0534 00B9 049C AD7F 4A00 0000 E110 1000 2155 @@ -167,7 +205,7 @@ local function main( args) -- NDEF compliant? if b3chars[1] ~= 0xE1 then - return oops("This tag is not NDEF-Complian") + return oops("This tag is not NDEF-Compliant") end local ndefVersion = b3chars[2] @@ -201,5 +239,10 @@ local function main( args) for k,v in ipairs(blockData) do prlog(string.format("Block %02x: %02x %02x %02x %02x",k-1, string.byte(v, 1,4))) end + local filename, err = utils.writeDumpFile(uidHexstr, blockData) + if err then return oops(err) end + + prlog(string.format("Dumped data into %s", filename)) + end main(args) \ No newline at end of file