Example #1
0
        public T[] Read <T>(MemoryAddress address, int count)
        {
            var snapshotAddress = ToSnapshotAddress(address);

            if (TypeHelper <T> .IsMemoryObjectType)
            {
                var array      = BaseMemory.Reader.Read <T>(address, count);
                var itemOffset = snapshotAddress;
                for (int i = 0; i < count; i++)
                {
                    (array[i] as MemoryObject).SetSnapshot(
                        SnapshotReader.Segment.Array,
                        SnapshotReader.Segment.Offset + itemOffset,
                        SnapshotReader.Segment.Array.Length - (SnapshotReader.Segment.Offset + itemOffset));
                    itemOffset += TypeHelper <T> .SizeOf;
                }
                return(array);
            }
            else if (TypeHelper <T> .IsMemoryPointerType)
            {
                // It is important that a pointer doesn't get a snapshot as context!
                var array = new T[count];
                for (int i = 0; i < count; i++)
                {
                    array[i] = (T)MemoryPointerFactory.Create <T>(BaseMemory,
                                                                  SnapshotReader.ReadMemoryAddress(snapshotAddress + i * BaseMemory.Reader.PointerSize));
                }
                return(array);
            }
            return(SnapshotReader.Read <T>(snapshotAddress, count));
        }
Example #2
0
        public virtual T Read <T>(int offset)
        {
            if (!TypeHelper <T> .IsTypeSupportedByMemoryReader)
            {
                throw new NotSupportedException();
            }

            var snapshot = Snapshot;

            if (snapshot != null)
            {
                if (TypeHelper <T> .IsMemoryObjectType)
                {
                    var value = Memory.Reader.Read <T>(GetAbsoluteAddress(offset));
                    (value as MemoryObject).SetSnapshot(
                        snapshot.Segment.Array,
                        snapshot.Segment.Offset + offset,
                        TypeHelper <T> .SizeOf);
                    return(value);
                }
                else if (TypeHelper <T> .IsMemoryPointerType)
                {
                    // It is important that a pointer doesn't get a snapshot as context!
                    return((T)MemoryPointerFactory.Create <T>(Memory,
                                                              ReadMemoryAddress(offset)));
                }
                return(snapshot.Read <T>(offset));
            }
            return(Memory.Reader.Read <T>(GetAbsoluteAddress(offset)));
        }
Example #3
0
        public virtual T[] Read <T>(int offset, int count)
        {
            if (!TypeHelper <T> .IsTypeSupportedByMemoryReader)
            {
                throw new NotSupportedException();
            }

            var snapshot = Snapshot;

            if (snapshot != null)
            {
                if (TypeHelper <T> .IsMemoryObjectType)
                {
                    var array      = Memory.Reader.Read <T>(GetAbsoluteAddress(offset), count);
                    var itemOffset = offset;
                    for (int i = 0; i < count; i++)
                    {
                        (array[i] as MemoryObject).SetSnapshot(
                            snapshot.Segment.Array,
                            snapshot.Segment.Offset + itemOffset,
                            TypeHelper <T> .SizeOf);
                        itemOffset += TypeHelper <T> .SizeOf;
                    }
                    return(array);
                }

                else if (TypeHelper <T> .IsMemoryPointerType)
                {
                    // It is important that a pointer doesn't get a snapshot as context!
                    var array = new T[count];
                    for (int i = 0; i < count; i++)
                    {
                        array[i] = (T)MemoryPointerFactory.Create <T>(Memory,
                                                                      ReadMemoryAddress(offset + i * Memory.Reader.PointerSize));
                    }
                    return(array);
                }
                return(snapshot.Read <T>(offset, count));
            }
            return(Memory.Reader.Read <T>(GetAbsoluteAddress(offset), count));
        }
Example #4
0
        public T Read <T>(MemoryAddress address)
        {
            var snapshotAddress = ToSnapshotAddress(address);

            if (TypeHelper <T> .IsMemoryObjectType)
            {
                var value = BaseMemory.Reader.Read <T>(address);
                (value as MemoryObject).SetSnapshot(
                    SnapshotReader.Segment.Array,
                    SnapshotReader.Segment.Offset + snapshotAddress,
                    SnapshotReader.Segment.Array.Length - (SnapshotReader.Segment.Offset + snapshotAddress));
                return(value);
            }
            else if (TypeHelper <T> .IsMemoryPointerType)
            {
                // It is important that a pointer doesn't get a snapshot as context!
                return((T)MemoryPointerFactory.Create <T>(BaseMemory,
                                                          SnapshotReader.ReadMemoryAddress(snapshotAddress)));
            }
            return(SnapshotReader.Read <T>(snapshotAddress));
        }