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
|
return tag
|
||||||
end
|
end
|
||||||
|
|
||||||
function padString(str)
|
local function padString(str)
|
||||||
if (str:len() == 1) then
|
if (#str == 1) then
|
||||||
return '0'..str
|
return '0'..str
|
||||||
end
|
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
|
if(utils.confirm(acred.."\nplace the (empty) Tag onto the PM3\nand confirm writing to this Tag: "..acoff) == false) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- get used bytes / tag-len
|
-- get used bytes / tag-len
|
||||||
if (istable(tag.SEG)) then
|
if (istable(tag.SEG)) then
|
||||||
if (istable(tag.Bck)) then
|
if (istable(tag.Bck)) then
|
||||||
|
@ -538,6 +539,7 @@ function writeToTag(tag)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local uid_old = tag.MCD..tag.MSN0..tag.MSN1..tag.MSN2
|
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
|
-- read new tag into memory so we can xor the new data with the new MCC
|
||||||
outTAG = readFromPM3()
|
outTAG = readFromPM3()
|
||||||
outbytes = tagToBytes(outTAG)
|
outbytes = tagToBytes(outTAG)
|
||||||
|
@ -557,13 +559,17 @@ function writeToTag(tag)
|
||||||
io.write(accyan.."\nfixing known checksums"..acoff.." ... ")
|
io.write(accyan.."\nfixing known checksums"..acoff.." ... ")
|
||||||
if (fix3rdPartyCash1(uid_new, tag.SEG[i].data)) then
|
if (fix3rdPartyCash1(uid_new, tag.SEG[i].data)) then
|
||||||
io.write(acgreen.." done\n"..acoff)
|
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
|
end
|
||||||
end
|
end
|
||||||
bytes = tagToBytes(tag)
|
bytes = tagToBytes(tag)
|
||||||
-- master-token-crc
|
-- 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
|
if (bytes) then
|
||||||
print("write temp-file '"..filename.."'")
|
print("write temp-file '"..filename.."'")
|
||||||
print(accyan)
|
print(accyan)
|
||||||
|
@ -576,20 +582,25 @@ function writeToTag(tag)
|
||||||
if (taglen > 0) then
|
if (taglen > 0) then
|
||||||
WriteBytes = utils.input(acyellow.."enter number of bytes to write?"..acoff, taglen)
|
WriteBytes = utils.input(acyellow.."enter number of bytes to write?"..acoff, taglen)
|
||||||
-- load file into pm3-buffer
|
-- 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
|
cmd = 'hf legic eload 2 '..filename
|
||||||
core.console(cmd)
|
core.console(cmd)
|
||||||
-- write pm3-buffer to Tag
|
-- write pm3-buffer to Tag
|
||||||
for i=0, WriteBytes do
|
for i=0, WriteBytes do
|
||||||
if (i > 6) then
|
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)
|
print(acgreen..cmd..acoff)
|
||||||
core.console(cmd)
|
core.console(cmd)
|
||||||
|
core.clearCommandBuffer()
|
||||||
elseif (i == 6) then
|
elseif (i == 6) then
|
||||||
-- write DCF in reverse order (requires 'mosci-patch')
|
-- 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)
|
print(acgreen..cmd..acoff)
|
||||||
core.console(cmd)
|
core.console(cmd)
|
||||||
|
core.clearCommandBuffer()
|
||||||
elseif (i == 5) then
|
elseif (i == 5) then
|
||||||
print(acgreen.."skip byte 0x05 - will be written next step"..acoff)
|
print(acgreen.."skip byte 0x05 - will be written next step"..acoff)
|
||||||
else
|
else
|
||||||
|
@ -603,11 +614,13 @@ end
|
||||||
--- File I/O ---
|
--- File I/O ---
|
||||||
---
|
---
|
||||||
-- read file into virtual-tag
|
-- read file into virtual-tag
|
||||||
function readFile(filename)
|
local function readFile(filename)
|
||||||
print(accyan)
|
print(accyan)
|
||||||
local bytes = {}
|
local bytes = {}
|
||||||
local tag = {}
|
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)
|
bytes = getInputBytes(filename)
|
||||||
|
|
||||||
|
@ -631,13 +644,15 @@ function writeFile(bytes, filename)
|
||||||
if (filename ~= 'MylegicClone.hex') then
|
if (filename ~= 'MylegicClone.hex') then
|
||||||
if (file_check(filename)) then
|
if (file_check(filename)) then
|
||||||
local answer = confirm("\nthe output-file "..filename.." already exists!\nthis will delete the previous content!\ncontinue?")
|
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
|
||||||
end
|
end
|
||||||
local line
|
local line
|
||||||
local bcnt = 0
|
local bcnt = 0
|
||||||
local fho, err = io.open(filename, "w")
|
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])
|
bytes = xorBytes(bytes, bytes[5])
|
||||||
for i = 1, #bytes do
|
for i = 1, #bytes do
|
||||||
if (bcnt == 0) then
|
if (bcnt == 0) then
|
||||||
|
@ -662,7 +677,7 @@ end
|
||||||
--- Map related ---
|
--- Map related ---
|
||||||
---
|
---
|
||||||
-- make tagMap
|
-- make tagMap
|
||||||
function makeTagMap()
|
local function makeTagMap()
|
||||||
local tagMap = {}
|
local tagMap = {}
|
||||||
if (#tagMap == 0) then
|
if (#tagMap == 0) then
|
||||||
tagMap['name'] = input(accyan.."enter Name for this Map: "..acoff , "newTagMap")
|
tagMap['name'] = input(accyan.."enter Name for this Map: "..acoff , "newTagMap")
|
||||||
|
@ -678,11 +693,11 @@ end
|
||||||
|
|
||||||
---
|
---
|
||||||
-- save mapping to file
|
-- save mapping to file
|
||||||
function saveTagMap(map, filename)
|
local function saveTagMap(map, filename)
|
||||||
if (string.len(filename)>0) then
|
if (string.len(filename)>0) then
|
||||||
if (file_check(filename)) then
|
if (file_check(filename)) then
|
||||||
local answer = confirm("\nthe output-file "..filename.." alredy exists!\nthis will delete the previous content!\ncontinue?")
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -713,7 +728,7 @@ end
|
||||||
|
|
||||||
---
|
---
|
||||||
-- toggle higligh
|
-- toggle higligh
|
||||||
function toggleHighlight(tbl)
|
local function toggleHighlight(tbl)
|
||||||
if (tbl['highlight']) then
|
if (tbl['highlight']) then
|
||||||
tbl['highlight'] = false
|
tbl['highlight'] = false
|
||||||
else
|
else
|
||||||
|
@ -724,7 +739,7 @@ end
|
||||||
|
|
||||||
---
|
---
|
||||||
-- return table od seqence-string
|
-- return table od seqence-string
|
||||||
function seqstr2tbl(seqstr)
|
local function seqstr2tbl(seqstr)
|
||||||
local s = split(seqstr)
|
local s = split(seqstr)
|
||||||
local res = {}
|
local res = {}
|
||||||
if (#s >= 1) then
|
if (#s >= 1) then
|
||||||
|
@ -741,7 +756,7 @@ end
|
||||||
|
|
||||||
---
|
---
|
||||||
-- return sequence-string from table
|
-- return sequence-string from table
|
||||||
function tbl2seqstr(seqtbl)
|
local function tbl2seqstr(seqtbl)
|
||||||
local res = ""
|
local res = ""
|
||||||
if (istable(seqtbl)) then
|
if (istable(seqtbl)) then
|
||||||
for sk, sv in pairs(seqtbl) do
|
for sk, sv in pairs(seqtbl) do
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue