示例#1
0
        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);
            }
        }
示例#2
0
 void readConstants(BuffReader buf)
 {
     Constants = new Object[buf.ReadInt32()];
     for (int i = 0; i < Constants.Length; i++)
     {
         Constants[i] = readConstant(buf);
     }
 }
示例#3
0
 void readUpvalueNames(BuffReader buf)
 {
     UpvalueNames = new string[buf.ReadInt32()];
     for (int i = 0; i < UpvalueNames.Length; i++)
     {
         UpvalueNames[i] = buf.ReadLuaString();
     }
 }
示例#4
0
 void readCode(BuffReader buf)
 {
     Code = new int[buf.ReadInt32()];
     for (int i = 0; i < Code.Length; i++)
     {
         Code[i] = buf.ReadInt32();
     }
 }
示例#5
0
 void readLineInfo(BuffReader buf)
 {
     LineInfo = new int[buf.ReadInt32()];
     for (int i = 0; i < LineInfo.Length; i++)
     {
         LineInfo[i] = buf.ReadInt32();
     }
 }
示例#6
0
 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);
     }
 }
示例#7
0
 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);
     }
 }
示例#8
0
 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);
     }
 }
示例#9
0
        public static Prototype Undump(byte[] data)
        {
            BuffReader reader = new BuffReader(data);

            checkHead(reader);
            reader.ReadByte();
            Prototype mainFunc = new Prototype();

            mainFunc.Read(reader, "");
            return(mainFunc);
        }
示例#10
0
        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);
        }
示例#11
0
 public void Read(BuffReader reader)
 {
     Instack = reader.ReadByte();
     Idx     = reader.ReadByte();
 }
示例#12
0
 public void Read(BuffReader buf)
 {
     VarName = buf.ReadLuaString();
     StartPc = buf.ReadInt32();
     EndPc   = buf.ReadInt32();
 }
示例#13
0
        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");
            }
        }