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

Port aglib.symbol + aglib.kernel + aglib.godbg #2605

Merged
merged 60 commits into from
Dec 18, 2024

Conversation

patryk4815
Copy link
Member

@patryk4815 patryk4815 commented Dec 6, 2024

Trying to address issues:

Changes:

  • port gdblib.kernel -> aglib.kernel
  • port gdblib.godbg -> aglib.godbg
  • port binder to aglib
  • new aglib.symbol
  • new FUNC type

Todo:

  • do a lot of tests...
  • cache?

@patryk4815 patryk4815 changed the title Draft aglib.symbol Draft aglib.symbol + aglib.kernel Dec 6, 2024
@patryk4815 patryk4815 changed the title Draft aglib.symbol + aglib.kernel Draft aglib.symbol + aglib.kernel + aglib.godbg Dec 9, 2024
@@ -99,8 +97,6 @@ def update() -> None:
else:
raise Exception("Pointer size not supported")

module.null = pwndbg.dbg.selected_inferior().evaluate_expression("0").cast(void)
Copy link
Member Author

@patryk4815 patryk4815 Dec 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not used anywhere, but it cause a lot of trouble in lldb - soo I removed it

try:
n_args_default = len(sym[0].type.fields())
n_args_default = len(sym.type.fields())
Copy link
Member Author

@patryk4815 patryk4815 Dec 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

len(sym.type.fields()) returns 0 if functions is found, but no debug info...
How should we fallback? Maybe we should create another method for that?
sym.type.func_arguments() -> List[Type] | None and detect no symbols and raise exception? or return None

Only for gdb:

In [26]: sym.type
Out[26]: <gdb.Type code=TYPE_CODE_FUNC name=<text variable, no debug info>>

In [28]: sym.type.name
Out[28]: '<text variable, no debug info>'

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in previous version gdb.lookup_symbol returns None when function don't have debug info.
And in new version with aglib.symbol.lookup_frame_symbol we returns *function address, but some data is missing like function argument (due to missing debug info - when debugging binary without debug info)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

# Conflicts:
#	pwndbg/aglib/kernel/rbtree.py
#	pwndbg/aglib/tls.py
#	pwndbg/commands/start.py
#	pwndbg/dbg/lldb/__init__.py
rb_root_type = gdb.lookup_type("struct rb_root")
rb_node_type = gdb.lookup_type("struct rb_node")
rb_root_type = pwndbg.aglib.typeinfo.load("struct rb_root")
rb_node_type = pwndbg.aglib.typeinfo.load("struct rb_node")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After this change, there is no exception here that can be thrown

In [1]: gdb.lookup_type('asdf')
---------------------------------------------------------------------------
error                                     Traceback (most recent call last)
Cell In[1], line 1
----> 1 gdb.lookup_type('asdf')

error: No type named asdf.

In [2]: pwndbg.aglib.typeinfo.load('asdf')

In [3]:

so the try: ... except: .. can be removed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also this was wrong before as failure to fetch struct, should set the types to None while it could keep an old/previous value I guess.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also wonder if NEW_MODULE is ever valid in the context of kernel debugging?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably NEW_MODULE is invalid in kernel context

pwndbg.dbg_mod.SymbolLookupType.ANY: Domain.ANY,
pwndbg.dbg_mod.SymbolLookupType.VARIABLE: Domain.VARIABLE,
pwndbg.dbg_mod.SymbolLookupType.FUNCTION: Domain.FUNCTION,
}[type]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this mapping?

If it is really needed, can we do if/elif/elif/else

@patryk4815 patryk4815 merged commit 644f7c1 into pwndbg:dev Dec 18, 2024
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants