@Test(expected = IllegalArgumentException.class) public void readStringUTF16LEThrowsIfTryingToReadNegativeAmountOfCharacters() { reader.readStringUTF16LE(process, 0, -1512); }
@Override public String readStringUTF16LE(NativeProcess process, int offset, int maxCodeUnitsToRead) { if (maxCodeUnitsToRead < 1) { throw new IllegalArgumentException("Cannot read strings shorter than 1 character!"); } final int charSize = TypeSize.CHAR_UTF16LE.getSize(); int totalByteSize = maxCodeUnitsToRead * charSize; ByteBuffer buffer = ByteBuffer.allocate(totalByteSize); buffer.order(ByteOrder.LITTLE_ENDIAN); for (int i = 0; i < totalByteSize; i += charSize) { short readShort = readShort(process, offset + i); if (readShort == 0) { break; } buffer.putShort(readShort); } buffer.flip(); byte[] truncatedBuf = new byte[buffer.remaining()]; buffer.get(truncatedBuf); return new String(truncatedBuf, StandardCharsets.UTF_16LE); }
MemoryReaderImpl implements MemoryReader { @Override public String readStringUTF16LE(NativeProcess process, int offset, int maxCodeUnitsToRead) { if (maxCodeUnitsToRead < 1) { throw new IllegalArgumentException("Cannot read strings shorter than 1 character!"); } final int charSize = TypeSize.CHAR_UTF16LE.getSize(); int totalByteSize = maxCodeUnitsToRead * charSize; ByteBuffer buffer = ByteBuffer.allocate(totalByteSize); buffer.order(ByteOrder.LITTLE_ENDIAN); for (int i = 0; i < totalByteSize; i += charSize) { short readShort = readShort(process, offset + i); if (readShort == 0) { break; } buffer.putShort(readShort); } buffer.flip(); byte[] truncatedBuf = new byte[buffer.remaining()]; buffer.get(truncatedBuf); return new String(truncatedBuf, StandardCharsets.UTF_16LE); } }
MemoryReaderImpl implements MemoryReader { @Override public String readStringUTF16LE(NativeProcess process, int offset, int maxCodeUnitsToRead) { if (maxCodeUnitsToRead < 1) { throw new IllegalArgumentException("Cannot read strings shorter than 1 character!"); } final int charSize = TypeSize.CHAR_UTF16LE.getSize(); int totalByteSize = maxCodeUnitsToRead * charSize; ByteBuffer buffer = ByteBuffer.allocate(totalByteSize); buffer.order(ByteOrder.LITTLE_ENDIAN); for (int i = 0; i < totalByteSize; i += charSize) { short readShort = readShort(process, offset + i); if (readShort == 0) { break; } buffer.putShort(readShort); } buffer.flip(); byte[] truncatedBuf = new byte[buffer.remaining()]; buffer.get(truncatedBuf); return new String(truncatedBuf, StandardCharsets.UTF_16LE); } MemoryReaderImpl(RawMemoryReader rawMemoryReader); }
MemoryReaderImpl implements MemoryReader { @Override public String readStringUTF16LE(NativeProcess process, int offset, int maxCodeUnitsToRead) { if (maxCodeUnitsToRead < 1) { throw new IllegalArgumentException("Cannot read strings shorter than 1 character!"); } final int charSize = TypeSize.CHAR_UTF16LE.getSize(); int totalByteSize = maxCodeUnitsToRead * charSize; ByteBuffer buffer = ByteBuffer.allocate(totalByteSize); buffer.order(ByteOrder.LITTLE_ENDIAN); for (int i = 0; i < totalByteSize; i += charSize) { short readShort = readShort(process, offset + i); if (readShort == 0) { break; } buffer.putShort(readShort); } buffer.flip(); byte[] truncatedBuf = new byte[buffer.remaining()]; buffer.get(truncatedBuf); return new String(truncatedBuf, StandardCharsets.UTF_16LE); } MemoryReaderImpl(RawMemoryReader rawMemoryReader); @Override boolean readBoolean(NativeProcess process, int offset); @Override byte readByte(NativeProcess process, int offset); @Override char readCharUTF8(NativeProcess process, int offset); @Override char readCharUTF16LE(NativeProcess process, int offset); @Override short readShort(NativeProcess process, int offset); @Override int readInt(NativeProcess process, int offset); @Override float readFloat(NativeProcess process, int offset); @Override long readLong(NativeProcess process, int offset); @Override double readDouble(NativeProcess process, int offset); @Override String readStringUTF8(NativeProcess process, int offset, int maxCodeUnitsToRead); @Override String readStringUTF16LE(NativeProcess process, int offset, int maxCodeUnitsToRead); @Override byte[] read(NativeProcess process, int offset, int bytesToRead); }
MemoryReaderImpl implements MemoryReader { @Override public String readStringUTF16LE(NativeProcess process, int offset, int maxCodeUnitsToRead) { if (maxCodeUnitsToRead < 1) { throw new IllegalArgumentException("Cannot read strings shorter than 1 character!"); } final int charSize = TypeSize.CHAR_UTF16LE.getSize(); int totalByteSize = maxCodeUnitsToRead * charSize; ByteBuffer buffer = ByteBuffer.allocate(totalByteSize); buffer.order(ByteOrder.LITTLE_ENDIAN); for (int i = 0; i < totalByteSize; i += charSize) { short readShort = readShort(process, offset + i); if (readShort == 0) { break; } buffer.putShort(readShort); } buffer.flip(); byte[] truncatedBuf = new byte[buffer.remaining()]; buffer.get(truncatedBuf); return new String(truncatedBuf, StandardCharsets.UTF_16LE); } MemoryReaderImpl(RawMemoryReader rawMemoryReader); @Override boolean readBoolean(NativeProcess process, int offset); @Override byte readByte(NativeProcess process, int offset); @Override char readCharUTF8(NativeProcess process, int offset); @Override char readCharUTF16LE(NativeProcess process, int offset); @Override short readShort(NativeProcess process, int offset); @Override int readInt(NativeProcess process, int offset); @Override float readFloat(NativeProcess process, int offset); @Override long readLong(NativeProcess process, int offset); @Override double readDouble(NativeProcess process, int offset); @Override String readStringUTF8(NativeProcess process, int offset, int maxCodeUnitsToRead); @Override String readStringUTF16LE(NativeProcess process, int offset, int maxCodeUnitsToRead); @Override byte[] read(NativeProcess process, int offset, int bytesToRead);  }