added more keys (@equipter)
[RRG-proxmark3.git] / client / luascripts / hf_mf_magicrevive.lua
blobb50422123393077134846da638928311eaf6d3ba
1 local getopt = require('getopt')
2 local ansicolors = require('ansicolors')
4 copyright = ''
5 author = 'Iceman'
6 version = 'v1.0.3'
7 desc = [[
8 This is a script that tries to bring back a chinese magic card (1k generation1)
9 from the dead when it's block 0 has been written with bad values.
10 or mifare Ultralight magic card which answers to chinese backdoor commands
12 example = [[
13 -- target a Ultralight based card
14 1. script run hf_mf_magicrevive -u
17 usage = [[
18 script run hf_mf_magicrevive [-h] [-u]
20 arguments = [[
21 -h this help
22 -u try to revive a bricked magic Ultralight tag w 7 bytes UID.
24 ---
25 -- A debug printout-function
26 local function dbg(args)
27 if not DEBUG then return end
28 if type(args) == 'table' then
29 local i = 1
30 while result[i] do
31 dbg(result[i])
32 i = i+1
33 end
34 else
35 print('###', args)
36 end
37 end
38 ---
39 -- This is only meant to be used when errors occur
40 local function oops(err)
41 print('ERROR:', err)
42 core.clearCommandBuffer()
43 return nil, err
44 end
45 ---
46 -- Usage help
47 local function help()
48 print(copyright)
49 print(author)
50 print(version)
51 print(desc)
52 print(ansicolors.cyan..'Usage'..ansicolors.reset)
53 print(usage)
54 print(ansicolors.cyan..'Arguments'..ansicolors.reset)
55 print(arguments)
56 print(ansicolors.cyan..'Example usage'..ansicolors.reset)
57 print(example)
58 end
60 local function cmdUltralight()
61 return {
62 [0] = 'hf 14a raw -k -a -b 7 40',
63 [1] = 'hf 14a raw -k -a 43',
64 [2] = 'hf 14a raw -c -a A2005380712A',
65 [3] = 'hf 14a raw -k -a -b 7 40',
66 [4] = 'hf 14a raw -k -a 43',
67 [5] = 'hf 14a raw -c -a A2010200D980',
68 [6] = 'hf 14a raw -k -a -b 7 40',
69 [7] = 'hf 14a raw -k -a 43',
70 [8] = 'hf 14a raw -c -a A2025B480000',
71 [9] = 'hf 14a raw -c -a 5000',
73 end
74 local function cmdClassic()
75 return {
76 [0] = 'hf 14a raw -k -a -b 7 40',
77 [1] = 'hf 14a raw -k -a 43',
78 [2] = 'hf 14a raw -c -k -a A000',
79 [3] = 'hf 14a raw -c -k -a 01020304049802000000000000001001',
80 [4] = 'hf 14a raw -c -a 5000',
82 end
83 local function cmdRestoreST()
84 local arr = {}
85 for i = 0, 15 do
86 local blk = 3 + (4*i)
87 arr[i] = 'hf mf csetbl --blk '..blk..' -d FFFFFFFFFFFFFF078000FFFFFFFFFFFF'
88 end
89 return arr
90 end
91 local function sendCmds( cmds )
92 for i = 0, #cmds do
93 if cmds[i] then
94 print ( cmds[i] )
95 core.console( cmds[i] )
96 core.clearCommandBuffer()
97 end
98 end
99 end
101 -- The main entry point
102 function main(args)
104 local i
105 local cmds = {}
106 local isUltralight = false
108 -- Read the parameters
109 for o, a in getopt.getopt(args, 'hu') do
110 if o == 'h' then return help() end
111 if o == 'u' then isUltralight = true end
114 core.clearCommandBuffer()
116 if isUltralight then
117 sendCmds ( cmdUltralight() )
118 else
119 sendCmds( cmdClassic() )
120 sendCmds( cmdRestoreST() )
124 main(args)