import com.sun.jna.Native; import com.sun.jna.platform.win32.*; import com.sun.jna.win32.W32APIOptions; public class ProcessList { public static void main(String[] args) { WinNT winNT = (WinNT) Native.loadLibrary(WinNT.class, W32APIOptions.UNICODE_OPTIONS); WinNT.HANDLE snapshot = winNT.CreateToolhelp32Snapshot(Tlhelp32.TH32CS_SNAPPROCESS, new WinDef.DWORD(0)); Tlhelp32.PROCESSENTRY32.ByReference processEntry = new Tlhelp32.PROCESSENTRY32.ByReference(); while (winNT.Process32Next(snapshot, processEntry)) { System.out.println(processEntry.th32ProcessID + "\t" + Native.toString(processEntry.szExeFile)); } winNT.CloseHandle(snapshot); } }
@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); } };
@Override public void setAffinity(final long affinity) { final CLibrary lib = CLibrary.INSTANCE; WinDef.DWORD aff = new WinDef.DWORD(affinity); try { lib.SetThreadAffinityMask(lib.GetCurrentThread(), aff); } catch (LastErrorException e) { throw new IllegalStateException("sched_getaffinity((" + Long.SIZE / 8 + ") , &(" + affinity + ") ) errorNo=" + e.getErrorCode(), e); } } }
public STARTUPINFO() { super(W32APITypeMapper.DEFAULT); cb = new DWORD(size()); } }
public SECURITY_ATTRIBUTES() { dwLength = new DWORD(size()); } }
public OSVERSIONINFOEX() { szCSDVersion = new char[128]; dwOSVersionInfoSize = new DWORD(size()); // sizeof(OSVERSIONINFOEX) }
public OSVERSIONINFO() { szCSDVersion = new char[128]; dwOSVersionInfoSize = new DWORD(size()); // sizeof(OSVERSIONINFO) }
/** * Waits for the application to accept input, i.e. not be idle. * @param timeout Timeout to wait for. */ public void waitForInputIdle(final int timeout) { if (user32 == null) { user32 = User32.INSTANCE; } user32.WaitForInputIdle(this.handle, new WinDef.DWORD(timeout)); }
public void shutdown() throws SystemException { final boolean success = advapi32.InitiateSystemShutdown( null, null, new WinDef.DWORD(0), true, false ); if (!success) { throw new SystemException(Kernel32Util.formatMessage(kernel32.GetLastError())); } }
public OSVERSIONINFO() { dwMajorVersion = new WinDef.DWORD(0); dwMinorVersion = new WinDef.DWORD(0); dwBuildNumber = new WinDef.DWORD(0); dwPlatformId = new WinDef.DWORD(0); szCSDVersion = new char[128]; for (int i = 0; i < szCSDVersion.length; i++) { szCSDVersion[i] = 0; } dwOSVersionInfoSize = new WinDef.DWORD(size()); }
/** * Decrypts an encrypted file or directory. * * @param file * The file or directory to decrypt. */ public static void decryptFile(File file) { String lpFileName = file.getAbsolutePath(); if (!Advapi32.INSTANCE.DecryptFile(lpFileName, new DWORD(0))) { throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); } }
/** Initialize a TOKEN_PRIVILEGES instance from initialized memory. * @param p base address */ public TOKEN_PRIVILEGES(Pointer p) { super(p); int count = p.getInt(0); PrivilegeCount = new DWORD(count); Privileges = new LUID_AND_ATTRIBUTES[count]; read(); } }
public STARTUPINFO() { cb = new DWORD(size()); } }
public DWORD getValue() { return new DWORD(getPointer().getInt(0)); } }
/** Initialize a TOKEN_PRIVILEGES instance from initialized memory. */ public TOKEN_PRIVILEGES(Pointer p) { super(p); int count = p.getInt(0); PrivilegeCount = new DWORD(count); Privileges = new LUID_AND_ATTRIBUTES[count]; read(); } }
/** * @param nbOfPrivileges * Desired size of the Privileges array */ public TOKEN_PRIVILEGES(int nbOfPrivileges) { PrivilegeCount = new DWORD(nbOfPrivileges); Privileges = new LUID_AND_ATTRIBUTES[nbOfPrivileges]; }
/** * @param nbOfPrivileges * Desired size of the Privileges array */ public TOKEN_PRIVILEGES(int nbOfPrivileges) { PrivilegeCount = new DWORD(nbOfPrivileges); Privileges = new LUID_AND_ATTRIBUTES[nbOfPrivileges]; }
/** * Instantiates a new dWOR dby reference. */ public DWORDByReference() { this(new DWORD(0)); }
private void addShutdownPrivilegeToProcess() { HANDLEByReference hToken = new HANDLEByReference(); LUID luid = new LUID(); Advapi32.INSTANCE.OpenProcessToken(Kernel32.INSTANCE.GetCurrentProcess(), WinNT.TOKEN_ADJUST_PRIVILEGES, hToken); Advapi32.INSTANCE.LookupPrivilegeValue("", WinNT.SE_SHUTDOWN_NAME, luid); TOKEN_PRIVILEGES tp = new TOKEN_PRIVILEGES(1); tp.Privileges[0] = new LUID_AND_ATTRIBUTES(luid, new DWORD(WinNT.SE_PRIVILEGE_ENABLED)); Advapi32.INSTANCE.AdjustTokenPrivileges(hToken.getValue(), false, tp, tp.size(), null, new IntByReference()); }
/** * @param nbOfPrivileges * Desired size of the Privileges array */ public PRIVILEGE_SET(int nbOfPrivileges) { PrivilegeCount = new DWORD(nbOfPrivileges); if(nbOfPrivileges > 0) { Privileges = new LUID_AND_ATTRIBUTES[nbOfPrivileges]; } }