lf_t55xx_multiwriter.lua v1.05

Added - verification blocks

Signed-off-by: Jarek Barwinski <116510448+jareckib@users.noreply.github.com>
This commit is contained in:
Jarek Barwinski 2025-03-20 15:16:28 +00:00 committed by GitHub
commit c1ae8dd6d6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -6,9 +6,11 @@ local dash = string.rep('--', 32)
local dir = os.getenv('HOME') .. '/.proxmark3/logs/' local dir = os.getenv('HOME') .. '/.proxmark3/logs/'
local logfile = (io.popen('dir /a-d /o-d /tw /b/s "' .. dir .. '" 2>nul:'):read("*a"):match("%C+")) local logfile = (io.popen('dir /a-d /o-d /tw /b/s "' .. dir .. '" 2>nul:'):read("*a"):match("%C+"))
local command = core.console local command = core.console
local pm3 = require('pm3')
p = pm3.pm3()
command('clear') command('clear')
author = ' Author: jareckib - 12.03.2025' author = ' Author: jareckib - 12.03.2025'
version = ' version v1.03' version = ' version v1.05'
desc = [[ desc = [[
This simple script stores 1, 2 or 3 different EM4102 on a single T5577. This simple script stores 1, 2 or 3 different EM4102 on a single T5577.
There is an option to enter the number engraved on the fob in decimal form. There is an option to enter the number engraved on the fob in decimal form.
@ -40,6 +42,27 @@ local function help()
print(arguments) print(arguments)
end end
local function sleep(n)
os.execute("sleep " ..tonumber(n))
end
function wait(msec)
local t = os.clock()
repeat
until os.clock() > t + msec * 1e-3
end
local function timer(n)
while n > 0 do
io.write(ac.cyan.."::::: "..ac.yellow.. tonumber(n) ..ac.yellow.." sec "..ac.cyan..":::::\r"..ac.reset)
sleep(1)
io.flush()
n = n-1
end
end
local function reset_log_file() local function reset_log_file()
local file = io.open(logfile, "w+") local file = io.open(logfile, "w+")
file:write("") file:write("")
@ -160,11 +183,12 @@ local function get_uid_from_user()
while true do while true do
reset_log_file() reset_log_file()
command('lf em 410x read') p:console('lf em 410x read')
local log_content = read_log_file(logfile) local log_content = read_log_file(logfile)
local uid = extract_uid(log_content) local uid = extract_uid(log_content)
if uid and #uid == 10 then if uid and #uid == 10 then
print("Readed EM4102 ID: " ..ac.green.. uid ..ac.reset)
return uid return uid
else else
io.write(ac.yellow .. "Error reading UID. Please adjust FOB position and press Enter..." .. ac.reset) io.write(ac.yellow .. "Error reading UID. Please adjust FOB position and press Enter..." .. ac.reset)
@ -175,6 +199,46 @@ local function get_uid_from_user()
end end
end end
local function verify_written_data(blocks, block0_value)
reset_log_file()
local block0_value = (uid_count == 1) and "00148040" or (uid_count == 2) and "00148080" or "001480C0"
p:console('lf t55 detect')
for i = 0, #blocks do
p:console('lf t55 read -b ' .. i)
end
local log_content = read_log_file(logfile)
local verified = true
local pattern_block0 = "%[%s*%+%]%s*00 |%s*([A-F0-9]+)"
local found_block0 = log_content:match(pattern_block0)
if not found_block0 or found_block0:upper() ~= block0_value:upper() then
print("Error in block 0 Expected " ..ac.green.. block0_value .. ac.reset.." Found " .. ac.green.. (found_block0 or "N/A")..ac.reset)
verified = false
end
for i = 1, #blocks do
local expected_block = blocks[i]
local pattern = "%[%s*%+%]%s*" .. string.format("%02X", i) .. " |%s*([A-F0-9]+)"
local found_block = log_content:match(pattern)
if not found_block or found_block:upper() ~= expected_block:upper() then
print("Error in block " .. i .. " Expected " ..ac.green.. expected_block ..ac.reset.. " Found " ..ac.green.. (found_block or "N/A")..ac.reset)
verified = false
end
end
return verified
end
local function write(blocks)
local block0_value = (uid_count == 1) and "00148040" or (uid_count == 2) and "00148080" or "001480C0"
p:console('lf t55xx write -b 0 -d ' .. block0_value)
for i = 1, #blocks do
p:console('lf t55xx write -b ' .. i .. ' -d ' .. blocks[i])
end
end
local function main(args) local function main(args)
for o, a in getopt.getopt(args, 'h') do for o, a in getopt.getopt(args, 'h') do
if o == 'h' then return help() end if o == 'h' then return help() end
@ -211,17 +275,21 @@ local function main(args)
end end
end end
local block0_value = (uid_count == 1) and "00148040" or (uid_count == 2) and "00148080" or "001480C0"
io.write("Place "..ac.cyan.."T5577"..ac.reset.." tag on coil for writing and press"..ac.cyan.." Enter..."..ac.reset) io.write("Place "..ac.cyan.."T5577"..ac.reset.." tag on coil for writing and press"..ac.cyan.." Enter..."..ac.reset)
io.read() io.read()
write(blocks)
command('lf t55xx write -b 0 -d ' .. block0_value)
for i = 1, #blocks do
command('lf t55xx write -b ' .. i .. ' -d ' .. blocks[i])
end
print(dash) print(dash)
print(ac.green .. "Successfully written " .. uid_count .. " EM4102 UID(s) to T5577" .. ac.reset) timer(3)
local verified = verify_written_data(blocks, block0_value)
while not verified do
print("Verification failed. Please correct the"..ac.cyan.." T5577"..ac.reset.." position and try again.")
io.write("Press " .. ac.cyan .. "Enter" .. ac.reset .. " to retry...")
io.read()
write(blocks)
timer(3)
verified = verify_written_data(blocks)
end
print(ac.green .. "Successfully written " ..ac.reset.. uid_count .. ac.green.." EM4102 UID(s) to T5577" .. ac.reset)
end end
main(args) main(args)