Java 类com.sun.jna.platform.win32.WinDef.HMODULE 实例源码

项目:Mem-Eater-Bug    文件:Process.java   
/**
 * Gets the list of modules that belong to this process.
 * 
 * @see <a href=
 *      "https://msdn.microsoft.com/en-us/library/ms682631(v=vs.85).aspx">
 *      MSDN webpage#EnumProcessModules function</a>
 * 
 * @return The list of modules that belong to this process
 */
public List<Module> getModules() {
    try {
        final List<HMODULE> pointers = PsapiUtil.enumProcessModules(getHandle());
        final List<Module> modules = new LinkedList<>();
        for (final HMODULE hModule : pointers) {
            modules.add(new Module(getHandle(), hModule));
        }
        return modules;
    } catch (final Exception e) {
        return null;
    }
}
项目:AppWoksUtils    文件:FileIconExporter.java   
public static BufferedImage getIcon(final String path, final int num, final int width, final int height) throws FileNotFoundException {
    final HMODULE hinst = org.appwork.jna.winapi.kernel32.Kernel.I.LoadLibraryExA(path, null, org.appwork.jna.winapi.kernel32.Kernel.LOAD_LIBRARY_AS_DATAFILE);
    // Kernel32.INSTANCE.e
    // final HMODULE hinst =
    // final int err = Kernel32.INSTANCE.GetLastError();
    if (hinst == null) { throw new FileNotFoundException(path + " could not be loaded"); }
    final HANDLE hicon = com.sun.jna.platform.win32.User32.INSTANCE.LoadImage(hinst, "IDR_MAINFRAME", 1, width, height, 0);
    if (hicon == null) { throw new FileNotFoundException(path + ": No icon #" + num); }
    return getImageByHICON(width, height, hicon);

}
项目:Clipcon-Client    文件:ClipboardController.java   
public static void clipboardMonitor() {

    WString windowClass = new WString("MyWindowClass");
    HMODULE hInst = Kernel32.INSTANCE.GetModuleHandle("");
    WNDCLASSEX wClass = new WNDCLASSEX();
    wClass.hInstance = hInst;
    WindowProc wProc = new WindowProc();
    wClass.lpfnWndProc = wProc;
    wClass.lpszClassName = windowClass;

    // register window class
    User32.INSTANCE.RegisterClassEx(wClass);
    getLastError();

    // create new window
    HWND hWnd = User32.INSTANCE.CreateWindowEx(User32.WS_EX_TOPMOST, windowClass, "My hidden helper window, used only to catch the windows events", 0, 0, 0, 0, 0, null, null, hInst, null);
    getLastError();

    // set clipboard viewer
    HWND nextViewer = User32X.INSTANCE.SetClipboardViewer(hWnd);
    wProc.setNextViewer(nextViewer);

    // pump messages
    MSG msg = new MSG();
    while (User32.INSTANCE.GetMessage(msg, hWnd, 0, 0) != 0) {
        User32.INSTANCE.TranslateMessage(msg);
        User32.INSTANCE.DispatchMessage(msg);
    }

    // wait for input
    try {
        System.in.read();
    } catch (IOException e) {
        e.printStackTrace();
    }

    // destroy window
    User32.INSTANCE.UnregisterClass(windowClass, hInst);
    User32.INSTANCE.DestroyWindow(hWnd);
    System.exit(0);
}
项目:Mem-Eater-Bug    文件:PsapiUtil.java   
/**
 * Retrieves a list of handles for each module in the specified process,
 * that meets the filter criteria specified by the list flag.
 * 
 * @see <a href=
 *      "https://msdn.microsoft.com/en-us/library/ms682631(v=vs.85).aspx">
 *      MSDN webpage#EnumProcessModules function</a>
 * @param hProcess
 *            A handle to the process.
 * @param listFlag
 *            Specifies the modules to list. Possible values are the
 *            following.
 *            <ul>
 *            <li>
 *            {@link de.zabuza.memeaterbug.winapi.jna.Psapi#LIST_MODULES_32BIT
 *            LIST_MODULES_32BIT}</li>
 *            <li>
 *            {@link de.zabuza.memeaterbug.winapi.jna.Psapi#LIST_MODULES_64BIT
 *            LIST_MODULES_64BIT}</li>
 *            <li>
 *            {@link de.zabuza.memeaterbug.winapi.jna.Psapi#LIST_MODULES_ALL
 *            LIST_MODULES_ALL} or <tt>null</tt></li>
 *            <li>
 *            {@link de.zabuza.memeaterbug.winapi.jna.Psapi#LIST_MODULES_DEFAULT
 *            LIST_MODULES_DEFAULT}</li>
 *            </ul>
 * @return A list of handles for each module in the specified process, that
 *         meets the filter criteria specified by the list flag.
 * @throws Win32Exception
 *             If the operation was not successful
 */
public static List<HMODULE> enumProcessModulesEx(final HANDLE hProcess, final Integer listFlag)
        throws Win32Exception {
    final int moduleSize = MemSize.getSizeOfModule(hProcess);
    final List<HMODULE> list = new LinkedList<>();

    final HMODULE[] lphModule = new HMODULE[MODULE_BUFFER_AMOUNT * moduleSize];
    final IntByReference lpcbNeededs = new IntByReference();

    if (listFlag == null) {
        if (!Psapi.INSTANCE.EnumProcessModules(hProcess, lphModule, lphModule.length, lpcbNeededs)) {
            throw new Win32Exception(Native.getLastError());
        }
    } else {
        if (!Psapi.INSTANCE.EnumProcessModulesEx(hProcess, lphModule, lphModule.length, lpcbNeededs,
                listFlag.intValue())) {
            throw new Win32Exception(Native.getLastError());
        }
    }

    for (int i = 0; i < lpcbNeededs.getValue() / moduleSize; i++) {
        list.add(lphModule[i]);
    }

    return list;
}
项目:spark-svn-mirror    文件:UserIdlePlugin.java   
public void initKeyHook() {

        thread = new Thread(new Runnable() {

        @Override
        public void run() {
            final User32 lib = User32.INSTANCE;
            HMODULE hMod = Kernel32.INSTANCE.GetModuleHandle(null);
            keyboardHook = new LowLevelKeyboardProc() {
            public LRESULT callback(int nCode, WPARAM wParam,
                KBDLLHOOKSTRUCT info) {
                if (nCode >= 0) {
                switch (wParam.intValue()) {
                // case WinUser.WM_KEYUP:
                case WinUser.WM_KEYDOWN:
                    // case WinUser.WM_SYSKEYUP:
                case WinUser.WM_SYSKEYDOWN:
                    // do active
                    userActive();
                }
                }
                return lib.CallNextHookEx(hhk, nCode, wParam,
                    info.getPointer());
            }
            };
            hhk = lib.SetWindowsHookEx(WinUser.WH_KEYBOARD_LL,
                keyboardHook, hMod, 0);

            // This bit never returns from GetMessage
            int result;
            MSG msg = new MSG();
            while ((result = lib.GetMessage(msg, null, 0, 0)) != 0) {
            if (result == -1) {
                System.err.println("error in get message");
                break;
            } else {
                System.err.println("got message");
                lib.TranslateMessage(msg);
                lib.DispatchMessage(msg);
            }
            }
            lib.UnhookWindowsHookEx(hhk);
        }
        });
        thread.start();
    }
项目:Mem-Eater-Bug    文件:Module.java   
/**
 * Creates a new module that is able to read information from the module of
 * the given process, by the given module handle.
 * 
 * @see <a href=
 *      "https://msdn.microsoft.com/en-us/library/ms684868(v=vs.85).aspx">
 *      MSDN webpage#Process Handles and Identifiers</a>
 * @see <a href=
 *      "https://msdn.microsoft.com/en-us/library/aa383751(v=vs.85).aspx">
 *      MSDN webpage#Windows Data Types</a>
 * @see <a href=
 *      "https://msdn.microsoft.com/en-us/library/ms684229(v=vs.85).aspx">
 *      MSDN webpage#MODULEINFO structure</a>
 * 
 * @param hProcess
 *            Handle to the process of this module
 * @param hModule
 *            Handle of the module to create around
 */
public Module(final HANDLE hProcess, final HMODULE hModule) {
    this.mHProcess = hProcess;
    this.mHModule = hModule;

    this.mLpBaseOfDll = null;
    this.mEntryPoint = null;
    this.mSizeOfImage = 0;
}
项目:Mem-Eater-Bug    文件:PsapiUtil.java   
/**
 * Retrieves information about the specified module in the
 * {@link LPMODULEINFO} structure.
 * 
 * @see <a href=
 *      "https://msdn.microsoft.com/en-us/library/ms683201(v=vs.85).aspx">
 *      MSDN webpage#GetModuleInformation function</a>
 * @param hProcess
 *            A handle to the process that contains the module.<br/>
 *            <br/>
 *            The handle must have the
 *            {@link de.zabuza.memeaterbug.winapi.Process#PROCESS_QUERY_INFORMATION
 *            PROCESS_QUERY_INFORMATION} and
 *            {@link de.zabuza.memeaterbug.winapi.Process#PROCESS_VM_READ
 *            PROCESS_VM_READ} access rights.
 * @param hModule
 *            A handle to the module.
 * @return Information about the specified module as {@link LPMODULEINFO}
 *         structure.
 * @throws Win32Exception
 *             If the operation was not successful
 */
public static LPMODULEINFO getModuleInformation(final HANDLE hProcess, final HMODULE hModule)
        throws Win32Exception {
    final LPMODULEINFO lpmodinfo = new LPMODULEINFO();

    if (!Psapi.INSTANCE.GetModuleInformation(hProcess, hModule, lpmodinfo, lpmodinfo.size())) {
        throw new Win32Exception(Native.getLastError());
    }
    return lpmodinfo;
}
项目:Mem-Eater-Bug    文件:Module.java   
/**
 * Gets a handle to this module.
 * 
 * @see <a href=
 *      "https://msdn.microsoft.com/en-us/library/aa383751(v=vs.85).aspx">
 *      MSDN webpage#Windows Data Types</a>
 * 
 * @return A handle to this module
 */
public HMODULE getHModule() {
    return this.mHModule;
}
项目:Mem-Eater-Bug    文件:Psapi.java   
/**
 * Retrieves a handle for each module in the specified process.
 * 
 * @see <a href=
 *      "https://msdn.microsoft.com/en-us/library/ms682631(v=vs.85).aspx">
 *      MSDN webpage#EnumProcessModules function</a>
 * 
 * @param hProcess
 *            A handle to the process.
 * @param lphModule
 *            An array that receives the list of module handles.
 * @param cb
 *            The size of the lphModule array, in bytes.
 * @param lpcbNeededs
 *            The number of bytes required to store all module handles in
 *            the lphModule array.
 * @return If the function succeeds, the return value is nonzero.<br/>
 *         <br/>
 *         If the function fails, the return value is zero. To get extended
 *         error information, call {@link Native#getLastError()}.
 */
public boolean EnumProcessModules(final HANDLE hProcess, final HMODULE[] lphModule, final int cb,
        final IntByReference lpcbNeededs);
项目:Mem-Eater-Bug    文件:Psapi.java   
/**
 * Retrieves a handle for each module in the specified process that meets
 * the specified filter criteria.
 * 
 * @see <a href=
 *      "https://msdn.microsoft.com/en-us/library/ms682633(v=vs.85).aspx">
 *      MSDN webpage#EnumProcessModulesEx function</a>
 * 
 * @param hProcess
 *            A handle to the process.
 * @param lphModule
 *            An array that receives the list of module handles.
 * @param cb
 *            The size of the lphModule array, in bytes.
 * @param lpcbNeededs
 *            The number of bytes required to store all module handles in
 *            the lphModule array.
 * @param dwFilterFlag
 *            The filter criteria. This parameter can be one of the
 *            following values.
 *            <ul>
 *            <li>{@link #LIST_MODULES_32BIT}</li>
 *            <li>{@link #LIST_MODULES_64BIT}</li>
 *            <li>{@link #LIST_MODULES_ALL}</li>
 *            <li>{@link #LIST_MODULES_DEFAULT}</li>
 *            </ul>
 * @return If the function succeeds, the return value is nonzero.<br/>
 *         <br/>
 *         If the function fails, the return value is zero. To get extended
 *         error information, call {@link Native#getLastError()}.
 */
public boolean EnumProcessModulesEx(final HANDLE hProcess, final HMODULE[] lphModule, final int cb,
        final IntByReference lpcbNeededs, final int dwFilterFlag);
项目:Mem-Eater-Bug    文件:Psapi.java   
/**
 * Retrieves information about the specified module in the
 * {@link LPMODULEINFO} structure.
 * 
 * @see <a href=
 *      "https://msdn.microsoft.com/en-us/library/ms683201(v=vs.85).aspx">
 *      MSDN webpage#GetModuleInformation function</a>
 * 
 * @param hProcess
 *            A handle to the process that contains the module.<br/>
 *            <br/>
 *            The handle must have the
 *            {@link de.zabuza.memeaterbug.winapi.Process#PROCESS_QUERY_INFORMATION
 *            PROCESS_QUERY_INFORMATION} and
 *            {@link de.zabuza.memeaterbug.winapi.Process#PROCESS_VM_READ
 *            PROCESS_VM_READ} access rights.
 * @param hModule
 *            A handle to the module.
 * @param lpmodinfo
 *            A pointer to the {@link LPMODULEINFO} structure that receives
 *            information about the module.
 * @param cb
 *            The size of the {@link LPMODULEINFO} structure, in bytes.
 * @return If the function succeeds, the return value is nonzero.<br/>
 *         <br/>
 *         If the function fails, the return value is zero. To get extended
 *         error information, call {@link Native#getLastError()}.
 */
public boolean GetModuleInformation(final HANDLE hProcess, final HMODULE hModule, final LPMODULEINFO lpmodinfo,
        final int cb);
项目:Mem-Eater-Bug    文件:PsapiUtil.java   
/**
 * Retrieves a list of handles for each module in the specified process.
 * 
 * @see <a href=
 *      "https://msdn.microsoft.com/en-us/library/ms682631(v=vs.85).aspx">
 *      MSDN webpage#EnumProcessModules function</a>
 * @param hProcess
 *            A handle to the process.
 * @return A list of handles for each module in the specified process
 * @throws Win32Exception
 *             If the operation was not successful
 */
public static List<HMODULE> enumProcessModules(final HANDLE hProcess) throws Win32Exception {
    return enumProcessModulesEx(hProcess, null);
}
项目:Mem-Eater-Bug    文件:PsapiUtil.java   
/**
 * Retrieves a list of handles for each 32-bit module in the specified
 * process.
 * 
 * @see <a href=
 *      "https://msdn.microsoft.com/en-us/library/ms682633(v=vs.85).aspx">
 *      MSDN webpage#EnumProcessModulesEx function</a>
 * @param hProcess
 *            A handle to the process.
 * @return A list of handles for each 32-bit module in the specified process
 * @throws Win32Exception
 *             If the operation was not successful
 */
public static List<HMODULE> enumProcessModulesEx32(final HANDLE hProcess) throws Win32Exception {
    return enumProcessModulesEx(hProcess, Integer.valueOf(Psapi.LIST_MODULES_32BIT));
}
项目:Mem-Eater-Bug    文件:PsapiUtil.java   
/**
 * Retrieves a list of handles for each 64-bit module in the specified
 * process.
 * 
 * @see <a href=
 *      "https://msdn.microsoft.com/en-us/library/ms682633(v=vs.85).aspx">
 *      MSDN webpage#EnumProcessModulesEx function</a>
 * @param hProcess
 *            A handle to the process.
 * @return A list of handles for each 64-bit module in the specified process
 * @throws Win32Exception
 *             If the operation was not successful
 */
public static List<HMODULE> enumProcessModulesEx64(final HANDLE hProcess) throws Win32Exception {
    return enumProcessModulesEx(hProcess, Integer.valueOf(Psapi.LIST_MODULES_64BIT));
}
项目:AppWoksUtils    文件:Kernel.java   
/**
 * http://msdn.microsoft.com/en-us/library/ms648037(v=VS.85).aspx
 * 
 * @param lib
 * @param resType
 * @param enumResourceNamesCallback
 * @param data
 */
public void EnumResourceNamesA(HMODULE lib, String resType, EnumResourceNamesCallback enumResourceNamesCallback, long data);
项目:AppWoksUtils    文件:Kernel.java   
/**
 * http://msdn.microsoft.com/en-us/library/ms648042(v=vs.85).aspx<br>
 * 
 * @return
 * 
 */
public HRSRC FindResourceA(HMODULE lib, Pointer name, String type);
项目:AppWoksUtils    文件:Kernel.java   
/**
 * http://msdn.microsoft.com/en-us/library/ms683152%28v=VS.85%29.aspx
 * 
 * @param lib
 * @return
 */
public boolean FreeLibrary(HMODULE lib);
项目:AppWoksUtils    文件:Kernel.java   
/**
 * http://msdn.microsoft.com/en-us/library/ms648046(v=VS.85).aspx
 * 
 * @param module
 * @param resourceHandle
 * @return
 */
public HGLOBAL LoadResource(HMODULE module, HRSRC resourceHandle);
项目:AppWoksUtils    文件:EnumResourceNamesCallback.java   
/** Return whether to continue enumeration. */

    boolean callback(HMODULE module, Pointer type, int name, Pointer data);
项目:AppWoksUtils    文件:Kernel.java   
public HMODULE LoadLibraryExA(String path, Object fileHandle, int flags);
项目:Harmonia-1.5    文件:Kernel32Ext.java   
public boolean EnumResourceNames(HMODULE hModule, String lpszType, ENUMRESNAMEPROC lpEnumFunc, Pointer lParam);
项目:Harmonia-1.5    文件:Kernel32Ext.java   
public boolean callback(HMODULE hModule, String lpszType, String lpszName, Pointer lParam);