Skip to content

Instantly share code, notes, and snippets.

@IVogel

IVogel/what.lua Secret

Last active April 5, 2021 11:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IVogel/24bbdb87eed132893cafbc0ef25c8c17 to your computer and use it in GitHub Desktop.
Save IVogel/24bbdb87eed132893cafbc0ef25c8c17 to your computer and use it in GitHub Desktop.
local table_insert = table.insert;
local string_byte, string_substr = string.byte, string.sub;
local bit_lshift, bit_bor = bit.lshift, bit.bor;
local function read_long(ptr, data)
return ptr + 4, bit_bor(
string_byte(data, ptr),
bit_lshift(string_byte(data, ptr + 1), 8),
bit_lshift(string_byte(data, ptr + 2), 16),
bit_lshift(string_byte(data, ptr + 3), 24)
);
end
local function read_null_string(ptr, data)
local str_end = #data;
for offset = ptr, str_end do
if string_byte(data, offset) == 0 then str_end = offset break; end
end
return str_end + 1, string_substr(data, ptr, str_end - 1);
end
local HEADER = 23;
--[[
buffer.Write( Addon::Ident, 4 );
buffer.WriteType( ( char ) Addon::Version );
buffer.WriteType( ( uint64_t ) 0ULL );
buffer.WriteType( ( uint64_t ) Time::UnixTimestamp() );
buffer.WriteType( ( char ) 0 ); // signifies nothing
]]
local function read_gma(data)
local files = {};
local data_block = 0;
do
local ptr = HEADER;
ptr = (read_null_string(ptr, data)); -- buffer.WriteString( strTitle );
ptr = (read_null_string(ptr, data)); -- buffer.WriteString( strDescription );
ptr = (read_null_string(ptr, data)) + 4; -- buffer.WriteString( "Author Name" ); buffer.WriteType( ( int32_t ) 1 );
local file_offset = 0;
local str, size;
while string_byte(data, ptr) ~= 0 do
ptr, str = read_null_string(ptr + 4, data);
ptr, size = read_long(ptr, data);
ptr = ptr + 8;
table_insert(files, {
str, size, file_offset, false
});
file_offset = file_offset + size
end
data_block = ptr + 4;
end
local index = 1
return function()
local file_entry = files[index];
index = index + 1;
if file_entry then
local offset = data_block + file_entry[3];
return file_entry[1], string_substr(data, offset, offset + file_entry[2] - 1);
end
return nil, nil;
end;
end
for file_name, file_data in read_gma(file.Read("advdupe2.gma")) do
print(file_name)
print(string.sub(file_data, 1, 40))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment