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)
 
  21 local function save_HTML(javascript, filename)
 
  23         -- Read the HTML-skel file
 
  24         local skel = require("htmlskel")
 
  25         html = skel.getHTML(javascript);
 
  27         -- Open the output file
 
  29         local outfile = io.open(filename, "w")
 
  30         if outfile == nil then 
 
  31                 return oops("Could not write to file ", filename)
 
  33         -- Write the data into it
 
  44 local function convert_ascii_dump_to_JS(infile)
 
  45         local t = infile:read("*all")
 
  48         for line in string.gmatch(t, "[^\n]+") do 
 
  49                 output = output .. "'"..line.."',\n"
 
  51         output = output .. "]"
 
  56 local function convert_binary_dump_to_JS(infile, blockLen)
 
  57          local bindata = infile:read("*all")
 
  58          len = string.len(bindata)
 
  60         if len % blockLen ~= 0 then 
 
  61                 return oops(("Bad data, length (%d) should be a multiple of blocklen (%d)"):format(len, blockLen))
 
  64         local _,hex = bin.unpack(("H%d"):format(len),bindata)
 
  66         -- Now that we've converted binary data into hex, we doubled the size. 
 
  67         -- One byte, like 0xDE is now 
 
  68         -- the characters 'D' and 'E' : one byte each. 
 
  70         blockLen = blockLen * 2
 
  73         for i = 1, string.len(hex),blockLen do
 
  74                 js = js .."'" ..string.sub(hex,i,i+blockLen -1).."',\n"
 
  81 -- Converts a .eml-file into a HTML/Javascript file. 
 
  82 -- @param input the file to convert
 
  83 -- @param output the file to write to
 
  84 -- @return the name of the new file. 
 
  85 local function convert_eml_to_html(input, output)
 
  86         input = input or 'dumpdata.eml'
 
  87         output = output or input .. 'html'
 
  89         local infile = io.open(input, "r")
 
  91                 return oops("Could not read file ", input)
 
  95         local javascript = convert_ascii_dump_to_JS(infile)
 
  97         return save_HTML(javascript, output )
 
 100 --- Converts a binary dump into HTML/Javascript file
 
 101 -- @param input the file containing the dump  (defaults to dumpdata.bin)
 
 102 -- @param output the file to write to
 
 103 -- @param blockLen, the length of each block. Defaults to 16 bytes
 
 104 local function convert_bin_to_html(input, output, blockLen)
 
 105         input = input or 'dumpdata.bin'
 
 106         blockLen = blockLen or 16
 
 107         output = output or input .. 'html'
 
 109         local infile = io.open(input, "r")
 
 110         if infile == nil then 
 
 111                 return oops("Could not read file ", input)
 
 114         local javascript = convert_binary_dump_to_JS(infile, blockLen)
 
 117         return save_HTML(javascript, output )
 
 121         convert_bin_to_html = convert_bin_to_html,
 
 122         convert_eml_to_html = convert_eml_to_html,