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; }
/** * Find name. * * @param name * the name * @param hashVal * the hash val or 0 if unknown * @param maxResult * maximum number of items to search * @return the find name */ public FindName FindName(String name, int hashVal, short maxResult) { Pointer p = Ole32.INSTANCE.CoTaskMemAlloc((name.length() + 1L) * Native.WCHAR_SIZE); WTypes.LPOLESTR olestr = new WTypes.LPOLESTR(p); olestr.setValue(name); ULONG lHashVal = new ULONG(hashVal); USHORTByReference pcFound = new USHORTByReference(maxResult); Pointer[] ppTInfo = new Pointer[maxResult]; MEMBERID[] rgMemId = new MEMBERID[maxResult]; HRESULT hr = this.typelib.FindName(olestr, lHashVal, ppTInfo, rgMemId, pcFound); COMUtils.checkRC(hr); FindName findName = new FindName(olestr.getValue(), ppTInfo, rgMemId, pcFound.getValue().shortValue()); Ole32.INSTANCE.CoTaskMemFree(p); return findName; }
/** * Create a SAFEARRAY with supplied element type. * * <p> * The array will have as many dimensions as parameters are passed in. * The lowerbound for each dimension is set to zero, the count to the * parameter value.</p> * * @param vartype type of array contents (see Variant.VT_* constants) * @param size array of dimension size * @return SAFEARRAYWrapper or {@code NULL} if creation fails. */ public static SAFEARRAY.ByReference createSafeArray(VARTYPE vartype, int... size) { OaIdl.SAFEARRAYBOUND[] rgsabound = (OaIdl.SAFEARRAYBOUND[]) new OaIdl.SAFEARRAYBOUND().toArray(size.length); for (int i = 0; i < size.length; i++) { rgsabound[i].lLbound = new WinDef.LONG(0); rgsabound[i].cElements = new WinDef.ULONG(size[size.length - i - 1]); } SAFEARRAY.ByReference data = OleAuto.INSTANCE.SafeArrayCreate(vartype, new WinDef.UINT(size.length), rgsabound); return data; }
/** * Checks if is name. * * @param nameBuf * the name buf * @param hashVal * the hash val * @return the checks if is name */ public IsName IsName(String nameBuf, int hashVal) { LPOLESTR szNameBuf = new LPOLESTR(nameBuf); ULONG lHashVal = new ULONG(hashVal); BOOLByReference pfName = new BOOLByReference(); HRESULT hr = this.typelib.IsName(szNameBuf, lHashVal, pfName); COMUtils.checkRC(hr); return new IsName(szNameBuf.getValue(), pfName.getValue() .booleanValue()); }
public void setValue(ULONG value) { getPointer().setInt(0, value.intValue()); }
protected void cacheNext() { assert COMUtils.comIsInitialized() : "COM not initialized"; final PointerByReference rgelt = new PointerByReference(); final WinDef.ULONGByReference pceltFetched = new WinDef.ULONGByReference(); WinNT.HRESULT hr = this.raw.Next(new WinDef.ULONG(1), rgelt, pceltFetched); if (WinNT.S_OK.equals(hr) && pceltFetched.getValue().intValue() > 0) { this.rawNext = new Moniker(rgelt.getValue()); } else { if (!WinNT.S_FALSE.equals(hr)) { COMUtils.checkRC(hr); } this.rawNext = null; } }
public ULONGbyReference() { this(new ULONG(0)); }
@Override public DWORD callback(Pointer pbData, Pointer pvCallbackContext, ULONGByReference ulLength) { int elementsRead = elementsReadWrapper.getValue(); int remainingElements = outputStream.size() - elementsRead; int length = Math.min(remainingElements, ulLength.getValue().intValue()); pbData.write(0, outputStream.toByteArray(), elementsRead, length); elementsReadWrapper.setValue(elementsRead + length); ulLength.setValue(new ULONG(length)); return new DWORD(W32Errors.ERROR_SUCCESS); } };
public ULONG getValue() { return new ULONG(getPointer().getInt(0)); } }
@Override public DWORD callback(Pointer pbData, Pointer pvCallbackContext, ULONG ulLength) { byte[] arr = pbData.getByteArray(0, ulLength.intValue()); try { outputStream.write(arr); } catch (IOException e) { throw new RuntimeException(e); } return new DWORD(W32Errors.ERROR_SUCCESS); } };
public SAFEARRAYBOUND(int cElements, int lLbound) { this.cElements = new ULONG(cElements); this.lLbound = new LONG(lLbound); this.write(); }
public SAFEARRAYBOUND(int cElements, int lLbound) { this.cElements = new ULONG(cElements); this.lLbound = new LONG(lLbound); this.write(); } }
/** * Sets the value. * * @param value the new value */ public void setValue(ULONG value) { getPointer().setInt(0, value.intValue()); }
/** * Instantiates a new ULONG by reference. */ public ULONGByReference() { this(new ULONG(0)); }
@Override public int compareTo(ULONG other) { return compare(this, other); } }
/** * Gets the value. * * @return the value */ public ULONG getValue() { return new ULONG(getPointer().getInt(0)); } }