Object readConstant(BuffReader buf) { switch (buf.ReadByte()) { case TAG_NIL: return(null); case TAG_BOOLEAN: return(buf.ReadByte() != 0); case TAG_INTEGER: return(buf.ReadInt64()); case TAG_NUMBER: return(buf.ReadDouble()); case TAG_SHORT_STR: return(buf.ReadLuaString()); case TAG_LONG_STR: return(buf.ReadLuaString()); default: { } return(null); } }
void readConstants(BuffReader buf) { Constants = new Object[buf.ReadInt32()]; for (int i = 0; i < Constants.Length; i++) { Constants[i] = readConstant(buf); } }
void readUpvalueNames(BuffReader buf) { UpvalueNames = new string[buf.ReadInt32()]; for (int i = 0; i < UpvalueNames.Length; i++) { UpvalueNames[i] = buf.ReadLuaString(); } }
void readCode(BuffReader buf) { Code = new int[buf.ReadInt32()]; for (int i = 0; i < Code.Length; i++) { Code[i] = buf.ReadInt32(); } }
void readLineInfo(BuffReader buf) { LineInfo = new int[buf.ReadInt32()]; for (int i = 0; i < LineInfo.Length; i++) { LineInfo[i] = buf.ReadInt32(); } }
void readLocVars(BuffReader buf) { LocVars = new LocVar[buf.ReadInt32()]; for (int i = 0; i < LocVars.Length; i++) { LocVars[i] = new LocVar(); LocVars[i].Read(buf); } }
void readProtos(BuffReader buf, string parentSource) { Protos = new Prototype[buf.ReadInt32()]; for (int i = 0; i < Protos.Length; i++) { Protos[i] = new Prototype(); Protos[i].Read(buf, parentSource); } }
void readUpvalues(BuffReader buf) { Upvalues = new Upvalue[buf.ReadInt32()]; for (int i = 0; i < Upvalues.Length; i++) { Upvalues[i] = new Upvalue(); Upvalues[i].Read(buf); } }
public static Prototype Undump(byte[] data) { BuffReader reader = new BuffReader(data); checkHead(reader); reader.ReadByte(); Prototype mainFunc = new Prototype(); mainFunc.Read(reader, ""); return(mainFunc); }
public void Read(BuffReader buffReader, string parentSource) { Source = buffReader.ReadLuaString(); if (string.Empty == Source) { Source = parentSource; } LineDefined = buffReader.ReadInt32(); LastLineDefined = buffReader.ReadInt32(); NumParams = buffReader.ReadByte(); IsVararg = buffReader.ReadByte(); MaxStackSize = buffReader.ReadByte(); readCode(buffReader); readConstants(buffReader); readUpvalues(buffReader); readProtos(buffReader, Source); readLineInfo(buffReader); readLocVars(buffReader); readUpvalueNames(buffReader); }
public void Read(BuffReader reader) { Instack = reader.ReadByte(); Idx = reader.ReadByte(); }
public void Read(BuffReader buf) { VarName = buf.ReadLuaString(); StartPc = buf.ReadInt32(); EndPc = buf.ReadInt32(); }
static void checkHead(BuffReader buf) { if (!Enumerable.SequenceEqual(LUA_SIGNATURE, buf.ReadBytes(4))) { Console.WriteLine("!Array.Equals(LUA_SIGNATURE, buf.ReadBytes(4))"); for (int i = 0; i < 4; i++) { Console.WriteLine($"byte {i}: {LUA_SIGNATURE[i]}"); } return; } if (buf.ReadByte() != LUAC_VERSION) { Console.WriteLine($"Version {LUAC_VERSION}"); Console.WriteLine("buf.ReadByte() != LUAC_VERSION"); } if (buf.ReadByte() != LUAC_FORMAT) { Console.WriteLine("buf.ReadByte() != LUAC_FORMAT"); } if (!Enumerable.SequenceEqual(LUAC_DATA, buf.ReadBytes(6))) { Console.WriteLine("!Enumerable.SequenceEqual(LUAC_DATA, buf.ReadBytes(6))"); } if (buf.ReadByte() != CINT_SIZE) { Console.WriteLine("buf.ReadByte() != CINT_SIZE"); } if (buf.ReadByte() != CSZIET_SIZE) { Console.WriteLine($"CSZIET_SIZE {CSZIET_SIZE}"); Console.WriteLine("buf.ReadByte() != CSZIET_SIZE"); } if (buf.ReadByte() != INSTRUCTION_SIZE) { Console.WriteLine("buf.ReadByte() != INSTRUCTION_SIZE"); } if (buf.ReadByte() != LUA_INTEGER_SIZE) { Console.WriteLine("buf.ReadByte() != LUA_INTEGER_SIZE"); } if (buf.ReadByte() != LUA_NUMBER_SIZE) { Console.WriteLine("buf.ReadByte() != LUA_NUMBER_SIZE"); } if (buf.ReadInt64() != LUAC_INT) { Console.WriteLine("buf.ReadInt64() != LUAC_INT"); } if (buf.ReadDouble() != LUAC_NUM) { Console.WriteLine("buf.ReadDouble() != LUAC_NUM"); } }