Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/AlessandroZ/memorpy into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
n1nj4sec committed Apr 29, 2017
2 parents 79587d3 + 395bd8c commit c685a7e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
18 changes: 11 additions & 7 deletions memorpy/WinProcess.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,18 @@
import struct
import utils
import platform
import win32security
import win32api
from BaseProcess import BaseProcess, ProcessException

psapi = windll.psapi
kernel32 = windll.kernel32
psapi = windll.psapi
kernel32 = windll.kernel32
advapi32 = windll.advapi32

IsWow64Process=None
if hasattr(kernel32,'IsWow64Process'):
IsWow64Process=kernel32.IsWow64Process
IsWow64Process.restype = c_bool
IsWow64Process.argtypes = [c_void_p, POINTER(c_bool)]


class WinProcess(BaseProcess):

def __init__(self, pid=None, name=None, debug=True):
Expand Down Expand Up @@ -118,9 +116,15 @@ def name_from_process(dwProcessId):

def _open(self, dwProcessId, debug=False):
if debug:
ppsidOwner = DWORD()
ppsidGroup = DWORD()
ppDacl = DWORD()
ppSacl = DWORD()
ppSecurityDescriptor = SECURITY_DESCRIPTOR()

process = kernel32.OpenProcess(262144, 0, dwProcessId)
info = win32security.GetSecurityInfo(kernel32.GetCurrentProcess(), 6, 0)
win32security.SetSecurityInfo(process, 6, win32security.DACL_SECURITY_INFORMATION | win32security.UNPROTECTED_DACL_SECURITY_INFORMATION, None, None, info.GetSecurityDescriptorDacl(), info.GetSecurityDescriptorGroup())
advapi32.GetSecurityInfo(kernel32.GetCurrentProcess(), 6, 0, byref(ppsidOwner), byref(ppsidGroup), byref(ppDacl), byref(ppSacl), byref(ppSecurityDescriptor))
advapi32.SetSecurityInfo(process, 6, DACL_SECURITY_INFORMATION | UNPROTECTED_DACL_SECURITY_INFORMATION, None, None, ppSecurityDescriptor.dacl, ppSecurityDescriptor.group)
kernel32.CloseHandle(process)
self.h_process = kernel32.OpenProcess(2035711, 0, dwProcessId)
if self.h_process is not None:
Expand Down
12 changes: 12 additions & 0 deletions memorpy/WinStructures.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@
ULONG_PTR = c_ulong


class SECURITY_DESCRIPTOR(Structure):
_fields_ = [
('SID', DWORD),
('group', DWORD),
('dacl', DWORD),
('sacl', DWORD),
('test', DWORD)
]
PSECURITY_DESCRIPTOR = POINTER(SECURITY_DESCRIPTOR)

class MEMORY_BASIC_INFORMATION(Structure):
_fields_ = [('BaseAddress', c_void_p),
('AllocationBase', c_void_p),
Expand Down Expand Up @@ -176,3 +186,5 @@ class TH32CS_CLASS(object):
MEM_FREE = 65536
MEM_RESERVE = 8192

UNPROTECTED_DACL_SECURITY_INFORMATION = 536870912
DACL_SECURITY_INFORMATION = 4
13 changes: 7 additions & 6 deletions memorpy/wintools.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,22 @@
# You should have received a copy of the GNU General Public License
# along with memorpy. If not, see <http://www.gnu.org/licenses/>.

import win32gui
import win32con
import win32console
from ctypes import windll
import time

def start_winforeground_daemon():
import threading
t=threading.Thread(target=window_foreground_loop)
t.daemon=True
t.start()

def window_foreground_loop(timeout=20):
""" set the windows python console to the foreground (for example when you are working with a fullscreen program) """
hwnd=int(win32console.GetConsoleWindow())
hwnd = windll.kernel32.GetConsoleWindow()
HWND_TOPMOST = -1
SWP_NOMOVE = 2
SWP_NOSIZE = 1
while True:
win32gui.SetWindowPos(hwnd, win32con.HWND_TOPMOST, 0,0,0,0, win32con.SWP_NOMOVE | win32con.SWP_NOSIZE)
windll.user32.SetWindowPos(hwnd, HWND_TOPMOST, 0,0,0,0, SWP_NOMOVE | SWP_NOSIZE)
time.sleep(timeout)

0 comments on commit c685a7e

Please sign in to comment.