我正在尝试制作一个 WriteProcessMemory 程序,但我需要调整我的权限才能成功打开进程的内存。但我不知道怎么办。我用谷歌搜索了几个小时,找到了一段代码,但我仍然被困住了。我在互联网上找到的代码:
BOOL isOK;
HANDLE hToken;
HANDLE hCurrentProcess;
hCurrentProcess = GetCurrentProcess(); // 1
isOK = OpenProcessToken( hCurrentProcess, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken );
SetPrivilege( hToken, SE_DEBUG_NAME, TRUE );
Run Code Online (Sandbox Code Playgroud)
“SetPrivilege”带来了“错误 C3861:“SetPrivilege”:找不到标识符” 我应该如何启用 SE_DEBUG_NAME 权限?欢迎任何帮助!
该函数不是 Win32 API 函数。最有可能的是这里找到的 MSDN 示例中的这个函数:http://msdn.microsoft.com/en-us/library/windows/desktop/aa446619.aspx
#include <windows.h>
#include <stdio.h>
#pragma comment(lib, "cmcfg32.lib")
BOOL SetPrivilege(
HANDLE hToken, // access token handle
LPCTSTR lpszPrivilege, // name of privilege to enable/disable
BOOL bEnablePrivilege // to enable or disable privilege
)
{
TOKEN_PRIVILEGES tp;
LUID luid;
if ( !LookupPrivilegeValue(
NULL, // lookup privilege on local system
lpszPrivilege, // privilege to lookup
&luid ) ) // receives LUID of privilege
{
printf("LookupPrivilegeValue error: %u\n", GetLastError() );
return FALSE;
}
tp.PrivilegeCount = 1;
tp.Privileges[0].Luid = luid;
if (bEnablePrivilege)
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
else
tp.Privileges[0].Attributes = 0;
// Enable the privilege or disable all privileges.
if ( !AdjustTokenPrivileges(
hToken,
FALSE,
&tp,
sizeof(TOKEN_PRIVILEGES),
(PTOKEN_PRIVILEGES) NULL,
(PDWORD) NULL) )
{
printf("AdjustTokenPrivileges error: %u\n", GetLastError() );
return FALSE;
}
if (GetLastError() == ERROR_NOT_ALL_ASSIGNED)
{
printf("The token does not have the specified privilege. \n");
return FALSE;
}
return TRUE;
}
Run Code Online (Sandbox Code Playgroud)
我无法确定此函数与您正在使用的代码示例的作者使用的函数相同。我建议您重新阅读该代码示例,看看是否可以找到丢失的链接。