Beispiel #1
0
        public void loadfile()
        {
            Natives = new Dictionary <ulong, Tuple <Stack.DataType, Stack.DataType[]> >();
            Stream natfile;
            string file = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location),
                                       "x64nativeinfo.dat");

            if (File.Exists(file))
            {
                natfile = File.OpenRead(file);
            }
            else
            {
                natfile = new MemoryStream(Properties.Resources.x64nativeinfo);
            }
            IO.Reader reader = new IO.Reader(natfile, false);
            while (natfile.Position < natfile.Length)
            {
                ulong            native     = reader.ReadUInt64();
                Stack.DataType   returntype = Types.getatindex(reader.ReadByte());
                byte             count      = reader.ReadByte();
                Stack.DataType[] param      = new Stack.DataType[count];
                for (byte i = 0; i < count; i++)
                {
                    param[i] = Types.getatindex(reader.ReadByte());
                }
                Natives.Add(native, new Tuple <Stack.DataType, Stack.DataType[]>(returntype, param));
            }
        }
        public NativeTable(Stream scriptFile, int position, int length)
        {
            IO.Reader reader = new IO.Reader(scriptFile, true);
            int       count  = 0;
            uint      nat;

            reader.BaseStream.Position = position;
            _natives    = new List <string>();
            _nativehash = new List <uint>();
            while (count < length)
            {
                nat = reader.SReadUInt32();
                _nativehash.Add(nat);
                if (Program.nativefile.ContainsKey(nat))
                {
                    _natives.Add(Program.nativefile[nat]);
                }
                else
                {
                    string temps = nat.ToString("X");
                    while (temps.Length < 8)
                    {
                        temps = "0" + temps;
                    }
                    _natives.Add("unk_0x" + temps);
                }
                count++;
            }
        }
Beispiel #3
0
        public void loadfile()
        {
            Natives = new Dictionary <uint, Tuple <Stack.DataType, Stack.DataType[]> >();
            string file = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location),
                                       "nativeinfo.dat");

            if (!File.Exists(file))
            {
                return;
            }
            Stream natfile = File.OpenRead(file);

            IO.Reader reader = new IO.Reader(natfile, true);
            while (natfile.Position < natfile.Length)
            {
                uint             native     = reader.ReadUInt32();
                Stack.DataType   returntype = Types.getatindex(reader.ReadByte());
                byte             count      = reader.ReadByte();
                Stack.DataType[] param      = new Stack.DataType[count];
                for (byte i = 0; i < count; i++)
                {
                    param[i] = Types.getatindex(reader.ReadByte());
                }
                Natives.Add(native, new Tuple <Stack.DataType, Stack.DataType[]>(returntype, param));
            }
        }
        public X64NativeTable(Stream scriptFile, int position, int length, int codeSize)
        {
            IO.Reader reader = new IO.Reader(scriptFile, false);
            int       count  = 0;
            ulong     nat;

            reader.BaseStream.Position = position;
            _natives    = new List <string>();
            _nativehash = new List <ulong>();
            while (count < length)
            {
                //GTA V PC natives arent stored sequentially in the table. Each native needs a bitwise rotate depending on its position and codetable size
                //Then the natives needs to go back through translation tables to get to their hash as defined in the vanilla game version
                //or the earliest game version that native was introduced in.
                //Just some of the steps Rockstar take to make reverse engineering harder
                nat = Program.x64nativefile.TranslateHash(rotl(reader.ReadUInt64(), codeSize + count));
                _nativehash.Add(nat);

                if (Program.x64nativefile.ContainsKey(nat) && !Translate)
                {
                    _natives.Add(Program.x64nativefile[nat]);
                }
                else
                {
                    string temps = nat.ToString("X");
                    while (temps.Length < 16)
                    {
                        temps = "0" + temps;
                    }
                    _natives.Add("unk_0x" + temps);
                }
                count++;
            }
        }
        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);
        }
 private void GetStaticInfo()
 {
     Statics = new Vars_Info(Vars_Info.ListType.Statics);
     Statics.SetScriptParamCount(Header.ParameterCount);
     IO.Reader reader = new IO.Reader(file);
     reader.BaseStream.Position = Header.StaticsOffset + Header.RSC7Offset;
     for (int count = 0; count < Header.StaticsCount; count++)
     {
         Statics.AddVar(Program.IsBit32 ? reader.CReadInt32() : reader.ReadInt64());
     }
 }
Beispiel #7
0
        public X64NativeTable(Stream scriptFile, int position, int length, int codeSize)
        {
            scriptFile.Position = position;

            Stream stream;

            if (Program.RDRNativeCipher)
            {
                stream = new MemoryStream();
                byte carry = (byte)codeSize;
                for (int i = 0; i < length * 8; ++i)
                {
                    int b;
                    if ((b = scriptFile.ReadByte()) == -1)
                    {
                        throw new EndOfStreamException("Invalid Scriptfile!");
                    }

                    byte xordeciphed = (byte)(carry ^ (byte)b);
                    carry = (byte)b;
                    stream.WriteByte(xordeciphed);
                }
                stream.Position = 0;
            }
            else
            {
                stream = scriptFile;
            }

            IO.Reader reader = new IO.Reader(stream);
            int       count  = 0;
            ulong     nat;

            while (count < length)
            {
                //GTA V PC natives arent stored sequentially in the table. Each native needs a bitwise rotate depending on its position and codetable size
                //Then the natives needs to go back through translation tables to get to their hash as defined in the vanilla game version
                //or the earliest game version that native was introduced in.
                //Just some of the steps Rockstar take to make reverse engineering harder
                nat = Program.IsBit32 ? reader.CReadUInt32() : Utils.RotateLeft(reader.ReadUInt64(), (codeSize + count) & 0x3F);

                _nativehash.Add(nat);
                if (Program.X64npi.ContainsKey(nat))
                {
                    _natives.Add(Program.X64npi[nat].Display);
                }
                else
                {
                    _natives.Add(Program.NativeName(Native.UnkPrefix) + Native.CreateNativeHash(nat));
                }
                count++;
            }
        }
 private void GetStaticInfo()
 {
     Statics = new Vars_Info(Vars_Info.ListType.Statics);
     IO.Reader reader = new IO.Reader(file, ConsoleVer);
     reader.BaseStream.Position = Header.StaticsOffset + Header.RSC7Offset;
     for (int count = 0; count < Header.StaticsCount; count++)
     {
         if (ConsoleVer)
         {
             Statics.AddVar(reader.SReadInt32());
         }
         else
         {
             Statics.AddVar(reader.ReadInt64());
         }
     }
 }