public static string ReadLuaString(BinaryReaderEx br, LuaVersion version, bool sizeminusone = true) { ulong length; if (version == LuaVersion.Lua53Smash) { length = br.ReadByte(); if (!sizeminusone) { length++; } } else { length = br.ReadUInt64(); } if (length > 0) { string ret; if (version == LuaVersion.Lua50) { ret = br.ReadShiftJIS((int)length - 1); } else { ret = br.ReadUTF8((int)length - 1); } if (version != LuaVersion.Lua53Smash) { br.AssertByte(0); // Eat null terminator } return(ret); } return(null); }
public Header(BinaryReaderEx br) { br.ReadUInt32(); // Magic Version = br.ReadByte(); if (Version == 0x50) { LuaVersion = LuaVersion.Lua50; } else if (Version == 0x51) { byte format = br.AssertByte(0x0E); // HKS LuaVersion = LuaVersion.Lua51HKS; } else if (Version == 0x53) { LuaVersion = LuaVersion.Lua53Smash; br.ReadBytes(7); //unk } if (LuaVersion == LuaVersion.Lua53Smash) { Endianess = 0; } else { Endianess = br.ReadByte(); } IntSize = br.ReadByte(); LongSize = br.ReadByte(); InstructionSize = br.ReadByte(); if (LuaVersion == LuaVersion.Lua50) { OpSize = br.ReadByte(); ASize = br.ReadByte(); BSize = br.ReadByte(); CSize = br.ReadByte(); } LuaNumberSize = br.ReadByte(); if (LuaVersion == LuaVersion.Lua53Smash) { FloatSize = br.ReadByte(); } if (LuaVersion == LuaVersion.Lua50) { br.ReadDouble(); // test number } else if (LuaVersion == LuaVersion.Lua53Smash) { br.ReadUInt64(); // test int br.ReadSingle(); // test number } else { br.ReadByte(); // Isintegral } }
public LuaFile(BinaryReaderEx br) { LuaHeader = new Header(br); Version = LuaHeader.LuaVersion; if (Version == LuaVersion.Lua51HKS) { br.BigEndian = true; br.Position = 0xee; // lel } MainFunction = new Function(this, Version, br); }
public LuaFile(BinaryReaderEx br) { LuaHeader = new Header(br); Version = LuaHeader.LuaVersion; if (Version == LuaVersion.Lua51HKS) { br.BigEndian = true; br.Position = 0xee; // lel } else if (Version == LuaVersion.Lua53Smash) { // read "upval size" br.ReadByte(); } MainFunction = new Function(this, Version, br); }
public Constant(LuaFile file, BinaryReaderEx br, LuaVersion version) { byte type = br.ReadByte(); if (type == 1) { Type = ConstantType.TypeBoolean; BoolValue = br.ReadBoolean(); } if (type == 3) { if (version == LuaVersion.Lua50) { NumberValue = br.ReadDouble(); } else { NumberValue = br.ReadSingle(); } Type = ConstantType.TypeNumber; } else if (type == 4) { StringValue = LuaFile.ReadLuaString(br, version); Type = ConstantType.TypeString; } else if (type == 0x13) { IntValue = br.ReadUInt64(); Type = ConstantType.TypeInt; } else { Type = ConstantType.TypeNil; } }
public VersionWrapper(LuaVersion version, string verString) { Version = version; m_verString = verString; }
private void LuaVerBoxSelectedIndexChanged(object sender, EventArgs e) { var wrapper = (VersionWrapper)m_luaVerBox.SelectedItem; CurrentLuaVersion = wrapper.Version; }
public Function(LuaFile file, LuaVersion version, BinaryReaderEx br) { if (version == LuaVersion.Lua53Smash) { ReadLua53Smash(file, br); } else if (version == LuaVersion.Lua50) { Name = LuaFile.ReadLuaString(br, version); LineDefined = br.ReadInt32(); Nups = br.ReadByte(); NumParams = br.ReadByte(); IsVarArg = br.ReadByte(); MaxStackSize = br.ReadByte(); SizeLineInfo = br.ReadInt32(); // Eat line numbers br.ReadInt32s(SizeLineInfo); LocalVarsCount = br.ReadInt32(); Locals = new Local[LocalVarsCount]; LocalMap = new Dictionary <int, List <Local> >(); for (int i = 0; i < LocalVarsCount; i++) { Locals[i] = new Local(br, version); if (!Locals[i].Name.StartsWith("(")) { if (!LocalMap.ContainsKey(Locals[i].Start)) { LocalMap[Locals[i].Start] = new List <Local>(); } LocalMap[Locals[i].Start].Add(Locals[i]); } } UpValuesCount = br.ReadInt32(); UpvalueNames = new UpvalueName[UpValuesCount]; for (int i = 0; i < UpValuesCount; i++) { UpvalueNames[i] = new UpvalueName(br, version); } int constantsCount = br.ReadInt32(); Constants = new Constant[constantsCount]; for (int i = 0; i < constantsCount; i++) { Constants[i] = new Constant(file, br, version); } int funcCount = br.ReadInt32(); ChildFunctions = new Function[funcCount]; for (int i = 0; i < funcCount; i++) { ChildFunctions[i] = new Function(file, version, br); } int bytecodeCount = br.ReadInt32(); Bytecode = br.ReadBytes(bytecodeCount * 4); } else if (version == LuaVersion.Lua51HKS) { // Thanks @horkrux for reverse engineering this br.ReadInt32(); NumParams = br.ReadUInt32(); br.ReadByte(); // Unk NumSlots = br.ReadUInt32(); br.ReadUInt32(); // unk int bytecodeCount = br.ReadInt32(); br.Pad(4); Bytecode = br.ReadBytes(bytecodeCount * 4); int constantsCount = br.ReadInt32(); ConstantsHKS = new ConstantHKS[constantsCount]; for (int i = 0; i < constantsCount; i++) { ConstantsHKS[i] = new ConstantHKS(file, br); } br.ReadInt32(); // unk br.ReadInt32(); // unk LocalVarsCount = br.ReadInt32(); UpValuesCount = br.ReadInt32(); br.ReadInt32(); // line begin br.ReadInt32(); // line end Path = ReadLuaString(br, version); Name = ReadLuaString(br, version); // Eat line numbers br.ReadInt32s(bytecodeCount); Locals = new Local[LocalVarsCount]; LocalMap = new Dictionary <int, List <Local> >(); for (int i = 0; i < LocalVarsCount; i++) { Locals[i] = new Local(br, version); if (!Locals[i].Name.StartsWith("(")) { if (!LocalMap.ContainsKey(Locals[i].Start)) { LocalMap[Locals[i].Start] = new List <Local>(); } LocalMap[Locals[i].Start].Add(Locals[i]); } } UpvalueNames = new UpvalueName[UpValuesCount]; for (int i = 0; i < UpValuesCount; i++) { UpvalueNames[i] = new UpvalueName(br, version); } int funcCount = br.ReadInt32(); ChildFunctions = new Function[funcCount]; for (int i = 0; i < funcCount; i++) { ChildFunctions[i] = new Function(file, version, br); } } }
public UpvalueName(BinaryReaderEx br, LuaVersion version) { Name = ReadLuaString(br, version); }
public Local(BinaryReaderEx br, LuaVersion version) { Name = ReadLuaString(br, version, false); Start = br.ReadInt32(); End = br.ReadInt32(); }