maur keys
[RRG-proxmark3.git] / client / luascripts / hf_15_magic.lua
blob173cf1ee7baa092fa8aa140c37260b8d735c1e0e
1 local cmds = require('commands')
2 local lib15 = require('read15')
3 local getopt = require('getopt')
4 local utils = require('utils')
5 local ansicolors = require('ansicolors')
7 copyright = 'Copyright (c) 2018 IceSQL AB. All rights reserved.'
8 author = 'Christian Herrmann'
9 version = 'v1.0.6'
10 desc = [[
11 This script tries to set UID on a IS15693 SLIX magic card
12 Remember the UID ->MUST<- start with 0xE0
14 example = [[
16 -- ISO15693 slix magic tag
18 script run hf_15_magic -u E004013344556677
20 script run hf_15_magic -u E004013344556677 -a
22 usage = [[
23 script run hf_15_magic -h -u <uid>
25 arguments = [[
26 -h : this help
27 -u <UID> : UID (16 hexsymbols)
28 -a : use offical pm3 repo ISO15 commands instead of iceman fork.
31 local DEBUG = true
32 ---
33 -- A debug printout-function
34 local function dbg(args)
35 if not DEBUG then return end
36 if type(args) == 'table' then
37 local i = 1
38 while args[i] do
39 dbg(args[i])
40 i = i+1
41 end
42 else
43 print('###', args)
44 end
45 end
46 ---
47 -- This is only meant to be used when errors occur
48 local function oops(err)
49 print('ERROR:', err)
50 core.clearCommandBuffer()
51 return nil, err
52 end
53 ---
54 -- Usage help
55 local function help()
56 print(copyright)
57 print(author)
58 print(version)
59 print(desc)
60 print(ansicolors.cyan..'Usage'..ansicolors.reset)
61 print(usage)
62 print(ansicolors.cyan..'Arguments'..ansicolors.reset)
63 print(arguments)
64 print(ansicolors.cyan..'Example usage'..ansicolors.reset)
65 print(example)
66 end
68 --- Set UID on magic command enabled on a ICEMAN based REPO
69 local function magicUID_iceman(b0, b1)
70 print('Using backdoor Magic tag function')
71 core.console('hf 15 raw -2 -c 02213E00000000')
72 core.console('hf 15 raw -2 -c 02213F69960000')
73 core.console('hf 15 raw -2 -c 022138'..b1)
74 core.console('hf 15 raw -2 -c 022139'..b0)
75 end
77 --- Set UID on magic command enabled, OFFICAL REPO
78 local function magicUID_offical(b0, b1)
79 print('Using backdoor Magic tag function OFFICAL REPO')
80 core.console('hf 15 cmd raw -c 02213E00000000')
81 core.console('hf 15 cmd raw -c 02213F69960000')
82 core.console('hf 15 cmd raw -c 022138'..b1)
83 core.console('hf 15 cmd raw -c 022139'..b0)
84 end
85 ---
86 -- The main entry point
87 function main(args)
89 print( string.rep('--',20) )
90 print( string.rep('--',20) )
91 print()
93 local uid = 'E004013344556677'
94 local use_iceman = true
96 -- Read the parameters
97 for o, a in getopt.getopt(args, 'hu:a') do
98 if o == 'h' then return help() end
99 if o == 'u' then uid = a end
100 if o == 'a' then use_iceman = false end
103 -- uid string checks
104 if uid == nil then return oops('empty uid string') end
105 if #uid == 0 then return oops('empty uid string') end
106 if #uid ~= 16 then return oops('uid wrong length. Should be 8 hex bytes') end
108 local bytes = utils.ConvertHexToBytes(uid)
110 local block0 = string.format('%02X%02X%02X%02X', bytes[4], bytes[3], bytes[2], bytes[1])
111 local block1 = string.format('%02X%02X%02X%02X', bytes[8], bytes[7], bytes[6], bytes[5])
113 print('new UID | '..uid)
115 core.clearCommandBuffer()
117 if use_iceman then
118 magicUID_iceman(block0, block1)
119 else
120 magicUID_offical(block0, block1)
124 main(args)