fix legic reading and writing

This commit is contained in:
David Cumps 2018-11-11 01:18:14 +01:00
commit 00fdac0986
No known key found for this signature in database
GPG key ID: 637C7180FEFDFA8E

View file

@ -506,8 +506,9 @@ function tagToBytes(tag)
function readFromPM3() function readFromPM3()
local tag, bytes, infile local tag, bytes, infile
infile="legic.temp" infile="legic.temp"
core.console("hf legic reader") -- core.console("hf legic reader")
core.console("hf legic esave "..infile) -- core.console("hf legic esave "..infile)
core.console("hf legic dump o "..infile)
tag=readFile(infile..".bin") tag=readFile(infile..".bin")
return tag return tag
end end
@ -558,7 +559,7 @@ function writeToTag(tag)
if (bytes) then if (bytes) then
print("write temp-file '"..filename.."'") print("write temp-file '"..filename.."'")
print(accyan) print(accyan)
writeFile(bytes, filename) writeFile(bytes, filename..".bin")
--writeToTag(bytes, taglen, 'MylegicClone.hex') --writeToTag(bytes, taglen, 'MylegicClone.hex')
print(acoff) print(acoff)
end end
@ -568,17 +569,18 @@ function writeToTag(tag)
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 load '..filename cmd = 'hf legic eload '..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<5 or i>6) then if ( i<5 or i>6) then
cmd = ('hf legic write o 0x%02x d 0x01'):format(i) cmd = ('hf legic write o %02x d 01'):format(i)
print(cmd)
core.console(cmd) core.console(cmd)
--print(cmd) --print(cmd)
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 0x05 d 0x02' cmd = 'hf legic write o 05 d 02'
print(acgreen..cmd..acoff) print(acgreen..cmd..acoff)
core.console(cmd) core.console(cmd)
--print(cmd) --print(cmd)