public static bool ReadString(this Process process, IntPtr addr, StringEnumType type, int size, out string value, bool swap = false) { var bytes = new byte[size]; IntPtr read = IntPtr.Zero; value = null; if (!NativeWrappers.ReadProcessMemory(process.Handle, addr, bytes, size, out read)) { return(false); } if (swap) { Array.Reverse(bytes); } if (type == StringEnumType.AutoDetect) { if (read.ToInt64() >= 2 && bytes[1] == '\x0') { value = Encoding.Unicode.GetString(bytes); } else { value = Encoding.UTF8.GetString(bytes); } } else if (type == StringEnumType.UTF8) { value = Encoding.UTF8.GetString(bytes); } else if (type == StringEnumType.UTF16) { value = Encoding.Unicode.GetString(bytes); } else { value = Encoding.ASCII.GetString(bytes); } return(true); }
public static bool ReadBytes(this Process process, IntPtr addr, int size, out byte[] value, bool swap = false) { var bytes = new byte[size]; IntPtr read = IntPtr.Zero; value = null; if (!NativeWrappers.ReadProcessMemory(process.Handle, addr, bytes, size, out read)) { return(false); } if (swap) { Array.Reverse(bytes); } value = bytes; return(true); }