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, exe_ctx: lldb.SBExecutionContext, args : lldb.SBStructuredData): 11 super().__init__(exe_ctx, 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, error: lldb.SBError) -> lldb.SBData: 24 error.SetErrorString("This is an invalid scripted process!") 25 return lldb.SBData() 26 27 def get_loaded_images(self): 28 return self.loaded_images 29 30 def get_process_id(self) -> int: 31 return 666 32 33 def should_stop(self) -> bool: 34 return True 35 36 def is_alive(self) -> bool: 37 return True 38 39 def get_scripted_thread_plugin(self): 40 return InvalidScriptedThread.__module__ + "." + InvalidScriptedThread.__name__ 41 42 43class InvalidScriptedThread(ScriptedThread): 44 def __init__(self, process, args): 45 super().__init__(process, args) 46 47 def get_thread_id(self) -> int: 48 return 0x19 49 50 def get_name(self) -> str: 51 return InvalidScriptedThread.__name__ + ".thread-1" 52 53 def get_state(self) -> int: 54 return lldb.eStateInvalid 55 56 def get_stop_reason(self) -> Dict[str, Any]: 57 return { "type": lldb.eStopReasonSignal, "data": { 58 "signal": signal.SIGTRAP 59 } } 60 61 def get_register_context(self) -> str: 62 return None 63 64def __lldb_init_module(debugger, dict): 65 if not 'SKIP_SCRIPTED_PROCESS_LAUNCH' in os.environ: 66 debugger.HandleCommand( 67 "process launch -C %s.%s" % (__name__, 68 InvalidScriptedProcess.__name__)) 69 else: 70 print("Name of the class that will manage the scripted process: '%s.%s'" 71 % (__name__, InvalidScriptedProcess.__name__)) 72