]> git.zerfleddert.de Git - proxmark3-svn/blame - client/lualibs/html_dumplib.lua
hack to add missing directory structure for loclass binaries
[proxmark3-svn] / client / lualibs / html_dumplib.lua
CommitLineData
6742c089 1bin = require('bin')
2
3
4-------------------------------
5-- Some utilities
6-------------------------------
7
8---
9-- A debug printout-function
10local function dbg(args)
11 if DEBUG then
12 print("###", args)
13 end
14end
15---
16-- This is only meant to be used when errors occur
17local function oops(err)
18 print("ERROR: ",err)
c44241fd 19 return nil, err
6742c089 20end
21
22local function save_HTML(javascript, filename)
23
24 -- Read the HTML-skel file
25 local skel = require("htmlskel")
26 html = skel.getHTML(javascript);
27
28 -- Open the output file
29
30 local outfile = io.open(filename, "w")
31 if outfile == nil then
c44241fd 32 return oops(string.format("Could not write to file %s",tostring(filename)))
6742c089 33 end
34 -- Write the data into it
35 outfile:write(html)
36 io.close(outfile)
37
38 -- Done
39 return filename
40
41end
42
43
44
45local function convert_ascii_dump_to_JS(infile)
46 local t = infile:read("*all")
47
48 local output = "[";
49 for line in string.gmatch(t, "[^\n]+") do
50 output = output .. "'"..line.."',\n"
51 end
52 output = output .. "]"
53 return output
54end
55
56
57local function convert_binary_dump_to_JS(infile, blockLen)
58 local bindata = infile:read("*all")
59 len = string.len(bindata)
60
61 if len % blockLen ~= 0 then
62 return oops(("Bad data, length (%d) should be a multiple of blocklen (%d)"):format(len, blockLen))
63 end
64
65 local _,hex = bin.unpack(("H%d"):format(len),bindata)
66
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.
70 -- Thus:
71 blockLen = blockLen * 2
72
73 local js,i = "[";
74 for i = 1, string.len(hex),blockLen do
75 js = js .."'" ..string.sub(hex,i,i+blockLen -1).."',\n"
76 end
77 js = js .. "]"
78 return js
79end
80
81---
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.
86local function convert_eml_to_html(input, output)
87 input = input or 'dumpdata.eml'
88 output = output or input .. 'html'
89
90 local infile = io.open(input, "r")
91 if infile == nil then
c44241fd 92 return oops(string.format("Could not read file %s",tostring(input)))
6742c089 93 end
94
95 -- Read file, get JS
96 local javascript = convert_ascii_dump_to_JS(infile)
97 io.close(infile)
98 return save_HTML(javascript, output )
99end
100
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
105local 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'
109
4c367827 110 local infile = io.open(input, "rb")
6742c089 111 if infile == nil then
c44241fd 112 return oops(string.format("Could not read file %s",tostring(input)))
6742c089 113 end
114 -- Read file, get JS
115 local javascript = convert_binary_dump_to_JS(infile, blockLen)
116 io.close(infile)
117
118 return save_HTML(javascript, output )
119end
120
121return {
122 convert_bin_to_html = convert_bin_to_html,
123 convert_eml_to_html = convert_eml_to_html,
124}
Impressum, Datenschutz