mirror of
https://github.com/0x5eal/luau-unzip.git
synced 2025-04-10 17:20:53 +01:00
fix: fix invalid '---' syntax for MoonWave
This commit is contained in:
parent
c86855ca0c
commit
f1b67b86df
2 changed files with 24 additions and 24 deletions
|
@ -7,7 +7,7 @@ type TreeInner = {
|
||||||
trans: { number }, -- Length of 288, stores code to symbol translations
|
trans: { number }, -- Length of 288, stores code to symbol translations
|
||||||
}
|
}
|
||||||
|
|
||||||
--- Creates a new Tree instance with initialized tables
|
--] Creates a new Tree instance with initialized tables
|
||||||
function Tree.new(): Tree
|
function Tree.new(): Tree
|
||||||
return setmetatable(
|
return setmetatable(
|
||||||
{
|
{
|
||||||
|
@ -35,7 +35,7 @@ export type DataInner = {
|
||||||
dtree: Tree, -- Distance tree for current block
|
dtree: Tree, -- Distance tree for current block
|
||||||
}
|
}
|
||||||
|
|
||||||
--- Creates a new Data instance with initialized compression state
|
--] Creates a new Data instance with initialized compression state
|
||||||
function Data.new(source: buffer, dest: buffer): Data
|
function Data.new(source: buffer, dest: buffer): Data
|
||||||
return setmetatable(
|
return setmetatable(
|
||||||
{
|
{
|
||||||
|
@ -74,7 +74,7 @@ local clcIndex = {
|
||||||
local codeTree = Tree.new()
|
local codeTree = Tree.new()
|
||||||
local lengths = table.create(288 + 32, 0)
|
local lengths = table.create(288 + 32, 0)
|
||||||
|
|
||||||
--- Builds the extra bits and base tables for length and distance codes
|
--] Builds the extra bits and base tables for length and distance codes
|
||||||
local function buildBitsBase(bits: { number }, base: { number }, delta: number, first: number)
|
local function buildBitsBase(bits: { number }, base: { number }, delta: number, first: number)
|
||||||
local sum = first
|
local sum = first
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ local function buildBitsBase(bits: { number }, base: { number }, delta: number,
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Constructs the fixed Huffman trees used in DEFLATE format
|
--] Constructs the fixed Huffman trees used in DEFLATE format
|
||||||
local function buildFixedTrees(lengthTree: Tree, distTree: Tree)
|
local function buildFixedTrees(lengthTree: Tree, distTree: Tree)
|
||||||
-- Build the fixed length tree according to DEFLATE specification
|
-- Build the fixed length tree according to DEFLATE specification
|
||||||
for i = 0, 6 do
|
for i = 0, 6 do
|
||||||
|
@ -128,10 +128,10 @@ local function buildFixedTrees(lengthTree: Tree, distTree: Tree)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Temporary array for building trees
|
--] Temporary array for building trees
|
||||||
local offs = table.create(16, 0)
|
local offs = table.create(16, 0)
|
||||||
|
|
||||||
--- Builds a Huffman tree from a list of code lengths
|
--] Builds a Huffman tree from a list of code lengths
|
||||||
local function buildTree(t: Tree, lengths: { number }, off: number, num: number)
|
local function buildTree(t: Tree, lengths: { number }, off: number, num: number)
|
||||||
-- Initialize the code length count table
|
-- Initialize the code length count table
|
||||||
for i = 0, 15 do
|
for i = 0, 15 do
|
||||||
|
@ -162,7 +162,7 @@ local function buildTree(t: Tree, lengths: { number }, off: number, num: number)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Reads a single bit from the input stream
|
--] Reads a single bit from the input stream
|
||||||
local function getBit(d: Data): number
|
local function getBit(d: Data): number
|
||||||
if d.bitcount <= 0 then
|
if d.bitcount <= 0 then
|
||||||
d.tag = buffer.readu8(d.source, d.sourceIndex)
|
d.tag = buffer.readu8(d.source, d.sourceIndex)
|
||||||
|
@ -177,7 +177,7 @@ local function getBit(d: Data): number
|
||||||
return bit
|
return bit
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Reads multiple bits from the input stream with a base value
|
--] Reads multiple bits from the input stream with a base value
|
||||||
local function readBits(d: Data, num: number?, base: number): number
|
local function readBits(d: Data, num: number?, base: number): number
|
||||||
if not num then
|
if not num then
|
||||||
return base
|
return base
|
||||||
|
@ -197,7 +197,7 @@ local function readBits(d: Data, num: number?, base: number): number
|
||||||
return val + base
|
return val + base
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Decodes a symbol using a Huffman tree
|
--] Decodes a symbol using a Huffman tree
|
||||||
local function decodeSymbol(d: Data, t: Tree): number
|
local function decodeSymbol(d: Data, t: Tree): number
|
||||||
while d.bitcount < 24 and d.sourceIndex < buffer.len(d.source) do
|
while d.bitcount < 24 and d.sourceIndex < buffer.len(d.source) do
|
||||||
d.tag = bit32.bor(d.tag, bit32.lshift(buffer.readu8(d.source, d.sourceIndex), d.bitcount))
|
d.tag = bit32.bor(d.tag, bit32.lshift(buffer.readu8(d.source, d.sourceIndex), d.bitcount))
|
||||||
|
@ -223,7 +223,7 @@ local function decodeSymbol(d: Data, t: Tree): number
|
||||||
return t.trans[sum + cur]
|
return t.trans[sum + cur]
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Decodes the dynamic Huffman trees for a block
|
--] Decodes the dynamic Huffman trees for a block
|
||||||
local function decodeTrees(d: Data, lengthTree: Tree, distTree: Tree)
|
local function decodeTrees(d: Data, lengthTree: Tree, distTree: Tree)
|
||||||
local hlit = readBits(d, 5, 257) -- Number of literal/length codes
|
local hlit = readBits(d, 5, 257) -- Number of literal/length codes
|
||||||
local hdist = readBits(d, 5, 1) -- Number of distance codes
|
local hdist = readBits(d, 5, 1) -- Number of distance codes
|
||||||
|
@ -278,7 +278,7 @@ local function decodeTrees(d: Data, lengthTree: Tree, distTree: Tree)
|
||||||
buildTree(distTree, lengths, hlit, hdist)
|
buildTree(distTree, lengths, hlit, hdist)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Inflates a block of data using Huffman trees
|
--] Inflates a block of data using Huffman trees
|
||||||
local function inflateBlockData(d: Data, lengthTree: Tree, distTree: Tree)
|
local function inflateBlockData(d: Data, lengthTree: Tree, distTree: Tree)
|
||||||
while true do
|
while true do
|
||||||
local sym = decodeSymbol(d, lengthTree)
|
local sym = decodeSymbol(d, lengthTree)
|
||||||
|
@ -310,7 +310,7 @@ local function inflateBlockData(d: Data, lengthTree: Tree, distTree: Tree)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Processes an uncompressed block
|
--] Processes an uncompressed block
|
||||||
local function inflateUncompressedBlock(d: Data)
|
local function inflateUncompressedBlock(d: Data)
|
||||||
-- Align to byte boundary
|
-- Align to byte boundary
|
||||||
local bytesToMove = d.bitcount // 8
|
local bytesToMove = d.bitcount // 8
|
||||||
|
@ -342,7 +342,7 @@ local function inflateUncompressedBlock(d: Data)
|
||||||
d.bitcount = 0
|
d.bitcount = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Main decompression function that processes DEFLATE compressed data
|
--] Main decompression function that processes DEFLATE compressed data
|
||||||
local function uncompress(source: buffer, uncompressedSize: number?): buffer
|
local function uncompress(source: buffer, uncompressedSize: number?): buffer
|
||||||
local dest = buffer.create(
|
local dest = buffer.create(
|
||||||
-- If the uncompressed size is known, we use that, otherwise we use a default
|
-- If the uncompressed size is known, we use that, otherwise we use a default
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
--- Canonicalize a path by removing redundant components
|
--] Canonicalize a path by removing redundant components
|
||||||
local function canonicalize(path: string): string
|
local function canonicalize(path: string): string
|
||||||
-- We convert any `\\` separators to `/` separators to ensure consistency
|
-- We convert any `\\` separators to `/` separators to ensure consistency
|
||||||
local components = string.split(path:gsub("\\", "/"), "/")
|
local components = string.split(path:gsub("\\", "/"), "/")
|
||||||
|
@ -22,7 +22,7 @@ local function canonicalize(path: string): string
|
||||||
return table.concat(result, "/")
|
return table.concat(result, "/")
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Check if a path is absolute
|
--] Check if a path is absolute
|
||||||
local function isAbsolute(path: string): boolean
|
local function isAbsolute(path: string): boolean
|
||||||
return (
|
return (
|
||||||
string.match(path, "^/")
|
string.match(path, "^/")
|
||||||
|
@ -32,7 +32,7 @@ local function isAbsolute(path: string): boolean
|
||||||
) ~= nil
|
) ~= nil
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Check if a path is relative
|
--] Check if a path is relative
|
||||||
local function isRelative(path: string): boolean
|
local function isRelative(path: string): boolean
|
||||||
return not isAbsolute(path)
|
return not isAbsolute(path)
|
||||||
end
|
end
|
||||||
|
@ -48,10 +48,10 @@ local function replaceBackslashes(input: string, replacement: "/"): string
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Check if a path is safe to use, i.e., it does not:
|
--] Check if a path is safe to use, i.e., it does not:
|
||||||
--- - Contain null bytes
|
--] - Contain null bytes
|
||||||
--- - Resolve to a directory outside of the current directory
|
--] - Resolve to a directory outside of the current directory
|
||||||
--- - Have absolute components
|
--] - Have absolute components
|
||||||
local function isSafe(path: string): boolean
|
local function isSafe(path: string): boolean
|
||||||
if string.find(path, "\0") or isAbsolute(path) then
|
if string.find(path, "\0") or isAbsolute(path) then
|
||||||
-- Null bytes or absolute path, path is unsafe
|
-- Null bytes or absolute path, path is unsafe
|
||||||
|
@ -89,10 +89,10 @@ local function isSafe(path: string): boolean
|
||||||
return depth >= 0
|
return depth >= 0
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Sanitize a path by ignoring special components
|
--] Sanitize a path by ignoring special components
|
||||||
--- - Absolute paths become relative
|
--] - Absolute paths become relative
|
||||||
--- - Special components (like upwards traversing) are removed
|
--] - Special components (like upwards traversing) are removed
|
||||||
--- - Truncates path to the first null byte
|
--] - Truncates path to the first null byte
|
||||||
local function sanitize(path: string): string
|
local function sanitize(path: string): string
|
||||||
local truncatedPath = if string.find(path, "\0") then string.split(path, "\0")[1] else path
|
local truncatedPath = if string.find(path, "\0") then string.split(path, "\0")[1] else path
|
||||||
local components = string.split(replaceBackslashes(truncatedPath, "/"), "/")
|
local components = string.split(replaceBackslashes(truncatedPath, "/"), "/")
|
||||||
|
|
Loading…
Add table
Reference in a new issue