4 -------------------------------
6 -------------------------------
9 -- A debug printout-function
10 local function dbg(args)
16 -- This is only meant to be used when errors occur
17 local function oops(err)
22 local function save_HTML(javascript, filename)
24 -- Read the HTML-skel file
25 local skel = require("htmlskel")
26 html = skel.getHTML(javascript);
28 -- Open the output file
30 local outfile = io.open(filename, "w")
31 if outfile == nil then
32 return oops(string.format("Could not write to file %s",tostring(filename)))
34 -- Write the data into it
45 local function convert_ascii_dump_to_JS(infile)
46 local t = infile:read("*all")
49 for line in string.gmatch(t, "[^\n]+") do
50 output = output .. "'"..line.."',\n"
52 output = output .. "]"
57 local function convert_binary_dump_to_JS(infile, blockLen)
58 local bindata = infile:read("*all")
59 len = string.len(bindata)
61 if len % blockLen ~= 0 then
62 return oops(("Bad data, length (%d) should be a multiple of blocklen (%d)"):format(len, blockLen))
65 local _,hex = bin.unpack(("H%d"):format(len),bindata)
67 -- Now that we've converted binary data into hex, we doubled the size.
68 -- One byte, like 0xDE is now
69 -- the characters 'D' and 'E' : one byte each.
71 blockLen = blockLen * 2
74 for i = 1, string.len(hex),blockLen do
75 js = js .."'" ..string.sub(hex,i,i+blockLen -1).."',\n"
82 -- Converts a .eml-file into a HTML/Javascript file.
83 -- @param input the file to convert
84 -- @param output the file to write to
85 -- @return the name of the new file.
86 local function convert_eml_to_html(input, output)
87 input = input or 'dumpdata.eml'
88 output = output or input .. 'html'
90 local infile = io.open(input, "r")
92 return oops(string.format("Could not read file %s",tostring(input)))
96 local javascript = convert_ascii_dump_to_JS(infile)
98 return save_HTML(javascript, output )
101 --- Converts a binary dump into HTML/Javascript file
102 -- @param input the file containing the dump (defaults to dumpdata.bin)
103 -- @param output the file to write to
104 -- @param blockLen, the length of each block. Defaults to 16 bytes
105 local function convert_bin_to_html(input, output, blockLen)
106 input = input or 'dumpdata.bin'
107 blockLen = blockLen or 16
108 output = output or input .. 'html'
110 local infile = io.open(input, "r")
111 if infile == nil then
112 return oops(string.format("Could not read file %s",tostring(input)))
115 local javascript = convert_binary_dump_to_JS(infile, blockLen)
118 return save_HTML(javascript, output )
122 convert_bin_to_html = convert_bin_to_html,
123 convert_eml_to_html = convert_eml_to_html,