Merge pull request #243 from M3351AN/main
use native api instead of standard winapi to OpenProcess
This commit is contained in:
@@ -58,6 +58,19 @@ HWND pProcess::GetWindowHandleFromProcessId(DWORD ProcessId) {
|
|||||||
return NULL; // No main window found for the given process ID
|
return NULL; // No main window found for the given process ID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HANDLE OpenProcessNt(DWORD dwDesiredAccess, BOOL bInheritHandle,
|
||||||
|
DWORD dwProcessId) {
|
||||||
|
// At last is same with "OpenProcess", but we call NativeAPI instead of WindowsAPI directly.
|
||||||
|
HANDLE hProcess = 0;
|
||||||
|
_NtOpenProcess NtOpenProcess = (_NtOpenProcess)GetProcAddress(
|
||||||
|
GetModuleHandleA("ntdll.dll"), "NtOpenProcess");
|
||||||
|
CLIENT_ID clientId = {(HANDLE)dwProcessId, NULL};
|
||||||
|
OBJECT_ATTRIBUTES objAttr = hj::InitObjectAttributes(NULL, 0, NULL, NULL);
|
||||||
|
NtOpenProcess(&hProcess, dwDesiredAccess,
|
||||||
|
&objAttr, &clientId);
|
||||||
|
return hProcess;
|
||||||
|
}
|
||||||
|
|
||||||
bool pProcess::AttachProcess(const char* ProcessName)
|
bool pProcess::AttachProcess(const char* ProcessName)
|
||||||
{
|
{
|
||||||
this->pid_ = this->FindProcessIdByProcessName(ProcessName);
|
this->pid_ = this->FindProcessIdByProcessName(ProcessName);
|
||||||
@@ -68,7 +81,8 @@ bool pProcess::AttachProcess(const char* ProcessName)
|
|||||||
MODULEINFO module_info;
|
MODULEINFO module_info;
|
||||||
DWORD _;
|
DWORD _;
|
||||||
|
|
||||||
handle_ = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid_);
|
handle_ = OpenProcessNt(PROCESS_QUERY_INFORMATION |PROCESS_VM_OPERATION |
|
||||||
|
PROCESS_VM_READ,FALSE, pid_);
|
||||||
|
|
||||||
EnumProcessModulesEx(this->handle_, modules, sizeof(modules), &_, LIST_MODULES_64BIT);
|
EnumProcessModulesEx(this->handle_, modules, sizeof(modules), &_, LIST_MODULES_64BIT);
|
||||||
base_client_.base = (uintptr_t)modules[0];
|
base_client_.base = (uintptr_t)modules[0];
|
||||||
|
|||||||
Reference in New Issue
Block a user