]>
Commit | Line | Data |
---|---|---|
81740aa5 | 1 | local getopt = require('getopt') |
2 | ||
3 | example = "script run remagic" | |
4 | author = "Iceman" | |
81740aa5 | 5 | desc = |
6 | [[ | |
7 | This is a script that tries to bring back a chinese magic card (1k generation1) | |
8 | from the dead when it's block 0 has been written with bad values. | |
6648776f | 9 | or mifare Ultralight magic card which answers to chinese backdoor commands |
81740aa5 | 10 | |
11 | Arguments: | |
6648776f | 12 | -h this help |
13 | -u remagic a Ultralight tag w 7 bytes UID. | |
81740aa5 | 14 | ]] |
15 | --- | |
16 | -- A debug printout-function | |
17 | function dbg(args) | |
18 | if DEBUG then | |
19 | print("###", args) | |
20 | end | |
21 | end | |
22 | --- | |
23 | -- This is only meant to be used when errors occur | |
24 | function oops(err) | |
25 | print("ERROR: ",err) | |
26 | end | |
81740aa5 | 27 | --- |
28 | -- Usage help | |
29 | function help() | |
30 | print(desc) | |
31 | print("Example usage") | |
32 | print(example) | |
33 | end | |
34 | ||
6648776f | 35 | local function cmdUltralight() |
36 | return { | |
37 | --[[ | |
38 | --]] | |
39 | [0] = "hf 14a raw -p -a -b 7 40", | |
40 | [1] = "hf 14a raw -p -a 43", | |
41 | [2] = "hf 14a raw -c -a A2005380712A", | |
42 | [3] = "hf 14a raw -p -a -b 7 40", | |
43 | [4] = "hf 14a raw -p -a 43", | |
44 | [5] = "hf 14a raw -c -a A2010200D980", | |
45 | [6] = "hf 14a raw -p -a -b 7 40", | |
46 | [7] = "hf 14a raw -p -a 43", | |
47 | [8] = "hf 14a raw -c -a A2025B480000", | |
48 | [9] = "hf 14a raw -c -a 5000", | |
49 | } | |
50 | end | |
51 | local function cmdClassic() | |
52 | return { | |
53 | --[[ | |
54 | --]] | |
55 | [0] = "hf 14a raw -p -a -b 7 40", | |
56 | [1] = "hf 14a raw -p -a 43", | |
57 | [2] = "hf 14a raw -c -p -a A000", | |
58 | [3] = "hf 14a raw -c -p -a 01020304049802000000000000001001", | |
59 | [4] = "hf 14a raw -c -a 5000", | |
60 | } | |
61 | end | |
dd015c59 | 62 | local function cmdRestoreST() |
63 | local arr = {} | |
64 | for i = 0, 15 do | |
65 | local blk = 3 + (4*i) | |
66 | arr[i] = "hf mf csetbl "..blk.." FFFFFFFFFFFFFF078000FFFFFFFFFFFF" | |
67 | end | |
68 | return arr | |
69 | end | |
70 | local function sendCmds( cmds ) | |
71 | for i = 0, #cmds do | |
72 | if cmds[i] then | |
73 | print ( cmds[i] ) | |
74 | core.console( cmds[i] ) | |
75 | end | |
76 | end | |
77 | end | |
81740aa5 | 78 | --- |
79 | -- The main entry point | |
80 | function main(args) | |
81 | ||
6648776f | 82 | local i |
83 | local cmds = {} | |
84 | local isUltralight = false | |
81740aa5 | 85 | |
86 | -- Read the parameters | |
6648776f | 87 | for o, a in getopt.getopt(args, 'hu') do |
88 | if o == "h" then return help() end | |
89 | if o == "u" then isUltralight = true end | |
81740aa5 | 90 | end |
6648776f | 91 | |
81740aa5 | 92 | core.clearCommandBuffer() |
93 | ||
6648776f | 94 | if isUltralight then |
dd015c59 | 95 | sendCmds ( cmdUltralight() ) |
6648776f | 96 | else |
dd015c59 | 97 | sendCmds( cmdClassic() ) |
98 | sendCmds( cmdRestoreST() ) | |
81740aa5 | 99 | end |
100 | end | |
101 | ||
102 | main(args) |