proxmark3/client/luascripts/data_mf_eml2bin.lua

89 lines
2.2 KiB
Lua
Raw Normal View History

2019-03-09 17:34:43 +08:00
local getopt = require('getopt')
local bin = require('bin')
local dumplib = require('html_dumplib')
2020-04-05 18:41:38 +08:00
local ansicolors = require('ansicolors')
2019-03-09 17:34:43 +08:00
2019-05-08 05:19:22 +08:00
copyright = ''
author = 'Iceman'
2020-04-05 16:05:14 +08:00
version = 'v1.0.2'
2019-05-08 05:19:22 +08:00
desc =[[
2020-04-05 23:00:16 +08:00
This script takes an dumpfile in EML (ASCII) format and converts it to the PM3 dumpbin file to be used with `hf mf restore`
2019-05-08 05:19:22 +08:00
]]
2019-03-09 17:34:43 +08:00
example =[[
2020-09-23 07:00:05 +08:00
1. script run data_mf_eml2bin
2. script run data_mf_eml2bin -i myfile.eml
3. script run data_mf_eml2bin -i myfile.eml -o myfile.bin
2019-03-09 17:34:43 +08:00
]]
2019-05-08 05:19:22 +08:00
usage = [[
2020-09-23 07:00:05 +08:00
script run data_mf_eml2bin [-i <file>] [-o <file>]
2020-04-05 14:50:31 +08:00
]]
arguments = [[
2019-03-09 17:34:43 +08:00
-h This help
-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.
2019-05-08 05:19:22 +08:00
]]
2019-03-09 17:34:43 +08:00
---
-- This is only meant to be used when errors occur
2020-04-05 23:00:16 +08:00
local function dbg(args)
2019-05-08 05:19:22 +08:00
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
2019-03-09 17:34:43 +08:00
end
---
2020-04-05 16:05:14 +08:00
-- This is only meant to be used when errors occur
local function oops(err)
print('ERROR:', err)
core.clearCommandBuffer()
return nil, err
end
---
2019-03-09 17:34:43 +08:00
-- Usage help
2019-05-08 05:19:22 +08:00
local function help()
print(copyright)
print(author)
print(version)
2019-03-09 17:34:43 +08:00
print(desc)
2020-04-05 14:50:31 +08:00
print(ansicolors.cyan..'Usage'..ansicolors.reset)
2019-05-08 05:19:22 +08:00
print(usage)
2020-04-05 14:50:31 +08:00
print(ansicolors.cyan..'Arguments'..ansicolors.reset)
print(arguments)
print(ansicolors.cyan..'Example usage'..ansicolors.reset)
print(example)
2019-03-09 17:34:43 +08:00
end
--
-- Exit message
2019-05-08 05:19:22 +08:00
local function ExitMsg(msg)
2019-03-09 17:34:43 +08:00
print( string.rep('--',20) )
print( string.rep('--',20) )
print(msg)
print()
end
local function main(args)
2019-05-08 05:19:22 +08:00
local input = 'dumpdata.eml'
local output = os.date('%Y-%m-%d_%H%M%S.bin');
2019-03-09 17:34:43 +08:00
-- Arguments for the script
for o, a in getopt.getopt(args, 'hi:o:') do
2019-05-08 05:19:22 +08:00
if o == 'h' then return help() end
if o == 'i' then input = a end
if o == 'o' then output = a end
2019-03-09 17:34:43 +08:00
end
local filename, err = dumplib.convert_eml_to_bin(input,output)
if err then return oops(err) end
2019-05-08 05:19:22 +08:00
ExitMsg(('Wrote a BIN dump to the file %s'):format(filename))
2019-03-09 17:34:43 +08:00
end
2019-03-12 07:12:26 +08:00
main(args)