text
[RRG-proxmark3.git] / client / luascripts / data_mf_bin2html.lua
blobf412a35e773b754a767a22323c9553350345e941
1 -- The getopt-functionality is loaded from pm3/getopt.lua
2 -- Have a look there for further details
3 getopt = require('getopt')
4 bin = require('bin')
5 dumplib = require('html_dumplib')
6 local ansicolors = require('ansicolors')
8 copyright = ''
9 author = 'Martin Holst Swende'
10 version = 'v1.0.3'
11 desc =[[
12 This script takes a dumpfile and produces a html based dump, which is a
13 bit more easily analyzed.
15 example = [[
16 script run data_mf_bin2html -o mifarecard_foo.html
18 usage = [[
19 script run data_mf_bin2html [-i <file>] [-o <file>]
21 arguments = [[
22 -h This help
23 -i <file> Specifies the dump-file (input). If omitted, 'dumpdata.bin' is used
24 -o <filename> Speciies the output file. If omitted, <curtime>.html is used.
27 -------------------------------
28 -- Some utilities
29 -------------------------------
31 ---
32 -- A debug printout-function
33 local function dbg(args)
34 if not DEBUG then return end
35 if type(args) == 'table' then
36 local i = 1
37 while args[i] do
38 dbg(args[i])
39 i = i+1
40 end
41 else
42 print('###', args)
43 end
44 end
45 ---
46 -- This is only meant to be used when errors occur
47 local function oops(err)
48 print('[!!] ERROR:', err)
49 core.clearCommandBuffer()
50 return nil, err
51 end
52 ---
53 -- Usage help
54 local function help()
55 print(copyright)
56 print(author)
57 print(version)
58 print(desc)
59 print(ansicolors.cyan..'Usage'..ansicolors.reset)
60 print(usage)
61 print(ansicolors.cyan..'Arguments'..ansicolors.reset)
62 print(arguments)
63 print(ansicolors.cyan..'Example usage'..ansicolors.reset)
64 print(example)
65 end
67 local function main(args)
69 local input = 'dumpdata.bin'
70 local output = os.date('%Y-%m-%d_%H%M%S.html');
71 for o, a in getopt.getopt(args, 'i:o:h') do
72 if o == 'h' then return help() end
73 if o == 'i' then input = a end
74 if o == 'o' then output = a end
75 end
76 local filename, err = dumplib.convert_bin_to_html(input,output, 16)
77 if err then return oops(err) end
79 print(('[+] Wrote a HTML dump to the file %s'):format(filename))
80 end
82 --[[
83 In the future, we may implement so that scripts are invoked directly
84 into a 'main' function, instead of being executed blindly. For future
85 compatibility, I have done so, but I invoke my main from here.
86 --]]
87 main(args)