diff --git a/client/scripts/legic.lua b/client/scripts/legic.lua index 2acf27bc2..546e5cc1a 100644 --- a/client/scripts/legic.lua +++ b/client/scripts/legic.lua @@ -513,6 +513,14 @@ function readFromPM3() return tag end +function padString(str) + if (str:len() == 1) then + return '0'..str + end + + return str +end + --- -- write virtual Tag to real Tag function writeToTag(tag) @@ -560,32 +568,32 @@ function writeToTag(tag) print("write temp-file '"..filename.."'") print(accyan) writeFile(bytes, filename..".bin") - --writeToTag(bytes, taglen, 'MylegicClone.hex') print(acoff) end end - -- write data to file + + -- write data to file 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 - cmd = 'hf legic eload '..filename + cmd = 'hf legic eload 2 '..filename core.console(cmd) -- write pm3-buffer to Tag for i=0, WriteBytes do - if ( i<5 or i>6) then - cmd = ('hf legic write o %02x d 01'):format(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' + if (i > 6) then + cmd = 'hf legic write o '..string.format("%x", i)..' d '..padString(bytes[i]) print(acgreen..cmd..acoff) core.console(cmd) - --print(cmd) - else + 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]) + print(acgreen..cmd..acoff) + core.console(cmd) + elseif (i == 5) then print(acgreen.."skip byte 0x05 - will be written next step"..acoff) + else + print(acgreen.."skip byte 0x00-0x04 - unwritable area"..acoff) end utils.Sleep(0.2) end @@ -622,14 +630,14 @@ end function writeFile(bytes, filename) if (filename ~= 'MylegicClone.hex') 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 end end local line local bcnt=0 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]) for i = 1, #bytes do if (bcnt == 0) then