proxmark3/client/luascripts/hf_mf_magicrevive.lua

125 lines
2.9 KiB
Lua
Raw Normal View History

local getopt = require('getopt')
2020-04-05 18:49:25 +08:00
local ansicolors = require('ansicolors')
2019-04-29 01:51:25 +08:00
copyright = ''
author = 'Iceman'
2020-04-05 18:49:25 +08:00
version = 'v1.0.2'
desc = [[
2019-03-09 17:34:43 +08:00
This is a script that tries to bring back a chinese magic card (1k generation1)
from the dead when it's block 0 has been written with bad values.
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 hf_mf_magicrevive -u
2019-04-29 01:51:25 +08:00
]]
usage = [[
script run hf_mf_magicrevive [-h] [-u]
2020-04-05 18:49:25 +08:00
]]
arguments = [[
2019-03-09 17:34:43 +08:00
-h this help
2020-09-23 06:11:11 +08:00
-u try to revive a bricked magic Ultralight tag w 7 bytes UID.
]]
2019-03-09 17:34:43 +08:00
---
-- A debug printout-function
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
---
-- This is only meant to be used when errors occur
local function oops(err)
2019-04-29 01:51:25 +08:00
print('ERROR:', err)
core.clearCommandBuffer()
return nil, err
end
2019-03-09 17:34:43 +08:00
---
-- Usage help
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)
2020-04-05 18:49:25 +08:00
print(ansicolors.cyan..'Usage'..ansicolors.reset)
2019-04-29 01:51:25 +08:00
print(usage)
2020-04-05 18:49:25 +08:00
print(ansicolors.cyan..'Arguments'..ansicolors.reset)
print(arguments)
print(ansicolors.cyan..'Example usage'..ansicolors.reset)
print(example)
end
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
}
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
}
end
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
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
end
2019-03-09 17:34:43 +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()
2019-03-09 17:34:43 +08:00
if isUltralight then
sendCmds ( cmdUltralight() )
else
sendCmds( cmdClassic() )
sendCmds( cmdRestoreST() )
end
end
main(args)