diff --git a/README.md b/README.md index 71d18ad..e4cee24 100644 --- a/README.md +++ b/README.md @@ -284,6 +284,15 @@ Here is a gist of methods you can access from `p`: - `unwind` - Unwind the stack (useful when get_evaluation_unwind() == False) +## Magic functions + +Sometimes accessing the python API can be tiring, so we added some magic functions to help you out! + +- `%objc ` + - Equivalent to: `className = p.objc_get_class(className)` +- `%fbp ` + - Equivalent to: `p.file_symbol(addressInHex, filename).bp()` + ## UI Configuration Hilda contains minimal UI for examining the target state. @@ -507,7 +516,8 @@ NSDictionary = p.objc_get_class('NSDictionary') d = NSDictionary.new() # Or you can use the IPython magic function -%objc NSDictionary +%objc +NSDictionary ``` This is possible only since `NSDictionary` is exported. In case it is not, you must call `objc_get_class()` explicitly. diff --git a/hilda/hilda_client.py b/hilda/hilda_client.py index 589da66..cf15395 100644 --- a/hilda/hilda_client.py +++ b/hilda/hilda_client.py @@ -61,6 +61,7 @@ """ MAGIC_FUNCTIONS = """ +import shlex from IPython.core.magic import register_line_magic, needs_local_scope @register_line_magic @@ -69,15 +70,22 @@ def objc(line, local_ns=None): p = local_ns['p'] className = line.strip() if not className: - print("Error: className is required.") + p.log_error("Error: className is required.") return try: - # Assuming `p.objc_get_class` is a method you have defined or imported - # Replace `p` with the correct reference to where `objc_get_class` is defined local_ns[className] = p.objc_get_class(className) - p.log_info(f"{className} class loaded successfully.") + p.log_info(f'{className} class loaded successfully') except Exception: - p.log_error(f"Error loading class {className}") + p.log_error(f'Error loading class {className}') + + +@register_line_magic +@needs_local_scope +def fbp(line, local_ns=None): + p = local_ns['p'] + module_name, address = shlex.split(line.strip()) + address = int(address, 16) + p.file_symbol(address, module_name).bp() """ SerializableSymbol = namedtuple('SerializableSymbol', 'address type_ filename')