maur keys
[RRG-proxmark3.git] / client / luascripts / data_mf_eml2bin.lua
blob4291f13b9c02f61f87f10e9b80f370aba686609f
1 local getopt = require('getopt')
2 local bin = require('bin')
3 local dumplib = require('html_dumplib')
4 local ansicolors = require('ansicolors')
6 copyright = ''
7 author = 'Iceman'
8 version = 'v1.0.3'
9 desc =[[
10 This script takes an dumpfile in EML (ASCII) format and converts it to the PM3 dumpbin file to be used with `hf mf restore`
12 example =[[
13 1. script run data_mf_eml2bin
14 2. script run data_mf_eml2bin -i myfile.eml
15 3. script run data_mf_eml2bin -i myfile.eml -o myfile.bin
17 usage = [[
18 script run data_mf_eml2bin [-i <file>] [-o <file>]
20 arguments = [[
21 -h This help
22 -i <filename> Specifies the dump-file (input). If omitted, 'dumpdata.eml' is used
23 -o <filename> Specifies the output file. If omitted, <currdate>.bin is used.
26 ---
27 -- This is only meant to be used when errors occur
28 local function dbg(args)
29 if not DEBUG then return end
30 if type(args) == 'table' then
31 local i = 1
32 while args[i] do
33 dbg(args[i])
34 i = i+1
35 end
36 else
37 print('###', args)
38 end
39 end
40 ---
41 -- This is only meant to be used when errors occur
42 local function oops(err)
43 print('[!!] ERROR:', err)
44 core.clearCommandBuffer()
45 return nil, err
46 end
47 ---
48 -- Usage help
49 local function help()
50 print(copyright)
51 print(author)
52 print(version)
53 print(desc)
54 print(ansicolors.cyan..'Usage'..ansicolors.reset)
55 print(usage)
56 print(ansicolors.cyan..'Arguments'..ansicolors.reset)
57 print(arguments)
58 print(ansicolors.cyan..'Example usage'..ansicolors.reset)
59 print(example)
60 end
62 -- Exit message
63 local function ExitMsg(msg)
64 print( string.rep('--',20) )
65 print( string.rep('--',20) )
66 print(msg)
67 print()
68 end
70 local function main(args)
72 local input = 'dumpdata.eml'
73 local output = os.date('%Y-%m-%d_%H%M%S.bin');
75 -- Arguments for the script
76 for o, a in getopt.getopt(args, 'hi:o:') do
77 if o == 'h' then return help() end
78 if o == 'i' then input = a end
79 if o == 'o' then output = a end
80 end
82 local filename, err = dumplib.convert_eml_to_bin(input,output)
83 if err then return oops(err) end
85 ExitMsg(('[+] Wrote a BIN dump to the file %s'):format(filename))
86 end
88 main(args)