Refine search
private byte[] getValue(String valueName) { IntByReference pType, lpcbData; byte[] lpData = new byte[1]; pType = new IntByReference(); lpcbData = new IntByReference(); OUTER: while(true) { int r = Advapi32.INSTANCE.RegQueryValueEx(handle, valueName, null, pType, lpData, lpcbData); switch (r) { case WINERROR.ERROR_MORE_DATA: lpData = new byte[lpcbData.getValue()]; continue OUTER; case WINERROR.ERROR_SUCCESS: return lpData; } throw new JnaException(r); } }
@Override public void getRenderSize(Vector2f store) { if( vrsystemFunctions == null ) { // 1344x1512 store.x = 1344f; store.y = 1512f; } else { IntByReference x = new IntByReference(); IntByReference y = new IntByReference(); vrsystemFunctions.GetRecommendedRenderTargetSize.apply(x, y); store.x = x.getValue(); store.y = y.getValue(); } } /*
/** * Does a specified value exist? */ public boolean valueExists(String name) { IntByReference pType, lpcbData; byte[] lpData = new byte[1]; pType = new IntByReference(); lpcbData = new IntByReference(); OUTER: while(true) { int r = Advapi32.INSTANCE.RegQueryValueEx(handle, name, null, pType, lpData, lpcbData); switch(r) { case WINERROR.ERROR_MORE_DATA: lpData = new byte[lpcbData.getValue()]; continue OUTER; case WINERROR.ERROR_FILE_NOT_FOUND: return false; case WINERROR.ERROR_SUCCESS: return true; default: throw new JnaException(r); } } }
/** * Given the process handle, waits for its completion and returns the exit code. */ public static int waitForExitProcess(Pointer hProcess) throws InterruptedException { while (true) { if (Thread.interrupted()) throw new InterruptedException(); Kernel32.INSTANCE.WaitForSingleObject(hProcess,1000); IntByReference exitCode = new IntByReference(); exitCode.setValue(-1); Kernel32.INSTANCE.GetExitCodeProcess(hProcess,exitCode); int v = exitCode.getValue(); if (v !=Kernel32.STILL_ACTIVE) { return v; } } }
public RegistryKey open(String subKeyName, int access) { IntByReference pHandle = new IntByReference(); check(Advapi32.INSTANCE.RegOpenKeyEx(handle, subKeyName, 0, access, pHandle)); return new RegistryKey(this,subKeyName,pHandle.getValue()); }
/** * Get all sub keys of a key. * * @return array with all sub key names */ public Collection<String> getSubKeys() { WINBASE.FILETIME lpftLastWriteTime; TreeSet<String> subKeys = new TreeSet<String>(); char[] lpName = new char[256]; IntByReference lpcName = new IntByReference(256); lpftLastWriteTime = new WINBASE.FILETIME(); int dwIndex = 0; while (Advapi32.INSTANCE.RegEnumKeyEx(handle, dwIndex, lpName, lpcName, null, null, null, lpftLastWriteTime) == WINERROR.ERROR_SUCCESS) { subKeys.add(new String(lpName, 0, lpcName.getValue())); lpcName.setValue(256); dwIndex++; } return subKeys; }
lpcchValueName = new IntByReference(16384); lpType = new IntByReference(); lpData = new byte[1]; lpcbData = new IntByReference(); lpcbData.setValue(0); lpData = new byte[lpcbData.getValue()]; lpcchValueName = new IntByReference(16384); continue OUTER; name = new String(lpValueName, 0, lpcchValueName.getValue()); switch (lpType.getValue()) { case WINNT.REG_SZ: values.put(name, convertBufferToString(lpData));
public interface Psapi extends StdCallLibrary { Psapi INSTANCE = (Psapi) Native.loadLibrary("Psapi", Psapi.class); WinDef.DWORD GetModuleBaseNameW(Pointer hProcess, Pointer hModule, byte[] lpBaseName, int nSize); } if (Platform.isWindows()) { final int PROCESS_VM_READ=0x0010; final int PROCESS_QUERY_INFORMATION=0x0400; final User32 user32 = User32.INSTANCE; final Kernel32 kernel32=Kernel32.INSTANCE; final Psapi psapi = Psapi.INSTANCE; WinDef.HWND windowHandle=user32.GetForegroundWindow(); IntByReference pid= new IntByReference(); user32.GetWindowThreadProcessId(windowHandle, pid); WinNT.HANDLE processHandle=kernel32.OpenProcess(PROCESS_VM_READ | PROCESS_QUERY_INFORMATION, true, pid.getValue()); byte[] filename = new byte[512]; Psapi.INSTANCE.GetModuleBaseNameW(processHandle.getPointer(), Pointer.NULL, filename, filename.length); String name=new String(filename); System.out.println(name); if (name.endsWith("wwahost.exe")) { // Metro App // There is no stable API to get the current Metro app // But you can guestimate the name form the current directory of the process // To query this, see: // http://stackoverflow.com/questions/16110936/read-other-process-current-directory-in-c-sharp }
IntByReference ref = new IntByReference(sizeOfInt); IntByReference size = new IntByReference(sizeOfInt); Memory m; int nRetry = 0; m = new Memory(size.getValue()); if(LIBC.sysctl(MIB_PROC_ALL,3, m, size, NULL, ref)!=0) { if(Native.getLastError()==ENOMEM && nRetry++<16) int count = size.getValue()/sizeOf_kinfo_proc; LOGGER.fine("Found "+count+" processes"); for( int base=0; base<size.getValue(); base+=sizeOf_kinfo_proc) { int pid = m.getInt(base+ kinfo_proc_pid_offset); int ppid = m.getInt(base+ kinfo_proc_ppid_offset);
IntByReference pError = new IntByReference(); if (pError.getValue() == ETrackedPropertyError.ETrackedPropertyError_TrackedProp_Success){ str = pchValue.getString(0); } else if (pError.getValue() == ETrackedPropertyError.ETrackedPropertyError_TrackedProp_BufferTooSmall){ throw new IllegalArgumentException("Cannot access property \""+getETrackedDevicePropertyString(property)+"\" ("+property+") for device "+deviceIndex+": "+getETrackedPropertyErrorString(pError.getValue())+" ("+pError.getValue()+")"); } else if (pError.getValue() == ETrackedPropertyError.ETrackedPropertyError_TrackedProp_CouldNotContactServer){ throw new IllegalArgumentException("Cannot access property \""+getETrackedDevicePropertyString(property)+"\" ("+property+") for device "+deviceIndex+": "+getETrackedPropertyErrorString(pError.getValue())+" ("+pError.getValue()+")");
IntByReference spnLength = new IntByReference(2048); char[] spn = new char[spnLength.getValue()]; return new String(spn, 0, spnLength.getValue());
/** * @see NativeCalls#isProcessActive(int) */ @Override public boolean isProcessActive(final int processId) { try { final Pointer procHandle = Kernel32.OpenProcess(Kernel32.PROCESS_QUERY_INFORMATION, false, processId); final long hval; if (procHandle == null || (hval = Pointer.nativeValue(procHandle)) == Kernel32.INVALID_HANDLE || hval == 0) { return false; } else { final IntByReference status = new IntByReference(); final boolean result = Kernel32.GetExitCodeProcess(procHandle, status) && status.getValue() == Kernel32.STILL_ACTIVE; Kernel32.CloseHandle(procHandle); return result; } } catch (LastErrorException le) { // some problem in getting process status return false; } }
envVars = new EnvVars(); IntByReference intByRef = new IntByReference(); IntByReference argmaxRef = new IntByReference(0); IntByReference size = new IntByReference(sizeOfInt); throw new IOException("Failed to get kern.argmax: "+LIBC.strerror(Native.getLastError())); int argmax = argmaxRef.getValue();
hmdErrorStore = new IntByReference(); vrsystemFunctions = null; if( hmdErrorStore.getValue() == 0 ) { vrsystemFunctions = new VR_IVRSystem_FnTable(JOpenVRLibrary.VR_GetGenericInterface(JOpenVRLibrary.IVRSystem_Version, hmdErrorStore).getPointer()); if( vrsystemFunctions == null || hmdErrorStore.getValue() != 0 ) { logger.severe("OpenVR Initialize Result: " + JOpenVRLibrary.VR_GetVRInitErrorAsEnglishDescription(hmdErrorStore.getValue()).getString(0)); logger.severe("Initializing OpenVR system [FAILED]"); return false;
/** * @param devName devName * @return an {@link org.pcap4j.util.Inet4NetworkAddress Inet4NetworkAddress} object. * @throws PcapNativeException if an error occurs in the pcap native library. */ public static Inet4NetworkAddress lookupNet(String devName) throws PcapNativeException { if (devName == null) { StringBuilder sb = new StringBuilder(); sb.append("devName: ").append(devName); throw new NullPointerException(sb.toString()); } PcapErrbuf errbuf = new PcapErrbuf(); IntByReference netp = new IntByReference(); IntByReference maskp = new IntByReference(); int rc = NativeMappings.pcap_lookupnet(devName, netp, maskp, errbuf); if (rc < 0) { throw new PcapNativeException(errbuf.toString(), rc); } int net = netp.getValue(); int mask = maskp.getValue(); return new Inet4NetworkAddress(Inets.itoInetAddress(net), Inets.itoInetAddress(mask)); }
IntByReference pcapStatSize = new IntByReference(); Pointer psp = PcapLibrary.INSTANCE.win_pcap_stats_ex(handle, pcapStatSize); if (!getError() .equals("Cannot retrieve the extended statistics from a file or a TurboCap port")) { if (pcapStatSize.getValue() != 24) { throw new PcapNativeException(getError());
private void waitpid(int options) { IntByReference status = new IntByReference(); boolean isDead = LIBC.waitpid(pid, status, options) > 0; if (isDead) { int x = status.getValue(); if ((x&0x7F)!=0) exitCode=128+(x&0x7F); exitCode = (x>>8)&0xFF; } }
/** * Get current keyboard mode. * * @return Keyboard mode (raw, transformed or off) - K_* constants. * @throws LastErrorException when the operation fails. */ public int getKeyboardMode() throws LastErrorException { IntByReference kbd = new IntByReference(0); super.ioctl(KDGKBMODE, kbd); return kbd.getValue(); }
public boolean isEnabled() { IntByReference selected = new IntByReference(); int result = lib.wdeIsEnabled(element, selected); errors.verifyErrorCode(result, "get enabled state"); return selected.getValue() == 1; }
public boolean isDisplayed() { IntByReference displayed = new IntByReference(); int result = lib.wdeIsDisplayed(element, displayed); errors.verifyErrorCode(result, "clear"); return displayed.getValue() == 1; }