@Test(expected = NullPointerException.class) public void readThrowsIfProcessIsNull() { reader.read(null, 0, 10); }
@Override public ByteBuffer read(NativeProcess process, int offset, int bytesToRead) { Objects.requireNonNull(process, "process cannot be null!"); if (bytesToRead < 1) { throw new IllegalArgumentException("Cannot read fewer than 1 byte!"); } try (ProcessHandle handle = processOpener.open(process.getPid(), FLAGS_READMEMORY)) { Memory buffer = new Memory(bytesToRead); IntByReference bytesRead = new IntByReference(0); boolean success = memoryReader.readProcessMemory( handle.getNativeHandle(), offset, buffer, bytesToRead, bytesRead); if (!success) { int errorCode = Native.getLastError(); throw createReadExceptionFromErrorCode(errorCode); } ByteBuffer buf; try { buf = buffer.getByteBuffer(0, bytesToRead); } catch (Error err) { throw new MemoryAccessException( "An error occurred while reading memory. Use getCause() to get the cause.", err); } buf.order(ByteOrder.LITTLE_ENDIAN); return buf; } }
WindowsRawMemoryReader implements RawMemoryReader { @Override public ByteBuffer read(NativeProcess process, int offset, int bytesToRead) { Objects.requireNonNull(process, "process cannot be null!"); if (bytesToRead < 1) { throw new IllegalArgumentException("Cannot read fewer than 1 byte!"); } try (ProcessHandle handle = processOpener.open(process.getPid(), FLAGS_READMEMORY)) { Memory buffer = new Memory(bytesToRead); IntByReference bytesRead = new IntByReference(0); boolean success = memoryReader.readProcessMemory( handle.getNativeHandle(), offset, buffer, bytesToRead, bytesRead); if (!success) { int errorCode = Native.getLastError(); throw createReadExceptionFromErrorCode(errorCode); } ByteBuffer buf; try { buf = buffer.getByteBuffer(0, bytesToRead); } catch (Error err) { throw new MemoryAccessException( "An error occurred while reading memory. Use getCause() to get the cause.", err); } buf.order(ByteOrder.LITTLE_ENDIAN); return buf; } } }
WindowsRawMemoryReader implements RawMemoryReader { @Override public ByteBuffer read(NativeProcess process, int offset, int bytesToRead) { Objects.requireNonNull(process, "process cannot be null!"); if (bytesToRead < 1) { throw new IllegalArgumentException("Cannot read fewer than 1 byte!"); } try (ProcessHandle handle = processOpener.open(process.getPid(), FLAGS_READMEMORY)) { Memory buffer = new Memory(bytesToRead); IntByReference bytesRead = new IntByReference(0); boolean success = memoryReader.readProcessMemory( handle.getNativeHandle(), offset, buffer, bytesToRead, bytesRead); if (!success) { int errorCode = Native.getLastError(); throw createReadExceptionFromErrorCode(errorCode); } ByteBuffer buf; try { buf = buffer.getByteBuffer(0, bytesToRead); } catch (Error err) { throw new MemoryAccessException( "An error occurred while reading memory. Use getCause() to get the cause.", err); } buf.order(ByteOrder.LITTLE_ENDIAN); return buf; } } WindowsRawMemoryReader(ProcessOpener processOpener, ReadProcessMemory memoryReader); }
WindowsRawMemoryReader implements RawMemoryReader { @Override public ByteBuffer read(NativeProcess process, int offset, int bytesToRead) { Objects.requireNonNull(process, "process cannot be null!"); if (bytesToRead < 1) { throw new IllegalArgumentException("Cannot read fewer than 1 byte!"); } try (ProcessHandle handle = processOpener.open(process.getPid(), FLAGS_READMEMORY)) { Memory buffer = new Memory(bytesToRead); IntByReference bytesRead = new IntByReference(0); boolean success = memoryReader.readProcessMemory( handle.getNativeHandle(), offset, buffer, bytesToRead, bytesRead); if (!success) { int errorCode = Native.getLastError(); throw createReadExceptionFromErrorCode(errorCode); } ByteBuffer buf; try { buf = buffer.getByteBuffer(0, bytesToRead); } catch (Error err) { throw new MemoryAccessException( "An error occurred while reading memory. Use getCause() to get the cause.", err); } buf.order(ByteOrder.LITTLE_ENDIAN); return buf; } } WindowsRawMemoryReader(ProcessOpener processOpener, ReadProcessMemory memoryReader); @Override ByteBuffer read(NativeProcess process, int offset, int bytesToRead); }
WindowsRawMemoryReader implements RawMemoryReader { @Override public ByteBuffer read(NativeProcess process, int offset, int bytesToRead) { Objects.requireNonNull(process, "process cannot be null!"); if (bytesToRead < 1) { throw new IllegalArgumentException("Cannot read fewer than 1 byte!"); } try (ProcessHandle handle = processOpener.open(process.getPid(), FLAGS_READMEMORY)) { Memory buffer = new Memory(bytesToRead); IntByReference bytesRead = new IntByReference(0); boolean success = memoryReader.readProcessMemory( handle.getNativeHandle(), offset, buffer, bytesToRead, bytesRead); if (!success) { int errorCode = Native.getLastError(); throw createReadExceptionFromErrorCode(errorCode); } ByteBuffer buf; try { buf = buffer.getByteBuffer(0, bytesToRead); } catch (Error err) { throw new MemoryAccessException( "An error occurred while reading memory. Use getCause() to get the cause.", err); } buf.order(ByteOrder.LITTLE_ENDIAN); return buf; } } WindowsRawMemoryReader(ProcessOpener processOpener, ReadProcessMemory memoryReader); @Override ByteBuffer read(NativeProcess process, int offset, int bytesToRead);  }