/** * Sets the new state of a given line. * * @param line * The GPIO line. * * @param value * The new state. * * @return This instance. */ public GpioBuffer set( GpioLine line , boolean value ) { this.buffer.setByte( line.index , (byte)( value ? 1 : 0 ) ) ; return this ; }
@Override public Memory bufferForResult(Object methodCallResult) { Memory result = new Memory(1); result.setByte(0, ((Boolean) methodCallResult) ? (byte) 1 : (byte) 0); return result; } });
@Override public Memory bufferForResult(Object methodCallResult) { Memory result = new Memory(1); result.setByte(0, ((Byte) methodCallResult).byteValue()); return result; } });
@Override public void write(int b) throws IOException { if (closed) { throw new IOException("Stream closed."); } Memory m = new Memory(1); m.setByte(0, (byte) b); int written = library.ssh_channel_write(channel, m, 1); if (written != 1) { throw new IOException("Failed to write."); } }
/** * Adds a GPIO line to the request with a default value. * <p> * A handle can drive at most 64 lines. * <p> * Providing a default value works only for outputs and will be ignored for inputs. * * @param lineNumber * Which line. * * @param value * Default value. * * @return A GPIO line useful for handling a buffer. * * @see GpioBuffer */ public GpioLine addLine( int lineNumber , boolean value ) { GpioLine gpioLine = this.addLine( lineNumber ) ; this.memory.setByte( NativeGpioHandleRequest.OFFSET_DEFAULT_VALUES + gpioLine.index , (byte)( value ? 1 : 0 ) ) ; return gpioLine ; } }
protected static Memory encodeString(String s) { // create NULL-terminated UTF-8 String byte[] bb = s.getBytes(Charset.forName("UTF-8")); Memory valueBuffer = new Memory(bb.length + 1); valueBuffer.write(0, bb, 0, bb.length); valueBuffer.setByte(valueBuffer.size() - 1, (byte) 0); return valueBuffer; }
public static void main(String... args) { int pid = getProcessId("Solitaire"); Pointer process = openProcess(PROCESS_VM_READ|PROCESS_VM_WRITE|PROCESS_VM_OPERATION, pid); long dynAddress = findDynAddress(process,offsets,baseAddress); Memory scoreMem = readMemory(process,dynAddress,4); int score = scoreMem.getInt(0); System.out.println(score); byte[] newScore = new byte[]{0x22,0x22,0x22,0x22}; writeMemory(process, dynAddress, newScore); } public static void writeMemory(Pointer process, long address, byte[] data) { int size = data.length; Memory toWrite = new Memory(size); for(int i = 0; i < size; i++) { toWrite.setByte(i, data[i]); } boolean b = kernel32.WriteProcessMemory(process, address, toWrite, size, null); }
data.setByte(offset++, (byte) 0);
public final Object marshal(Invocation invocation, IRubyObject parameter) { // Ruby strings are UTF-8, so should be able to just copy directly RubyString s = parameter.asString(); ByteList bl = s.getByteList(); final Memory memory = new Memory(bl.length() + 1); memory.write(0, bl.unsafeBytes(), bl.begin(), bl.length()); memory.setByte(bl.length(), (byte) 0); return memory; } public static final Marshaller INSTANCE = new StringMarshaller();
public final Object marshal(Invocation invocation, IRubyObject parameter) { // Ruby strings are UTF-8, so should be able to just copy directly final ByteList bl = parameter.asString().getByteList(); final int strlen = bl.length(); final Memory memory = new Memory(strlen + 1); memory.write(0, bl.unsafeBytes(), bl.begin(), strlen); memory.setByte(bl.length(), (byte) 0); // // Arrange for the bytes to be copied back after the function is called // invocation.addPostInvoke(new Runnable() { public void run() { memory.read(0, bl.unsafeBytes(), bl.begin(), strlen); } }); return memory; } public static final Marshaller INSTANCE = new RbxStringMarshaller();
passwordData = new Memory(utf8Password.length + 1); passwordData.write(0, utf8Password, 0, utf8Password.length); passwordData.setByte(utf8Password.length, (byte) 0); result = gnomeKeyringLibrary.gnome_keyring_set_network_password_sync(null, userName, realm, null, null, null, null, 0, passwordData, itemId); } finally {
toWrite.setByte(i, data[i]);
case VT_I1: mem = new Memory(1); mem.setByte(0, ((Number) arg).byteValue()); hr = OleAuto.INSTANCE.SafeArrayPutElement(this, paramIndices, mem); COMUtils.checkRC(hr);
passwordData = new Memory(keyringUTF8Password.length + 1); passwordData.write(0, keyringUTF8Password, 0, keyringUTF8Password.length); passwordData.setByte(keyringUTF8Password.length, (byte) 0); gnomeKeyringLibrary.gnome_keyring_unlock(keyringName, passwordData, DONE_CALLBACK, context.getPointer(), null); gLibrary.g_main_loop_run(context.loop);