2015-01-21 04:29:55 +08:00
|
|
|
local getopt = require('getopt')
|
|
|
|
|
2019-04-29 01:51:25 +08:00
|
|
|
copyright = ''
|
|
|
|
author = 'Iceman'
|
|
|
|
version = 'v1.0.1'
|
2015-01-21 04:29:55 +08:00
|
|
|
desc =
|
|
|
|
[[
|
2019-03-09 17:34:43 +08:00
|
|
|
This is a script that tries to bring back a chinese magic card (1k generation1)
|
2015-01-21 04:29:55 +08:00
|
|
|
from the dead when it's block 0 has been written with bad values.
|
2016-05-16 01:27:04 +08:00
|
|
|
or mifare Ultralight magic card which answers to chinese backdoor commands
|
2019-04-29 01:51:25 +08:00
|
|
|
]]
|
|
|
|
example = [[
|
|
|
|
-- target a Ultralight based card
|
|
|
|
1. script run remagic -u
|
|
|
|
|
|
|
|
]]
|
|
|
|
usage = [[
|
|
|
|
script run remagic
|
2015-01-21 04:29:55 +08:00
|
|
|
|
|
|
|
Arguments:
|
2019-03-09 17:34:43 +08:00
|
|
|
-h this help
|
|
|
|
-u remagic a Ultralight tag w 7 bytes UID.
|
2015-01-21 04:29:55 +08:00
|
|
|
]]
|
2019-03-09 17:34:43 +08:00
|
|
|
---
|
2015-01-21 04:29:55 +08:00
|
|
|
-- A debug printout-function
|
2017-07-27 15:36:16 +08:00
|
|
|
local function dbg(args)
|
2019-04-29 01:51:25 +08:00
|
|
|
if not DEBUG then return end
|
|
|
|
if type(args) == 'table' then
|
|
|
|
local i = 1
|
|
|
|
while result[i] do
|
|
|
|
dbg(result[i])
|
|
|
|
i = i+1
|
|
|
|
end
|
|
|
|
else
|
2019-03-09 17:34:43 +08:00
|
|
|
print('###', args)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
---
|
2015-01-21 04:29:55 +08:00
|
|
|
-- This is only meant to be used when errors occur
|
2017-07-27 15:36:16 +08:00
|
|
|
local function oops(err)
|
2019-04-29 01:51:25 +08:00
|
|
|
print('ERROR:', err)
|
|
|
|
core.clearCommandBuffer()
|
|
|
|
return nil, err
|
2015-01-21 04:29:55 +08:00
|
|
|
end
|
2019-03-09 17:34:43 +08:00
|
|
|
---
|
2015-01-21 04:29:55 +08:00
|
|
|
-- Usage help
|
2017-07-27 15:36:16 +08:00
|
|
|
local function help()
|
2019-04-29 01:51:25 +08:00
|
|
|
print(copyright)
|
|
|
|
print(author)
|
|
|
|
print(version)
|
2019-03-09 17:34:43 +08:00
|
|
|
print(desc)
|
|
|
|
print('Example usage')
|
|
|
|
print(example)
|
2019-04-29 01:51:25 +08:00
|
|
|
print(usage)
|
2015-01-21 04:29:55 +08:00
|
|
|
end
|
|
|
|
|
2016-05-16 01:27:04 +08:00
|
|
|
local function cmdUltralight()
|
2019-03-09 17:34:43 +08:00
|
|
|
return {
|
2019-04-29 01:51:25 +08:00
|
|
|
[0] = 'hf 14a raw -p -a -b 7 40',
|
|
|
|
[1] = 'hf 14a raw -p -a 43',
|
|
|
|
[2] = 'hf 14a raw -c -a A2005380712A',
|
|
|
|
[3] = 'hf 14a raw -p -a -b 7 40',
|
|
|
|
[4] = 'hf 14a raw -p -a 43',
|
|
|
|
[5] = 'hf 14a raw -c -a A2010200D980',
|
|
|
|
[6] = 'hf 14a raw -p -a -b 7 40',
|
|
|
|
[7] = 'hf 14a raw -p -a 43',
|
|
|
|
[8] = 'hf 14a raw -c -a A2025B480000',
|
|
|
|
[9] = 'hf 14a raw -c -a 5000',
|
2019-03-09 17:34:43 +08:00
|
|
|
}
|
2016-05-16 01:27:04 +08:00
|
|
|
end
|
|
|
|
local function cmdClassic()
|
2019-03-09 17:34:43 +08:00
|
|
|
return {
|
2019-04-29 01:51:25 +08:00
|
|
|
[0] = 'hf 14a raw -p -a -b 7 40',
|
|
|
|
[1] = 'hf 14a raw -p -a 43',
|
|
|
|
[2] = 'hf 14a raw -c -p -a A000',
|
|
|
|
[3] = 'hf 14a raw -c -p -a 01020304049802000000000000001001',
|
|
|
|
[4] = 'hf 14a raw -c -a 5000',
|
2019-03-09 17:34:43 +08:00
|
|
|
}
|
2016-05-16 01:27:04 +08:00
|
|
|
end
|
2017-02-14 22:54:10 +08:00
|
|
|
local function cmdRestoreST()
|
2019-03-09 17:34:43 +08:00
|
|
|
local arr = {}
|
|
|
|
for i = 0, 15 do
|
|
|
|
local blk = 3 + (4*i)
|
2019-04-29 01:51:25 +08:00
|
|
|
arr[i] = 'hf mf csetbl '..blk..' FFFFFFFFFFFFFF078000FFFFFFFFFFFF'
|
2019-03-09 17:34:43 +08:00
|
|
|
end
|
|
|
|
return arr
|
|
|
|
end
|
2017-02-14 22:54:10 +08:00
|
|
|
local function sendCmds( cmds )
|
2019-03-09 17:34:43 +08:00
|
|
|
for i = 0, #cmds do
|
|
|
|
if cmds[i] then
|
|
|
|
print ( cmds[i] )
|
|
|
|
core.console( cmds[i] )
|
|
|
|
core.clearCommandBuffer()
|
|
|
|
end
|
|
|
|
end
|
2017-02-14 22:54:10 +08:00
|
|
|
end
|
2019-03-09 17:34:43 +08:00
|
|
|
---
|
2015-01-21 04:29:55 +08:00
|
|
|
-- The main entry point
|
|
|
|
function main(args)
|
|
|
|
|
2019-03-09 17:34:43 +08:00
|
|
|
local i
|
|
|
|
local cmds = {}
|
|
|
|
local isUltralight = false
|
|
|
|
|
|
|
|
-- Read the parameters
|
|
|
|
for o, a in getopt.getopt(args, 'hu') do
|
2019-04-29 01:51:25 +08:00
|
|
|
if o == 'h' then return help() end
|
|
|
|
if o == 'u' then isUltralight = true end
|
2019-03-09 17:34:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
core.clearCommandBuffer()
|
2016-05-16 01:27:04 +08:00
|
|
|
|
2019-03-09 17:34:43 +08:00
|
|
|
if isUltralight then
|
|
|
|
sendCmds ( cmdUltralight() )
|
|
|
|
else
|
|
|
|
sendCmds( cmdClassic() )
|
|
|
|
sendCmds( cmdRestoreST() )
|
|
|
|
end
|
2015-01-21 04:29:55 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
main(args)
|