This commit is contained in:
iceman1001 2019-05-07 23:19:22 +02:00
commit 7ccff2db4a
2 changed files with 71 additions and 39 deletions

View file

@ -2,37 +2,54 @@ local getopt = require('getopt')
local bin = require('bin') local bin = require('bin')
local dumplib = require('html_dumplib') local dumplib = require('html_dumplib')
copyright = ''
author = 'Iceman'
version = 'v1.0.1'
desc =[[
This script takes an dumpfile on EML (ASCII) format and converts it to the PM3 dumpbin file to be used with `hf mf restore`
]]
example =[[ example =[[
1. script run emul2dump 1. script run emul2dump
2. script run emul2dump -i myfile.eml 2. script run emul2dump -i myfile.eml
3. script run emul2dump -i myfile.eml -o myfile.bin 3. script run emul2dump -i myfile.eml -o myfile.bin
]] ]]
author = "Iceman" usage = [[
usage = "script run emul2dump [-i <file>] [-o <file>]" script run emul2dump [-i <file>] [-o <file>]
desc =[[
This script takes an dumpfile on EML (ASCII) format and converts it to the PM3 dumpbin file to be used with "hf mf restore"
Arguments: Arguments:
-h This help -h This help
-i <filename> Specifies the dump-file (input). If omitted, 'dumpdata.eml' is used -i <filename> Specifies the dump-file (input). If omitted, 'dumpdata.eml' is used
-o <filename> Specifies the output file. If omitted, <currdate>.bin is used. -o <filename> Specifies the output file. If omitted, <currdate>.bin is used.
]]
]]
--- ---
-- This is only meant to be used when errors occur -- This is only meant to be used when errors occur
function oops(err) local function oops(err)
print("ERROR: ",err) if not DEBUG then return end
if type(args) == 'table' then
local i = 1
while args[i] do
dbg(args[i])
i = i+1
end
else
print('###', args)
end
end end
--- ---
-- Usage help -- Usage help
function help() local function help()
print(copyright)
print(author)
print(version)
print(desc) print(desc)
print("Example usage") print('Example usage')
print(example) print(example)
print(usage)
end end
-- --
-- Exit message -- Exit message
function ExitMsg(msg) local function ExitMsg(msg)
print( string.rep('--',20) ) print( string.rep('--',20) )
print( string.rep('--',20) ) print( string.rep('--',20) )
print(msg) print(msg)
@ -41,20 +58,20 @@ end
local function main(args) local function main(args)
local input = "dumpdata.eml" local input = 'dumpdata.eml'
local output = os.date("%Y-%m-%d_%H%M%S.bin"); local output = os.date('%Y-%m-%d_%H%M%S.bin');
-- Arguments for the script -- Arguments for the script
for o, a in getopt.getopt(args, 'hi:o:') do for o, a in getopt.getopt(args, 'hi:o:') do
if o == "h" then return help() end if o == 'h' then return help() end
if o == "i" then input = a end if o == 'i' then input = a end
if o == "o" then output = a end if o == 'o' then output = a end
end end
local filename, err = dumplib.convert_eml_to_bin(input,output) local filename, err = dumplib.convert_eml_to_bin(input,output)
if err then return oops(err) end if err then return oops(err) end
ExitMsg(("Wrote a BIN dump to the file %s"):format(filename)) ExitMsg(('Wrote a BIN dump to the file %s'):format(filename))
end end
main(args) main(args)

View file

@ -4,12 +4,18 @@ getopt = require('getopt')
bin = require('bin') bin = require('bin')
dumplib = require('html_dumplib') dumplib = require('html_dumplib')
example = "script run emul2html -o dumpdata.eml " copyright = ''
author = "Martin Holst Swende" author = 'Martin Holst Swende'
usage = "script run htmldump [-i <file>] [-o <file>]" version = 'v1.0.1'
desc =[[ desc = [[
This script takes a dumpfile on EML (ASCII) format and produces a html based dump, which is a This script takes a dumpfile on EML (ASCII) format and produces a html based dump, which is a
bit more easily analyzed. bit more easily analyzed.
]]
example = [[
script run emul2html -o dumpdata.eml
]]
usage = [[
script run htmldump [-i <file>] [-o <file>]
Arguments: Arguments:
-h This help -h This help
@ -18,45 +24,54 @@ Arguments:
]] ]]
------------------------------- -- Some globals
-- Some utilities local DEBUG = false -- the debug flag
-------------------------------
--- ---
-- A debug printout-function -- A debug printout-function
function dbg(args) local function dbg(args)
if DEBUG then if not DEBUG then return end
print("###", args) if type(args) == 'table' then
local i = 1
while args[i] do
dbg(args[i])
i = i+1
end
else
print('###', args)
end end
end end
--- ---
-- This is only meant to be used when errors occur -- This is only meant to be used when errors occur
function oops(err) local function oops(err)
print("ERROR: ",err) print('ERROR:', err)
core.clearCommandBuffer()
return nil, err
end end
--- ---
-- Usage help -- Usage help
function help() local function help()
print(copyright)
print(author)
print(version)
print(desc) print(desc)
print("Example usage") print('Example usage')
print(example) print(example)
print(usage)
end end
local function main(args) local function main(args)
local input = "dumpdata.eml" local input = 'dumpdata.eml'
local output = os.date("%Y-%m-%d_%H%M%S.html"); local output = os.date('%Y-%m-%d_%H%M%S.html');
for o, a in getopt.getopt(args, 'i:o:h') do for o, a in getopt.getopt(args, 'i:o:h') do
if o == "h" then return help() end if o == 'h' then return help() end
if o == "i" then input = a end if o == 'i' then input = a end
if o == "o" then output = a end if o == 'o' then output = a end
end end
local filename, err = dumplib.convert_eml_to_html(input,output) local filename, err = dumplib.convert_eml_to_html(input,output)
if err then return oops(err) end if err then return oops(err) end
print(("Wrote a HTML dump to the file %s"):format(filename)) print(('Wrote a HTML dump to the file %s'):format(filename))
end end
--[[ --[[