.getByteBuffer(0, memory.size()) .get(bytes);
/** Dumps the contents of this memory object. */ public String dump() { return dump(0, (int)size()); } }
/** Provide a view of this memory using the given offset as the base address. The * returned {@link Pointer} will have a size equal to that of the original * minus the offset. * @throws IndexOutOfBoundsException if the requested memory is outside * the allocated bounds. */ @Override public Pointer share(long offset) { return share(offset, size() - offset); }
if (m.size() < requiredSize) { useMemory(autoAllocate(requiredSize));
Memory memory = new Memory(required.getValue()); Advapi32Ex.QUERY_SERVICE_CONFIG query = new Advapi32Ex.QUERY_SERVICE_CONFIG(memory); Advapi32Ex.INSTANCE.QueryServiceConfigA(session.getHandle(), query, (int) memory.size(), required);
/** Provide a view of this memory using the given offset as the base address. The * returned {@link Pointer} will have a size equal to that of the original * minus the offset. * @throws IndexOutOfBoundsException if the requested memory is outside * the allocated bounds. */ @Override public Pointer share(long offset) { return share(offset, size() - offset); }
/** Dumps the contents of this memory object. */ public String dump() { return dump(0, (int)size()); } }
protected void initializeBuffers() { outClosed = false; errClosed = false; pendingWrites = new ConcurrentLinkedQueue<>(); outBufferMemory = new Memory(BUFFER_CAPACITY); outBuffer = outBufferMemory.getByteBuffer(0, outBufferMemory.size()).order(ByteOrder.nativeOrder()); errBufferMemory = new Memory(BUFFER_CAPACITY); errBuffer = errBufferMemory.getByteBuffer(0, outBufferMemory.size()).order(ByteOrder.nativeOrder()); inBufferMemory = new Memory(BUFFER_CAPACITY); inBuffer = inBufferMemory.getByteBuffer(0, outBufferMemory.size()).order(ByteOrder.nativeOrder()); // Ensure stdin initially has 0 bytes pending write. We'll // update this before invoking onStdinReady. inBuffer.limit(0); }
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 HRESULTException(int hresult) { Memory m = new Memory(1024); Kernel32.INSTANCE.FormatMessage(Kernel32.FORMAT_MESSAGE_FROM_SYSTEM, null, hresult, 0, m, (int) m.size(), null); String mm = m.getString(0, true); mm = mm.trim(); str = String.format("HRESULT: 0x%08x [%s]", hresult, mm); }
public static int setXAttr(String path, String name, String value) { Memory valueBuffer = encodeString(value); return XAttr.INSTANCE.setxattr(path, name, valueBuffer, valueBuffer.size(), 0, 0); }
/** * Given a managed pointer, sets all bytes to value `<strong>b</strong>`. * * @param ptr Managed pointer. * * @param b Unsigned byte. */ public static void fill( Memory ptr , int b ) { fill( ptr , b , new SizeT( ptr.size() ) ) ; }
/** * Copies all the bytes of a managed pointer to another one. * * @param ptrOrigin Managed pointer whose bytes will be copied. * * @param ptrTarget Pointer where the bytes will be copied. */ public static void copy( Memory ptrOrigin , Pointer ptrTarget ) { memcpy( ptrOrigin , ptrTarget , new SizeT( ptrOrigin.size() ) ) ; }
/** * Tests a regular pointer against a managed one for equality. * * @param ptr1 Regular pointer. * * @param ptr2 Managed pointer. * * @return True if all tested bytes are equal. */ public static boolean equal( Pointer ptr1 , Memory ptr2 ) { return equal( ptr1 , ptr2 , new SizeT( ptr2.size() ) ) ; }
@Override public void execute(String executeString, int timeout, WinDef.DWORDByReference result, DWORD_PTR userHandle) { Memory mem = new Memory(executeString.length() * 2 + 2); mem.setWideString(0, executeString); clientTransaction(mem, (int) mem.size(), (HSZ) null, 0, Ddeml.XTYP_EXECUTE, timeout, result, userHandle); }
synchronized public void fail() throws Fail { int err = GetLastError(); Memory buffer = new Memory(2048); FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, null, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buffer, (int) buffer.size(), null); log = log && log(1, "fail() %s, Windows GetLastError()= %d, %s\n", lineno(1), err, buffer.getWideString(0)); // FIXME here convert from Windows error code to 'posix' error code Fail f = new Fail(); throw f; }
synchronized public void fail() throws Fail { int err = GetLastError(); Memory buffer = new Memory(2048); FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, null, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buffer, (int) buffer.size(), null); log = log && log(1, "fail() %s, Windows GetLastError()= %d, %s\n", lineno(1), err, buffer.getWideString(0)); // FIXME here convert from Windows error code to 'posix' error code Fail f = new Fail(); throw f; }
synchronized public void fail() throws Fail { int err = GetLastError(); Memory buffer = new Memory(2048); int res = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, null, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buffer, (int) buffer.size(), null); log = log && log(1, "fail() %s, Windows GetLastError()= %d, %s\n", lineno(1), err, buffer.getString(0, true)); // FIXME here convert from Windows error code to 'posix' error code Fail f = new Fail(); throw f; }