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 DummyScriptedProcess(ScriptedProcess): 10 def __init__(self, exe_ctx: lldb.SBExecutionContext, args : lldb.SBStructuredData): 11 super().__init__(exe_ctx, args) 12 self.threads[0] = DummyScriptedThread(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 data = lldb.SBData().CreateDataFromCString( 25 self.target.GetByteOrder(), 26 self.target.GetCodeByteSize(), 27 "Hello, world!") 28 29 return data 30 31 def get_loaded_images(self): 32 return self.loaded_images 33 34 def get_process_id(self) -> int: 35 return 42 36 37 def should_stop(self) -> bool: 38 return True 39 40 def is_alive(self) -> bool: 41 return True 42 43 def get_scripted_thread_plugin(self): 44 return DummyScriptedThread.__module__ + "." + DummyScriptedThread.__name__ 45 46 47class DummyScriptedThread(ScriptedThread): 48 def __init__(self, process, args): 49 super().__init__(process, args) 50 self.frames.append({"pc": 0x0100001b00 }) 51 52 def get_thread_id(self) -> int: 53 return 0x19 54 55 def get_name(self) -> str: 56 return DummyScriptedThread.__name__ + ".thread-1" 57 58 def get_state(self) -> int: 59 return lldb.eStateStopped 60 61 def get_stop_reason(self) -> Dict[str, Any]: 62 return { "type": lldb.eStopReasonSignal, "data": { 63 "signal": signal.SIGINT 64 } } 65 66 def get_register_context(self) -> str: 67 return struct.pack( 68 '21Q', 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21) 69 70 71def __lldb_init_module(debugger, dict): 72 if not 'SKIP_SCRIPTED_PROCESS_LAUNCH' in os.environ: 73 debugger.HandleCommand( 74 "process launch -C %s.%s" % (__name__, 75 DummyScriptedProcess.__name__)) 76 else: 77 print("Name of the class that will manage the scripted process: '%s.%s'" 78 % (__name__, DummyScriptedProcess.__name__)) 79