⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kernel32.java

📁 jnative java 调用动态库需要的包和dll
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
	 *  	 PROCESS_SET_INFORMATION (0x0200) 	Required to set certain information about a process, such as its priority class (see SetPriorityClass).
	 *  	 PROCESS_SUSPEND_RESUME (0x0800) 	Required to suspend or resume a process.
	 *  	 PROCESS_TERMINATE (0x0001) 	Required to terminate a process using TerminateProcess.
	 *  	 PROCESS_VM_OPERATION (0x0008) 	Required to perform an operation on the address space of a process (see VirtualProtectEx and WriteProcessMemory).
	 *  	 PROCESS_VM_READ (0x0010) 	Required to read memory in a process using ReadProcessMemory.
	 *  	 PROCESS_VM_WRITE (0x0020) 	Required to write to memory in a process using WriteProcessMemory.
	 *  	 SYNCHRONIZE (0x00100000L) 	Required to wait for the process to terminate using the wait functions.
	 *
	 *  	 To open a handle to another process and obtain full access rights, you must enable the SeDebugPrivilege privilege. For more information, see Changing Privileges in a Token.
	 *
	 *  	 The handle returned by the CreateProcess function has PROCESS_ALL_ACCESS access to the process object. When you call the OpenProcess function, the system checks the requested access rights against the DACL in the process's security descriptor. When you call the GetCurrentProcess function, the system returns a pseudohandle with the maximum access that the DACL allows to the caller.
	 *
	 *  	 You can request the ACCESS_SYSTEM_SECURITY access right to a process object if you want to read or write the object's SACL. For more information, see Access-Control Lists (ACLs) and SACL Access Right.
	 *
	 *  	 Warning  A process that has some of the access rights noted here can use them to gain other access rights. For example, if process A has a handle to process B with PROCESS_DUP_HANDLE access, it can duplicate the pseudo handle for process B. This creates a handle that has maximum access to process B. For more information on pseudo handles, see GetCurrentProcess.
	 *
	 *
	 * </pre>
	 */
	
	public static HANDLE OpenProcess(int dwDesiredAccess,
			boolean bInheritHandle, int dwProcessId) throws NativeException,
			IllegalAccessException {
		if (nOpenProcess == null) {
			nOpenProcess = new JNative(DLL_NAME, "OpenProcess");
			nOpenProcess.setRetVal(Type.INT);
		}
		nOpenProcess.setParameter(0, dwDesiredAccess);
		nOpenProcess.setParameter(1, bInheritHandle ? 1 : 0);
		nOpenProcess.setParameter(2, dwProcessId);
		nOpenProcess.invoke();
		int ret = Integer.parseInt(nOpenProcess.getRetVal());
		if (ret == 0) {
			return null;
		} else {
			return new HANDLE(ret);
		}
	}
	
	/**
	 * <pre>
	 *   Closes an open object handle.
	 *
	 *  	 BOOL CloseHandle(
	 *  	 HANDLE hObject
	 *  	 );
	 *
	 *  	 Parameters
	 *
	 *  	 hObject
	 *  	 [in] A handle to an open object. This parameter can be a pseudo handle or INVALID_HANDLE_VALUE.
	 *
	 *  	 Return Values
	 *
	 *  	 If the function succeeds, the return value is nonzero.
	 *
	 *  	 If the function fails, the return value is zero. To get extended error information, call GetLastError.
	 *
	 *  	 If the application is running under a debugger, the function will throw an exception if it receives either a handle value that is not valid or a pseudo-handle value. This can happen if you close a handle twice, or if you call CloseHandle on a handle returned by the FindFirstFile function.
	 *  	 Remarks
	 *
	 *  	 The CloseHandle function closes handles to the following objects:
	 *
	 *   Access token
	 *   Communications device
	 *   Console input
	 *   Console screen buffer
	 *   Event
	 *   File
	 *   File mapping
	 *   Job
	 *   Mailslot
	 *   Memory resource notification
	 *   Mutex
	 *   Named pipe
	 *   Pipe
	 *   Process
	 *   Semaphore
	 *   Socket
	 *   Thread
	 *   Waitable timer
	 *
	 *  	 CloseHandle invalidates the specified object handle, decrements the object's handle count, and performs object retention checks. After the last handle to an object is closed, the object is removed from the system.
	 *
	 *  	 Closing a thread handle does not terminate the associated thread. To remove a thread object, you must terminate the thread, then close all handles to the thread.
	 *
	 *  	 Use CloseHandle to close handles returned by calls to the CreateFile function. Use FindClose to close handles returned by calls to FindFirstFile.
	 * </pre>
	 */
	public static boolean CloseHandle(HANDLE handle) throws NativeException,
			IllegalAccessException {
		if (nCloseHandle == null) {
			nCloseHandle = new JNative(DLL_NAME, "CloseHandle");
			nCloseHandle.setRetVal(Type.INT);
		}
		nCloseHandle.setParameter(0, handle.getValue());
		nCloseHandle.invoke();
		return !"0".equals(nCloseHandle.getRetVal());
	}
	
	/**
	 * <pre>
	 *   TerminateProcess
	 *
	 *  	 Terminates the specified process and all of its threads.
	 *
	 *  	 BOOL WINAPI TerminateProcess(
	 *  	 HANDLE hProcess,
	 *  	 UINT uExitCode
	 *  	 );
	 *
	 *  	 Parameters
	 *
	 *  	 hProcess
	 *  	 [in] A handle to the process to be terminated.
	 *
	 *  	 The handle must have the PROCESS_TERMINATE access right. For more information, see Process Security and Access Rights.
	 *  	 uExitCode
	 *  	 [in] The exit code to be used by the process and threads terminated as a result of this call. Use the GetExitCodeProcess function to retrieve a process's exit value. Use the GetExitCodeThread function to retrieve a thread's exit value.
	 *
	 *  	 Return Values
	 *
	 *  	 If the function succeeds, the return value is nonzero.
	 *
	 *  	 If the function fails, the return value is zero. To get extended error information, call GetLastError.
	 *  	 Remarks
	 *
	 *  	 The TerminateProcess function is used to unconditionally cause a process to exit. The state of global data maintained by dynamic-link libraries (DLLs) may be compromised if TerminateProcess is used rather than ExitProcess.
	 *
	 *  	 TerminateProcess initiates termination and returns immediately. This stops execution of all threads within the process and requests cancellation of all pending I/O. The terminated process cannot exit until all pending I/O has been completed or canceled.
	 *
	 *  	 A process cannot prevent itself from being terminated.
	 *
	 * </pre>
	 */
	public static boolean TerminateProcess(HANDLE lHandle, int exitCode)
	throws NativeException, IllegalAccessException {
		if (nTerminateProcess == null) {
			nTerminateProcess = new JNative(DLL_NAME, "TerminateProcess");
			nTerminateProcess.setRetVal(Type.INT);
		}
		nTerminateProcess.setParameter(0, lHandle.getValue());
		nTerminateProcess.setParameter(1, exitCode);
		nTerminateProcess.invoke();
		return !"0".equals(nTerminateProcess.getRetVal());
	}
	
	/**
	 * <b>SetLastError</b>
	 *
	 * <pre>
	 *  	 Sets the last-error code for the calling thread.
	 *
	 *  	 void SetLastError(
	 *  	 DWORD dwErrCode
	 *  	 );
	 *
	 *  	 Parameters
	 *
	 *  	 dwErrCode
	 *  	 [in] The last-error code for the thread.
	 *
	 *  	 Return Values
	 *
	 *  	 This function does not return a value.
	 *  	 Remarks
	 *
	 *  	 The last-error code is kept in thread local storage so that multiple threads do not overwrite each other's values.
	 *
	 *  	 This function is intended primarily for use by dynamic-link libraries (DLL). A DLL can provide the applications that are using it with additional diagnostic information by calling this function after an error occurs. Most functions call SetLastError or SetLastErrorEx only when they fail. However, some system functions call SetLastError or SetLastErrorEx under conditions of success; those cases are noted in each function's documentation.
	 *
	 *  	 Applications can optionally retrieve the value set by this function by using the GetLastError function immediately after a function fails.
	 *
	 *  	 Error codes are 32-bit values (bit 31 is the most significant bit). Bit 29 is reserved for application-defined error codes; no system error code has this bit set. If you are defining an error code for your application, set this bit to indicate that the error code has been defined by your application and to ensure that your error code does not conflict with any system-defined error codes.
	 *
	 * </pre>
	 *
	 * @throws NativeException
	 * @throws IllegalAccessException
	 */
	
	public static void SetLastError(int value) throws NativeException,
			IllegalAccessException {
		if (nSetLastError == null) {
			nSetLastError = new JNative(DLL_NAME, "SetLastError");
		}
		nSetLastError.setParameter(0, value);
		nSetLastError.invoke();
	}
	
	/**
	 * <pre>
	 *    CreateFileMapping
	 *
	 *  	 Creates or opens a named or unnamed file mapping object for a specified file.
	 *
	 *  	 To specify the NUMA node for the physical memory, see CreateFileMappingNuma.
	 *
	 *  	 HANDLE CreateFileMapping(
	 *  	 HANDLE hFile,
	 *  	 LPSECURITY_ATTRIBUTES lpAttributes,
	 *  	 DWORD flProtect,
	 *  	 DWORD dwMaximumSizeHigh,
	 *  	 DWORD dwMaximumSizeLow,
	 *  	 LPCTSTR lpName
	 *  	 );
	 *
	 *  	 Parameters
	 *
	 *  	 hFile
	 *  	 [in] A handle to the file from which to create a mapping object.
	 *
	 *  	 The file must be opened with access rights that are compatible with the protection flags that the flProtect parameter specifies. It is not required, but it is recommended that files you intend to map be opened for exclusive access. For more information, see File Security and Access Rights.
	 *
	 *  	 If hFile is INVALID_HANDLE_VALUE, the calling process must also specify a mapping object size in the dwMaximumSizeHigh and dwMaximumSizeLow parameters. In this scenario, CreateFileMapping creates a file mapping object of a specified size that the operating system paging file backs, instead of by a named file in the file system.
	 *
	 *  	 The file mapping object can be shared by duplication, inheritance, or by name. The initial contents of the pages in a file mapping object are 0 (zero).
	 *  	 lpAttributes
	 *  	 [in] A pointer to a SECURITY_ATTRIBUTES structure that determines whether or not a returned handle can be inherited by child processes.
	 *
	 *  	 If lpAttributes is NULL, the handle cannot be inherited.
	 *
	 *  	 The lpSecurityDescriptor member of the structure specifies a security descriptor for a new file mapping object.
	 *
	 *  	 If lpAttributes is NULL, the file mapping object gets a default security descriptor. The access control lists (ACL) in the default security descriptor for a file mapping object come from the primary or impersonation token of the creator.
	 *  	 flProtect
	 *  	 [in] The protection for the file view, when the file is mapped.
	 *
	 *  	 This parameter can be one of the following values.
	 *  	 Value 	Meaning
	 *  	 PAGE_READONLY 	Gives read-only access to a specific region of pages.
	 *
	 *  	 An attempt to write to a specific region results in an access violation. The file that the hFile parameter specifies must be created with the GENERIC_READ access right.
	 *  	 PAGE_READWRITE 	Gives read/write access to a specific region of pages.
	 *
	 *  	 The file that hFile specifies must be created with the GENERIC_READ and GENERIC_WRITE access rights.
	 *  	 PAGE_WRITECOPY 	Gives copy-on-write access to a specific region of pages.
	 *
	 *  	 The files that the hFile parameter specifies must be created with the GENERIC_READ access right.
	 *  	 PAGE_EXECUTE_READ 	Gives read and execute access to a specific region of pages.
	 *
	 *  	 The file specified by hFile must be created with the GENERIC_READ and GENERIC_EXECUTE access rights.
	 *
	 *  	 Windows Server 2003 and Windows XP:  This feature is not available until Windows XP SP2 and Windows Server 2003 SP1.
	 *
	 *  	 PAGE_EXECUTE_READWRITE 	Gives read, write, and execute access to a specific region of pages.
	 *
	 *  	 The file that hFile specifies must be created with the GENERIC_READ, GENERIC_WRITE, and GENERIC_EXECUTE access rights.
	 *
	 *  	 Windows Server 2003 and Windows XP:  This feature is not available until Windows XP SP2 and Windows Server 2003 SP1.
	 *
	 *  	 An application can specify section attributes by combining (using the bitwise OR operator) one or more of the following section attribute values with one of the preceding page protection values.
	 *  	 Value 	Meaning
	 *  	 SEC_COMMIT 	Allocates physical storage in memory or the paging file on disk for all pages of a section.
	 *
	 *  	 This is the default setting.
	 *  	 SEC_IMAGE 	Sets the file that is specified for section file mapping to be an executable image file.
	 *
	 *  	 Because the mapping information and file protection are taken from the image file, no other attributes are valid with SEC_IMAGE.
	 *
	 *  	 Windows Me/98/95:  This flag is not supported.
	 *
	 *  	 SEC_LARGE_PAGES 	Enables large pages to be used when mapping images or pagefile-backed sections, but not when mapping data for regular-sized files. Be sure to specify the maximum size of the file mapping as the minimum size of a large page reported by the GetLargePageMinimum function and to enable the SeLockMemoryPrivilege privilege.
	 *
	 *  	 Windows XP/2000:  This flag is not supported until Windows Server 2003 SP1.
	 *
	 *  	 SEC_NOCACHE 	Sets all pages of a section to non-cachable.
	 *
	 *  	 Applications should not use this flag except when explicitly required for a device. Using the interlocked functions with memory mapped by a SEC_NOCACHE section can result in an EXCEPTION_ILLEGAL_INSTRUCTION exception.
	 *
	 *  	 SEC_NOCACHE requires either the SEC_RESERVE or SEC_COMMIT to be set.
	 *
	 *  	 Windows Me/98/95:  This flag is not supported.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -