d78792f5 |
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') |
6742c089 |
5 | dumplib = require('html_dumplib') |
d78792f5 |
6 | |
2fca3ad9 |
7 | example = "script run htmldump -o mifarecard_foo.html" |
d78792f5 |
8 | author = "Martin Holst Swende" |
2fca3ad9 |
9 | usage = "script run htmldump [-i <file>] [-o <file>]" |
d78792f5 |
10 | desc =[[ |
11 | This script takes a dumpfile and produces a html based dump, which is a |
12 | bit more easily analyzed. |
13 | |
14 | Arguments: |
15 | -h This help |
16 | -i <file> Specifies the dump-file (input). If omitted, 'dumpdata.bin' is used |
17 | -o <filename> Speciies the output file. If omitted, <curtime>.html is used. |
18 | |
19 | ]] |
20 | |
21 | ------------------------------- |
22 | -- Some utilities |
23 | ------------------------------- |
24 | |
25 | --- |
26 | -- A debug printout-function |
27 | function dbg(args) |
28 | if DEBUG then |
29 | print("###", args) |
30 | end |
31 | end |
32 | --- |
33 | -- This is only meant to be used when errors occur |
34 | function oops(err) |
35 | print("ERROR: ",err) |
36 | end |
37 | |
38 | |
39 | --- |
40 | -- Usage help |
41 | function help() |
42 | print(desc) |
43 | print("Example usage") |
44 | print(example) |
45 | end |
46 | |
d78792f5 |
47 | local function main(args) |
48 | |
d78792f5 |
49 | local input = "dumpdata.bin" |
50 | local output = os.date("%Y-%m-%d_%H%M%S.html"); |
51 | for o, a in getopt.getopt(args, 'i:o:h') do |
52 | if o == "h" then return help() end |
53 | if o == "i" then input = a end |
54 | if o == "o" then output = a end |
55 | end |
6742c089 |
56 | local filename, err = dumplib.convert_bin_to_html(input,output,16) |
57 | if err then return oops(err) end |
d78792f5 |
58 | |
6742c089 |
59 | print(("Wrote a HTML dump to the file %s"):format(filename)) |
d78792f5 |
60 | end |
61 | |
d78792f5 |
62 | --[[ |
63 | In the future, we may implement so that scripts are invoked directly |
64 | into a 'main' function, instead of being executed blindly. For future |
65 | compatibility, I have done so, but I invoke my main from here. |
66 | --]] |
67 | main(args) |