一个游戏的进程(魔兽争霸),
想要读写内存.
直接openprocess获取的都是0.
一个朋友说是要打开令牌环,修改权限.
他提供的API
OpenProcessToken这句是打开令牌环
LookupPrivilegeValue这句是寻找令牌环权限模块
AdjustTokenPrivileges改变权限
c++代码,爱要不要
//提升进程访问权限
bool enableDebugPriv()
{
HANDLE hToken;
LUID sedebugnameValue;
TOKEN_PRIVILEGES tkp;
if (!OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) {
return false;
}
if (!LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &sedebugnameValue)) {
CloseHandle(hToken);
return false;
}
tkp.PrivilegeCount = 1;
tkp.Privileges[0].Luid = sedebugnameValue;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
if (!AdjustTokenPrivileges(hToken, FALSE, &tkp, sizeof(tkp), NULL, NULL)) {
CloseHandle(hToken);
return false;
}
return true;
}
vb 解决了
var hwar3 = Api.FindWindow("", "Warcraft III");
var hcurrent = Api.GetCurrentProcess();
var hToken = IntPtr.Zero;
Api.OpenProcessToken(hcurrent, 40, ref hToken);
var luid = new LUID();
Api.LookupPrivilegeValue(null, "SeDebugPrivilege", ref luid);
TOKEN_PRIVILEGES NewState, PreviousState = new TOKEN_PRIVILEGES();
const int ReturnLength = 0;
NewState.PrivilegeCount = 1;
NewState.Luid = luid;
NewState.Attributes = 2;
Api.AdjustTokenPrivileges(hToken, 0, ref NewState, 28, ref PreviousState, ReturnLength);
int PID;
Api.GetWindowThreadProcessId(hwar3, out PID);
var hopen = Api.OpenProcess(PROCESS_ALL_ACCESS, false, (UInt32)PID);
放出代码,免得以后有人需要同样的内容搜索不到.