public ScriptFile Predecode()
        {
            GetStaticInfo();
            GetFunctions();
            foreach (Function func in Functions)
            {
                func.PreDecode();
            }
            Statics.checkvars();

            int count = 0;

            while (PredecodeFunctions())
            {
                count++;
                if (count > 10000)
                {
                    throw new Exception("decodeinsructionsforvarinfo: infinite loop");
                }
            }
            return(this);
        }
Пример #2
0
 public ScriptFile(Stream scriptStream, bool Console)
 {
     ConsoleVer  = Console;
     file        = scriptStream;
     Header      = ScriptHeader.Generate(scriptStream, Console);
     StringTable = new StringTable(scriptStream, Header.StringTableOffsets, Header.StringBlocks, Header.StringsSize);
     if (Console)
     {
         NativeTable = new NativeTable(scriptStream, Header.NativesOffset + Header.RSC7Offset, Header.NativesCount);
     }
     else
     {
         X64NativeTable = new X64NativeTable(scriptStream, Header.NativesOffset + Header.RSC7Offset, Header.NativesCount, Header.CodeLength);
     }
     name      = Header.ScriptName;
     CodeTable = new List <byte>();
     for (int i = 0; i < Header.CodeBlocks; i++)
     {
         int    tablesize = ((i + 1) * 0x4000 >= Header.CodeLength) ? Header.CodeLength % 0x4000 : 0x4000;
         byte[] working   = new byte[tablesize];
         scriptStream.Position = Header.CodeTableOffsets[i];
         scriptStream.Read(working, 0, tablesize);
         CodeTable.AddRange(working);
     }
     GetStaticInfo();
     Functions   = new List <Function>();
     FunctionLoc = new Dictionary <int, FunctionName>();
     GetFunctions();
     foreach (Function func in Functions)
     {
         func.PreDecode();
     }
     Statics.checkvars();
     foreach (Function func in Functions)
     {
         func.Decode();
     }
 }
Пример #3
0
        public ScriptFile(Stream scriptStream, OpcodeSet opcodeSet)
        {
            file    = scriptStream;
            CodeSet = opcodeSet;

            CodeTable    = new List <byte>();
            Functions    = new List <Function>();
            AggFunctions = new List <Function>();
            FunctionLoc  = new Dictionary <int, FunctionName>();

            Header         = ScriptHeader.Generate(scriptStream);
            StringTable    = new StringTable(scriptStream, Header.StringTableOffsets, Header.StringBlocks, Header.StringsSize);
            X64NativeTable = new X64NativeTable(scriptStream, Header.NativesOffset + Header.RSC7Offset, Header.NativesCount, Header.CodeLength);
            name           = Header.ScriptName;

            for (int i = 0; i < Header.CodeBlocks; i++)
            {
                int    tablesize = ((i + 1) * 0x4000 >= Header.CodeLength) ? Header.CodeLength % 0x4000 : 0x4000;
                byte[] working   = new byte[tablesize];
                scriptStream.Position = Header.CodeTableOffsets[i];
                scriptStream.Read(working, 0, tablesize);
                CodeTable.AddRange(working);
            }

            GetStaticInfo();
            GetFunctions();
            foreach (Function func in Functions)
            {
                func.PreDecode();
            }
            Statics.checkvars();

            bool dirty = true;

            while (dirty)
            {
                dirty = false;
                foreach (Function func in Functions)
                {
                    if (func.Dirty)
                    {
                        dirty      = true;
                        func.Dirty = false;
                        func.decodeinsructionsforvarinfo();
                    }
                }
            }

            if (Program.AggregateFunctions)
            {
                foreach (Function func in AggFunctions)
                {
                    func.PreDecode();
                }
            }
            foreach (Function func in Functions)
            {
                func.Decode();
            }
            if (Program.AggregateFunctions)
            {
                foreach (Function func in AggFunctions)
                {
                    func.Decode();
                }
            }
        }