skip first 4 bytes of legic writing

This commit is contained in:
David Cumps 2018-11-11 12:34:59 +01:00
commit dc69357820
No known key found for this signature in database
GPG key ID: 637C7180FEFDFA8E

View file

@ -513,6 +513,14 @@ function readFromPM3()
return tag return tag
end end
function padString(str)
if (str:len() == 1) then
return '0'..str
end
return str
end
--- ---
-- write virtual Tag to real Tag -- write virtual Tag to real Tag
function writeToTag(tag) function writeToTag(tag)
@ -560,32 +568,32 @@ function writeToTag(tag)
print("write temp-file '"..filename.."'") print("write temp-file '"..filename.."'")
print(accyan) print(accyan)
writeFile(bytes, filename..".bin") writeFile(bytes, filename..".bin")
--writeToTag(bytes, taglen, 'MylegicClone.hex')
print(acoff) print(acoff)
end end
end end
-- write data to file -- write data to file
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 '..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<5 or i>6) then if (i > 6) then
cmd = ('hf legic write o %02x d 01'):format(i) cmd = 'hf legic write o '..string.format("%x", i)..' d '..padString(bytes[i])
print(cmd)
core.console(cmd)
--print(cmd)
elseif (i == 6) then
-- write DCF in reverse order (requires 'mosci-patch')
cmd = 'hf legic write o 05 d 02'
print(acgreen..cmd..acoff) print(acgreen..cmd..acoff)
core.console(cmd) core.console(cmd)
--print(cmd) elseif (i == 6) then
else -- write DCF in reverse order (requires 'mosci-patch')
cmd = 'hf legic write o 05 d '..padString(bytes[i-1])..padString(bytes[i])
print(acgreen..cmd..acoff)
core.console(cmd)
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
print(acgreen.."skip byte 0x00-0x04 - unwritable area"..acoff)
end end
utils.Sleep(0.2) utils.Sleep(0.2)
end end
@ -622,14 +630,14 @@ end
function writeFile(bytes, filename) 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.." alredy 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 (answer==false) 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 ... faild to open output-file ".. filename) end if err then 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