示例#1
0
        private static Dictionary <ushort, string> GetSystemMessages(ModuleSnapshot snapshot, string pattern, int patternOffset)
        {
            Dictionary <ushort, string> result = new Dictionary <ushort, string>();
            IntPtr             funcAddress     = new IntPtr(snapshot.FindPattern(pattern, 0, 0, false, false));
            GetMessageNameFunc func            = funcAddress.ToDelegate <GetMessageNameFunc>();
            uint count = LocalMemory.Read <uint>(funcAddress + patternOffset);

            for (ushort i = 0; i < count; i++)
            {
                result.Add(i, Marshal.PtrToStringUni(func(i)));
            }
            return(result);
        }
示例#2
0
        /// <summary>
        /// Read an object of the specified struct from the current process.
        /// </summary>
        /// <typeparam name="T">The type of the struct.</typeparam>
        /// <param name="address">The address to read from.</param>
        /// <param name="result">The resulting object.</param>
        /// <returns>Whether or not the read succeeded.</returns>
        public static bool Read <T>(IntPtr address, out T result) where T : struct
        {
            if (!ReadBytes(address, SizeCache <T> .Size, out var buffer))
            {
                result = default;
                return(false);
            }

            using var mem = new LocalMemory(buffer.Length);
            mem.Write(buffer);

            result = mem.Read <T>();
            return(true);
        }
示例#3
0
        /// <summary>
        /// Marshals data from an unmanaged block of memory to a managed object.
        /// </summary>
        /// <param name="addr">The address to read from.</param>
        /// <param name="type">The type to create.</param>
        /// <returns>The read object, or null, if it could not be read.</returns>
        public static object?PtrToStructure(IntPtr addr, Type type)
        {
            var size = Marshal.SizeOf(type);

            if (!ReadBytes(addr, size, out var buffer))
            {
                return(null);
            }

            var mem = new LocalMemory(size);

            mem.Write(buffer);

            return(mem.Read(type));
        }
示例#4
0
        /// <summary>
        /// Write an array of structs to the current process.
        /// </summary>
        /// <typeparam name="T">The type of the structs.</typeparam>
        /// <param name="address">The address to write to.</param>
        /// <param name="objArray">The array to write.</param>
        /// <returns>Whether or not the write succeeded.</returns>
        public static bool Write <T>(IntPtr address, T[] objArray) where T : struct
        {
            if (objArray == null || objArray.Length == 0)
            {
                return(true);
            }
            var size = SizeCache <T> .Size;

            using var mem = new LocalMemory(objArray.Length * size);
            for (var i = 0; i < objArray.Length; i++)
            {
                mem.Write(objArray[i], i * size);
            }
            return(WriteBytes(address, mem.Read()));
        }
示例#5
0
        /// <summary>
        /// Read an array of objects of the specified struct from the current process.
        /// </summary>
        /// <typeparam name="T">The type of the struct.</typeparam>
        /// <param name="address">The address to read from.</param>
        /// <param name="count">The length of the array.</param>
        /// <returns>An array of the read objects, or null if any entry of the array failed to read.</returns>
        public static T[]? Read <T>(IntPtr address, int count) where T : struct
        {
            var size = SizeOf <T>();

            if (!ReadBytes(address, count * size, out var buffer))
            {
                return(null);
            }
            var result = new T[count];

            using var mem = new LocalMemory(buffer.Length);
            mem.Write(buffer);
            for (var i = 0; i < result.Length; i++)
            {
                result[i] = mem.Read <T>(i * size);
            }
            return(result);
        }
示例#6
0
 /// <summary>
 /// Write a struct to the current process.
 /// </summary>
 /// <typeparam name="T">The type of the struct.</typeparam>
 /// <param name="address">The address to write to.</param>
 /// <param name="obj">The object to write.</param>
 /// <returns>Whether or not the write succeeded.</returns>
 public static bool Write <T>(IntPtr address, T obj) where T : struct
 {
     using var mem = new LocalMemory(SizeCache <T> .Size);
     mem.Write(obj);
     return(WriteBytes(address, mem.Read()));
 }
示例#7
0
 private static uint GetVersion(ModuleSnapshot snapshot, string pattern, int patternOffset) => LocalMemory.Read <uint>((IntPtr)snapshot.FindPattern(pattern, patternOffset, 0, true, false));