relax ecdsa_publickey_ng_t, should help MacOS compilation
[RRG-proxmark3.git] / client / luascripts / lf_hid_bulkclone_v2.lua
blob33d084dd8727f6b4f278f27fa7f4f448bf8b68db
1 local getopt = require('getopt')
2 local ansicolors = require('ansicolors')
3 local cmds = require('commands')
5 copyright = ''
6 author = "TheChamop669"
7 version = 'v1.0.1'
8 desc = [[
9 Perform bulk enrollment of 26 bit H10301 style RFID Tags
10 For more info, check the comments in the code
12 example = [[
14 script run lf_hid_bulkclone_v2.lua -f 1 -b 1000
16 usage = [[
17 script run lf_hid_bulkclone_v2.lua -f facility -b base_id_num
19 arguments = [[
20 -h : this help
21 -f : facility id
22 -b : starting card id
24 local DEBUG = true
25 ---
26 -- A debug printout-function
27 local function dbg(args)
28 if not DEBUG then return end
29 if type(args) == 'table' then
30 local i = 1
31 while args[i] do
32 dbg(args[i])
33 i = i+1
34 end
35 else
36 print('###', args)
37 end
38 end
39 ---
40 -- This is only meant to be used when errors occur
41 local function oops(err)
42 print('ERROR:', err)
43 core.clearCommandBuffer()
44 return nil, errr
45 end
46 ---
47 -- Usage help
48 local function help()
49 print(copyright)
50 print(author)
51 print(version)
52 print(desc)
53 print(ansicolors.cyan..'Usage'..ansicolors.reset)
54 print(usage)
55 print(ansicolors.cyan..'Arguments'..ansicolors.reset)
56 print(arguments)
57 print(ansicolors.cyan..'Example usage'..ansicolors.reset)
58 print(example)
59 end
60 ---
61 -- Exit message
62 local function exitMsg(msg)
63 print( string.rep('--',20) )
64 print( string.rep('--',20) )
65 print(msg)
66 print()
67 end
69 local function main(args)
71 print( string.rep('--',20) )
72 print( string.rep('--',20) )
73 print()
75 if #args == 0 then return help() end
77 for o, a in getopt.getopt(args, 'f:b:h') do
78 if o == 'h' then return help() end
79 if o == 'f' then
80 if isempty(a) then
81 print('You did not supply a facility code, using 0')
82 fc = 10
83 else
84 fc = a
85 end
86 end
87 if o == 'b' then
88 if isempty(a) then
89 print('You did not supply a starting card number, using 1000')
90 cn = 1000
91 else
92 cn = a
93 end
94 end
95 end
97 local successful_writes = {}
98 local timestamp = os.date('%Y-%m-%d %H:%M:%S', os.time())
100 while true do
101 print(string.format("Writing Facility Code: %d, Card Number: %d", fc, cn))
103 local command = string.format("lf hid clone -w H10301 --fc %d --cn %d", fc, cn)
104 core.console(command)
106 table.insert(successful_writes, string.format("%d,%d", fc, cn))
108 print("Press Enter to write the next card, type 'r' and press Enter to retry, or type 'q' and press Enter to quit.")
109 local user_input = io.read()
111 if user_input:lower() == 'q' then
112 print("Timestamp: ", timestamp)
113 print("Successful Writes:")
114 for _, v in ipairs(successful_writes) do print(v) end
115 break
116 elseif user_input:lower() ~= 'r' then
117 cn = cn + 1
122 main(args)
124 --[[
125 Notes:
126 1. The `lf hid clone` command is used to write HID formatted data to T5577 cards, using the H10301 format.
127 2. The script prompts the user for the initial facility code and card number at the start of the session.
128 3. Users can continue to write to the next card, retry the current write, or quit the session by responding to the prompts.
129 4. Upon quitting, the script prints all successful writes along with a timestamp.
130 5. Password-related features have been removed in this version of the script as they are not supported by the `lf hid clone` command.