1 local getopt
= require('getopt')
2 local ansicolors
= require('ansicolors')
11 This is a script that write Sector Trailers to the emulator memory.
13 By default, both keys A and B are set to 0xFFFFFFFFFFFF.
14 The Access Bytes are set to 0xFF0780 and User Bytes to 0x00.
17 -- Use default formatting
18 1. script run hf_mf_em_util
20 -- Change keys A and B
21 2. script run hf_mf_em_util -a 112233445566 -b AABBCCDDEEFF
23 -- Define access bits and User byte
24 3. script run hf_mf_em_util -x 00f0ff -u 12
28 script run hf_mf_em_util [-h] [-4] [-a <hex>] [-b <hex>] [-x <hex>] [-u <hex>]
36 -x <hex> define Access Bytes
37 -u <hex> define User Byte
45 print(ansicolors
.cyan
..'Usage'..ansicolors
.reset
)
47 print(ansicolors
.cyan
..'Arguments'..ansicolors
.reset
)
49 print(ansicolors
.cyan
..'Example usage'..ansicolors
.reset
)
53 local function oops(err
)
59 local function card_format(key_a
,key_b
,ab
,user
,s70
)
60 local blocks
= {3,7,11,15,19,23,27,31,35,39,43,47,51,55,59,63,67,71,75,79,83,87,91,95,99,103,107,111,115,119,123,127,143,159,175,191,207,223,239,255}
61 for k
,v
in ipairs(blocks
) do
62 local cmd
= string.format("hf mf esetblk --blk %s -d %s%s%s%s",v
,key_a
,ab
,user
,key_b
)
65 core
.clearCommandBuffer()
66 if s70
== false and k
> 15 then
72 local function main(args
)
74 for o
, a
in getopt
.getopt(args
, 'ha:b:x:u:4') do
75 if o
== 'h' then return help() end
76 if o
== 'a' then KeyA
= a
end
77 if o
== 'b' then KeyB
= a
end
78 if o
== 'x' then Accessbit
= a
end
79 if o
== 'u' then User
= a
end
80 if o
== '4' then kkkk
= true end
83 local KeyA
= KeyA
or 'FFFFFFFFFFFF'
85 return oops( string.format('Wrong length of the Key A, receveid %d, expected 12', #KeyA
))
88 local KeyB
= KeyB
or 'FFFFFFFFFFFF'
90 return oops( string.format('Wrong length of the Key B, received %d, expected 12', #KeyB
))
93 local Accessbit
= Accessbit
or 'FF0780'
94 if #(Accessbit
) ~= 6 then
95 return oops( string.format('Wrong length of the Access bit, received %d, expected 6', #Accessbit
))
98 local User
= User
or '00'
100 return oops( string.format('Wrong lenght for the user defined byte, received %d, expected 2', #User
))
103 local kkkk
= kkkk
or false
105 -- Call card_format function
106 card_format(KeyA
,KeyB
,Accessbit
,User
,kkkk
)