-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopen_process.py
36 lines (27 loc) · 1011 Bytes
/
open_process.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""
Filename: open_process.py
Description: Opens a handle of a process based on the process ID. All code in
this file copied from Brandon Dennis' "Hacking Windows API With Python" course
on Udemy.
Created by: Benjamin M. Singleton
Created: 03-09-2020
"""
import ctypes
k_handle = ctypes.WinDLL("Kernel32.dll")
# FIX ME - update this to prompt the user for it
process_id = 0x4E8 # just the hex of the current process ID at time of coding.
# set the arguments for the OpenProcess API call
dwDesiredAccess = (0x000F0000 | 0x00100000 | 0xFFF) # equivalent of PROCESS_ALL_ACCESS
bInheritHandle = False # we're not spinning off other processes, so this is irrelevant
dwProcessId = process_id
# make the call
response = k_handle.OpenProcess(dwDesiredAccess, bInheritHandle, dwProcessId)
error = k_handle.GetLastError()
if error != 0:
print("Error code: {0}".format(error))
exit(1)
print(response)
if response <= 0:
print("The handle was not created")
else:
print("Handle was created")