Skip to content

Commit

Permalink
Merge pull request #52 from doronz88/feature/fbp
Browse files Browse the repository at this point in the history
hilda_client: add `fbp` magic function
  • Loading branch information
doronz88 authored Mar 11, 2024
2 parents 42101ea + 5c85d05 commit 6053155
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <className>`
- Equivalent to: `className = p.objc_get_class(className)`
- `%fbp <filename> <addressInHex>`
- Equivalent to: `p.file_symbol(addressInHex, filename).bp()`

## UI Configuration

Hilda contains minimal UI for examining the target state.
Expand Down Expand Up @@ -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.
Expand Down
18 changes: 13 additions & 5 deletions hilda/hilda_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"""

MAGIC_FUNCTIONS = """
import shlex
from IPython.core.magic import register_line_magic, needs_local_scope
@register_line_magic
Expand All @@ -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')
Expand Down

0 comments on commit 6053155

Please sign in to comment.