this should fix the ~ (tilde) bug I introduced...

In lua,  you need to evaluate false ie;   statement == false,    not like in C-style  ~statement
This commit is contained in:
iceman1001 2017-08-13 15:06:30 +02:00
commit 69c8970201

View file

@ -346,8 +346,7 @@ function getInputBytes(infile)
if err then oops("faild to read from file ".. infile); return false; end
file_data = fhi:read("*a");
for i = 1, #file_data
do
for i = 1, #file_data do
bytes[i] = string.format("%x",file_data:byte(i))
end
fhi:close()
@ -386,9 +385,7 @@ end
---
-- put bytes into tag-table
function bytesToTag(bytes, tag)
if ~istable(tag) then
return oops("tag is no table in: bytesToTag ("..type(tag)..")")
end
if istable(tag) == false then return oops("tag is no table in: bytesToTag ("..type(tag)..")") end
tag.MCD =bytes[1];
tag.MSN0=bytes[2];
@ -456,9 +453,7 @@ end
---
-- read Tag-Table in bytes-table
function tagToBytes(tag)
if ~istable(tag) then
return oops("tag is no table in tagToBytes ("..type(tag)..")")
end
if istable(tag) == false then return oops("tag is no table in tagToBytes ("..type(tag)..")") end
local bytes = {}
local i, i2
@ -602,11 +597,11 @@ function readFile(filename)
print(accyan)
local bytes = {}
local tag = {}
if ~file_check(filename) 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)
if ~bytes then return oops('couldnt get input bytes') end
if bytes == false then return oops('couldnt get input bytes') end
-- make plain bytes
bytes = xorBytes(bytes,bytes[5])
@ -1357,7 +1352,7 @@ end
-- dump Legic-Cash data
function dumpLegicCash(tag, x)
if ~istable(tag.SEG[x]) then return end
if istable(tag.SEG[x]) == false then return end
io.write("in Segment "..tag.SEG[x].index.." :\n")
print("--------------------------------\n\tLegic-Cash Values\n--------------------------------")
@ -1383,7 +1378,7 @@ function dumpLegicCash(tag, x)
-- raw 3rd-party
function print3rdPartyCash1(tag, x)
if ~istable(tag.SEG[x]) then return end
if istable(tag.SEG[x]) == false then return end
local uid=tag.MCD..tag.MSN0..tag.MSN1..tag.MSN2
print("\n\t\tStamp : "..dumpTable(tag.SEG[x].data, "", 0 , 2))
@ -1457,11 +1452,14 @@ function makeToken()
end
-- fill bytes
for i = #bytes, 1023 do table.insert(bytes, "00") end
-- if Master-Token -> calc Master-Token-CRC
if (mtq>1) then bytes[22] = calcMtCrc(bytes) end
local tempTag = createTagTable()
-- remove segment if MasterToken
if (mtq>1) then tempTag.SEG[0] = nil end
return bytesToTag(bytes, tempTag)
end
@ -1531,10 +1529,9 @@ end
---
-- calculates header-byte (addr 0x07)
function calcHeaderRaw(wrp, wrc, rd)
local res
wrp = ("%02x"):format(tonumber(wrp, 10))
rd = tonumber(rd, 16)
res=("%02x"):format(tonumber(wrp, 16)+tonumber(wrc.."0", 16)+((rd>0) and tonumber("8"..(rd-1), 16) or 0))
local res = ("%02x"):format(tonumber(wrp, 16)+tonumber(wrc.."0", 16)+((rd>0) and tonumber("8"..(rd-1), 16) or 0))
return res
end
@ -1700,9 +1697,7 @@ end
-- edit Segment Data
function editSegmentData(data)
io.write("\n")
if ~istable(data) then
print("no Segment-Data found")
end
if istable(data) == false then print("no Segment-Data found") end
local lc = check4LegicCash(data)
@ -2686,7 +2681,7 @@ function main(args)
end
-- file conversion (output to file)
if ~ofs then return end
if ofs == false then return end
-- dump infile / tag-read
if (dfs) then