-
-
Notifications
You must be signed in to change notification settings - Fork 243
Add stack variable support #81
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution! I added some comments to adjust.
@idaread | ||
def get_stack_frame_variables( | ||
function_address: Annotated[str, "Address of the disassembled function to retrieve the stack frame variables"] | ||
) -> list[dict]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please return a TypedDict
with the appropriate dict members.
@@ -501,6 +502,73 @@ def create_demangled_to_ea_map(): | |||
if demangled: | |||
DEMANGLED_TO_EA[demangled] = ea | |||
|
|||
|
|||
def get_type_by_name(type_name: str) -> ida_typeinf.tinfo_t: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't there a way to directly go from name
-> tinfo_t
? I vaguely remember you can use one of the constructors for this.
size = udm.size // 8 | ||
type = str(udm.type) | ||
|
||
members += [{'name': name, 'offset': hex(offset), 'size': hex(size), 'type': type}] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would prefer formatting this with a key per line. Also use "
instead of '`' to match the existing codebase.
|
||
@jsonrpc | ||
@idaread | ||
def get_defined_structures() -> list[dict]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TypedDict
for structure definition.
raise IDAError(f"{old_name} is an argument member. Will not change the name.") | ||
|
||
sval = ida_frame.soff_to_fpoff(func, offset) | ||
return ida_frame.define_stkvar(func, new_name, sval, udm.type) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it will be better to return None
and then raise IDAError("failed to define stack variable")
to get more actionable error messages.
offset: Annotated[str, "Offset of the stack frame variable"], | ||
variable_name: Annotated[str, "Name of the stack variable"], | ||
type_name: Annotated[str, "Type of the stack variable"] | ||
) -> bool: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same error comment as above.
function_address: Annotated[str, "Address of the disassembled function to set the stack frame variables"], | ||
variable_name: Annotated[str, "Name of the stack variable"], | ||
type_name: Annotated[str, "Type of the stack variable"] | ||
) -> bool: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same error comment.
def delete_stack_frame_variable( | ||
function_address: Annotated[str, "Address of the function to set the stack frame variables"], | ||
variable_name: Annotated[str, "Name of the stack variable"] | ||
) -> bool: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same error comment.
This adds a few functions for manipulating IDA stack variables. These are mostly relevant when no decompiler is available, but it will make decompilation better as well (I wish they'd finally unify their type systems!)
I also added a helper function for resolving types by name which handles many of the standard types (it assumes sizeof(int) == 32, sizeof(long) == 32 though).