67 lines · python
1import os, struct, signal2 3from typing import Any, Dict4 5import lldb6from lldb.plugins.scripted_process import ScriptedProcess7from lldb.plugins.scripted_process import ScriptedThread8 9 10class InvalidScriptedProcess(ScriptedProcess):11 def __init__(self, exe_ctx: lldb.SBExecutionContext, args: lldb.SBStructuredData):12 super().__init__(exe_ctx, args)13 self.threads[0] = InvalidScriptedThread(self, None)14 15 def read_memory_at_address(16 self, addr: int, size: int, error: lldb.SBError17 ) -> lldb.SBData:18 error.SetErrorString("This is an invalid scripted process!")19 return lldb.SBData()20 21 def get_loaded_images(self):22 return self.loaded_images23 24 def get_process_id(self) -> int:25 return 66626 27 def should_stop(self) -> bool:28 return True29 30 def is_alive(self) -> bool:31 return True32 33 def get_scripted_thread_plugin(self):34 return InvalidScriptedThread.__module__ + "." + InvalidScriptedThread.__name__35 36 37class InvalidScriptedThread(ScriptedThread):38 def __init__(self, process, args):39 super().__init__(process, args)40 41 def get_thread_id(self) -> int:42 return 0x1943 44 def get_name(self) -> str:45 return InvalidScriptedThread.__name__ + ".thread-1"46 47 def get_state(self) -> int:48 return lldb.eStateInvalid49 50 def get_stop_reason(self) -> Dict[str, Any]:51 return {"type": lldb.eStopReasonSignal, "data": {"signal": signal.SIGTRAP}}52 53 def get_register_context(self) -> str:54 return None55 56 57def __lldb_init_module(debugger, dict):58 if not "SKIP_SCRIPTED_PROCESS_LAUNCH" in os.environ:59 debugger.HandleCommand(60 "process launch -C %s.%s" % (__name__, InvalidScriptedProcess.__name__)61 )62 else:63 print(64 "Name of the class that will manage the scripted process: '%s.%s'"65 % (__name__, InvalidScriptedProcess.__name__)66 )67