mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-02-13 02:34:48 +08:00
textual
This commit is contained in:
parent
a59f2a1b60
commit
89e25a4d1d
2 changed files with 70 additions and 52 deletions
|
@ -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 <file>] [-o <file>]"
|
||||
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 <file>] [-o <file>]
|
||||
|
||||
Arguments:
|
||||
-h This help
|
||||
|
@ -18,13 +22,13 @@ Arguments:
|
|||
-o <filename> Specifies the output file. If omitted, <uid>.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
|
||||
|
||||
--[[
|
||||
|
|
|
@ -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 <file>] [-o <file>]"
|
||||
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 <file>] [-o <file>]
|
||||
|
||||
Arguments:
|
||||
-h This help
|
||||
|
@ -16,6 +22,7 @@ Arguments:
|
|||
-o <filename> Specifies the output file. If omitted, <uid>.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
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue