@Test public void writeWritesToRightOffset() { int writeOffset = 0xBA1BA1; opener.setOpenReturnValue(handle); opener.doNotThrowExceptionOnOpen(); writeProcessMemory = (handle1, offset, data, numberOfBytes, bytesWritten) -> { assertEquals(writeOffset, offset); return true; }; writer.write(process, writeOffset, new byte[]{5}); }
@Override public void write(NativeProcess process, int offset, byte[] buffer) throws MemoryAccessException { Objects.requireNonNull(process, "process cannot be null!"); Objects.requireNonNull(buffer, "buffer cannot be null!"); if (buffer.length < 1) { throw new IllegalArgumentException("Can't write fewer than 1 byte!"); } try (ProcessHandle handle = processOpener.open(process.getPid(), FLAGS_WRITEMEMORY)) { boolean success = memoryWriter.writeProcessMemory( handle.getNativeHandle(), offset, buffer, buffer.length, null); if (!success) { int errorCode = Native.getLastError(); throw createReadExceptionFromErrorCode(errorCode); } } }
WindowsRawMemoryWriter implements RawMemoryWriter { @Override public void write(NativeProcess process, int offset, byte[] buffer) throws MemoryAccessException { Objects.requireNonNull(process, "process cannot be null!"); Objects.requireNonNull(buffer, "buffer cannot be null!"); if (buffer.length < 1) { throw new IllegalArgumentException("Can't write fewer than 1 byte!"); } try (ProcessHandle handle = processOpener.open(process.getPid(), FLAGS_WRITEMEMORY)) { boolean success = memoryWriter.writeProcessMemory( handle.getNativeHandle(), offset, buffer, buffer.length, null); if (!success) { int errorCode = Native.getLastError(); throw createReadExceptionFromErrorCode(errorCode); } } } }
WindowsRawMemoryWriter implements RawMemoryWriter { @Override public void write(NativeProcess process, int offset, byte[] buffer) throws MemoryAccessException { Objects.requireNonNull(process, "process cannot be null!"); Objects.requireNonNull(buffer, "buffer cannot be null!"); if (buffer.length < 1) { throw new IllegalArgumentException("Can't write fewer than 1 byte!"); } try (ProcessHandle handle = processOpener.open(process.getPid(), FLAGS_WRITEMEMORY)) { boolean success = memoryWriter.writeProcessMemory( handle.getNativeHandle(), offset, buffer, buffer.length, null); if (!success) { int errorCode = Native.getLastError(); throw createReadExceptionFromErrorCode(errorCode); } } } WindowsRawMemoryWriter(ProcessOpener processOpener, WriteProcessMemory memoryWriter); }
WindowsRawMemoryWriter implements RawMemoryWriter { @Override public void write(NativeProcess process, int offset, byte[] buffer) throws MemoryAccessException { Objects.requireNonNull(process, "process cannot be null!"); Objects.requireNonNull(buffer, "buffer cannot be null!"); if (buffer.length < 1) { throw new IllegalArgumentException("Can't write fewer than 1 byte!"); } try (ProcessHandle handle = processOpener.open(process.getPid(), FLAGS_WRITEMEMORY)) { boolean success = memoryWriter.writeProcessMemory( handle.getNativeHandle(), offset, buffer, buffer.length, null); if (!success) { int errorCode = Native.getLastError(); throw createReadExceptionFromErrorCode(errorCode); } } } WindowsRawMemoryWriter(ProcessOpener processOpener, WriteProcessMemory memoryWriter); @Override void write(NativeProcess process, int offset, byte[] buffer); }
WindowsRawMemoryWriter implements RawMemoryWriter { @Override public void write(NativeProcess process, int offset, byte[] buffer) throws MemoryAccessException { Objects.requireNonNull(process, "process cannot be null!"); Objects.requireNonNull(buffer, "buffer cannot be null!"); if (buffer.length < 1) { throw new IllegalArgumentException("Can't write fewer than 1 byte!"); } try (ProcessHandle handle = processOpener.open(process.getPid(), FLAGS_WRITEMEMORY)) { boolean success = memoryWriter.writeProcessMemory( handle.getNativeHandle(), offset, buffer, buffer.length, null); if (!success) { int errorCode = Native.getLastError(); throw createReadExceptionFromErrorCode(errorCode); } } } WindowsRawMemoryWriter(ProcessOpener processOpener, WriteProcessMemory memoryWriter); @Override void write(NativeProcess process, int offset, byte[] buffer);  }