Pointer spawnCfg = null; Pointer winpty = null; WinNT.HANDLEByReference processHandle = new WinNT.HANDLEByReference(); NamedPipe coninPipe = null; NamedPipe conoutPipe = null; myProcess = processHandle.getValue(); myConinPipe = coninPipe; myConoutPipe = conoutPipe; processHandle.setValue(null); coninPipe = conoutPipe = conerrPipe = null; INSTANCE.winpty_spawn_config_free(spawnCfg); INSTANCE.winpty_free(winpty); if (processHandle.getValue() != null) { Kernel32.INSTANCE.CloseHandle(processHandle.getValue());
Memory securityDescriptorMemoryPointer = getSecurityDescriptorForFile(file.getAbsolutePath().replace('/', '\\')); HANDLEByReference openedAccessToken = new HANDLEByReference(); HANDLEByReference duplicatedToken = new HANDLEByReference(); Win32Exception err = null; try{ if (!Advapi32.INSTANCE.DuplicateToken(openedAccessToken.getValue(), SECURITY_IMPERSONATION_LEVEL.SecurityImpersonation, duplicatedToken)) { throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); BOOLByReference result = new BOOLByReference(); if (!Advapi32.INSTANCE.AccessCheck(securityDescriptorMemoryPointer, duplicatedToken.getValue(), rights.getValue(), mapping,
final HANDLEByReference phThreadToken = new HANDLEByReference(); phThreadToken.setValue(getThreadToken()); WinNT.TOKEN_PRIVILEGES tp = new WinNT.TOKEN_PRIVILEGES(pLuids.length); for (int i = 0; i < pLuids.length; i++) { tp.Privileges[i] = new WinNT.LUID_AND_ATTRIBUTES(pLuids[i], new DWORD(WinNT.SE_PRIVILEGE_ENABLED)); if (!Advapi32.INSTANCE.AdjustTokenPrivileges(phThreadToken.getValue(), false, tp, 0, null, null)) { throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); tp.Privileges[i] = new WinNT.LUID_AND_ATTRIBUTES(pLuids[i], new DWORD(0)); Advapi32.INSTANCE.AdjustTokenPrivileges(phThreadToken.getValue(), false, tp, 0, null, null); privilegesEnabled = false; if ((phThreadToken.getValue() != WinBase.INVALID_HANDLE_VALUE) && (phThreadToken.getValue() != null)) { Kernel32.INSTANCE.CloseHandle(phThreadToken.getValue()); phThreadToken.setValue(null);
final WinNT.HANDLE accessToken; final WinNT.HANDLEByReference tokenReference = new WinNT.HANDLEByReference(); final boolean success = advapi32.OpenProcessToken( kernel32.GetCurrentProcess(), throw new SystemException("Cannot open access token"); accessToken = tokenReference.getValue();
final HANDLEByReference phThreadToken = new HANDLEByReference(); final HANDLEByReference phProcessToken = new HANDLEByReference(); if (!Advapi32.INSTANCE.DuplicateTokenEx(phProcessToken.getValue(), TOKEN_ADJUST_PRIVILEGES | TOKEN_IMPERSONATE, null, if (!Advapi32.INSTANCE.SetThreadToken(null, phThreadToken.getValue())) { throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); if ((phThreadToken.getValue() != WinBase.INVALID_HANDLE_VALUE) && (phThreadToken.getValue() != null)) { Kernel32.INSTANCE.CloseHandle(phThreadToken.getValue()); phThreadToken.setValue(null); if ((phProcessToken.getValue() != WinBase.INVALID_HANDLE_VALUE) && (phProcessToken.getValue() != null)) { Kernel32.INSTANCE.CloseHandle(phProcessToken.getValue()); phProcessToken.setValue(null); return phThreadToken.getValue();
HANDLEByReference phToken = new HANDLEByReference(); Win32Exception err = null; try { return getTokenGroups(phToken.getValue()); } catch(Win32Exception e) { err = e; throw err; // re-throw in order to invoke finally block } finally { HANDLE hToken = phToken.getValue(); if (!WinBase.INVALID_HANDLE_VALUE.equals(hToken)) { try {
WinNT.FILE_SHARE_READ, new WinBase.SECURITY_ATTRIBUTES(), WinNT.OPEN_EXISTING, WinNT.FILE_ATTRIBUTE_NORMAL, new HANDLEByReference().getValue());
public static PRINTER_INFO_2 getPrinterInfo2(String printerName) { IntByReference pcbNeeded = new IntByReference(); IntByReference pcReturned = new IntByReference(); HANDLEByReference pHandle = new HANDLEByReference(); Winspool.INSTANCE.GetPrinter(pHandle.getValue(), 2, null, 0, pcbNeeded); if (pcbNeeded.getValue() <= 0) return new PRINTER_INFO_2(); if (!Winspool.INSTANCE.GetPrinter(pHandle.getValue(), 2, pinfo2.getPointer(), pcbNeeded.getValue(), pcReturned)) throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); we = e; } finally { if (!Winspool.INSTANCE.ClosePrinter(pHandle.getValue())) { Win32Exception ex = new Win32Exception(Kernel32.INSTANCE.GetLastError()); if (we != null) {
/** * Dial a phone book entry by name (Synchronously) * @param entryName The phone book entry name * @return result reference * @throws Ras32Exception errors */ public static HANDLE dialEntry(String entryName) throws Ras32Exception { // get the RAS Credentials RASCREDENTIALS.ByReference credentials = new RASCREDENTIALS.ByReference(); synchronized (phoneBookMutex) { credentials.dwMask = WinRas.RASCM_UserName | WinRas.RASCM_Password | WinRas.RASCM_Domain; int err = Rasapi32.INSTANCE.RasGetCredentials(null, entryName, credentials); if (err != WinError.ERROR_SUCCESS) throw new Ras32Exception(err); } // set the dialing parameters RASDIALPARAMS.ByReference rasDialParams = new RASDIALPARAMS.ByReference(); System.arraycopy(entryName.toCharArray(), 0, rasDialParams.szEntryName, 0, entryName.length()); System.arraycopy(credentials.szUserName, 0, rasDialParams.szUserName, 0, credentials.szUserName.length); System.arraycopy(credentials.szPassword, 0, rasDialParams.szPassword, 0, credentials.szPassword.length); System.arraycopy(credentials.szDomain, 0, rasDialParams.szDomain, 0, credentials.szDomain.length); // dial HANDLEByReference hrasConn = new HANDLEByReference(); int err = Rasapi32.INSTANCE.RasDial(null, null, rasDialParams, 0, null, hrasConn); if (err != WinError.ERROR_SUCCESS) { if (hrasConn.getValue() != null) Rasapi32.INSTANCE.RasHangUp(hrasConn.getValue()); throw new Ras32Exception(err); } return hrasConn.getValue(); }
WinNT.OPEN_EXISTING, WinNT.FILE_ATTRIBUTE_NORMAL, new HANDLEByReference().getValue());
HANDLEByReference phToken = new HANDLEByReference(); try { return getTokenGroups(phToken.getValue()); } finally { if (phToken.getValue() != WinBase.INVALID_HANDLE_VALUE) { if (!Kernel32.INSTANCE.CloseHandle(phToken.getValue())) { throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
final HANDLEByReference phThreadToken = new HANDLEByReference(); phThreadToken.setValue(getThreadToken()); if (currentlyImpersonating) { Advapi32.INSTANCE.SetThreadToken(null, null); tp.Privileges[i] = new WinNT.LUID_AND_ATTRIBUTES(pLuids[i], new DWORD(0)); Advapi32.INSTANCE.AdjustTokenPrivileges(phThreadToken.getValue(), false, tp, 0, null, null); privilegesEnabled = false; if ((phThreadToken.getValue() != WinBase.INVALID_HANDLE_VALUE) && (phThreadToken.getValue() != null)) { Kernel32.INSTANCE.CloseHandle(phThreadToken.getValue()); phThreadToken.setValue(null);
/** * Dial a phone book entry by name (Asynchronously - callback type 2) * @param entryName The phone book entry name * @param func2 * @return the HRASCONN for this connection * @throws Ras32Exception errors */ public static HANDLE dialEntry(String entryName, RasDialFunc2 func2) throws Ras32Exception { // get the RAS Credentials RASCREDENTIALS.ByReference credentials = new RASCREDENTIALS.ByReference(); synchronized (phoneBookMutex) { credentials.dwMask = WinRas.RASCM_UserName | WinRas.RASCM_Password | WinRas.RASCM_Domain; int err = Rasapi32.INSTANCE.RasGetCredentials(null, entryName, credentials); if (err != WinError.ERROR_SUCCESS) throw new Ras32Exception(err); } // set the dialing parameters RASDIALPARAMS.ByReference rasDialParams = new RASDIALPARAMS.ByReference(); System.arraycopy(entryName.toCharArray(), 0, rasDialParams.szEntryName, 0, entryName.length()); System.arraycopy(credentials.szUserName, 0, rasDialParams.szUserName, 0, credentials.szUserName.length); System.arraycopy(credentials.szPassword, 0, rasDialParams.szPassword, 0, credentials.szPassword.length); System.arraycopy(credentials.szDomain, 0, rasDialParams.szDomain, 0, credentials.szDomain.length); // dial HANDLEByReference hrasConn = new HANDLEByReference(); int err = Rasapi32.INSTANCE.RasDial(null, null, rasDialParams, 2, func2, hrasConn); if (err != WinError.ERROR_SUCCESS) { if (hrasConn.getValue() != null) Rasapi32.INSTANCE.RasHangUp(hrasConn.getValue()); throw new Ras32Exception(err); } return hrasConn.getValue(); }
public static JOB_INFO_1[] getJobInfo1(HANDLEByReference phPrinter) { IntByReference pcbNeeded = new IntByReference(); IntByReference pcReturned = new IntByReference(); Winspool.INSTANCE.EnumJobs(phPrinter.getValue(), 0, 255, 1, null, 0, pcbNeeded, pcReturned); if (pcbNeeded.getValue() <= 0) { return new JOB_INFO_1[0]; } JOB_INFO_1 pJobEnum = new JOB_INFO_1(pcbNeeded.getValue()); if (!Winspool.INSTANCE.EnumJobs(phPrinter.getValue(), 0, 255, 1, pJobEnum.getPointer(), pcbNeeded.getValue(), pcbNeeded, pcReturned)) { throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); } pJobEnum.read(); return (JOB_INFO_1[]) pJobEnum.toArray(pcReturned.getValue()); }
public void setValue(HANDLE h) { getPointer().setPointer(0, h != null ? h.getPointer() : null); }
public HANDLEByReference(HANDLE h) { super(Native.POINTER_SIZE); setValue(h); }
@Override public IWindowsIdentity getIdentity() { final HANDLEByReference phContextToken = new HANDLEByReference(); final int rc = Secur32.INSTANCE.QuerySecurityContextToken(this.ctx, phContextToken); if (WinError.SEC_E_OK != rc) { throw new Win32Exception(rc); } return new WindowsIdentityImpl(phContextToken.getValue()); }
public void setValue(HANDLE h) { getPointer().setPointer(0, h != null ? h.getPointer() : null); }
public HANDLEByReference(HANDLE h) { super(Pointer.SIZE); setValue(h); }
/** * Closes the handle in the reference * * @param ref The handle reference - ignored if {@code null} * @see #closeHandle(WinNT.HANDLE) */ public static void closeHandleRef(HANDLEByReference ref) { closeHandle((ref == null) ? null : ref.getValue()); }