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++;
            }
        }
Пример #2
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));
            }
        }
Пример #3
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++;
            }
        }