From 4babe8f012be831b0da9871416508b206e19b62d Mon Sep 17 00:00:00 2001 From: Uli Heilmeier Date: Sat, 25 May 2024 16:14:01 +0200 Subject: [PATCH] fix: hf_legic_clone.lua script Fixes: #2236 --- client/luascripts/hf_legic_clone.lua | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/client/luascripts/hf_legic_clone.lua b/client/luascripts/hf_legic_clone.lua index d9a86dc81..01d44ebe6 100644 --- a/client/luascripts/hf_legic_clone.lua +++ b/client/luascripts/hf_legic_clone.lua @@ -167,12 +167,11 @@ local function help() print(ansicolors.cyan..'Example usage'..ansicolors.reset) print(example) end --- read LEGIC data -local function readlegicdata(offset, len, iv) +-- read LEGIC info +local function readlegicinfo() -- Read data - local d0 = ('%04X%04X%02X'):format(offset, len, iv) - local c = Command:newNG{cmd = cmds.CMD_HF_LEGIC_READER, data = d0} - local result, err = c:sendNG() + local c = Command:newNG{cmd = cmds.CMD_HF_LEGIC_INFO, data = nil} + local result, err = c:sendNG(false, 2000) if not result then return oops(err) end -- result is a packed data structure, data starts at offset 33 return result @@ -404,15 +403,15 @@ local function writeToTag(plainBytes) return end - readbytes = readlegicdata(0, 4, 0x55) + readbytes = readlegicinfo() -- gather MCD & MSN from new Tag - this must be enterd manually print("\nthese are the MCD MSN0 MSN1 MSN2 from the Tag that has being read:") - -- readbytes is a usbcommandOLD package, hence 32 bytes offset until data. - plainBytes[1] = ('%02x'):format(readbytes:byte(33)) - plainBytes[2] = ('%02x'):format(readbytes:byte(34)) - plainBytes[3] = ('%02x'):format(readbytes:byte(35)) - plainBytes[4] = ('%02x'):format(readbytes:byte(36)) + -- readbytes is a table with uid data as hex string in Data key + plainBytes[1] = readbytes.Data:sub(1,2) + plainBytes[2] = readbytes.Data:sub(3,4) + plainBytes[3] = readbytes.Data:sub(5,6) + plainBytes[4] = readbytes.Data:sub(7,8) MCD = plainBytes[1] MSN0 = plainBytes[2]