com.sun.jna.platform.win32.WinDef.DWORD Java Examples

The following examples show how to use com.sun.jna.platform.win32.WinDef.DWORD. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WinUtil.java    From SikuliX1 with MIT License 6 votes vote down vote up
public static List<ProcessInfo> allProcesses() {
  List<ProcessInfo> processList = new ArrayList<ProcessInfo>();

  HANDLE snapshot = Kernel32.INSTANCE.CreateToolhelp32Snapshot(
      Tlhelp32.TH32CS_SNAPPROCESS, new DWORD(0));

  try {
    Tlhelp32.PROCESSENTRY32.ByReference pe
        = new Tlhelp32.PROCESSENTRY32.ByReference();
    for (boolean more = Kernel32.INSTANCE.Process32First(snapshot, pe);
         more;
         more = Kernel32.INSTANCE.Process32Next(snapshot, pe)) {
      int pid = pe.th32ProcessID.intValue();
      String name = getProcessImageName(pe.th32ProcessID.intValue());
      if (null == name) {
        continue;
      }
      processList.add(new ProcessInfo(pid, name));
    }
    return processList;
  } finally {
    Kernel32.INSTANCE.CloseHandle(snapshot);
  }
}
 
Example #2
Source File: Mouse.java    From Simplified-JNA with MIT License 6 votes vote down vote up
/**
 * Sends an action (flags) at the given x,y coordinates.
 * 
 * @param x
 * @param y
 * @param flags
 */
public static void mouseAction(int x, int y, int flags) {
	INPUT input = new INPUT();

	input.type = new DWORD(INPUT.INPUT_MOUSE);
	input.input.setType("mi");
	if (x != -1) {
		input.input.mi.dx = new LONG(x);
	}
	if (y != -1) {
		input.input.mi.dy = new LONG(y);
	}
	input.input.mi.time = new DWORD(0);
	input.input.mi.dwExtraInfo = new ULONG_PTR(0);
	input.input.mi.dwFlags = new DWORD(flags);
	User32.INSTANCE.SendInput(new DWORD(1), new INPUT[] { input }, input.size());
}
 
Example #3
Source File: WinProcess.java    From sheepit-client with GNU General Public License v2.0 6 votes vote down vote up
private List<WinProcess> getChildren() throws IOException {
	ArrayList<WinProcess> result = new ArrayList<WinProcess>();
	
	WinNT.HANDLE hSnap = this.kernel32lib.CreateToolhelp32Snapshot(Kernel32Lib.TH32CS_SNAPPROCESS, new DWORD(0));
	Kernel32Lib.PROCESSENTRY32.ByReference ent = new Kernel32Lib.PROCESSENTRY32.ByReference();
	if (!this.kernel32lib.Process32First(hSnap, ent)) {
		return result;
	}
	do {
		if (ent.th32ParentProcessID.intValue() == this.pid) {
			try {
				result.add(new WinProcess(ent.th32ProcessID.intValue()));
			}
			catch (IOException e) {
				System.err.println("WinProcess::getChildren, IOException " + e);
			}
		}
	}
	while (this.kernel32lib.Process32Next(hSnap, ent));
	
	Kernel32.INSTANCE.CloseHandle(hSnap);
	
	return result;
}
 
Example #4
Source File: CobaltStrike.java    From R9000 with Eclipse Public License 2.0 5 votes vote down vote up
static long findProcessID( String processName )
{
    Tlhelp32.PROCESSENTRY32.ByReference processInfo = new Tlhelp32.PROCESSENTRY32.ByReference();
    WinNT.HANDLE processSnapshotHandle =
                    kernel32.CreateToolhelp32Snapshot( Tlhelp32.TH32CS_SNAPPROCESS, new DWORD( 0L ) );

    try
    {
        kernel32.Process32First( processSnapshotHandle, processInfo );

        if ( processName.equals( Native.toString( processInfo.szExeFile ) ) )
        {
            return processInfo.th32ProcessID.longValue();
        }

        while ( kernel32.Process32Next( processSnapshotHandle, processInfo ) )
        {
            if ( processName.equals( Native.toString( processInfo.szExeFile ) ) )
            {
                return processInfo.th32ProcessID.longValue();
            }
        }

        return 0L;

    }
    finally
    {
        kernel32.CloseHandle( processSnapshotHandle );
    }
}
 
Example #5
Source File: Keyboard.java    From Simplified-JNA with MIT License 5 votes vote down vote up
/**
 * Sends a key-down input followed by a key-up input for the given character
 * value c.
 * 
 * @param c
 */
public static void pressKey(int c) {
	INPUT input = new INPUT();
	input.type = new DWORD(INPUT.INPUT_KEYBOARD);
	input.input.setType("ki");
	input.input.ki.wScan = new WORD(0);
	input.input.ki.time = new DWORD(0);
	input.input.ki.dwExtraInfo = new ULONG_PTR(0);
	input.input.ki.wVk = new WORD(c);
	input.input.ki.dwFlags = new DWORD(KEYEVENTF_KEYDOWN);
	User32.INSTANCE.SendInput(new DWORD(1), (INPUT[]) input.toArray(1), input.size());
	input.input.ki.wVk = new WORD(c);
	input.input.ki.dwFlags = new DWORD(KEYEVENTF_KEYUP);
	User32.INSTANCE.SendInput(new DWORD(1), (INPUT[]) input.toArray(1), input.size());
}
 
Example #6
Source File: Keyboard.java    From Simplified-JNA with MIT License 5 votes vote down vote up
/**
 * Sends a key-down input for the given character value c.
 * 
 * @param c
 */
public static void sendKeyDown(int c) {
	INPUT input = new INPUT();
	input.type = new DWORD(INPUT.INPUT_KEYBOARD);
	input.input.setType("ki");
	input.input.ki.wScan = new WORD(0);
	input.input.ki.time = new DWORD(0);
	input.input.ki.dwExtraInfo = new ULONG_PTR(0);
	input.input.ki.wVk = new WORD(c);
	input.input.ki.dwFlags = new DWORD(KEYEVENTF_KEYDOWN);
	User32.INSTANCE.SendInput(new DWORD(1), (INPUT[]) input.toArray(1), input.size());
}
 
Example #7
Source File: Keyboard.java    From Simplified-JNA with MIT License 5 votes vote down vote up
/**
 * Sends a key-up input for the given character value c.
 * 
 * @param c
 */
public static void sendKeyUp(int c) {
	INPUT input = new INPUT();
	input.type = new DWORD(INPUT.INPUT_KEYBOARD);
	input.input.setType("ki");
	input.input.ki.wScan = new WORD(0);
	input.input.ki.time = new DWORD(0);
	input.input.ki.dwExtraInfo = new ULONG_PTR(0);
	input.input.ki.wVk = new WORD(c);
	input.input.ki.dwFlags = new DWORD(KEYEVENTF_KEYUP);
	User32.INSTANCE.SendInput(new DWORD(1), (INPUT[]) input.toArray(1), input.size());
}
 
Example #8
Source File: Win32Process.java    From jpexs-decompiler with GNU General Public License v3.0 4 votes vote down vote up
public Win32Process(String filePath, String fileName, BufferedImage icon, DWORD th32ProcessID) {
    this.filePath = filePath;
    this.fileName = fileName;
    this.icon = icon;
    this.th32ProcessID = th32ProcessID;
}
 
Example #9
Source File: Kernel32Lib.java    From sheepit-client with GNU General Public License v2.0 4 votes vote down vote up
public PROCESSENTRY32() {
	dwSize = new WinDef.DWORD(size());
}
 
Example #10
Source File: Kernel32Lib.java    From sheepit-client with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Takes a snapshot of the specified processes, as well as the heaps, modules, and threads used by these processes.
 *
 * @param dwFlags       The portions of the system to be included in the snapshot.
 * @param th32ProcessID The process identifier of the process to be included in the snapshot. This parameter can be zero to indicate
 *                      the current process. This parameter is used when the TH32CS_SNAPHEAPLIST, TH32CS_SNAPMODULE,
 *                      TH32CS_SNAPMODULE32, or TH32CS_SNAPALL value is specified. Otherwise, it is ignored and all processes are
 *                      included in the snapshot.
 *                      <p/>
 *                      If the specified process is the Idle process or one of the CSRSS processes, this function fails and the last
 *                      error code is ERROR_ACCESS_DENIED because their access restrictions prevent user-level code from opening them.
 *                      <p/>
 *                      If the specified process is a 64-bit process and the caller is a 32-bit process, this function fails and the
 *                      last error code is ERROR_PARTIAL_COPY (299).
 * @return If the function succeeds, it returns an open handle to the specified snapshot.
 * <p/>
 * If the function fails, it returns INVALID_HANDLE_VALUE. To get extended error information, call GetLastError.
 * Possible error codes include ERROR_BAD_LENGTH.
 */
public WinNT.HANDLE CreateToolhelp32Snapshot(WinDef.DWORD dwFlags, WinDef.DWORD th32ProcessID);
 
Example #11
Source File: Kernel32Lib.java    From sheepit-client with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Controls whether the system will handle the specified types of serious errors or whether the process will handle them.
 * See: http://msdn.microsoft.com/en-us/library/ms680621%28VS.85%29.aspx
 *
 * @param uMode The process error mode. This parameter can be one or more of the following values.
 */
public int SetErrorMode(DWORD uMode);
 
Example #12
Source File: Gdi32.java    From jpexs-decompiler with GNU General Public License v3.0 votes vote down vote up
DWORD GetPixel(HDC hdc, int nXPos, int nYPos); 
Example #13
Source File: Gdi32.java    From jpexs-decompiler with GNU General Public License v3.0 votes vote down vote up
HANDLE CreateSolidBrush(DWORD crColor);