Coder Social home page Coder Social logo

igogo-x86 / hexrayspytools Goto Github PK

View Code? Open in Web Editor NEW
1.4K 68.0 213.0 4.65 MB

IDA Pro plugin which improves work with HexRays decompiler and helps in process of reconstruction structures and classes

Python 100.00%
ida idapython ida-plugin hex-rays-decompiler

hexrayspytools's Introduction

Plugin for IDA Pro

Table of Contents

About

The plugin assists in the creation of classes/structures and detection of virtual tables. It also facilitates transforming decompiler output faster and allows to do some stuff which is otherwise impossible.

Note: The plugin supports IDA Pro 7.x with Python 2/3.

Installation

Just copy HexRaysPyTools.py file and HexRaysPyTools directory to Ida plugins directory.

Configuration

Can be found at IDADIR\cfg\HexRaysPyTools.cfg

  • debug_message_level. Set 10 if you have a bug and want to show the log along with the information about how it was encountered in the issue.
  • propagate_through_all_names. Set True if you want to rename not only the default variables for the Propagate Name feature.
  • store_xrefs. Specifies whether to store the cross-references collected during the decompilation phase inside the database. (Default - True)
  • scan_any_type. Set True if you want to apply scanning to any variable type. By default, it is possible to scan only basic types like DWORD, QWORD, void * e t.c. and pointers to non-defined structure declarations.

Features

Recently added

Structure reconstruction

The reconstruction process usually comprises the following steps:

  1. Open structure builder.
  2. Find a local variable that points to the structure you would like to reconstruct.
  3. Apply "Scan variable". It will collect the information about the fields that were accessed in the boundaries of one function. As an option, you can apply "Deep Scan variable", which will do the same thing but will also recursively visit other functions that has the same variable as its argument.
  4. After applying steps 2 and 3 enough times, resolve conflicts in the structure builder and finalize structure creation. All the scanned variables will get a new type. Also, cross-references will be remembered and usable anytime.

Now, a few more details.

Structure Builder (Alt + F8)

The place where all the collected information about the scanned variables can be viewed and modified. Ways of collecting information:

  • Right Click on a variable -> Scan Variable. Recognizes fields usage within the current function.
  • Right Click on a variable -> Deep Scan Variable. First, recursively touches functions to make Ida recognize proper arguments (it happens only once for each function during a session). Then, it recursively applies the scanner to variables and functions, which get the structure pointer as their argument.
  • Right Click on a function -> Deep Scan Returned Value. If you have the singleton pattern or the constructor is called in many places, it is possible to scan all the places, where a pointer to an object was recieved or an object was created.
  • API [TODO]

img

Structure builder stores collected information and enables interaction:

  • Types with the BOLD font are virtual tables. A double click opens the list with all virtual functions, which helps to visit them. The visited functions are marked with a cross and color:

img

  • Types with the ITALIC font have been found as passed argument. It can help in finding substructures. [TODO]
  • Double click on field Name or Type to edit.
  • Double click on Offset opens a window with all the places, where this field has been extracted. Click the "Ok" button to open a selected place in the pseudocode window:

img

Buttons serve the following purpose:

Finalize - opens a window with an editable C-like declaration and assigns new types to all scanned variables.

Disable, Enable - are used for collision resolution.

Origin - switches the base offset which is used to produce new fields to structure (this value will be added to every offset of a newly-scanned variable, default = 0).

Array - renders a selected field as an array the size of which is automatically calculated.

Pack - creates and substitutes a substructure for selected items (collisions for these items should be resolved).

Unpack - dismembers a selected structure and adds all its fields to the builder.

Remove - removes the information about selected fields.

Clear - clears all.

Recognize Shape - looks for appropriates structure for selected fields.

Resolve Conflicts (new) - attempts to disable less meaningful fields in favor of more useful ones. (char > _BYTE, SOCKET > _DWORD etc). Doesn't help to find arrays.

Structure Cross-references (Ctrl + X)

With HexRaysPyTools, every time the F5 button is pressed and code is decompiled, the information about addressing to fields is stored inside cache. It can be retrieved with the "Field Xrefs" menu. So, it is better to apply reconstructed types to as many locations as possible to have more information about the way structures are used.

Note: IDA 7.4 has now an official implementation of this feature, available through Shift-X hotkey.

Guessing Allocation

Warning!! Very raw feature. The idea is to help find where a variable came from so as to run Deep Scan Process at the very top level and not to skip large amounts of code.

Structures with given size

Usage:

  1. In Pseudocode viewer, right click on a number -> "Structures with this size". (hotkey "W")
  2. Select a library to be looked for structures.
  3. Select a structure. The Number will become sizeof(Structure Name), and type will be imported to Local Types.

Recognition of structures by shapes

Helps find a suitable structure by the information gleaned from pseudocode after variable scanning.

Usage:

  • Method 1
    1. Right click on a variable with -> Select "Recognize Shape".
    2. Select Type Library.
    3. Select structure.
    4. Type of the variable will be changed automatically.
  • Method 2
    1. Clear Structure Builder if it's currently used.
    2. Right click on the variables that are supposed to be the same -> "Scan Variable".
    3. Edit types (will be implemented later), disable or remove uninteresting fields, and click the "Recognize Shape" button.
    4. You can select several fields and try to recognize their shapes. If found and selected, they will be replaced with a new structure.
    5. After final structure selection, types of all scanned variables will be changed automatically.

Disassembler code manipulations

Containing structures

Helps find containing structure and makes code prettier by replacing pointers with CONTAINING_RECORD macro

Before:

img

After:

img

Usage:

If a variable is a structure pointer and there's an access to outside of the boundaries of that structure, then:

  1. Right click -> Select Containing Structure.
  2. Select Type Library.
  3. Select appropriate Structure and Offset.
  4. If the result does not satisfy the requirements, then Right Click -> Reset Containing Structure and go back to step 1.

Function signature manipulation

  1. Right click first line -> "Remove Return" converts return type to void (or from void to _DWORD).
  2. Right click on argument -> "Remove Argument" disposes of this argument.
  3. Right click on convention -> "Convert to __usercall" switches to __usercall or __userpurge (same as __usercall but the callee cleans the stack).

Recasting (Shift+R, Shift+L), Renaming (Shift+N, Ctrl+Shift+N)

Every time you have two sides in an expression, where each side may be a local or global variable, argument or return value of the function signature, it is possible to right-click or press the hotkey to give both sides of the expression similar types. Below, there is the table of possible conversions:

Original Shift+L Shift+R
var = (TYPE) expr var type -> TYPE
exp = (TYPE) var var type -> TYPE
function(..., (TYPE) var, ...) functions' argument -> TYPE var type -> TYPE
(TYPE) function(...) functions' return type -> TYPE
return (TYPE) var functions' return type -> TYPE var type -> TYPE
struct.field = (TYPE) var type(field) -> TYPE
pstruct->field = (TYPE) var type(field) -> TYPE

When you have an expression like function(..., some_good_name, ...), you can rename function parameter.

When you have an expression like function(..., v12, ...), and function has an appropriate parameter name, you can quickly apply this name to the variable.

Also possible to rename vXX = v_named into _v_named = v_named and vice versa.

And there's a feature for massive renaming functions using assert statements. If you find a function that looks like an assert, right-click the string argument with the function name and select "Rename as assert argument". All the functions where a call to assert statement has happened will be renamed (provided that there is no conflicts, either way, you'll see the warning in the output window)

Name Propagation (P)

This feature does the same recursive traversal over functions as the Deep Scan Variable does. But this time, all elements that have a connection with the selected one receive its name. It’s possible to rename it or use names of both local and global variables, as well as structure members. By default, the plugin propagates names only over default names like v1, a2. See Configuration in order to change that.

Untangling 'if' statements

  • Clicking if manually allows to switch then and else branches
  • Automatically applies the following transformations:

Before:

...
if (condition) {
    statement_1;
    statement_2;
    ...
    return another_value;
}
return value;

After:

...
if (opposite_condition) {
    return value;
}
statement_1;
statement_2;
...
return another_value;            // if 'then' branch has no return, than `return value;`

Classes

Also, it can be found at View->Open Subview->Classes. Helps to manage classes (structures with virtual tables).

img

!! Better to rename all functions before debugging, because Ida can mess up default names, and the information in virtual tables will be inconsistent.

Class, virtual tables, and functions names are editable. Also a function's declaration can be edited. After editting, the altered items change font to italic. Right click opens the following menu options:

  • Expand All / Collapse All.
  • Refresh - clear all and rescan local types for information again.
  • Rollback - undo changes.
  • Commit - apply changes. Functions will be renamed and recasted both in virtual tables in Local Types and disassembly code.
  • Set First Argument type - allows selecting the first argument for a function among all classes. If right click was used on class name, then its type will be automatically applied to the virtual table at offset 0.

You can also filter classes using Regexp either by class_name or by existence of specific functions. Simply input an expression in line edit for filtering by class_name or prepend it with "!" to filter by function name.

Structure Graph

Shows relationship between structures:

img

Also: dark green node is union, light green - enum.

Usage:

  1. Open Local Types.
  2. Select structures and right click -> "Show Graph" (Hotkey "G").
  3. Plugin creates a graph of all structures that have relationship with selected items.
  4. Double clicking on a node recalculates the graph for it.
  5. Every node has a hint message that shows C-like typedef.

API

Under construction

Presentations

hexrayspytools's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hexrayspytools's Issues

Creating __shifted pointers

This is a question rather than an issue.

Like in #33, question is about new functionality added in IDA 7.2, shifted pointers. While they resemble CONTAINING_RECORD macro which you use(?) in core/negative_offsets.py, Hex-Rays claims that shifted pointers are more powerful. I thought you might be interested in this feature.

I also want to note some quirks of shifted pointers: when you use them as seen in example and you take some other int from structure, Hex-Rays would likely show it as myptr[42], not expected ADJ(myptr)->some_other_int. I tried some tweaks to pointer type like _UNKNOWN *__shifted(mystruct,20) myptr; but failed to get consistent use of ADJ with complex structures with lots of members of different types. Maybe you will be more successful.

Finalize button not working on IDA 7.5

The vftable structure does get created, but the class itself doesn't.
Output Window:

Traceback (most recent call last):
  File "...plugins\HexRaysPyTools\forms.py", line 93, in <lambda>
    btn_finalize.clicked.connect(lambda: self.structure_model.finalize())
  File "...plugins\HexRaysPyTools\core\temporary_structure.py", line 692, in finalize
    if self.pack():
  File "...plugins\HexRaysPyTools\core\temporary_structure.py", line 557, in pack
    cdecl = idaapi.ask_text(0x10000, '#pragma pack(push, 1)\n' + cdecl, "The following new type will be created")
TypeError: can only concatenate str (not "NoneType") to str

Here is the line. Any tips how to make idaapi.print_tinfo() return something other than None? This function is listed in IDAPython docs, but with no description, maybe obsolete?

Show Structure Builder not working, sometimes

I have noticed sometimes (not sure why) when I run IDA and load and an IDB, I can't start the Structure Builder as it does not appear with the RIGHT CLICK menu and also the ALT+F8 hotkey does not work.

A workaround is to just close this IDA instance (closing and reopening the IDB in the same IDA does not solve the issue), and reload it. It usually then works fine.

It may be due to the plugin not loading properly?

It was tested with the latest IDA 7.5 SP1 but it used to do that with older IDA too.

Consider a git tag for compatibility

I noticed in #9 that at some point a fix was made for IDA 7.0 which seems to not be backwards compatible with earlier versions.

I was able to determine which commit has the breaking change, but this took some time. Would you consider tagging 1ed20b18e62cf2b4b746fd7778dd794 as the last commit to be compatible for IDA 6.x versions?

Alternatively, a release would also work.

Structure builder shows `?` instead of type

Stack trace:

Traceback (most recent call last):
  File "C:/Program Files/IDA Pro 7.3/plugins\HexRaysPyTools\forms.py", line 94, in <lambda>
    btn_finalize.clicked.connect(lambda: self.structure_model.finalize())
  File "C:/Program Files/IDA Pro 7.3/plugins\HexRaysPyTools\core\temporary_structure.py", line 708, in finalize
    if self.pack():
  File "C:/Program Files/IDA Pro 7.3/plugins\HexRaysPyTools\core\temporary_structure.py", line 550, in pack
    cdecl = idaapi.asktext(0x10000, '#pragma pack(push, 1)\n' + cdecl, "The following new type will be created")
TypeError: cannot concatenate 'str' and 'NoneType' objects

Happened because type of one variable was set as ?. After changing to _QWORD everything worked.

Failed to register "Edit/Open subviews/Classes"

The bug is caused by attaching the not-yet registered name to menu,

actions.action_manager.register(show_classes)
idaapi.attach_action_to_menu('View/Open subviews/Local types', show_classes.name, idaapi.SETMENU_APP)

since ActionManager.register doesn't register the action immediately but register it when ActionManager.initialize is called.
def register(self, action):
self.__actions.append(action)
if isinstance(action, HexRaysPopupAction):
hx_callback_manager.register(idaapi.hxe_populating_popup, HexRaysPopupRequestHandler(action))
def initialize(self):
for action in self.__actions:
idaapi.register_action(
idaapi.action_desc_t(action.name, action.description, action, action.hotkey)
)

Maybe I can move the registration part below to ActionManager.register and eliminate ActionManager.initialize ?

idaapi.register_action(
idaapi.action_desc_t(action.name, action.description, action, action.hotkey)
)

IDA 7.0 Support?

Any way to get the current state of the plugin to work on IDA 7.0?
It fails to load on initialization:

C:\Program Files\IDA 7.0\plugins\HexRaysPyTools.py: No module named configparser
Traceback (most recent call last):
  File "C:\Program Files\IDA 7.0\python\ida_idaapi.py", line 553, in IDAPython_ExecScript
    execfile(script, g)
  File "C:/Program Files/IDA 7.0/plugins/HexRaysPyTools.py", line 7, in <module>
    import HexRaysPyTools.settings as settings
  File "C:/Program Files/IDA 7.0/plugins\HexRaysPyTools\settings.py", line 2, in <module>
    import configparser
ImportError: No module named configparser

I fixed that one using the ConfigParser module instead, but then other failures on actions.py

TIA!

Idea: adding recasting/renaming for assignments with structure members

One idea that may not be hard to implement since what HexraysPyTools does is already more complicated would be to add support for recasting/renaming simple assignments:

So something similar to https://github.com/igogo-x86/HexRaysPyTools#recasting-shiftr-shiftl-renaming-shiftn-ctrlshiftn but for assignments

So the idea is if we have, with PVOID v1, and struct1 { int arg1};:

v1 = (PVOID)struct1->arg1;

When we click on v1 and hit SHIFT+L it would change the type of v1 to int:

v1 = struct1->arg1;

Then we hit SHIFT+N and it would rename v1 to arg1:

arg1 = struct1->arg1;

We just need to support appending an underscore to the name until the rename succeeds as the name may already exist, so it could generate something like:

arg1___ = struct1->arg1;

We could also imagine supporting the other direction (i.e. renaming the right part based on the left part but I think the initial idea is more useful.

What do you think?

init plugin error

/home/idapro-7.4/plugins/HexRaysPyTools.py: invalid syntax (actions.py, line 68)
Traceback (most recent call last):
  File "/home/idapro-7.4/python/2/ida_idaapi.py", line 622, in IDAPython_ExecScript
    exec(code, g)
  File "/home/idapro-7.4/plugins/HexRaysPyTools.py", line 8, in <module>
    from HexRaysPyTools.callbacks import hx_callback_manager, action_manager
  File "/home/idapro-7.4/plugins/HexRaysPyTools/callbacks/__init__.py", line 1, in <module>
    from .actions import *
  File "/home/idapro-7.4/plugins/HexRaysPyTools/callbacks/actions.py", line 68
    def check(self, hx_view: idaapi.vdui_t):
                           ^
SyntaxError: invalid syntax
/home/idapro-7.4/plugins/HexRaysPyTools.py: cannot import name variable_scanner
Traceback (most recent call last):
  File "/home/idapro-7.4/python/2/ida_idaapi.py", line 622, in IDAPython_ExecScript
    exec(code, g)
  File "/home/idapro-7.4/plugins/HexRaysPyTools.py", line 8, in <module>
    from HexRaysPyTools.callbacks import hx_callback_manager, action_manager
  File "/home/idapro-7.4/plugins/HexRaysPyTools/callbacks/__init__.py", line 11, in <module>
    from . import scanners
  File "/home/idapro-7.4/plugins/HexRaysPyTools/callbacks/scanners.py", line 6, in <module>
    from ..core.variable_scanner import NewShallowSearchVisitor, NewDeepSearchVisitor, DeepReturnVisitor
  File "/home/idapro-7.4/plugins/HexRaysPyTools/core/variable_scanner.py", line 6, in <module>
    from . import temporary_structure
  File "/home/idapro-7.4/plugins/HexRaysPyTools/core/temporary_structure.py", line 11, in <module>
    from . import variable_scanner
ImportError: cannot import name variable_scanner
IDAPython Hex-Rays bindings initialized.
/home/idapro-7.4/plugins/HexRaysPyTools.py: cannot import name form_requests
Traceback (most recent call last):
  File "/home/idapro-7.4/python/2/ida_idaapi.py", line 622, in IDAPython_ExecScript
    exec(code, g)
  File "/home/idapro-7.4/plugins/HexRaysPyTools.py", line 8, in <module>
    from HexRaysPyTools.callbacks import hx_callback_manager, action_manager
  File "/home/idapro-7.4/plugins/HexRaysPyTools/callbacks/__init__.py", line 3, in <module>
    from . import form_requests
ImportError: cannot import name form_requests

Creating structure members instead of vtables

Is there a way to tell the structure builder what structure member should be created when it sees a given vtable?

The function I'm reversing is a constructor and is full of code like this:

  *(_QWORD *)(this + 0x118) = &`vtable for'agl::utl::Parameter<int>;
  agl::utl::ParameterBase::ParameterBase((agl::utl::ParameterBase *)(this + 0x138));
  *(_QWORD *)(this + 0x138) = &`vtable for'agl::utl::Parameter<float>;
  agl::utl::ParameterBase::ParameterBase((agl::utl::ParameterBase *)(this + 0x158));
  *(_QWORD *)(this + 0x158) = &`vtable for'agl::utl::Parameter<float>;
  agl::utl::ParameterBase::ParameterBase((agl::utl::ParameterBase *)(this + 0x178));

Right now, scanning this causes conflicting members:

  • 0x118, the vtable pointer for the correct derived class (agl::utl::Parameter<int>)
  • 0x118, the base class (agl::utl::ParameterBase)

Same for agl::utl::Parameter<float>, which cause two entries: one for the vtable pointer and another for the base class.

Is there a way to associate the vtable for agl::utl::Parameter<int> with agl::utl::Parameter_int, and the vtable for agl::utl::Parameter<float> with agl::utl::Parameter<float>, and so on? With small functions I can just disable the vtable members and fix the class types manually but this is infeasible for large classes which have hundreds of members.

I've noticed that the structure builder is sometimes able to guess the correct structure correctly, but not always.

Feature request: Inversion of if statements

Would it be possible to have something like the if/then else swapping but one that only inverts a single statement if condition?

E.g:

if (!a || !b)
{
}

Inverted to:

if (a && b)
{
}

Because a lot of times the decompiler seems to pick a bad way to represent the logic.

DeepScan option not always shown

The 'Deep Scan' variable context menu option does not always show up. From what i've seen this can be fixed by setting the variables' type to char* manually. I presume this is so that the plugin can easily read offsets from the base of the variable instead of dealing with non-byte offsets, which makes sense. However, this doesn't appear to be documented and in the current form is confusing as some variables, if they have the wrong type, behave differently. A possible fix would be to show the button in all cases but warn when the type is not char*, or first set the variable type to char* before doing a scan if it's not already that type.

Deep Scan Variable on existing structures

I got binary file with debugging information and would like to find all cross-references to an existing field, that added automatically during the first analysis

got error while opening aarch64 elf

I'm using the latest commit f3d46b7 on IDA 7.0 opening an aarch64 file,
got this error pop-up

notify_when(): Error occured while notifying object.
Traceback (most recent call last):
  File "D:/IDA 7.0/plugins\HexRaysPyTools\core\cache.py", line 70, in initialize_cache
    _init_demangled_names()
  File "D:/IDA 7.0/plugins\HexRaysPyTools\core\cache.py", line 56, in _init_demangled_names
    short_name = common.demangled_name_to_c_str(short_name)
  File "D:/IDA 7.0/plugins\HexRaysPyTools\core\common.py", line 100, in demangled_name_to_c_str
    "implemented ({}). You can do it by yourself or create an issue".format(name))
AssertionError: Replacement of demangled string by c-string for keyword `operatorXXX` is not yetimplemented (boost::operators_impl::operators_detail::empty_base<boost::posix_time::time_duration>::empty_base(void)). You can do it by yourself or create an issue

but x86_64 works smoothly

Refactor temporary_structure.py and forms.StructureBuilder

New code should be able to do the following:

  • Add structure/class name selection at reconstruction stage (this is required in order to create inheritance
  • Make inheritance support. See #33
  • Add handy storage for collected during scanning information so as it would be possible to delete some scans of specified function or variable. See #22
  • Load temporary structure from local types
    Also I would like to:
  • Remove cute and pyside

Prevent irreversible effects when recognizing structures

  • Validate changes
    When resolving the fields, some of them may be disabled. As a result of such actions, an appeal to gaps will be formed. This should not be. It is necessary to warn about incorrect struct.

  • Preview and select changes
    The finalization of the structure applies it to all known dependencies, which can lead to problems in case of incorrect recognition or incorrect selection of a variable. It is necessary to display a list of changes, and to allow the user to uncheck a part of them if he wants to limit the changes to one area.

  • Continuation of the analysis of the existing structure.
    Often the analysis of the structure is incomplete. Even a deep scan cannot detect all fields. When this happens, it is necessary to continue the analysis, modify the existing fields or update a new one.

  • Undo changes
    If everything went wrong, it must be able to undo maden changes by pressing Ctrl+Z.

I hope some of these ideas seem interesting to you. While recognition of structures is not easy to use, but argument's name inference is already worth a lot. Thank you!

IDA 7.0 Cann't normal use

output as below,SDK maybe modify, ctx is don't have form_title

Traceback (most recent call last):
File "C:/Program Files/IDA 7.0/plugins\HexRaysPyTools\Actions.py", line 608, in update
if ctx.form_title[0:10] == "Pseudocode":
AttributeError: 'action_update_ctx_t' object has no attribute 'form_title'
Traceback (most recent call last):
File "C:/Program Files/IDA 7.0/plugins\HexRaysPyTools\Actions.py", line 1063, in update
if ctx.form_title[0:10] == "Pseudocode":
AttributeError: 'action_update_ctx_t' object has no attribute 'form_title'
Traceback (most recent call last):
File "C:/Program Files/IDA 7.0/plugins\HexRaysPyTools\Actions.py", line 1106, in update
if ctx.form_title[0:10] == "Pseudocode":
AttributeError: 'action_update_ctx_t' object has no attribute 'form_title'
Traceback (most recent call last):
File "C:/Program Files/IDA 7.0/plugins\HexRaysPyTools\Actions.py", line 507, in update
if ctx.form_title[0:10] == "Pseudocode":
AttributeError: 'action_update_ctx_t' object has no attribute 'form_title'
Traceback (most recent call last):
File "C:/Program Files/IDA 7.0/plugins\HexRaysPyTools\Actions.py", line 928, in update
if ctx.form_title[0:10] == "Pseudocode":
AttributeError: 'action_update_ctx_t' object has no attribute 'form_title'
Traceback (most recent call last):
File "C:/Program Files/IDA 7.0/plugins\HexRaysPyTools\Actions.py", line 928, in update
if ctx.form_title[0:10] == "Pseudocode":
AttributeError: 'action_update_ctx_t' object has no attribute 'form_title'
Traceback (most recent call last):
File "C:/Program Files/IDA 7.0/plugins\HexRaysPyTools\Actions.py", line 1141, in update
if ctx.form_title[0:10] == "Pseudocode":
AttributeError: 'action_update_ctx_t' object has no attribute 'form_title'
Traceback (most recent call last):
File "C:/Program Files/IDA 7.0/plugins\HexRaysPyTools\Actions.py", line 422, in update
if ctx.form_title[0:10] == "Pseudocode":
AttributeError: 'action_update_ctx_t' object has no attribute 'form_title'
Traceback (most recent call last):
File "C:/Program Files/IDA 7.0/plugins\HexRaysPyTools\Actions.py", line 368, in update
if ctx.form_title[0:10] == "Pseudocode":
AttributeError: 'action_update_ctx_t' object has no attribute 'form_title'
Traceback (most recent call last):
File "C:/Program Files/IDA 7.0/plugins\HexRaysPyTools\Actions.py", line 312, in update
if ctx.form_title[0:10] == "Pseudocode":
AttributeError: 'action_update_ctx_t' object has no attribute 'form_title'
Traceback (most recent call last):
File "C:/Program Files/IDA 7.0/plugins\HexRaysPyTools\Actions.py", line 261, in update
if ctx.form_title[0:10] == "Pseudocode":
AttributeError: 'action_update_ctx_t' object has no attribute 'form_title'
Traceback (most recent call last):
File "C:/Program Files/IDA 7.0/plugins\HexRaysPyTools\Actions.py", line 1015, in update
if ctx.form_title[0:10] == "Pseudocode":
AttributeError: 'action_update_ctx_t' object has no attribute 'form_title'
Traceback (most recent call last):
File "C:/Program Files/IDA 7.0/plugins\HexRaysPyTools\Actions.py", line 461, in update
idaapi.attach_action_to_popup(ctx.form, None, self.name)
AttributeError: 'action_update_ctx_t' object has no attribute 'form'

Propergating names fails in IDA 7.4 with Python 3

Propergating names fails on default settings in IDA 7.4 with Python 3 at idaapi.apply_tinfo2().

With IDA 7 the API changed from ida_typeinf.apply_tinfo2 to ida_typeinf.apply_tinfo
https://www.hex-rays.com/products/ida/support/ida74_idapython_no_bc695_porting_guide.shtml
IDA 7.4 turns compatibility to the 6.95 API by default off.

Python 2: 6.95 compatibility APIs OFF by default

IDA 7.4 also turns off 6.95 API compatibility by default. We have written a porting guide for helping with this as well.

when i open idb file, tips error

notify_when(): Error occured while notifying object.
Traceback (most recent call last):
  File "C:/Program Files/IDA 7.0/plugins\HexRaysPyTools\core\cache.py", line 49, in init_demangled_names
    short_name = common.demangled_name_to_c_str(short_name)
  File "C:/Program Files/IDA 7.0/plugins\HexRaysPyTools\core\common.py", line 100, in demangled_name_to_c_str
    "implemented ({}). You can do it by yourself or create an issue".format(name))
AssertionError: Replacement of demangled string by c-string for keyword `operatorXXX` is not yetimplemented (TemplatedTestRegistrator<Suitecore_string_refkUnitTestCategory::Testoperator_equal_ReturnsTrueForEqualString<core::basic_string_ref<char>>>::Create). You can do it by yourself or create an issue

IDA 7.0

Classes window does not work in IDA 7.3

Opening "Classes" window after creating any class (with vtable) causes IDA 7.3 to crash with INTERR 918.

I'm trying to get some more info from Hex-Rays regarding this INTERR, currently they've said this INTERR means "a tinfo_t object was missing while it was expected to be present". I will update this issue if they will share more information.

Problems with new feature - Improve demangled names translation

About the commit 7668c2d

  • There is a typo in the operator sub, mul and div.
  • In the current state, operator ptr and operator mul cannot be distinguished.
  • operator< is missing, as well as some other comparison operators.
  • Instead of chained elif list, I suggest doing something like this
name = name.replace("operator==", "operator_EQ_")
name = name.replace("operator!=", "operator_NEQ_")
# ...

That way it's also possible to avoid false detection (if identifier name contains operator as a substring), and don't (unnecessarily) error out if there is a operator XXX.

AttributeError: class Cache has no attribute 'temporary_structure'

Open any x64 file with IDA, do nothing and just exit. Got this warning:

Failed while executing plugin_t.term():
Traceback (most recent call last):
File "C:/Program Files/IDA 7.0/plugins/HexRaysPyTools.py", line 243, in term
if Cache.temporary_structure:
AttributeError: class Cache has no attribute 'temporary_structure'

Failed to create virtual table: _BOOL8 not recognised

While doing deep scan I got _BOOL8 return type in virtual function which failed structure builder.
I Fixed that with manual changing return type to char.
Hope handling these situations will be done automatically.

Syntax error near: _BOOL8
Syntax error near: }
[Error] Failed to create virtual table CCreature_vtbl

struct CCreature_vtbl
{
    ...
    BOOL8 (__fastcall *sub_408FDC)(__int64 a1);
    ...
}

error when i Finalized

File "C:/Program Files/IDA 7.0/plugins\HexRaysPyTools\forms.py", line 99, in
btn_pack.clicked.connect(lambda: self.structure_model.pack_substructure(struct_view.selectedIndexes()))
File "C:/Program Files/IDA 7.0/plugins\HexRaysPyTools\core\temporary_structure.py", line 744, in pack_substructure
tinfo = self.pack(start, stop)
File "C:/Program Files/IDA 7.0/plugins\HexRaysPyTools\core\temporary_structure.py", line 548, in pack
udt_data.push_back(item.get_udt_member(offset=origin))
File "C:/Program Files/IDA 7.0/plugins\HexRaysPyTools\core\temporary_structure.py", line 326, in get_udt_member
tid = self.import_to_structures()
File "C:/Program Files/IDA 7.0/plugins\HexRaysPyTools\core\temporary_structure.py", line 269, in import_to_structures
self.create_tinfo(), self.vtable_name, None)
File "C:/Program Files/IDA 7.0/plugins\HexRaysPyTools\core\temporary_structure.py", line 244, in create_tinfo
udt_data.push_back(function.get_udt_member())
File "C:/Program Files/IDA 7.0/plugins\HexRaysPyTools\core\temporary_structure.py", line 138, in get_udt_member
udt_member.name = self.name
File "C:/Program Files/IDA 7.0/plugins\HexRaysPyTools\core\temporary_structure.py", line 151, in name
return common.demangled_name_to_c_str(name)
File "C:/Program Files/IDA 7.0/plugins\HexRaysPyTools\core\common.py", line 11, in demangled_name_to_c_str
if not BAD_C_NAME_PATTERN.findall(name):
TypeError: expected string or buffer

Fail to work due to deprecated IDA Python APIs with IDA 7.4 / Python 2

Note that I am not even talking about Python 3 here.

C:\Users\<user>\AppData\Roaming\Hex-Rays\IDA Pro\plugins\HexRaysPyTools.py: 'module' object has no attribute 'Choose2'
Traceback (most recent call last):
  File "C:\Program Files\IDA Pro 7.4\python\2\ida_idaapi.py", line 619, in IDAPython_ExecScript
    exec(code, g)
  File "C:/Users/<user>/AppData/Roaming/Hex-Rays/IDA Pro/plugins/HexRaysPyTools.py", line 4, in <module>
    import HexRaysPyTools.actions as actions
  File "C:/Users/<user>/AppData/Roaming/Hex-Rays/IDA Pro/plugins\HexRaysPyTools\actions.py", line 9, in <module>
    import HexRaysPyTools.forms as forms
  File "C:/Users/<user>/AppData/Roaming/Hex-Rays/IDA Pro/plugins\HexRaysPyTools\forms.py", line 7, in <module>
    class MyChoose(idaapi.Choose2):
AttributeError: 'module' object has no attribute 'Choose2'

See https://github.com/igogo-x86/HexRaysPyTools/blob/master/HexRaysPyTools/forms.py#L6

Create Virtual Table error

Hi,

I used HexRaysPyTools to create vftable structures by selecting the vftable then "Create Virtual Table" or making object structures on Structure Builder, but I got the following error.

Syntax error near: azure::storage::storage_exception
Syntax error near: }
[Error] Failed to create virtual table DebugPortServer_vtbl


struct DebugPortServer_vtbl
{
azure::storage::storage_exception *(__fastcall __spoils<rcx,rdx,r8,r9,r10,r11,xmm0,xmm4,xmm5> *azure::storage::storage_exception::_scalar_deleting_destructor_uint)(azure::storage::storage_exception *this, char a2);
char (__fastcall *fn_l_DebugPortServer_AuthenticateRequest)(__int64 a1, __int64 a2, DWORD a3, __int64 a4, _BYTE *a5);
__int64 (__fastcall *fn_a_DebugPortServer_ProcessDebugRequest)(__int64 a1, __int64 a2, unsigned int a3, __int64 a4, unsigned int a5);
};


Any thought? Thanks.

Creating __cppobj structures

This is a question rather than an issue.

Have you looked into creating structures with __cppobj attribute and naming virtual tables __vftable as described here? This is a new functionality in IDA 7.2 and I'm interested in improvements it may bring comparing with your current approach. Main difference is that now you can create proper class hierarchy although it is not so simple comparing to simply creating structure with vtable pointer.

The only real difference I noticed in produced code is that there is no type conversion anymore when passing the class object to parent class method (for example, passing this to base class constructor). While it's nice, it surely is not enough of a reason to implement __cppobj support. I'll comment with other use cases if I find them.

clean up stored data in an idb

I noticed that my idb has been increased in size (i.e. 43MB -> 120MB) after using this plugin a bit - it's probably the "store_xrefs" default. There is a lot of empty space with some jsons inbetween.

I've disabled it, and would like to get rid of the unnecessary data - is there any way to do that? One off code hackily edited in is fine, it doesn't need to be a proper feature.

I'm already looking through the code myself, just wanted to ask if you had any idea.

Edit: I actually managed to do that but it only cleaned up a few KB. I'm assuming at this point that it's the swapped if/else that take up the most space (which would be fine)?

ImportError: DLL load failed while importing sip

Hi!
In ida 7.4 after start i got next:

C:\Program Files\IDA Pro 7.4\plugins\HexRaysPyTools.py: DLL load failed while importing sip: Не найден указанный модуль.
Traceback (most recent call last):
  File "C:\Program Files\IDA Pro 7.4\python\3\ida_idaapi.py", line 593, in IDAPython_ExecScript
    exec(code, g)
  File "C:/Program Files/IDA Pro 7.4/plugins/HexRaysPyTools.py", line 8, in <module>
    from HexRaysPyTools.callbacks import hx_callback_manager, action_manager
  File "C:/Program Files/IDA Pro 7.4/plugins\HexRaysPyTools\callbacks\__init__.py", line 3, in <module>
    from . import form_requests
  File "C:/Program Files/IDA Pro 7.4/plugins\HexRaysPyTools\callbacks\form_requests.py", line 5, in <module>
    import HexRaysPyTools.core.classes as classes
  File "C:/Program Files/IDA Pro 7.4/plugins\HexRaysPyTools\core\classes.py", line 1, in <module>
    from PyQt5 import QtCore, QtGui
ImportError: DLL load failed while importing sip: Не найден указанный модуль.

At the same time:
In Windows cmd:

C:\python3>python
Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 23:11:46) [MSC v.1916 64 bit (AM
D64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from PyQt5 import sip
>>>

And in Ida python cmd:

Python>from PyQt5 import sip
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: DLL load failed while importing sip: Не найден указанный модуль.
Python>import sys
Python>sys.version
'3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 23:11:46) [MSC v.1916 64 bit (AMD64)]'

Ida 7.4.191112 x64, Win7 x64.
Is this a bug or am I doing something wrong?
Thanks.

Helper AttributeError

Hi,

I've encountered the issue shown in image when starting IDA 6.9.
What can be the problem?

Thank you!
untitled

Recognize structures on global variables

Now it works only at local variables (that are initiated with some input parameters).
But is it possible to add recognizing on global variables too?

Situation:
there is some global structure. Ida recognizes first dword to it as dword_123456. Full code is like this:

memset(dword_123456, 0, 0x78);
dword_123456 = 1;
dword_12345A = 4;
...

So, dword_12345A is just the second dword field of the structure.

Can we manually create vtables?

Often I come across class inlinely constructed on the stack.
image
As variable like this does not has a pointer to class, the tool cannot perform a scan or deep scan.
I'm wondering if I can manually create a vtable or a class.

Can't create vtable structure with a function has special name?

Today I came across a problem when i try to finalize creating a new struct. I found that happened because the vtable of that struct contains a definition of a function which has special characters in its name.
Some thing like:
struct A {
Vtable_B *vtableB;
...
};
struct Vtable_B {
...
char (__stdcall *Concurrency__details___ContextCallback__operator==)(int a1);
...
};
Yes, problem is "==". So do you have any suggestion for this case, how can i deal with it? Sorry because take your time, I can't found any solutions on the internet.

Got AttributeError while deep scanning

Hi,
I've got an AttributeError while deep scanning. However there was still some output on the structure builder window.

Traceback (most recent call last):
  File "plugins\HexRaysPyTools\Actions.py", line 330, in activate
    visitor.process()
  File "plugins\HexRaysPyTools\Api.py", line 447, in process
    self._recursive_process()
  File "plugins\HexRaysPyTools\Api.py", line 551, in _recursive_process
    self._recursive_process()
  File "plugins\HexRaysPyTools\Api.py", line 540, in _recursive_process
    super(RecursiveObjectDownwardsVisitor, self)._recursive_process()
  File "plugins\HexRaysPyTools\Api.py", line 467, in _recursive_process
    super(RecursiveObjectVisitor, self).process()
  File "plugins\HexRaysPyTools\Api.py", line 230, in process
    self.apply_to(self._cfunc.body, None)
  File "python\ida_hexrays.py", line 4458, in apply_to
    return _ida_hexrays.ctree_visitor_t_apply_to(self, *args)
  File "plugins\HexRaysPyTools\Api.py", line 298, in leave_expr
    self._manipulate(cexpr, obj)
  File "plugins\HexRaysPyTools\Core\VariableScanner.py", line 132, in _manipulate
    member = self.__extract_member_from_xword(cexpr, obj)
  File "plugins\HexRaysPyTools\Core\VariableScanner.py", line 234, in __extract_member_from_xword
    return self.__extract_member(cexpr, obj, offset, parents, parents_type)
  File "plugins\HexRaysPyTools\Core\VariableScanner.py", line 280, in __extract_member
    return self._get_member(offset, cexpr, obj, self.__deref_tinfo(default_tinfo))
  File "plugins\HexRaysPyTools\Core\VariableScanner.py", line 146, in _get_member
    scan_obj = ScannedObject.create(obj, cexpr_ea, self.__origin, applicable)
  File "plugins\HexRaysPyTools\Core\VariableScanner.py", line 49, in create
    return ScannedStructureMemberObject(obj.struct_name, obj.offset, expression_address, origin, applicable)
AttributeError: 'StructRefObject' object has no attribute 'struct_name'

Crash with "Recognize Shape"

I've got some code that looks like this:

_DWORD *__cdecl sub_3B460(int a1, int a2)
{
  _DWORD *result; // eax

  result = sub_CD2F0();
  result[25] = sub_3B530;
  result[26] = sub_3B360;
  result[27] = sub_3B3B0;
  result[28] = sub_3B3C0;
  result[29] = sub_3B3D0;
  result[31] = sub_3B430;
  result[24] = sub_3B4D0;
  result[1] = a1;
  result[6] = a2;
  result[2] = a1;
  result[7] = a2;
  return result;
}

HexRaysPyTools is puking a stacktrace when I'm doing right-click → recognize shape on the result variable:

[Warning] Weird virtual table name - sub_3B3C0
Traceback (most recent call last):
  File "Z:/home/jvoisin/.wine/drive_c/Program Files/IDA 7.0/plugins\HexRaysPyTools\Actions.py", line 411, in activate
    visitor.process()
  File "Z:/home/jvoisin/.wine/drive_c/Program Files/IDA 7.0/plugins\HexRaysPyTools\Api.py", line 230, in process
    self.apply_to(self._cfunc.body, None)
  File "Z:\home\jvoisin\.wine\drive_c\Program Files\IDA 7.0\python\ida_hexrays.py", line 4458, in apply_to
    return _ida_hexrays.ctree_visitor_t_apply_to(self, *args)
  File "Z:/home/jvoisin/.wine/drive_c/Program Files/IDA 7.0/plugins\HexRaysPyTools\Api.py", line 298, in leave_expr
    self._manipulate(cexpr, obj)
  File "Z:/home/jvoisin/.wine/drive_c/Program Files/IDA 7.0/plugins\HexRaysPyTools\Core\VariableScanner.py", line 130, in _manipulate
    member = self.__extract_member_from_pointer(cexpr, obj)
  File "Z:/home/jvoisin/.wine/drive_c/Program Files/IDA 7.0/plugins\HexRaysPyTools\Core\VariableScanner.py", line 216, in __extract_member_from_pointer
    return self.__extract_member(cexpr, obj, offset, parents, parents_type)
  File "Z:/home/jvoisin/.wine/drive_c/Program Files/IDA 7.0/plugins\HexRaysPyTools\Core\VariableScanner.py", line 258, in __extract_member
    return self._get_member(offset, cexpr, obj, default_tinfo, obj_ea)
  File "Z:/home/jvoisin/.wine/drive_c/Program Files/IDA 7.0/plugins\HexRaysPyTools\Core\VariableScanner.py", line 149, in _get_member
    return TemporaryStructure.VirtualTable(offset, obj_ea, scan_obj, self.__origin)
  File "Z:/home/jvoisin/.wine/drive_c/Program Files/IDA 7.0/plugins\HexRaysPyTools\Core\TemporaryStructure.py", line 246, in __init__
    self.vtable_name, self.have_nice_name = parse_vtable_name(address)
ValueError: too many values to unpack

Change config file path

I would recommend changing the default config location in settings.py from

CONFIG_FILE_PATH = os.path.join(idc.idadir(), 'cfg', 'HexRaysPyTools.cfg')

to

CONFIG_FILE_PATH = os.path.join(os.path.dirname(__file__), 'cfg', 'HexRaysPyTools.cfg')

This allows to store the plugin under %APPDATA%\Hex-Rays\IDA Pro\plugins , allowing switching IDA version without having to re-install/moving around files. Note that the change expects a cfg folder to be present inside the HexRaysPyTools folder. This breaks the convention of keeping the cfg inside the cfg folder but makes it easier to copy in between versions, especially with the increase of IDA releases(service packs)

module object has no attribute 'cot_num '

Hi, thank you for this script, when I tried to execute it, got this exception
image

I think bug in this code block

      elif item.citype == idaapi.VDI_EXPR:
           if item.e.op == idaapi.cot_num:
               # number_format = item.e.n.nf                       # idaapi.number_format_t
               # print "(number) flags: {0:#010X}, type_name: {1}, opnum: {2}".format(
               #     number_format.flags,
               #     number_format.type_name,
               #     number_format.opnum
               # )
               idaapi.attach_action_to_popup(form, popup, Actions.GetStructureBySize.name, None)
           elif item.e.op == idaapi.cot_var:
               # Check if we clicked on variable that is a pointer to a structure that is potentially part of
               # containing structure
               if item.e.v.idx in potential_negatives:
                   idaapi.attach_action_to_popup(form, popup, Actions.SelectContainingStructure.name, None)
               if Actions.ResetContainingStructure.check(hx_view.cfunc.get_lvars()[item.e.v.idx]):
                   idaapi.attach_action_to_popup(form, popup, Actions.ResetContainingStructure.name, None)

Are you have any idea, how can fix it?

Tnx :-)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.