MCPcopy Create free account
hub / github.com/ElyDotDev/windows-kill / open

Method open

windows-kill-library/remote-process.cpp:28–55  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26 }
27
28 void RemoteProcess::open(void) {
29 this->handle = OpenProcess(RemoteProcess::NEEDEDACCESS, false, this->the_signal->getPid());
30
31 if (this->handle == NULL) {
32 if (GetLastError() != ERROR_ACCESS_DENIED) {
33 throw system_error(error_code(GetLastError(), system_category()), "remote-process:open:OpenProcess");
34 }
35
36 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &this->process_token)) {
37 this->closeProcessToken();
38 throw system_error(error_code(GetLastError(), system_category()), "remote-process:open:OpenProcessToken");
39 }
40
41 if (!this->setPrivilege(true)) {
42 this->closeProcessToken();
43 throw runtime_error(string("EPERM"));
44 }
45
46 this->handle = OpenProcess(RemoteProcess::NEEDEDACCESS, false, this->the_signal->getPid());
47
48 if (this->handle == NULL) {
49 this->setPrivilege(false);
50 this->closeProcessToken();
51 throw runtime_error(string("EPERM"));
52 // throw runtime_error(std::string("remote-process:open:setPrivilege(true):OpenProcess:code:") + std::to_string(GetLastError()));
53 }
54 }
55 }
56
57 void RemoteProcess::closeProcessToken(void) {
58 if (this->process_token != NULL) {

Callers 1

sendMethod · 0.80

Calls 3

closeProcessTokenMethod · 0.95
setPrivilegeMethod · 0.95
getPidMethod · 0.80

Tested by

no test coverage detected