Beispiel #1
0
 /// <summary>
 /// This does the actual searching of the hashes from the above function. Designed to run on multiple threads
 /// </summary>
 private void FindString()
 {
     while (CompileList.Count > 0)
     {
         Tuple <string, bool> scriptToSearch;
         lock (Program.ThreadLock)
         {
             scriptToSearch = CompileList.Dequeue();
         }
         using (Stream ScriptFile = File.OpenRead(scriptToSearch.Item1))
         {
             ScriptHeader header = ScriptHeader.Generate(ScriptFile, scriptToSearch.Item2);
             StringTable  table  = new StringTable(ScriptFile, header.StringTableOffsets, header.StringBlocks, header.StringsSize);
             foreach (string str in table.Values)
             {
                 if (HashToFind.Contains(Utils.jenkins_one_at_a_time_hash(str)))
                 {
                     if (IsLower(str))
                     {
                         continue;
                     }
                     lock (Program.ThreadLock)
                     {
                         if (!FoundStrings.Any(item => item.Item2 == str))
                         {
                             FoundStrings.Add(new Tuple <uint, string>(Utils.jenkins_one_at_a_time_hash(str), str));
                         }
                     }
                 }
             }
         }
     }
     Program.ThreadCount--;
 }
        static ScriptHeader GenerateConsoleHeader(Stream scriptStream)
        {
            ScriptHeader header = new ScriptHeader();

            IO.Reader reader = new IO.Reader(scriptStream);
            scriptStream.Seek(0, SeekOrigin.Begin);
            header.RSC7Offset = (reader.SReadUInt32() == 0x52534337) ? 0x10 : 0x0;
            scriptStream.Seek(header.RSC7Offset, SeekOrigin.Begin);
            header.Magic            = reader.SReadInt32();   //0x0
            header.SubHeader        = reader.SReadPointer(); //0x4
            header.CodeBlocksOffset = reader.SReadPointer(); //0x8
            header.GlobalsVersion   = reader.SReadInt32();   //0x C
            header.CodeLength       = reader.SReadInt32();   //0x10
            header.ParameterCount   = reader.SReadInt32();   //0x14
            header.StaticsCount     = reader.SReadInt32();   //0x18
            header.GlobalsCount     = reader.SReadInt32();   //0x1C
            header.NativesCount     = reader.SReadInt32();   //0x20
            header.StaticsOffset    = reader.SReadPointer(); //0x24
            header.GlobalsOffset    = reader.SReadPointer(); //0x28
            header.NativesOffset    = reader.SReadPointer(); //0x2C
            header.Null1            = reader.SReadInt32();   //0x30
            header.Null2            = reader.SReadInt32();   //0x34
            header.NameHash         = reader.SReadInt32();
            header.Null3            = reader.SReadInt32();   //0x38
            header.ScriptNameOffset = reader.SReadPointer(); //0x40
            header.StringsOffset    = reader.SReadPointer(); //0x44
            header.StringsSize      = reader.SReadInt32();   //0x48
            header.Null4            = reader.ReadInt32();    //0x4C

            header.StringBlocks = (header.StringsSize + 0x3FFF) >> 14;
            header.CodeBlocks   = (header.CodeLength + 0x3FFF) >> 14;

            header.StringTableOffsets = new Int32[header.StringBlocks];
            scriptStream.Seek(header.StringsOffset + header.RSC7Offset, SeekOrigin.Begin);
            for (int i = 0; i < header.StringBlocks; i++)
            {
                header.StringTableOffsets[i] = reader.SReadPointer() + header.RSC7Offset;
            }


            header.CodeTableOffsets = new Int32[header.CodeBlocks];
            scriptStream.Seek(header.CodeBlocksOffset + header.RSC7Offset, SeekOrigin.Begin);
            for (int i = 0; i < header.CodeBlocks; i++)
            {
                header.CodeTableOffsets[i] = reader.SReadPointer() + header.RSC7Offset;
            }
            scriptStream.Position = header.ScriptNameOffset + header.RSC7Offset;
            int data = scriptStream.ReadByte();

            header.ScriptName = "";
            while (data != 0 && data != -1)
            {
                header.ScriptName += (char)data;
                data = scriptStream.ReadByte();
            }
            return(header);
        }
        public ScriptFile(Stream scriptStream, OpcodeSet opcodeSet)
        {
            file    = scriptStream;
            CodeSet = opcodeSet;

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

            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);
            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);
            }
        }
Beispiel #4
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();
     }
 }
        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();
                }
            }
        }