fix: 'script run legic' - at last, it now saves in EML and BIN format.

This commit is contained in:
iceman1001 2019-05-14 17:13:29 +02:00
commit 8bfe669430

View file

@ -641,29 +641,25 @@ end
local function save_BIN(data, filename)
local outfile
local counter = 1
local ext = filename:match("^.+(%..+)$")
local ext = filename:match("^.+(%..+)$") or ''
local fn = filename
-- Make sure we don't overwrite a file
while file_check(fn) do
fn = filename:gsub(ext, tostring(counter)..ext)
print(filename, fn)
counter = counter + 1
end
outfile = io.open(fn, 'wb')
local bytes = utils.ConvertHexToBytes(data)
local i = 1
while bytes[i] do
outfile:write(bytes[i])
while data[i] do
local byte = string.char(tonumber(data[i], 16))
outfile:write(byte)
i = i + 1
end
outfile:close()
return fn, #bytes
return fn, #data
end
---
-- write bytes to file
@ -701,10 +697,14 @@ function writeFile(bytes, filename)
fho:close()
-- save binary
local fn_bin, num_of_bytes = save_BIN(bytes, filename)
local fn_bin, fn_bin_num = save_BIN(bytes, filename)
print("\nwrote "..acyellow..(#bytes * 3)..acoff.." bytes to " ..acyellow..filename..acoff)
if fn_bin and fn_bin_num then
print("\nwrote "..acyellow..fn_bin_num..acoff.." bytes to BINARY file "..acyellow..fn_bin..acoff)
end
print("\nwrote ".. #bytes * 3 .." bytes to " .. filename)
print("\nwrote ".. num_of_bytes .." bytes to " .. fn_bin)
return true
end