예제 #1
0
 /// <summary>
 /// Returns a decompiled chunk, with info based upon a default LuaFile
 /// </summary>
 /// <param name="chunk"></param>
 /// <returns></returns>
 public static Chunk DisassembleChunk(string c)
 {
     chunk      = c;
     index      = 0;
     file       = new LuaFile();
     loadNumber = PlatformConfig.GetNumberTypeConvertFrom(file);
     if (chunk == null || string.IsNullOrWhiteSpace(chunk))
     {
         throw new Exception("chunk is empty");
     }
     return(ReadFunction());
 }
예제 #2
0
        /// <summary>
        /// Returns a disassembled LuaFile
        /// </summary>
        /// <param name="c"></param>
        /// <returns></returns>
        public static LuaFile Disassemble(string c)
        {
            chunk = c;
            index = 0;
            file  = new LuaFile();
            Disassembler.loadNumber = null;
            if (chunk == null || string.IsNullOrWhiteSpace(chunk))
            {
                throw new Exception("chunk is empty");
            }

            file.Identifier = GetString(4); // \027Lua
            if (file.Identifier != (char)27 + "Lua")
            {
                throw new Exception("Not a valid Lua bytecode chunk");
            }

            file.Version = ReadInt8(); // 0x51
            if (file.Version != 0x51)
            {
                throw new Exception(string.Format("Invalid bytecode version, 0x51 expected, got 0x{0:X}", file.Version));
            }
            int fmt = ReadInt8();

            file.Format       = fmt == 0 ? Format.Official : Format.Unofficial;
            file.FormatNumber = fmt;
            if (file.Format == Format.Unofficial)
            {
                throw new Exception("Unknown binary chunk format");
            }

            file.BigEndian              = ReadInt8() == 0;
            file.IntegerSize            = ReadInt8();
            file.SizeT                  = ReadInt8();
            file.InstructionSize        = ReadInt8();
            file.NumberSize             = ReadInt8();
            file.IsFloatingPointNumbers = ReadInt8() == 0;
            loadNumber                  = PlatformConfig.GetNumberTypeConvertFrom(file);
            if (file.InstructionSize != 4)
            {
                throw new Exception("Unsupported instruction size '" + file.InstructionSize + "', expected '4'");
            }
            file.Main = ReadFunction();
            return(file);
        }