How to use enumChildProc method in fMBT

Best Python code snippet using fMBT_python

human.py

Source:human.py Github

copy

Full Screen

1#!/usr/bin/env python2# Copyright (C) 2010-2013 Cuckoo Sandbox Developers.3# This file is part of Cuckoo Sandbox - http://www.cuckoosandbox.org4# See the file 'docs/LICENSE' for copying permission.5import random6import logging7from threading import Thread8from ctypes import *9from lib.common.abstracts import Auxiliary10from lib.common.defines import KERNEL32, USER32, WM_GETTEXT, WM_GETTEXTLENGTH, BM_CLICK11log = logging.getLogger(__name__)12EnumWindowsProc = WINFUNCTYPE(c_bool, POINTER(c_int), POINTER(c_int))13EnumChildProc = WINFUNCTYPE(c_bool, POINTER(c_int), POINTER(c_int))14RESOLUTION = {15 "x" : USER32.GetSystemMetrics(0),16 "y" : USER32.GetSystemMetrics(1)17}18def foreach_child(hwnd, lparam):19 buttons = [20 "&yes",21 "&ok",22 "&accept",23 "&next",24 "&install",25 "&run",26 "&agree"27 ]28 classname = create_unicode_buffer(50)29 USER32.GetClassNameW(hwnd, classname, 50)30 # Check if the class of the child is button.31 if classname.value == "Button":32 # Get the text of the button.33 length = USER32.SendMessageW(hwnd, WM_GETTEXTLENGTH, 0, 0)34 text = create_unicode_buffer(length + 1)35 USER32.SendMessageW(hwnd, WM_GETTEXT, length + 1, text)36 # Check if the button is "positive".37 for button in buttons:38 if text.value.lower().startswith(button):39 log.info("Found button \"%s\", clicking it" % text.value)40 USER32.SetForegroundWindow(hwnd)41 KERNEL32.Sleep(1000)42 USER32.SendMessageW(hwnd, BM_CLICK, 0, 0)43# Callback procedure invoked for every enumerated window.44def foreach_window(hwnd, lparam):45 # If the window is visible, enumerate its child objects, looking46 # for buttons.47 if USER32.IsWindowVisible(hwnd):48 USER32.EnumChildWindows(hwnd, EnumChildProc(foreach_child), 0)49def move_mouse():50 x = random.randint(0, RESOLUTION["x"])51 y = random.randint(0, RESOLUTION["y"])52 USER32.mouse_event(1, x, y, 0, None)53def click_mouse():54 # mouse down55 USER32.mouse_event(2, 0, 0, 0, None)56 KERNEL32.Sleep(50)57 # mouse up58 USER32.mouse_event(4, 0, 0, 0, None)59class Human(Auxiliary, Thread):60 """Human after all"""61 def __init__(self):62 Thread.__init__(self)63 self.do_run = True64 def stop(self):65 self.do_run = False66 def run(self):67 while self.do_run:68 move_mouse()69 click_mouse()70 USER32.EnumWindows(EnumWindowsProc(foreach_window), 0)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run fMBT automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful