如何在python中调用VirtualAllocEx WinAPI?

2024-09-28 03:19:43 发布

您现在位置:Python中文网/ 问答频道 /正文

您好,我一直在遵循The poor Man's Process Migration技术来了解进程迁移。但每当我打开一个进程,它都会返回一个0作为进程句柄

>>> kernel32 = cdll.kernel32
>>> kernel32.OpenProcess()
0
>>> kernel32.OpenProcess('PROCESS_ALL_ACCESS', 0,13036)
0

Tags: theaccess进程all句柄processmigration技术
1条回答
网友
1楼 · 发布于 2024-09-28 03:19:43

第一个参数是数字,而不是字符串PROCESS_ALL_ACCESS因目标Windows系统而异。见this MSDN link了解常数及其值的讨论(以下引用):

PROCESS_ALL_ACCESS All possible access rights for a process object.Windows Server 2003 and Windows XP: The size of the PROCESS_ALL_ACCESS flag increased on Windows Server 2008 and Windows Vista. If an application compiled for Windows Server 2008 and Windows Vista is run on Windows Server 2003 or Windows XP, the PROCESS_ALL_ACCESS flag is too large and the function specifying this flag fails with ERROR_ACCESS_DENIED. To avoid this problem, specify the minimum set of access rights required for the operation. If PROCESS_ALL_ACCESS must be used, set _WIN32_WINNT to the minimum operating system targeted by your application (for example, #define _WIN32_WINNT _WIN32_WINNT_WINXP). For more information, see Using the Windows Headers.

PROCESS_CREATE_PROCESS (0x0080) Required to create a process.

PROCESS_CREATE_THREAD (0x0002) Required to create a thread.

PROCESS_DUP_HANDLE (0x0040) Required to duplicate a handle using DuplicateHandle.

PROCESS_QUERY_INFORMATION (0x0400) Required to retrieve certain information about a process, such as its token, exit code, and priority class (see OpenProcessToken).

PROCESS_QUERY_LIMITED_INFORMATION (0x1000) Required to retrieve certain information about a process (see GetExitCodeProcess, GetPriorityClass, IsProcessInJob, QueryFullProcessImageName). A handle that has the PROCESS_QUERY_INFORMATION access right is automatically granted PROCESS_QUERY_LIMITED_INFORMATION.Windows Server 2003 and Windows XP: This access right is not supported.

PROCESS_SET_INFORMATION (0x0200) Required to set certain information about a process, such as its priority class (see SetPriorityClass).

PROCESS_SET_QUOTA (0x0100) Required to set memory limits using SetProcessWorkingSetSize.

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.

相关问题 更多 >

    热门问题