mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-21 05:43:48 -07:00
Merge pull request #2615 from jmichelp/legic
Start fixing legic script to work with lu5.4
This commit is contained in:
commit
b6c493e7b7
1 changed files with 26 additions and 13 deletions
|
@ -332,14 +332,29 @@ local function split(str, sep)
|
||||||
return fields
|
return fields
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---
|
||||||
|
-- join table with a separator
|
||||||
|
local function join(list, sep)
|
||||||
|
local sep = sep or ','
|
||||||
|
local len = #list
|
||||||
|
if len == 0 then return "" end
|
||||||
|
local s = list[1]
|
||||||
|
for i = 2, len do
|
||||||
|
s = s .. sep .. list[i]
|
||||||
|
end
|
||||||
|
return s
|
||||||
|
end
|
||||||
|
|
||||||
---
|
---
|
||||||
-- check availability of file
|
-- check availability of file
|
||||||
function file_check(file_name)
|
function file_check(file_name)
|
||||||
if not file_name then return false, "" end
|
if not file_name then return false, "" end
|
||||||
|
|
||||||
local arr = split(file_name, ".")
|
local arr = split(file_name, ".")
|
||||||
local path = core.search_file(arr[1], "."..arr[2])
|
local ext = table.remove(arr)
|
||||||
if (path == nil) then return false end
|
local name = join(arr, '.')
|
||||||
|
local path = core.search_file(name, "."..ext)
|
||||||
|
if (path == nil) then return false, "" end
|
||||||
|
|
||||||
local file_found = io.open(path, "r")
|
local file_found = io.open(path, "r")
|
||||||
if file_found == nil then
|
if file_found == nil then
|
||||||
|
@ -380,7 +395,9 @@ function getInputBytes(infile)
|
||||||
local bytes = {}
|
local bytes = {}
|
||||||
|
|
||||||
local arr = split(infile, ".")
|
local arr = split(infile, ".")
|
||||||
local path = core.search_file(arr[1], "."..arr[2])
|
local ext = table.remove(arr)
|
||||||
|
local name = join(arr, '.')
|
||||||
|
local path = core.search_file(name, "."..ext)
|
||||||
if (path == nil) then oops("failed to read from file ".. infile); return false; end
|
if (path == nil) then oops("failed to read from file ".. infile); return false; end
|
||||||
|
|
||||||
local fhi,err = io.open(path,"rb")
|
local fhi,err = io.open(path,"rb")
|
||||||
|
@ -443,7 +460,7 @@ function bytesToTag(bytes, tag)
|
||||||
tag.WRC=("%d"):format(bbit("0x"..bytes[8],4,3))
|
tag.WRC=("%d"):format(bbit("0x"..bytes[8],4,3))
|
||||||
tag.RD=("%d"):format(bbit("0x"..bytes[8],7,1))
|
tag.RD=("%d"):format(bbit("0x"..bytes[8],7,1))
|
||||||
if (tag.Type=="SAM" and tag.raw=='9f') then
|
if (tag.Type=="SAM" and tag.raw=='9f') then
|
||||||
tag.Stamp_len=(tonumber(0xfc,10)-tonumber(bbit("0x"..tag.DCFh,0,8),10))
|
tag.Stamp_len=(0xfc-bbit("0x"..tag.DCFh,0,8))
|
||||||
elseif (tag.Type=="SAM" and (tag.raw=='08' or tag.raw=='09')) then
|
elseif (tag.Type=="SAM" and (tag.raw=='08' or tag.raw=='09')) then
|
||||||
tag.Stamp_len = tonumber(tag.raw,10)
|
tag.Stamp_len = tonumber(tag.raw,10)
|
||||||
end
|
end
|
||||||
|
@ -756,20 +773,16 @@ end
|
||||||
-- read from pm3 into virtual-tag
|
-- read from pm3 into virtual-tag
|
||||||
function readFromPM3()
|
function readFromPM3()
|
||||||
local tag, bytes, infile
|
local tag, bytes, infile
|
||||||
--infile="legic.temp"
|
|
||||||
infile=getRandomTempName()
|
infile=getRandomTempName()
|
||||||
core.console("hf legic dump -f "..infile)
|
core.console("hf legic dump -f "..infile)
|
||||||
tag=readFile(infile..".bin")
|
tag=readFile(infile..".bin")
|
||||||
|
|
||||||
res, path = file_check(infile..".bin")
|
res, path = file_check(infile..".bin")
|
||||||
if not res then return nil end
|
if res then os.remove(path) end
|
||||||
os.remove(path)
|
|
||||||
|
|
||||||
res, path = file_check(infile..".eml")
|
|
||||||
os.remove(path)
|
|
||||||
|
|
||||||
res, path = file_check(infile..".json")
|
res, path = file_check(infile..".json")
|
||||||
os.remove(path)
|
if res then os.remove(path) end
|
||||||
return tag
|
return tag
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1690,7 +1703,7 @@ function getTokenType(DCFl)
|
||||||
0x30–0x6f SAM
|
0x30–0x6f SAM
|
||||||
0x70–0x7f GAM
|
0x70–0x7f GAM
|
||||||
]]--
|
]]--
|
||||||
local tt = tonumber(bbit("0x"..DCFl,0,7),10)
|
local tt = bbit("0x"..DCFl,0,7)
|
||||||
if (tt >= 0 and tt <= 47) then tt = "IAM"
|
if (tt >= 0 and tt <= 47) then tt = "IAM"
|
||||||
elseif (tt == 49) then tt = "SAM63"
|
elseif (tt == 49) then tt = "SAM63"
|
||||||
elseif (tt == 48) then tt = "SAM64"
|
elseif (tt == 48) then tt = "SAM64"
|
||||||
|
@ -1744,9 +1757,9 @@ function getSegmentData(bytes, start, index)
|
||||||
-- wrp (write proteted) = byte 2
|
-- wrp (write proteted) = byte 2
|
||||||
segment.WRP = tonumber(bytes[start+2],16)
|
segment.WRP = tonumber(bytes[start+2],16)
|
||||||
-- wrc (write control) - bit 4-6 of byte 3
|
-- wrc (write control) - bit 4-6 of byte 3
|
||||||
segment.WRC = tonumber(bbit("0x"..bytes[start+3],4,3),16)
|
segment.WRC = bbit("0x"..bytes[start+3],4,3)
|
||||||
-- rd (read disabled) - bit 7 of byte 3
|
-- rd (read disabled) - bit 7 of byte 3
|
||||||
segment.RD = tonumber(bbit("0x"..bytes[start+3],7,1),16)
|
segment.RD = bbit("0x"..bytes[start+3],7,1)
|
||||||
-- crc byte 4
|
-- crc byte 4
|
||||||
segment.crc = bytes[start+4]
|
segment.crc = bytes[start+4]
|
||||||
-- segment-data starts at segment.len - segment.header - segment.crc
|
-- segment-data starts at segment.len - segment.header - segment.crc
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue