mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-20 21:33:47 -07:00
chg: 'script run legic' - minor adjustments.
This commit is contained in:
parent
8059f533af
commit
fa3dfa59b9
1 changed files with 155 additions and 140 deletions
|
@ -513,8 +513,8 @@ function readFromPM3()
|
|||
return tag
|
||||
end
|
||||
|
||||
function padString(str)
|
||||
if (str:len() == 1) then
|
||||
local function padString(str)
|
||||
if (#str == 1) then
|
||||
return '0'..str
|
||||
end
|
||||
|
||||
|
@ -530,6 +530,7 @@ function writeToTag(tag)
|
|||
if(utils.confirm(acred.."\nplace the (empty) Tag onto the PM3\nand confirm writing to this Tag: "..acoff) == false) then
|
||||
return
|
||||
end
|
||||
|
||||
-- get used bytes / tag-len
|
||||
if (istable(tag.SEG)) then
|
||||
if (istable(tag.Bck)) then
|
||||
|
@ -538,6 +539,7 @@ function writeToTag(tag)
|
|||
end
|
||||
end
|
||||
local uid_old = tag.MCD..tag.MSN0..tag.MSN1..tag.MSN2
|
||||
|
||||
-- read new tag into memory so we can xor the new data with the new MCC
|
||||
outTAG = readFromPM3()
|
||||
outbytes = tagToBytes(outTAG)
|
||||
|
@ -557,13 +559,17 @@ function writeToTag(tag)
|
|||
io.write(accyan.."\nfixing known checksums"..acoff.." ... ")
|
||||
if (fix3rdPartyCash1(uid_new, tag.SEG[i].data)) then
|
||||
io.write(acgreen.." done\n"..acoff)
|
||||
else oops("\nsomething went wrong at the repair of the 3rd-party-cash-segment") end
|
||||
else
|
||||
oops("\nsomething went wrong at the repair of the 3rd-party-cash-segment")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
bytes = tagToBytes(tag)
|
||||
-- master-token-crc
|
||||
if (tag.Type ~= "SAM") then bytes[22] = calcMtCrc(bytes) end
|
||||
if (tag.Type ~= "SAM") then
|
||||
bytes[22] = calcMtCrc(bytes)
|
||||
end
|
||||
if (bytes) then
|
||||
print("write temp-file '"..filename.."'")
|
||||
print(accyan)
|
||||
|
@ -576,20 +582,25 @@ function writeToTag(tag)
|
|||
if (taglen > 0) then
|
||||
WriteBytes = utils.input(acyellow.."enter number of bytes to write?"..acoff, taglen)
|
||||
-- load file into pm3-buffer
|
||||
if (type(filename) ~= "string") then filename=input(acyellow.."filename to load to pm3-buffer?"..acoff,"legic.temp") end
|
||||
if (type(filename) ~= "string") then
|
||||
filename = input(acyellow.."filename to load to pm3-buffer?"..acoff, "legic.temp")
|
||||
end
|
||||
|
||||
cmd = 'hf legic eload 2 '..filename
|
||||
core.console(cmd)
|
||||
-- write pm3-buffer to Tag
|
||||
for i=0, WriteBytes do
|
||||
if (i > 6) then
|
||||
cmd = 'hf legic write o '..string.format("%x", i)..' d '..padString(bytes[i])
|
||||
cmd = ("hf legic write o %x d %s "):format(i, padString(bytes[i]))
|
||||
print(acgreen..cmd..acoff)
|
||||
core.console(cmd)
|
||||
core.clearCommandBuffer()
|
||||
elseif (i == 6) then
|
||||
-- write DCF in reverse order (requires 'mosci-patch')
|
||||
cmd = 'hf legic write o 05 d '..padString(bytes[i-1])..padString(bytes[i])
|
||||
cmd = ('hf legic write o 05 d %s%s'):format(padString(bytes[i-1]), padString(bytes[i]))
|
||||
print(acgreen..cmd..acoff)
|
||||
core.console(cmd)
|
||||
core.clearCommandBuffer()
|
||||
elseif (i == 5) then
|
||||
print(acgreen.."skip byte 0x05 - will be written next step"..acoff)
|
||||
else
|
||||
|
@ -603,11 +614,13 @@ end
|
|||
--- File I/O ---
|
||||
---
|
||||
-- read file into virtual-tag
|
||||
function readFile(filename)
|
||||
local function readFile(filename)
|
||||
print(accyan)
|
||||
local bytes = {}
|
||||
local tag = {}
|
||||
if file_check(filename) == false then return oops("input file: "..filename.." not found") end
|
||||
if file_check(filename) == false then
|
||||
return oops("input file: "..filename.." not found")
|
||||
end
|
||||
|
||||
bytes = getInputBytes(filename)
|
||||
|
||||
|
@ -631,13 +644,15 @@ function writeFile(bytes, filename)
|
|||
if (filename ~= 'MylegicClone.hex') then
|
||||
if (file_check(filename)) then
|
||||
local answer = confirm("\nthe output-file "..filename.." already exists!\nthis will delete the previous content!\ncontinue?")
|
||||
if (answer==false) then return print("user abort") end
|
||||
if not answer then return print("user abort") end
|
||||
end
|
||||
end
|
||||
local line
|
||||
local bcnt = 0
|
||||
local fho, err = io.open(filename, "w")
|
||||
if err then oops("OOps ... failed to open output-file ".. filename) end
|
||||
if err then
|
||||
return oops("OOps ... failed to open output-file ".. filename)
|
||||
end
|
||||
bytes = xorBytes(bytes, bytes[5])
|
||||
for i = 1, #bytes do
|
||||
if (bcnt == 0) then
|
||||
|
@ -662,7 +677,7 @@ end
|
|||
--- Map related ---
|
||||
---
|
||||
-- make tagMap
|
||||
function makeTagMap()
|
||||
local function makeTagMap()
|
||||
local tagMap = {}
|
||||
if (#tagMap == 0) then
|
||||
tagMap['name'] = input(accyan.."enter Name for this Map: "..acoff , "newTagMap")
|
||||
|
@ -678,11 +693,11 @@ end
|
|||
|
||||
---
|
||||
-- save mapping to file
|
||||
function saveTagMap(map, filename)
|
||||
local function saveTagMap(map, filename)
|
||||
if (string.len(filename)>0) then
|
||||
if (file_check(filename)) then
|
||||
local answer = confirm("\nthe output-file "..filename.." alredy exists!\nthis will delete the previous content!\ncontinue?")
|
||||
if (answer==false) then return print("user abort") end
|
||||
if not answer then return print("user abort") end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -713,7 +728,7 @@ end
|
|||
|
||||
---
|
||||
-- toggle higligh
|
||||
function toggleHighlight(tbl)
|
||||
local function toggleHighlight(tbl)
|
||||
if (tbl['highlight']) then
|
||||
tbl['highlight'] = false
|
||||
else
|
||||
|
@ -724,7 +739,7 @@ end
|
|||
|
||||
---
|
||||
-- return table od seqence-string
|
||||
function seqstr2tbl(seqstr)
|
||||
local function seqstr2tbl(seqstr)
|
||||
local s = split(seqstr)
|
||||
local res = {}
|
||||
if (#s >= 1) then
|
||||
|
@ -741,7 +756,7 @@ end
|
|||
|
||||
---
|
||||
-- return sequence-string from table
|
||||
function tbl2seqstr(seqtbl)
|
||||
local function tbl2seqstr(seqtbl)
|
||||
local res = ""
|
||||
if (istable(seqtbl)) then
|
||||
for sk, sv in pairs(seqtbl) do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue