Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hilda_client: add fbp magic function #52

Merged
merged 1 commit into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading