public EventSubscribeXmlRenderingCallback(ComponentLog logger, Consumer<String> consumer, int maxBufferSize, WEvtApi wEvtApi, Kernel32 kernel32, ErrorLookup errorLookup) { this.logger = logger; this.consumer = consumer; this.maxBufferSize = maxBufferSize; this.wEvtApi = wEvtApi; this.kernel32 = kernel32; this.size = Math.min(maxBufferSize, INITIAL_BUFFER_SIZE); this.errorLookup = errorLookup; this.buffer = new Memory(size); this.used = new Memory(4); this.propertyCount = new Memory(4); }
public static File getTempDir() { Memory buf = new Memory(1024); if (Kernel32.INSTANCE.GetTempPathW(512,buf)!=0) {// the first arg is number of wchar return new File(buf.getString(0, true)); } else { return null; } }
private String readLine(int fd, long addr, String prefix) throws IOException { if(LOGGER.isLoggable(FINEST)) LOGGER.finest("Reading "+prefix+" at "+addr); Memory m = new Memory(1); byte ch = 1; ByteArrayOutputStream buf = new ByteArrayOutputStream(); int i = 0; while(true) { if (i++ > LINE_LENGTH_LIMIT) { LOGGER.finest("could not find end of line, giving up"); throw new IOException("could not find end of line, giving up"); } long r = LIBC.pread(fd, m, new NativeLong(1), new NativeLong(addr)); ch = m.getByte(0); if (ch == 0) break; buf.write(ch); addr++; } String line = buf.toString(); if(LOGGER.isLoggable(FINEST)) LOGGER.finest(prefix+" was "+line); return line; } }
private String readLine(int fd, long addr, String prefix) throws IOException { if(LOGGER.isLoggable(FINEST)) LOGGER.finest("Reading "+prefix+" at "+addr); Memory m = new Memory(1); byte ch = 1; ByteArrayOutputStream buf = new ByteArrayOutputStream(); int i = 0; while(true) { if (i++ > LINE_LENGTH_LIMIT) { LOGGER.finest("could not find end of line, giving up"); throw new IOException("could not find end of line, giving up"); } LIBC.pread(fd, m, new NativeLong(1), new NativeLong(addr)); ch = m.getByte(0); if (ch == 0) break; buf.write(ch); addr++; } String line = buf.toString(); if(LOGGER.isLoggable(FINEST)) LOGGER.finest(prefix+" was "+line); return line; } }
private static int windowsPing(World world) throws UnknownHostException { IPHlpAPI ipHlpAPI = IPHlpAPI.INSTANCE; Pointer ptr = ipHlpAPI.IcmpCreateFile(); InetAddress inetAddress = InetAddress.getByName(world.getAddress()); byte[] address = inetAddress.getAddress(); String dataStr = RUNELITE_PING; int dataLength = dataStr.length() + 1; Pointer data = new Memory(dataLength); data.setString(0L, dataStr); IcmpEchoReply icmpEchoReply = new IcmpEchoReply(new Memory(IcmpEchoReply.SIZE + dataLength)); assert icmpEchoReply.size() == IcmpEchoReply.SIZE; int packed = (address[0] & 0xff) | ((address[1] & 0xff) << 8) | ((address[2] & 0xff) << 16) | ((address[3] & 0xff) << 24); int ret = ipHlpAPI.IcmpSendEcho(ptr, packed, data, (short) (dataLength), Pointer.NULL, icmpEchoReply, IcmpEchoReply.SIZE + dataLength, TIMEOUT); if (ret != 1) { ipHlpAPI.IcmpCloseHandle(ptr); return -1; } int rtt = Math.toIntExact(icmpEchoReply.roundTripTime.longValue()); ipHlpAPI.IcmpCloseHandle(ptr); return rtt; }
public synchronized List<String> getArguments() { if(arguments!=null) return arguments; arguments = new ArrayList<String>(argc); if (argc == 0) { return arguments; } int psize = b64 ? 8 : 4; Memory m = new Memory(psize); try { if(LOGGER.isLoggable(FINER)) LOGGER.finer("Reading "+getFile("as")); int fd = LIBC.open(getFile("as").getAbsolutePath(), 0); try { for( int n=0; n<argc; n++ ) { // read a pointer to one entry LIBC.pread(fd, m, new NativeLong(psize), new NativeLong(argp+n*psize)); long addr = b64 ? m.getLong(0) : to64(m.getInt(0)); arguments.add(readLine(fd, addr, "argv["+ n +"]")); } } finally { LIBC.close(fd); } } catch (IOException | LastErrorException e) { // failed to read. this can happen under normal circumstances (most notably permission denied) // so don't report this as an error. } arguments = Collections.unmodifiableList(arguments); return arguments; }
/** * Turn on the keyboard overlay. This is a keyboard that hovers in front of the user, that can be typed upon by * pointing the ray extending from the top of the controller at the key the user wants to press. * @param showingState - true or false * @return - true if successful. If this call fails, an error is logged. */ public static boolean setKeyboardOverlayShowing(boolean showingState) { int ret; if (showingState) { Pointer pointer = new Memory(3); pointer.setString(0, "mc"); Pointer empty = new Memory(1); empty.setString(0, ""); ret = vrOverlay.ShowKeyboard.apply(0, 0, pointer, 256, empty, (byte) 1, 0); keyboardShowing = 0 == ret; //0 = no error, > 0 see EVROverlayError if (ret != 0) { logger.error("VR Overlay Error: " + vrOverlay.GetOverlayErrorNameFromEnum.apply(ret).getString(0)); } } else { try { vrOverlay.HideKeyboard.apply(); } catch (Error e) { logger.error("Error bringing up keyboard overlay: " + e.toString()); } keyboardShowing = false; } return keyboardShowing; }
m = new Memory(size.getValue()); if(LIBC.sysctl(MIB_PROC_ALL,3, m, size, NULL, ref)!=0) { if(Native.getLastError()==ENOMEM && nRetry++<16)
Memory m = new Memory(psize); try { if(LOGGER.isLoggable(FINER))
Memory m = new Memory(psize); int fd = LIBC.open(getFile("as").getAbsolutePath(), 0);
buffer = new Memory(size); wEvtApi.EvtRender(null, eventHandle, WEvtApi.EvtRenderFlags.EVENT_XML, size, buffer, used, propertyCount);
Memory m = new Memory(psize); int fd = LIBC.open(getFile("as").getAbsolutePath(), 0);
Pointer pchValue = new Memory(unBufferSize); IntByReference pError = new IntByReference();
@Override protected Memory initialValue() { Memory m = new Memory(4); m.clear(); return m; } };
protected ByReference(int dataSize) { setPointer(new Memory(dataSize)); } }
SockFProg(SockFilter filters[]) { len = (short) filters.length; // serialize struct sock_filter * explicitly, its less confusing than the JNA magic we would need Memory filter = new Memory(len * 8); ByteBuffer bbuf = filter.getByteBuffer(0, len * 8); bbuf.order(ByteOrder.nativeOrder()); // little endian for (SockFilter f : filters) { bbuf.putShort(f.code); bbuf.put(f.jt); bbuf.put(f.jf); bbuf.putInt(f.k); } this.filter = filter; }
private void init(Pointer[] els) { elements = new Memory(Native.POINTER_SIZE * els.length); elements.write(0, els, 0, els.length); write(); }
bmi.bmiHeader.biCompression = WinGDI.BI_RGB; Memory buffer = new Memory(width * height * 4); GDI32.INSTANCE.GetDIBits(hdcWindow, hBitmap, 0, height, buffer, bmi, WinGDI.DIB_RGB_COLORS);
private MacAddress getMacAddress(String nifName) { Pointer lpAdapter = NativePacketDllMappings.PacketOpenAdapter(nifName); long hFile = -1; if (lpAdapter != null) { if (Native.POINTER_SIZE == 4) { hFile = lpAdapter.getInt(0); } else { hFile = lpAdapter.getLong(0); } } if (hFile == -1L) { int err = Native.getLastError(); logger.error("Unable to open the NIF {}, Error Code: {}", nifName, err); return null; } Memory mem = new Memory(NativePacketDllMappings.PACKET_OID_DATA_SIZE); mem.clear(); PACKET_OID_DATA oidData = new PACKET_OID_DATA(mem); oidData.Length = new NativeLong(6L); oidData.Oid = new NativeLong(0x01010102L); int status = NativePacketDllMappings.PacketRequest(lpAdapter, 0, oidData); NativePacketDllMappings.PacketCloseAdapter(lpAdapter); if (status == 0) { logger.error("Failed to retrieve the link layer address of the NIF: {}", nifName); return null; } else { return MacAddress.getByAddress(oidData.Data); } }