From 89e25a4d1dd02de76c7eb82ec6507ac7790c2416 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Tue, 7 May 2019 23:34:05 +0200 Subject: [PATCH 1/2] textual --- client/scripts/dumptoemul-mfu.lua | 56 +++++++++++++++----------- client/scripts/dumptoemul.lua | 66 ++++++++++++++++++------------- 2 files changed, 70 insertions(+), 52 deletions(-) diff --git a/client/scripts/dumptoemul-mfu.lua b/client/scripts/dumptoemul-mfu.lua index fb14077d5..672f05e8f 100644 --- a/client/scripts/dumptoemul-mfu.lua +++ b/client/scripts/dumptoemul-mfu.lua @@ -4,13 +4,17 @@ getopt = require('getopt') bin = require('bin') copyright = '' -version = '' -example = "script run dumptoemul-mfu -i dumpdata-foobar.bin" author = "Martin Holst Swende \n @Marshmellow \n @iceman" -usage = "script run dumptoemul-mfu [-i ] [-o ]" +version = 'v1.0.1' desc =[[ This script takes a dumpfile from 'hf mfu dump' and converts it to a format that can be used by the emulator +]] +example = [[ + script run dumptoemul-mfu -i dumpdata-foobar.bin +]] +usage = [[ +script run dumptoemul-mfu [-i ] [-o ] Arguments: -h This help @@ -18,13 +22,13 @@ Arguments: -o Specifies the output file. If omitted, .eml is used. ]] + local DEBUG = false --- -- A debug printout-function local function dbg(args) if not DEBUG then return end - if type(args) == 'table' then local i = 1 while result[i] do @@ -38,16 +42,20 @@ end --- -- This is only meant to be used when errors occur local function oops(err) - print('ERROR: ',err) - return nil,err + print('ERROR:', err) + core.clearCommandBuffer() + return nil, err end --- -- Usage help -function help() - print(desc) +local function help() + print(copyright) print(author) - print("Example usage") + print(version) + print(desc) + print('Example usage') print(example) + print(usage) end local function convert_to_ascii(hexdata) @@ -64,38 +72,38 @@ local function convert_to_ascii(hexdata) end local function readdump(infile) - t = infile:read("*all") + t = infile:read('*all') len = string.len(t) - local len,hex = bin.unpack(("H%d"):format(len),t) + local len,hex = bin.unpack(('H%d'):format(len),t) return hex end local function convert_to_emulform(hexdata) if string.len(hexdata) % 8 ~= 0 then - return oops(("Bad data, length should be a multiple of 8 (was %d)"):format(string.len(hexdata))) + return oops(('Bad data, length should be a multiple of 8 (was %d)'):format(string.len(hexdata))) end - local ascii,i = ""; + local ascii,i = ''; for i = 1, string.len(hexdata), 8 do - ascii = ascii..string.sub(hexdata, i, i+7).."\n" + ascii = ascii..string.sub(hexdata, i, i+7)..'\n' end return string.sub(ascii, 1, -2) end local function main(args) - local input = "dumpdata.bin" + local input = 'dumpdata.bin' local output for o, a in getopt.getopt(args, 'i:o:h') do - if o == "h" then return help() end - if o == "i" then input = a end - if o == "o" then output = a end + if o == 'h' then return help() end + if o == 'i' then input = a end + if o == 'o' then output = a end end -- Validate the parameters - local infile = io.open(input, "rb") + local infile = io.open(input, 'rb') if infile == nil then - return oops("Could not read file ", input) + return oops('Could not read file ', input) end local dumpdata = readdump(infile) -- The hex-data is now in ascii-format, @@ -109,19 +117,19 @@ local function main(args) -- 119,120 bcc0 -- 121--- UID last four bytes local uid = string.sub(dumpdata, 113, 113+5)..string.sub(dumpdata, 113+8, 113+8+7) - output = output or (uid .. ".eml") + output = output or (uid .. '.eml') -- Format some linebreaks dumpdata = convert_to_emulform(dumpdata) - local outfile = io.open(output, "w") + local outfile = io.open(output, 'w') if outfile == nil then - return oops("Could not write to file ", output) + return oops('Could not write to file ', output) end outfile:write(dumpdata:lower()) io.close(outfile) - print(("Wrote an emulator-dump to the file %s"):format(output)) + print(('Wrote an emulator-dump to the file %s'):format(output)) end --[[ diff --git a/client/scripts/dumptoemul.lua b/client/scripts/dumptoemul.lua index 08e5e03dd..e364ccc8b 100644 --- a/client/scripts/dumptoemul.lua +++ b/client/scripts/dumptoemul.lua @@ -3,12 +3,18 @@ getopt = require('getopt') bin = require('bin') -example = "script run dumptoemul -i dumpdata-foobar.bin" -author = "Martin Holst Swende" -usage = "script run dumptoemul [-i ] [-o ]" -desc =[[ +copyright = '' +author = 'Martin Holst Swende' +version = 'v1.0.1' +desc = [[ This script takes a dumpfile from 'hf mf dump' and converts it to a format that can be used by the emulator +]] +example = [[ + script run dumptoemul -i dumpdata-foobar.bin +]] +usage = [[ +script run dumptoemul [-i ] [-o ] Arguments: -h This help @@ -16,6 +22,7 @@ Arguments: -o Specifies the output file. If omitted, .eml is used. ]] + local DEBUG = false ------------------------------- -- Some utilities @@ -25,7 +32,6 @@ local DEBUG = false -- A debug printout-function local function dbg(args) if not DEBUG then return end - if type(args) == 'table' then local i = 1 while result[i] do @@ -39,83 +45,87 @@ end --- -- This is only meant to be used when errors occur local function oops(err) - print('ERROR: ',err) - return nil,err + print('ERROR:', err) + core.clearCommandBuffer() + return nil, err end --- -- Usage help function help() - print(desc) + print(copyright) print(author) - print("Example usage") + print(version) + print(desc) + print('Example usage') print(example) + print(usage) end local function convert_to_ascii(hexdata) if string.len(hexdata) % 32 ~= 0 then - return oops(("Bad data, length should be a multiple of 32 (was %d)"):format(string.len(hexdata))) + return oops(('Bad data, length should be a multiple of 32 (was %d)'):format(string.len(hexdata))) end - local js,i = "["; + local js,i = '['; for i = 1, string.len(hexdata),32 do js = js .."'" ..string.sub(hexdata,i,i+31).."',\n" end - js = js .. "]" + js = js .. ']' return js end local function readdump(infile) - t = infile:read("*all") + t = infile:read('*all') len = string.len(t) - local len,hex = bin.unpack(("H%d"):format(len),t) + local len,hex = bin.unpack(('H%d'):format(len),t) return hex end local function convert_to_emulform(hexdata) if string.len(hexdata) % 32 ~= 0 then - return oops(("Bad data, length should be a multiple of 32 (was %d)"):format(string.len(hexdata))) + return oops(('Bad data, length should be a multiple of 32 (was %d)'):format(string.len(hexdata))) end - local ascii,i = ""; + local ascii,i = ''; for i = 1, string.len(hexdata),32 do - ascii = ascii..string.sub(hexdata,i,i+31).."\n" + ascii = ascii..string.sub(hexdata,i,i+31)..'\n' end return string.sub(ascii, 1, -2) end local function main(args) - local input = "dumpdata.bin" + local input = 'dumpdata.bin' local output for o, a in getopt.getopt(args, 'i:o:h') do - if o == "h" then return help() end - if o == "i" then input = a end - if o == "o" then output = a end + if o == 'h' then return help() end + if o == 'i' then input = a end + if o == 'o' then output = a end end -- Validate the parameters - local infile = io.open(input, "rb") + local infile = io.open(input, 'rb') if infile == nil then - return oops("Could not read file ", input) + return oops('Could not read file ', input) end local dumpdata = readdump(infile) -- The hex-data is now in ascii-format, -- But first, check the uid - local uid = string.sub(dumpdata,1,8) - output = output or (uid .. ".eml") + local uid = string.sub(dumpdata, 1, 8) + output = output or (uid .. '.eml') -- Format some linebreaks dumpdata = convert_to_emulform(dumpdata) - local outfile = io.open(output, "w") + local outfile = io.open(output, 'w') if outfile == nil then - return oops("Could not write to file ", output) + return oops('Could not write to file ', output) end outfile:write(dumpdata:lower()) io.close(outfile) - print(("Wrote an emulator-dump to the file %s"):format(output)) + print(('Wrote an emulator-dump to the file %s'):format(output)) end From 9c95a2e8aa471d9ddb1a63a1a36e1df784b37136 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Tue, 7 May 2019 23:37:15 +0200 Subject: [PATCH 2/2] textual --- client/scripts/e.lua | 55 +++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/client/scripts/e.lua b/client/scripts/e.lua index 1f9a14eb0..580e89a54 100644 --- a/client/scripts/e.lua +++ b/client/scripts/e.lua @@ -1,39 +1,52 @@ local getopt = require('getopt') local utils = require('utils') -example = "script calculates many different checksums (CRC) over the provided hex input" -author = "Iceman" -desc = -[[ +copyright = '' +author = 'Iceman' +version = 'v1.0.1' +desc = [[ This script calculates many checksums (CRC) over the provided hex input. - -Arguments: - -b data in hex - -w bitwidth of the CRC family of algorithm. defaults to all known CRC presets. -Examples : +]] +example = [[ script run e -b 010203040506070809 script run e -b 010203040506070809 -w 16 ]] - +usage = [[ +Arguments: + -b data in hex + -w bitwidth of the CRC family of algorithm. defaults to all known CRC presets. +]] --- -- A debug printout-function -function dbg(args) - if DEBUG then - print("###", args) +local function dbg(args) + 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 --- -- This is only meant to be used when errors occur -function oops(err) - print("[!] ERROR: ",err) - return nil,err +local function oops(err) + print('ERROR:', err) + core.clearCommandBuffer() + return nil, err end --- -- Usage help -function help() +local function help() + print(copyright) + print(author) + print(version) print(desc) - print("Example usage") + print('Example usage') print(example) + print(usage) end --- -- The main entry point @@ -44,9 +57,9 @@ function main(args) -- Read the parameters for o, a in getopt.getopt(args, 'hb:w:') do - if o == "h" then return help() end - if o == "b" then data = a end - if o == "w" then width = a end + if o == 'h' then return help() end + if o == 'b' then data = a end + if o == 'w' then width = a end end data = data or '01020304'