Start fixing legic.lua ! Now loads dumps fine

This commit is contained in:
BOURDY Romain 2017-05-17 18:52:30 +02:00
parent 7b8cbd38a8
commit bf413f1b87

View file

@ -296,6 +296,7 @@ function file_check(file_name)
if file_found==nil then if file_found==nil then
return false return false
else else
file_found:close()
return true return true
end end
end end
@ -339,15 +340,14 @@ end
function getInputBytes(infile) function getInputBytes(infile)
local line local line
local bytes = {} local bytes = {}
local fhi,err = io.open(infile) local fhi,err = io.open(infile,"rb")
if err then oops("faild to read from file ".. infile); return false; end if err then oops("faild to read from file ".. infile); return false; end
while true do
line = fhi:read() file_data = fhi:read("*a");
if line == nil then break end for i = 1, #file_data
for byte in line:gmatch("%w+") do do
table.insert(bytes, byte) bytes[i] = string.format("%x",file_data:byte(i))
end end
end
fhi:close() fhi:close()
if (bytes[7]=='00') then return false end if (bytes[7]=='00') then return false end
print(#bytes .. " bytes from "..infile.." loaded") print(#bytes .. " bytes from "..infile.." loaded")
@ -507,8 +507,8 @@ 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 save "..infile) core.console("hf legic esave "..infile)
tag=readFile(infile) tag=readFile(infile..".bin")
return tag return tag
end end