proxmark3/client/scripts/htmldump.lua

84 lines
2 KiB
Lua
Raw Normal View History

-- The getopt-functionality is loaded from pm3/getopt.lua
-- Have a look there for further details
getopt = require('getopt')
bin = require('bin')
dumplib = require('html_dumplib')
2019-05-08 05:41:41 +08:00
copyright = ''
author = 'Martin Holst Swende'
version = 'v1.0.1'
desc =[[
2019-03-09 17:34:43 +08:00
This script takes a dumpfile and produces a html based dump, which is a
bit more easily analyzed.
2019-05-08 05:41:41 +08:00
]]
example = [[
script run htmldump -o mifarecard_foo.html
]]
usage = [[
script run htmldump [-i <file>] [-o <file>]
Arguments:
2019-03-09 17:34:43 +08:00
-h This help
-i <file> Specifies the dump-file (input). If omitted, 'dumpdata.bin' is used
-o <filename> Speciies the output file. If omitted, <curtime>.html is used.
]]
-------------------------------
2019-03-09 17:34:43 +08:00
-- Some utilities
-------------------------------
2019-03-09 17:34:43 +08:00
---
-- A debug printout-function
2019-05-08 05:41:41 +08:00
local function dbg(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)
2019-03-09 17:34:43 +08:00
end
end
---
-- This is only meant to be used when errors occur
2019-05-08 05:41:41 +08:00
local function oops(err)
print('ERROR:', err)
core.clearCommandBuffer()
return nil, err
end
2019-03-09 17:34:43 +08:00
---
-- Usage help
2019-05-08 05:41:41 +08:00
local function help()
print(copyright)
print(author)
print(version)
2019-03-09 17:34:43 +08:00
print(desc)
2019-05-08 05:41:41 +08:00
print('Example usage')
2019-03-09 17:34:43 +08:00
print(example)
2019-05-08 05:41:41 +08:00
print(usage)
end
local function main(args)
2019-05-08 05:41:41 +08:00
local input = 'dumpdata.bin'
local output = os.date('%Y-%m-%d_%H%M%S.html');
2019-03-09 17:34:43 +08:00
for o, a in getopt.getopt(args, 'i:o:h') do
2019-05-08 05:41:41 +08:00
if o == 'h' then return help() end
if o == 'i' then input = a end
if o == 'o' then output = a end
2019-03-09 17:34:43 +08:00
end
2019-05-08 05:41:41 +08:00
local filename, err = dumplib.convert_bin_to_html(input,output, 16)
2019-03-09 17:34:43 +08:00
if err then return oops(err) end
2019-05-08 05:41:41 +08:00
print(('Wrote a HTML dump to the file %s'):format(filename))
end
--[[
2019-03-09 17:34:43 +08:00
In the future, we may implement so that scripts are invoked directly
into a 'main' function, instead of being executed blindly. For future
2019-03-09 17:34:43 +08:00
compatibility, I have done so, but I invoke my main from here.
--]]
2019-03-12 07:12:26 +08:00
main(args)