Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function TestFunction(a,b,c)
- local A = workspace:FindFirstChild("Nonexistent");
- return A;
- end
- local PrecompiledChunk = ("").dump(TestFunction);
- -- Pre-compiled chunk reading
- -- Lua binary chunk reading is simple for those who understand basic computer theory and bit marking.
- -- The format of Lua 5.1's binary structure can be found:
- -- http://luaforge.net/docman/83/98/ANoFrillsIntroToLua51VMInstructions.pdf
- local Lexer = 1;
- function ReadNextByte()
- local Byte = PrecompiledChunk:sub(Lexer,Lexer):byte();
- Lexer = Lexer + 1
- return Byte;
- end
- function ReadNextByte2()
- local B1 = ReadNextByte();
- local B2 = ReadNextByte();
- return (B2 * 256) + B1
- end
- function ReadNextByte4()
- local B1 = ReadNextByte();
- local B2 = ReadNextByte();
- local B3 = ReadNextByte();
- local B4 = ReadNextByte();
- return (B4 * 16777216 ) + (B3 * 65536 ) + (B2 * 256) + B1
- end
- function ReadNextByte8()
- local B1 = ReadNextByte();
- local B2 = ReadNextByte();
- local B3 = ReadNextByte();
- local B4 = ReadNextByte();
- local B5 = ReadNextByte();
- return (B5 * 4294967296 ) + (B4 * 16777216 ) + (B3 * 65536 ) + (B2 * 256) + B1
- end
- function ReadString(LengthOfString)
- local String = PrecompiledChunk:sub(Lexer, Lexer + (LengthOfString - 1));
- Lexer = Lexer + LengthOfString
- end
- -- Lua Header
- -- The Lua header is always 12 bytes, no matter what.
- local Identification = ReadString(4);
- local VersionNumber = ReadNextByte();
- local FormatVersion = ReadNextByte();
- local EndianFlag = ReadNextByte();
- local SizeOfInt = ReadNextByte();
- local Size_T = ReadNextByte();
- local SizeOfInstruction = ReadNextByte() -- Lua Assembly OpCode sizes
- local SizeOfLuaNumber = ReadNextByte();
- local IntFlag = ReadNextByte();
- print(SizeOfInt, Size_T, SizeOfInstruction); -- Should print three 4's. This means it is correct.
- -- That totals to 12 bytes. Success
- -- The next step is to get the source name. The size of the string is defined by Size_T. It is defaulted to 4.
- -- Obtain the string size like this:
- local SizeOfSourceName = (Size_T == 4) and ReadNextByte4() or ReadNextByte8();
- print(SizeOfSourceName);
- -- With the size of the string, loop through each position by 1 byte
- local SourceName = "";
- for i = 1, SizeOfSourceName do
- SourceName = SourceName .. ("").char(ReadNextByte());
- end
- print(SourceName); -- Should print the source name of this script (about the same as script:GetFullName());
- -- The next two function proto's are the line definitions of the ORIGINAL dumped function.
- -- It is optional debug data. The size of the intenger in the binary dump are define by SizeOfInt (default 4).
- local LineDefined = (SizeOfInt == 4) and ReadNextByte4() or ReadNextByte8();
- local LineEnded = (SizeOfInt == 4) and ReadNextByte4() or ReadNextByte8();
- print(LineDefined, LineEnded);
- -- The following is the number of upvalues the function had, and number of parameters:
- local NumOfUpvalues = ReadNextByte();
- local NumOfParameters = ReadNextByte();
- print(NumOfUpvalues, NumOfParameters);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement