How to use add_hook method in Lemoncheesecake

Best Python code snippet using lemoncheesecake

deviare_test.py

Source:deviare_test.py Github

copy

Full Screen

...33 self.pids = set()34 self.mod_funcs = set()35 self.hooks_enum = self.spy_mgr.CreateHooksCollection()3637 def add_hook(self, mod_fun, flag = 0x0001):38 # CreateHook takes a function string (whose format is functionModule!functionName) and flags to customize the hook.39 # PostCall only hook flag = 0x0020, PreCall only hook flag = 0x0010, AutoHookChildProcess flag = 0x000140 if mod_fun in self.mod_funcs:41 return42 self.mod_funcs.add(mod_fun)43 hook = self.spy_mgr.CreateHook(mod_fun, flag) #44 hook.Hook(True)45 for pid in self.pids:46 hook.Attach(pid, True)47 self.hooks_enum.Add(hook)48 print("hook {} registered successfully.".format(mod_fun))495051 def add_pid(self, pid):52 self.pids.add(pid)53 self.hooks_enum.Attach(pid, True)5455 def exec(self, exe):56 app, continue_event = self.spy_mgr.CreateProcess(exe, True)57 self.add_pid(app.Id)58 self.spy_mgr.ResumeProcess(app, continue_event)59606162if __name__ == "__main__":63 win32com.client.pythoncom.CoInitialize()64 spyManager = win32com.client.DispatchWithEvents("DeviareCOM.NktSpyMgr", NktSpyMgrEvents)65 result = spyManager.Initialize()66 if not result == 0:67 print("ERROR: Could not initialize the SpyManager. Error code: %d" % (result))68 sys.exit(0)6970 hook_mgr = HookManager(spyManager)71 hook_mgr.add_hook("Ws2_32.dll!WSAConnectByNameA")72 hook_mgr.add_hook("Ws2_32.dll!WSAConnectByNameW")73 hook_mgr.add_hook("Ws2_32.dll!gethostbyname")74 hook_mgr.add_hook("Ws2_32.dll!accept")75 hook_mgr.add_hook("Ws2_32.dll!WSAAccept")76 hook_mgr.add_hook("Mswsock.dll!AcceptEx")77 hook_mgr.add_hook("Mswsock.dll!GetAcceptExSockaddrs")78 hook_mgr.add_hook("Ws2_32.dll!getaddrinfo")79 hook_mgr.add_hook("Ws2_32.dll!GetAddrInfoExA")80 hook_mgr.add_hook("Ws2_32.dll!GetAddrInfoExW")81 hook_mgr.add_hook("Ws2_32.dll!GetAddrInfoW")82 hook_mgr.add_hook("Ws2_32.dll!WSASendTo")83 hook_mgr.add_hook("Ws2_32.dll!WSARecvFrom")84 hook_mgr.add_hook("Ws2_32.dll!sendto")85 hook_mgr.add_hook("Ws2_32.dll!recvfrom")86 hook_mgr.add_hook("Ws2_32.dll!connect")87 hook_mgr.add_hook("Ws2_32.dll!WSAConnect")88 hook_mgr.add_hook("Ws2_32.dll!WSAConnectByList")89 hook_mgr.add_hook("Ws2_32.dll!WSAConnectByNameA")90 hook_mgr.add_hook("Ws2_32.dll!WSAConnectByNameW")91 # hook_mgr.add_hook("kernel32.dll!CreateFileW")9293 if len(sys.argv) >= 3 and sys.argv[1] == '-e':94 hook_mgr.exec(sys.argv[2])95 else:96 for pid in sys.argv[1:]:97 hook_mgr.add_pid(int(pid))9899 MessageBox = ctypes.windll.user32.MessageBoxW100 MessageBox(None, "Press OK to end the demo.", "Deviare Python Demo", 0)101 ...

Full Screen

Full Screen

main.py

Source:main.py Github

copy

Full Screen

...10logging.basicConfig(filename=settings.LOGFILE, filemode="w", level=logging.DEBUG, format='#!# %(levelname)s - %(asctime)s \n%(message)s \n', datefmt='%m/%d/%Y %I:%M:%S %p')11def main() -> None:12 wrap = client.get_slack()13 # Add scroll handling14 wrap.add_hook(scroll_util.scroll_hook)15 # Add id handling16 wrap.add_hook(identifier.check_hook)17 wrap.add_hook(identifier.identify_hook)18 wrap.add_hook(identifier.identify_other_hook)19 wrap.add_hook(identifier.name_hook)20 # Add kill switch21 wrap.add_hook(management_commands.reboot_hook)22 wrap.add_hook(management_commands.log_hook)23 # Add towel rolling24 wrap.add_hook(slavestothemachine.count_work_hook)25 # wrap.add_hook(slavestothemachine.dump_work_hook)26 # Add job management27 wrap.add_hook(job_commands.signoff_hook)28 wrap.add_hook(job_commands.late_hook)29 wrap.add_hook(job_commands.reset_hook)30 wrap.add_hook(job_commands.nag_hook)31 wrap.add_hook(job_commands.reassign_hook)32 wrap.add_hook(job_commands.refresh_hook)33 # Add help34 wrap.add_hook(hooks.ChannelHook(help_callback, patterns=[r"help", r"bot\s+help"]))35 # Add boozebot36 # wrap.add_passive(periodicals.ItsTenPM())37 # Add automatic updating of users38 wrap.add_passive(periodicals.Updatinator(wrap, 120))39 # Do test.40 wrap.add_passive(periodicals.TestPassive())41 # Add nagloop42 wrap.add_passive(periodicals.NotifyJobs())43 wrap.add_passive(periodicals.RemindJobs())44 event_loop = asyncio.get_event_loop()45 event_loop.set_debug(settings.USE_ASYNC_DEBUG_MODE)46 event_handling = wrap.handle_events()47 passive_handling = wrap.run_passives()48 both = asyncio.gather(event_handling, passive_handling)...

Full Screen

Full Screen

manager_test.py

Source:manager_test.py Github

copy

Full Screen

...6 hm = HooksManager()7 h1 = "HOOK1"8 h2 = "HOOK2"9 h3 = "HOOK3"10 hm.add_hook(h1)11 hm.add_hook(h2, "pre")12 hm.add_hook(h3, "pre", "Text")13 hm.add_hook(h2, "post", "Text")14 self.assertIn("__end__", hm._access())15 self.assertIn("__end__", hm._access("pre"))16 self.assertIn("__end__", hm._access("pre", "Text"))17 self.assertIn("__end__", hm._access("post", "Text"))18 self.assertFalse(hm._access("inexistant")["__end__"])19 self.assertTrue(hm._access()["__end__"])20 self.assertTrue(hm._access("pre")["__end__"])21 self.assertTrue(hm._access("pre", "Text")["__end__"])22 self.assertTrue(hm._access("post", "Text")["__end__"])23 def test_search(self):24 hm = HooksManager()25 h1 = "HOOK1"26 h2 = "HOOK2"27 h3 = "HOOK3"28 h4 = "HOOK4"29 hm.add_hook(h1)30 hm.add_hook(h2, "pre")31 hm.add_hook(h3, "pre", "Text")32 hm.add_hook(h2, "post", "Text")33 self.assertTrue([h for h in hm._search(h1)])34 self.assertFalse([h for h in hm._search(h4)])35 self.assertEqual(2, len([h for h in hm._search(h2)]))36 self.assertEqual([("pre", "Text")], [h for h in hm._search(h3)])37 def test_delete(self):38 hm = HooksManager()39 h1 = "HOOK1"40 h2 = "HOOK2"41 h3 = "HOOK3"42 h4 = "HOOK4"43 hm.add_hook(h1)44 hm.add_hook(h2, "pre")45 hm.add_hook(h3, "pre", "Text")46 hm.add_hook(h2, "post", "Text")47 hm.del_hooks(hook=h4)48 self.assertTrue(hm._access("pre")["__end__"])49 self.assertTrue(hm._access("pre", "Text")["__end__"])50 hm.del_hooks("pre")51 self.assertFalse(hm._access("pre")["__end__"])52 self.assertTrue(hm._access("post", "Text")["__end__"])53 hm.del_hooks("post", "Text", hook=h2)54 self.assertFalse(hm._access("post", "Text")["__end__"])55 self.assertTrue(hm._access()["__end__"])56 hm.del_hooks(hook=h1)57 self.assertFalse(hm._access()["__end__"])58 def test_get(self):59 hm = HooksManager()60 h1 = "HOOK1"61 h2 = "HOOK2"62 h3 = "HOOK3"63 hm.add_hook(h1)64 hm.add_hook(h2, "pre")65 hm.add_hook(h3, "pre", "Text")66 hm.add_hook(h2, "post", "Text")67 self.assertEqual([h1, h2], [h for h in hm.get_hooks("pre")])68 self.assertEqual([h1, h2, h3], [h for h in hm.get_hooks("pre", "Text")])69 def test_get_rev(self):70 hm = HooksManager()71 h1 = "HOOK1"72 h2 = "HOOK2"73 h3 = "HOOK3"74 hm.add_hook(h1)75 hm.add_hook(h2, "pre")76 hm.add_hook(h3, "pre", "Text")77 hm.add_hook(h2, "post", "Text")78 self.assertEqual([h2, h3], [h for h in hm.get_reverse_hooks("pre")])79 self.assertEqual([h3], [h for h in hm.get_reverse_hooks("pre", exclude_first=True)])80if __name__ == '__main__':...

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 Lemoncheesecake 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