Example #1
0
        public bool ResolvePointerPath(HookProcess process)
        {
            IntPtr nextAddress = baseAddress;
            bool   asmStart    = false;

            foreach (var offset in PointerPath)
            {
                try {
                    baseAddress = new IntPtr(nextAddress.ToInt64() + offset);
                    if (baseAddress == IntPtr.Zero)
                    {
                        return(false);
                    }

                    if (!asmStart)
                    {
                        nextAddress = baseAddress + process.GetInt32(new IntPtr(baseAddress.ToInt64())) + 4;
                        asmStart    = true;
                    }
                    else
                    {
                        nextAddress = process.ReadPointer(baseAddress);
                    }
                } catch {
                    return(false);
                }
            }
            return(true);
        }
        public override object GetData(HookProcess process)
        {
            SigWorldData data = new SigWorldData {
                world = process.GetString(baseAddress, 0, 16)
            };

            return((object)data);
        }
Example #3
0
 public void EnsureArrayIndexes(HookProcess process)
 {
     Indexes.Clear();
     for (var i = 0; i < 1000; i++)
     {
         Indexes.Add((int)process.GetUInt(new IntPtr(ChatLogPointers.OffsetArrayStart + i * 4)));
     }
 }
Example #4
0
        public override object GetData(HookProcess process)
        {
            SigCharIdData data = new SigCharIdData {
                id = process.GetString(baseAddress, 0, 32),
            };

            return((object)data);
        }
Example #5
0
        public Memory(Process proc)
        {
            ffxivProcess = new HookProcess(proc);
            string pipename = string.Format("BmpPipe{0}", proc.Id);

            dataPipe = new NamedPipeServer <PipeData>(pipename);
            dataPipe.ClientConnected += ClientConnected;
            dataPipe.Start();
            Console.WriteLine(string.Format("Pipe name: {0}", pipename));
        }
Example #6
0
            public IEnumerable <List <byte> > ResolveEntries(HookProcess process, int offset, int length)
            {
                List <List <byte> > entries = new List <List <byte> >();

                for (var i = offset; i < length; i++)
                {
                    EnsureArrayIndexes(process);
                    var currentOffset = Indexes[i];
                    entries.Add(ResolveEntry(process, PreviousOffset, currentOffset));
                    PreviousOffset = currentOffset;
                }

                return(entries);
            }
        public override object GetData(HookProcess process)
        {
            var result = new SigPerfData();

            int entrySize  = 12;
            int numEntries = 99;

            byte[] performanceData = process.GetByteArray(baseAddress, entrySize * numEntries);

            for (int i = 0; i < numEntries; i++)
            {
                int offset = (i * entrySize);

                float animation  = BitConverter.TryToSingle(performanceData, offset + 0);
                byte  id         = performanceData[offset + 4];
                byte  unknown1   = performanceData[offset + 5];
                byte  variant    = performanceData[offset + 6];             // Animation (hand to left or right)
                byte  type       = performanceData[offset + 7];
                byte  status     = performanceData[offset + 8];
                byte  instrument = performanceData[offset + 9];
                int   unknown2   = BitConverter.TryToInt16(performanceData, offset + 10);

                if (id >= 0 && id <= 99)
                {
                    PerformanceData item = new PerformanceData();
                    item.Animation  = animation;
                    item.Unknown1   = (byte)unknown1;
                    item.Id         = (byte)id;
                    item.Variant    = (byte)variant;
                    item.Type       = (byte)type;
                    item.Status     = (Performance.Status)status;
                    item.Instrument = (Performance.Instrument)instrument;

                    if (!result.Performances.ContainsKey(id))
                    {
                        result.Performances[id] = item;
                    }
                }
            }
            return(result);
        }
        public override object GetData(HookProcess process)
        {
            IntPtr pointer  = (IntPtr)process.GetInt64(baseAddress);
            string chattext = string.Empty;

            if (pointer != IntPtr.Zero)
            {
                int len = process.GetInt32(pointer, Offsets["OffsetInputLength"]);
                if (len <= 501)  // ???
                {
                    IntPtr pointer2 = (IntPtr)process.GetInt64(pointer, Offsets["OffsetInputText"]);
                    if (pointer2 != IntPtr.Zero)
                    {
                        chattext = process.GetString(pointer2, 0, len);
                    }
                }
            }
            SigChatInputData data = new SigChatInputData {
                open = (pointer != IntPtr.Zero),
                text = chattext,
            };

            return((object)data);
        }
        public override object GetData(HookProcess process)
        {
            if (baseAddress.ToInt64() <= 6496)
            {
                return(null);
            }
            if (!Offsets.ContainsKey("SourceSize") || !Offsets.ContainsKey("EntityCount"))
            {
                Console.WriteLine("Couldn't find basic");
                return(null);
            }

            if (!Offsets.ContainsKey("ID") || !Offsets.ContainsKey("Type"))
            {
                Console.WriteLine("Couldn't find player basic");
                return(null);
            }

            var data = new SigActorsData();

            int sourceSize = (int)Offsets["SourceSize"];
            int limit      = (int)Offsets["EntityCount"];
            int ptrSize    = 8; // 64 bit

            byte[] characterAddressMap = process.GetByteArray(baseAddress, ptrSize * limit);
            //byte[] baseSource = process.GetByteArray(baseAddress, sourceSize);

            Dictionary <IntPtr, IntPtr> uniqueAddresses = new Dictionary <IntPtr, IntPtr>();
            IntPtr firstAddress = IntPtr.Zero;

            var firstTime = true;

            for (var i = 0; i < limit; i++)
            {
                IntPtr characterAddress = new IntPtr(BitConverter.TryToInt64(characterAddressMap, ptrSize * i));
                if (characterAddress == IntPtr.Zero)
                {
                    continue;
                }

                if (firstTime)
                {
                    firstAddress = characterAddress;
                    firstTime    = false;
                }

                uniqueAddresses[characterAddress] = characterAddress;
            }

            // Add everyone to removed
            foreach (KeyValuePair <uint, ActorData> kvp in tempActors)
            {
                data.removedActors.Add(kvp.Key, new ActorData()
                {
                    id = kvp.Value.id,
                });
            }

            foreach (KeyValuePair <IntPtr, IntPtr> kvp in uniqueAddresses)
            {
                var    characterAddress = new IntPtr(kvp.Value.ToInt64());
                byte[] playerSource     = process.GetByteArray(characterAddress, sourceSize);

                ActorData existing  = null;
                ActorData actorData = new ActorData()
                {
                    id = BitConverter.TryToUInt32(playerSource, Offsets["ID"]),
                };
                bool addActor = false;
                int  type     = playerSource[Offsets["Type"]];
                if (type == 0x01)   // Player
                {
                    if (data.removedActors.ContainsKey(actorData.id))
                    {
                        data.removedActors.Remove(actorData.id);
                        tempActors.TryGetValue(actorData.id, out existing);
                    }
                    else
                    {
                        addActor = true;
                    }

                    // Was used for TargetID
                    //var isFirstEntry = kvp.Value.ToInt64() == firstAddress.ToInt64();

                    if (true)
                    {
                        if (Offsets.TryGetValue("Name", out int nameid))
                        {
                            actorData.name = process.GetStringFromBytes(playerSource, nameid);
                        }
                        if (Offsets.TryGetValue("PerformanceID", out int perfid))
                        {
                            actorData.perfid = playerSource[perfid];
                        }
                    }

                    if (actorData.id != 0)
                    {
                        if (expiringActors.ContainsKey(actorData.id))
                        {
                            expiringActors.Remove(actorData.id);
                        }
                    }
                    else
                    {
                        // Removed
                        data.addedActors.Remove(actorData.id);
                        continue;
                    }

                    // Only getting memory, no checks?
                    //EnsureMapAndZone(entry);

                    /*
                     * if (isFirstEntry) {
                     *  if (targetAddress.ToInt64() > 0) {
                     *      byte[] targetInfoSource = MemoryHandler.Instance.GetByteArray(targetAddress, 128);
                     *      entry.TargetID = (int)BitConverter.TryToUInt32(targetInfoSource, MemoryHandler.Instance.Structures.ActorItem.ID);
                     *  }
                     * }
                     */

                    // If removed player, just continue
                    if (existing != null)
                    {
                        continue;
                    }
                    if (addActor)
                    {
                        if (!tempActors.ContainsKey(actorData.id))
                        {
                            tempActors.Add(actorData.id, actorData);
                        }
                        data.addedActors.Add(actorData.id, actorData);
                    }
                }
            }

            // Stale removal?

            DateTime now = DateTime.Now;
            TimeSpan staleActorRemovalTime = TimeSpan.FromSeconds(0.25);

            foreach (KeyValuePair <uint, ActorData> kvp2 in data.removedActors)
            {
                if (!expiringActors.ContainsKey(kvp2.Key))
                {
                    expiringActors[kvp2.Key] = now + staleActorRemovalTime;
                }
            }
            // check expiring list for stale actors
            foreach (KeyValuePair <uint, DateTime> kvp2 in expiringActors.ToList())
            {
                if (now > kvp2.Value)
                {
                    tempActors.Remove(kvp2.Key);
                    expiringActors.Remove(kvp2.Key);
                }
                else
                {
                    data.removedActors.Remove(kvp2.Key);
                }
            }

            data.currentActors = tempActors;
            return(data);
        }
Example #10
0
 public Memory(Process proc)
 {
     ffxivProcess = new HookProcess(proc);
 }
        // returns not found
        public static List <Signature> ResolveSignatures(HookProcess proc, ref List <Signature> signatures)
        {
            const int bufferSize      = 0x1200;
            const int regionIncrement = 0x1000;

            byte[]           buffer   = new byte[bufferSize];
            List <Signature> notFound = new List <Signature>(signatures);
            List <Signature> temp     = new List <Signature>();
            var regionCount           = 0;


            IntPtr baseAddress = proc.BaseAddress;
            IntPtr searchEnd   = proc.EndAddress;
            IntPtr searchStart = baseAddress;

            while (searchStart.ToInt64() < searchEnd.ToInt64())
            {
                try {
                    IntPtr lpNumberOfBytesRead;
                    var    regionSize = new IntPtr(bufferSize);
                    if (IntPtr.Add(searchStart, bufferSize).ToInt64() > searchEnd.ToInt64())
                    {
                        regionSize = (IntPtr)(searchEnd.ToInt64() - searchStart.ToInt64());
                    }

                    if (UnsafeNativeMethods.ReadProcessMemory(proc.Handle, searchStart, buffer, regionSize, out lpNumberOfBytesRead))
                    {
                        foreach (Signature signature in notFound)
                        {
                            string sig      = signature.Value;
                            byte[] sigbytes = SignatureToByte(sig, WildCardChar);
                            var    index    = FindSuperSignature(buffer, sigbytes);
                            if (index < 0)
                            {
                                temp.Add(signature);
                                continue;
                            }

                            var    baseResult   = new IntPtr((long)(baseAddress + regionCount * regionIncrement));
                            IntPtr searchResult = IntPtr.Add(baseResult, index + signature.Offset);

                            signature.baseAddress = new IntPtr(searchResult.ToInt64());
                        }

                        notFound = new List <Signature>(temp);
                        temp.Clear();
                    }

                    regionCount++;
                    searchStart = IntPtr.Add(searchStart, regionIncrement);
                }
                catch (Exception ex) {
                    //MemoryHandler.Instance.RaiseException(Logger, ex, true);
                    Console.WriteLine("Resolve signatures " + ex.ToString());
                }
            }
            // Clear out
            foreach (Signature signature in notFound)
            {
                signatures.Remove(signature);
            }

            List <Signature> fixedSignatures = new List <Signature>();

            foreach (Signature signature in signatures)
            {
                Signature sig = signature;
                if (!string.IsNullOrEmpty(sig.Type))
                {
                    Type t = Type.GetType("FFMemoryParser." + sig.Type);
                    if (t != null)
                    {
                        sig = (Signature)Activator.CreateInstance(t, sig);
                        sig.ResolvePointerPath(proc);
                        Console.WriteLine(string.Format("{0} {1} {2}", sig.Key, sig.baseAddress, sig.baseAddress));
                        fixedSignatures.Add(sig);
                        continue;
                    }
                }
                Console.WriteLine(string.Format("Could not find type for {0}", sig.Key));
            }
            signatures = fixedSignatures;
            return(notFound);
        }
        private static List <UnsafeNativeMethods.MEMORY_BASIC_INFORMATION> LoadRegions(HookProcess proc)
        {
            try {
                var    _regions = new List <UnsafeNativeMethods.MEMORY_BASIC_INFORMATION>();
                IntPtr address  = IntPtr.Zero;
                while (true)
                {
                    var info   = new UnsafeNativeMethods.MEMORY_BASIC_INFORMATION();
                    var result = UnsafeNativeMethods.VirtualQueryEx(proc.Handle, address, out info, (uint)Marshal.SizeOf(info));
                    if (result == 0)
                    {
                        break;
                    }

                    if (!proc.IsSystemModule(info.BaseAddress) && (info.State & MemCommit) != 0 && (info.Protect & Writable) != 0 && (info.Protect & PageGuard) == 0)
                    {
                        _regions.Add(info);
                    }
                    else
                    {
                        //MemoryHandler.Instance.RaiseException(Logger, new Exception(info.ToString()));
                    }

                    unchecked {
                        switch (IntPtr.Size)
                        {
                        case sizeof(int):
                            address = new IntPtr(info.BaseAddress.ToInt32() + info.RegionSize.ToInt32());
                            break;

                        default:
                            address = new IntPtr(info.BaseAddress.ToInt64() + info.RegionSize.ToInt64());
                            break;
                        }
                    }
                }
                return(_regions);
            } catch (Exception ex) {
                //MemoryHandler.Instance.RaiseException(Logger, ex, true);
                Console.WriteLine("DURRR ", ex.ToString());
                return(new List <UnsafeNativeMethods.MEMORY_BASIC_INFORMATION>());
            }
        }
Example #13
0
        public override object GetData(HookProcess process)
        {
            var result = new SigChatLogData();

            chatReader.PreviousArrayIndex = previousArrayIndex;
            chatReader.PreviousOffset     = previousOffset;

            if (baseAddress.ToInt64() <= 20)
            {
                return(result);
            }

            List <List <byte> > buffered = new List <List <byte> >();

            try {
                chatReader.Indexes.Clear();
                chatReader.ChatLogPointers = new ChatLogPointers {
                    LineCount        = (uint)process.GetUInt(baseAddress),
                    OffsetArrayStart = process.GetUInt(baseAddress, Offsets["OffsetArrayStart"]),
                    OffsetArrayPos   = process.GetUInt(baseAddress, Offsets["OffsetArrayPos"]),
                    OffsetArrayEnd   = process.GetUInt(baseAddress, Offsets["OffsetArrayEnd"]),
                    LogStart         = process.GetUInt(baseAddress, Offsets["LogStart"]),
                    LogNext          = process.GetUInt(baseAddress, Offsets["LogNext"]),
                    LogEnd           = process.GetUInt(baseAddress, Offsets["LogEnd"]),
                };

                chatReader.EnsureArrayIndexes(process);

                // Convenience
                ChatLogPointers ptrs = chatReader.ChatLogPointers;

                var currentArrayIndex = (ptrs.OffsetArrayPos - ptrs.OffsetArrayStart) / 4;
                if (chatReader.ChatLogFirstRun)
                {
                    chatReader.ChatLogFirstRun    = false;
                    chatReader.PreviousOffset     = chatReader.Indexes[(int)currentArrayIndex - 1];
                    chatReader.PreviousArrayIndex = (int)currentArrayIndex - 1;
                }
                else
                {
                    if (currentArrayIndex < chatReader.PreviousArrayIndex)
                    {
                        buffered.AddRange(chatReader.ResolveEntries(process, chatReader.PreviousArrayIndex, 1000));
                        chatReader.PreviousOffset     = 0;
                        chatReader.PreviousArrayIndex = 0;
                    }

                    if (chatReader.PreviousArrayIndex < currentArrayIndex)
                    {
                        buffered.AddRange(chatReader.ResolveEntries(process, chatReader.PreviousArrayIndex, (int)currentArrayIndex));
                    }

                    chatReader.PreviousArrayIndex = (int)currentArrayIndex;
                }
            }
            catch (Exception ex) {
                return(null);
            }

            foreach (List <byte> bytes in buffered.Where(b => b.Count > 0))
            {
                try {
                    ChatLogItem chatLogEntry = ChatEntry.Process(bytes.ToArray());
                    if (Regex.IsMatch(chatLogEntry.Combined, @"[\w\d]{4}::?.+"))
                    {
                        result.chatMessages.Add(chatLogEntry);
                    }
                }
                catch (Exception ex) {
                }
            }

            previousArrayIndex = chatReader.PreviousArrayIndex;
            previousOffset     = chatReader.PreviousOffset;

            return(result);
        }
Example #14
0
 private List <byte> ResolveEntry(HookProcess process, int offset, int length)
 {
     return(new List <byte>(process.GetByteArray(new IntPtr(ChatLogPointers.LogStart + offset), length - offset)));
 }
Example #15
0
 public virtual object GetData(HookProcess process)
 {
     return(null);
 }