From 9059749a6a0dd89545665bd70547fc5ad7b0aa77 Mon Sep 17 00:00:00 2001 From: sam Date: Wed, 13 May 2020 03:24:49 -0400 Subject: [PATCH] Velx fixes, velxdump. --- build.lua | 2 +- tkrnl.velx | Bin 3407 -> 3407 bytes utils/velxdump.lua | 195 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 196 insertions(+), 1 deletion(-) create mode 100644 utils/velxdump.lua diff --git a/build.lua b/build.lua index 9fabb5c..475040e 100644 --- a/build.lua +++ b/build.lua @@ -147,9 +147,9 @@ end local velx_spec = struct { endian = "<", {magic="c5"}, + {fver="B"}, {compression="B"}, {lver="B"}, - {fver="B"}, {os="B"}, {psize="I3"}, {lsize="I3"}, diff --git a/tkrnl.velx b/tkrnl.velx index 42f087efb4571f747ace6df2cdc5e66dadec1e8b..6392f31f09d775f70a6a8c2a4892651b95f61567 100644 GIT binary patch delta 2572 zcmZuzdsGuw9-c`8HG_}@L|ECa!|-q-mHPkY?00bO@n_Y|?a_H?%{q1x?s%PCNy548)Z=M)i>&FO3RkGr|e zk2(|(Ptd||L>O+MpMtG2OnI8~QNIEra7X<3v&zBvkOK0=q3~6B*f459{fJt@BkEBB zNIn4y04eGP5+M-|CJOMj_I$L>{*4{(Vk}T9ZqJ`r_Qj8rZa{h}z7$-zDy+Pik7BPv zy)^5>l0pdr7KtCHohUA~@)rP}SR9%g7n~U zII&P=jVs2R)~hnh>xVq|sA4xcEYgfl7u0c~~z zp%b9ZV3oAGOVuPE1%yDlHQLfU(mvV?%FP*>K%$8xxlaXZZIi^6_A|aHfqDtnM=Rp;H5E1)bR!vkYpTl37n7D zSZ_-1jUlQ$?BsB}-T+*5j? z#_DEkavFkA7a>T1YBgxW)vNq~X;DD;@SNA}8|)$v$o<7iD2%otnBtgDTOP&o5p|oF za7Ag-f|12odxY$E`hj4bvnQ!k=B^F6$&2PJD6@c}5@&^W=xx+uP)V(%1)7_ymT(!d{9k zhPjjR%|}}dRG8!V&ZaZMkV^ap7D*$jf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j95-Kab&8;vd=(Q2_cwB=EYX^;ah+7wD2FOLyxCaSHQnigzo{ch=* zVm)2=m~Zk_XT|S#K#-Q=NI@sW&EsqD(0!9p;=Z9B@X6X! zuS +--]]---------------------------------------------------------------------------- +-------------------------------------------------------------------------------- +local M = {} +local string, table = string, table + +-------------------------------------------------------------------------------- +local POS_BITS = 12 +local LEN_BITS = 16 - POS_BITS +local POS_SIZE = 1 << POS_BITS +local LEN_SIZE = 1 << LEN_BITS +local LEN_MIN = 3 + +-------------------------------------------------------------------------------- +function M.compress(input) + local offset, output = 1, {} + local window = '' + + local function search() + for i = LEN_SIZE + LEN_MIN - 1, LEN_MIN, -1 do + local str = string.sub(input, offset, offset + i - 1) + local pos = string.find(window, str, 1, true) + if pos then + return pos, str + end + end + end + + while offset <= #input do + local flags, buffer = 0, {} + + for i = 0, 7 do + if offset <= #input then + local pos, str = search() + if pos and #str >= LEN_MIN then + local tmp = ((pos - 1) << LEN_BITS) | (#str - LEN_MIN) + buffer[#buffer + 1] = string.pack('>I2', tmp) + else + flags = flags | (1 << i) + str = string.sub(input, offset, offset) + buffer[#buffer + 1] = str + end + window = string.sub(window .. str, -POS_SIZE) + offset = offset + #str + else + break + end + end + + if #buffer > 0 then + output[#output + 1] = string.char(flags) + output[#output + 1] = table.concat(buffer) + end + end + + return table.concat(output) +end + +-------------------------------------------------------------------------------- +function M.decompress(input) + local offset, output = 1, {} + local window = '' + + while offset <= #input do + local flags = string.byte(input, offset) + offset = offset + 1 + + for i = 1, 8 do + local str = nil + if (flags & 1) ~= 0 then + if offset <= #input then + str = string.sub(input, offset, offset) + offset = offset + 1 + end + else + if offset + 1 <= #input then + local tmp = string.unpack('>I2', input, offset) + offset = offset + 2 + local pos = (tmp >> LEN_BITS) + 1 + local len = (tmp & (LEN_SIZE - 1)) + LEN_MIN + str = string.sub(window, pos, pos + len - 1) + end + end + flags = flags >> 1 + if str then + output[#output + 1] = str + window = string.sub(window .. str, -POS_SIZE) + end + end + end + + return table.concat(output) +end + + +local function struct(tbl) + local pat = tbl.endian or "=" + local args = {} + for i=1, #tbl do + local a, b = pairs(tbl[i]) + local k, v = a(b) + args[i] = k + pat = pat .. v + end + return setmetatable({}, {__call=function(_, arg) + --checkArg(1, arg, "string", "table") + if (type(arg) == "string") then + local sval = {string.unpack(pat, arg)} + local rtn = {} + for i=1, #args do + rtn[args[i]] = sval[i] + end + return rtn, sval[#sval] + elseif (type(arg) == "table") then + local sval = {} + for i=1, #args do + sval[i] = arg[args[i]] + end + return string.pack(pat, unpack(sval)) + end + end, __len=function() + return string.packsize(pat) + end}) +end + +local velx_spec = struct { + endian = "<", + {magic="c5"}, + {fver="B"}, + {compression="B"}, + {lver="B"}, + {os="B"}, + {psize="I3"}, + {lsize="I3"}, + {ssize="I3"}, + {rsize="I4"} +} + +local compression = { + [0] = "None", + [1] = "LZSS" +} + +local os = { + [0] = "Tsuki", + [0x7F] = "BIOS", +} + +local f = io.open(arg[1], "rb") +local header = velx_spec(f:read(#velx_spec)) +local program = f:read(header.psize) +local linker = f:read(header.lsize) +local sigs = f:read(header.ssize) +local archive = f:read(header.rsize) +local lver = string.format("%x", header.lver) +lver = lver:sub(1,1).."."..lver:sub(2,2) +io.stdout:write(string.format([[File Version: %d +Compression: %s +Type: %s +OS: %s +Lua Version: %s]], +header.fver, +compression[header.compression] or "Unknown", +(((header.os & 0x80) > 0) and "Library") or "Executable", +os[header.os & 0x7F] or "Unknown", +lver),"\n") +local h = io.popen("tsar -t", "w") +h:write(archive) +h:close() +if (header.compression == 1) then + io.stderr:write(M.decompress(program)) +elseif (header.compression == 0) then + io.stderr:write(program) +end \ No newline at end of file