1import os,struct, signal 2 3from typing import Any, Dict 4 5import lldb 6from lldb.plugins.scripted_process import ScriptedProcess 7from lldb.plugins.scripted_process import ScriptedThread 8 9class InvalidScriptedProcess(ScriptedProcess): 10 def __init__(self, target: lldb.SBTarget, args : lldb.SBStructuredData): 11 super().__init__(target, args) 12 self.threads[0] = InvalidScriptedThread(self, None) 13 14 def get_memory_region_containing_address(self, addr: int) -> lldb.SBMemoryRegionInfo: 15 return None 16 17 def get_thread_with_id(self, tid: int): 18 return {} 19 20 def get_registers_for_thread(self, tid: int): 21 return {} 22 23 def read_memory_at_address(self, addr: int, size: int) -> lldb.SBData: 24 return None 25 26 def get_loaded_images(self): 27 return self.loaded_images 28 29 def get_process_id(self) -> int: 30 return 666 31 32 def should_stop(self) -> bool: 33 return True 34 35 def is_alive(self) -> bool: 36 return True 37 38 def get_scripted_thread_plugin(self): 39 return InvalidScriptedThread.__module__ + "." + InvalidScriptedThread.__name__ 40 41 42class InvalidScriptedThread(ScriptedThread): 43 def __init__(self, process, args): 44 super().__init__(process, args) 45 46 def get_thread_id(self) -> int: 47 return 0x19 48 49 def get_name(self) -> str: 50 return InvalidScriptedThread.__name__ + ".thread-1" 51 52 def get_state(self) -> int: 53 return lldb.eStateInvalid 54 55 def get_stop_reason(self) -> Dict[str, Any]: 56 return { "type": lldb.eStopReasonSignal, "data": { 57 "signal": signal.SIGTRAP 58 } } 59 60 def get_register_context(self) -> str: 61 return None 62 63def __lldb_init_module(debugger, dict): 64 if not 'SKIP_SCRIPTED_PROCESS_LAUNCH' in os.environ: 65 debugger.HandleCommand( 66 "process launch -C %s.%s" % (__name__, 67 InvalidScriptedProcess.__name__)) 68 else: 69 print("Name of the class that will manage the scripted process: '%s.%s'" 70 % (__name__, InvalidScriptedProcess.__name__)) 71