• Stars
    star
    204
  • Rank 187,852 (Top 4 %)
  • Language
    C++
  • Created almost 10 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Milan's useful functions for Hex-Rays decompiler
================================================

New hexrays features:

Assist in creation of new structure definitions / virtual calls detection
===========================================================================

1) use "Reset pointer type" on all variables that you want to scan.

2) Select one of these variables and choose "Scan variable (S)"
  Plugin deals with simple assignments "v1 = this;" automatically. 

3) Again right click on such variable and choose open structure builder.
Ajdust the structure to your likings. 

In Structure builder you can open a list of functions you scanned so far and
functions that were added from virtual function tables. 

Open some of the functions and scan other variables that are of the same
type. Be carefull there is no undo yet.

As you gather more evidence structure builder will show you guessed substructure sizes
and guessed types.

Colliding types have yellow background. Use delete to solve the ambiguity.

With red colour is marked current master offset into structure being created.

Use "*" to change master offset. But you should not need this too often,
because basic situations are detected automatically.

This deals with nested structures:

struct aa 
{
 int foo;
}

struct bb
{
 int foo;
}

struct cc
{
  aa a;
  bb b;
}

void foo(struct *b)
{
  b->foo=4;//while scanning b you should have master offset set to 4
}

void bar(struct *cc)
{
  c->a.foo=5;
  foo(&c->b);
}

substructures
-------------
use "+" and "-" on numeric keyboard to shift parts of the structure. Then use
"pack substruct" to build substructures before finishing the structure.


4) 
Click on some variable in pseudocode and choose "finalize structure"
You will be given a window with "C" declaration of the new structure that you
can tweak by hand and then the new type will by assigned to all variables you
have scanned.

Job done!


Jump directly to virtual function or structure member definition
==================================================================
A class is any structure (A) that has as a pointer into another structure
(A_VT). Where A_VT has a STRUCT comment containing address of the virtual
table and "@0x".



Gives list of structures with given size, with given offset
========================================================================

Right clicking on any number in hexrays view. There are two new items in the menu:
Which structs have this offset?
Which structs have this size?

This will give you list of structures having exact size or this offset (even
in substructures);


Finds structures with same "shape" as is used.
=============================================

Imagine there are structures like this:
00000000 ; ---------------------------------------------------------------------------
00000000 one             struc ; (sizeof=0x8, standard type)
00000000 vfptr           dd ?                    ; offset
00000004 x               dd ?
00000008 one             ends
00000000 ; ---------------------------------------------------------------------------
00000000 two             struc ; (sizeof=0x8)    ; XREF: three�r three�r
00000000 baseclass_0     one ?
00000008 two             ends
00000008
00000000 ; ---------------------------------------------------------------------------
00000000 two             struc ; (sizeof=0x8)    ; XREF: three�r three�r
00000000 baseclass_0     one ?
00000008 two             ends
00000000 ; ---------------------------------------------------------------------------
00000000
00000000 three           struc ; (sizeof=0x70)   ; XREF: four::four(void)+29�r
00000000                                         ; four::four(void)+2A�r ...
00000000 baseclass_0     two ?
00000008 a               one ?
00000010 b               two ?
00000018 c               dd 20 dup(?)
00000068 d               dd ?
0000006C e               dd ?
00000070 three           ends
00000070
00000000 ; ---------------------------------------------------------------------------
00000000
00000000 four            struc ; (sizeof=0xCC)   ; XREF: four::four(void)+3C�r
00000000                                         ; four::four(void)+43�r ...
00000000 baseclass_0     three ?
00000070 a               dd ?
00000074 b               dd ?
00000078 c               dd 20 dup(?)
000000C8 d               dd ?
000000CC four            ends


And you come across a code like this:

void __thiscall four::four(int this)
{
  int v1; // esi@1

  v1 = this;
  *(_DWORD *)(this + 4) = 5;
  *(_DWORD *)(this + 12) = 5;
  *(_DWORD *)(this + 8) = &one::`vftable';
  *(_DWORD *)(this + 20) = 5;
  *(_DWORD *)(this + 16) = &two::`vftable';
  *(_DWORD *)(this + 104) = 0;
  *(_DWORD *)(this + 108) = 0;
  memset((void *)(this + 24), 32, 0x50u);
  *(_DWORD *)v1 = &four::`vftable';
  *(_DWORD *)(v1 + 112) = 0;
  *(_DWORD *)(v1 + 116) = 0;
  *(_DWORD *)(v1 + 200) = 0;
  memset((void *)(v1 + 120), 33, 0x50u);
}

Right click on either "v1" or "this" and choose "recognize shape (T)".
The plugin will show you that the only structure that matches this shape is
"four".

See virtual_calls_4.idb.


convert function to __usercall or __userpurge
===============================================================
Once I dealt with project that mixed Delphi and Visual C++. These two uses
different registers for thiscall/fastcall etc so changing compiler resulted
in ruining analysis. So I made this functionality to deal with it forever.

Just right click on first line of pseudocode and choose "Convert to __usercall".


removes function's return type making it void fnc(...)
===============================================================
Sometimes function does not return any value but hex-rays thinks it does. It
was very tiresome to type "home, y, home, ctrl-shift-left, "void", enter" so I
made Ida do it on one click.

Just right click on first line of pseudocode and choose "Remove return type"
or type 'R'.


Adds Classes on top of structures
===============================================================
menu View / Open Subviews / Classes

Now just list of "interesting" structures inside database along with their
functions.


Automatically zero certain variables in hexrays output
===============================================================
Sometimes in pseudocode there is variable that gets assigned zero and is never
changed. This feature propagates this zero to all places where this variable
was.

The rules are:

"""
zeroizer.cpp
	variable is assigned zero
	variable is never referenced
	warn if variable is on stack

	replace every such variable with zero
"""

Works automatically.

Deals with structures with negative offsets
===========================================
see test2_negative_offsets.idb @004010B0

Without my plugin:
void __cdecl test3(pokusx *p)
{
  *(_DWORD *)&p[-1].array[19996] = 124;
  p[-1].k = 666;
}

With my plugin:
void __cdecl test3(pokusx *p)
{
  container_of(p, 8)->a = 124;
  container_of(p, 8)->cc = 666;
}

Removes function arguments
==========================
Sometimes hexrays thinks that a register is used as an argument for a function
but it isn't so. It was also tiresome to type "home, home, y, ctrl->right,
ctrl-shift-right, delete, enter" So I made this to deal with it.

Just select that argument in the first line of pseudocode and choose "Remove
this argument" or type 'A'.


Assists with changing types of structure members and variables
===============================================================

Imagine you have pseudocode like this.


CASE 1:
{
  type1 v1;
  type2 v2
  v2 = (type2)v1;
}

right click on "v2" in the last line and choose "recast item" v2 will be converted to type "type2";

CASE 2:
you have type declarations:

struct object
{
  struct vtable *v;
}

struct vtable
{
  int fnc1;
  int fnc2;
}


and there is code like this in pseudocode:

struct object * this;
(void (__thiscall *)(object *)this->v->fnc1)(this);

righ clicking on fnc1 and choosing "Recast item" will change type of
"vtable.fnc1" to "void (__thiscall *)(object *)".


Now suppose there is virtual table for object at address 0xABCDEF.

Setting STRUCT comment for "struct vtable" as something containing "@0xABCDEF"
(crucial part is "@0x" ) enables my plugin to navigate to functions located at 0xABCDEF.

But setting this by hand is seldom needed because structure builder takes care of this automatically.



Dealing with delphi classes
===========================
Also there is experimental code for dealing with delphi classes. In menu Edit
/ Structs / Create Delphi class.

The cursor must be on first line of delphi class in ida-view before using
this functionality.

warning: This feature is highly experimental.

New functionality in Structures view
====================================
Use right click in Structures view.

Extract object
--------------
Select few lines in a structure and it will create a new structure off
selected lines.


Unpack object
-------------
Does the opposite of Extract object. It in place unpacks selected structure.

Which structure matches here?
-----------------------------
It will try to guess which structure has the right offsets and types that can
matche selected lines in Structures view.

Add to classes
--------------
Promotes a structure to a class.


Add VT
------
Adds virtual table to a structure. It asks for address to a virtual table.
Then this happens:

00000000 struc_1         struc ; (sizeof=0x10)
00000000 field_0         dd ?
00000004 field_4         dd ?
00000008 field_8         dd ?
0000000C field_C         dd ?
00000010 struc_1         ends

--->

00000000 struc_1         struc ; (sizeof=0x10)
00000000 VT              dd ?                    ; offset
00000004 field_4         dd ?
00000008 field_8         dd ?
0000000C field_C         dd ?
00000010 struc_1         ends
00000010
00000000 ; ---------------------------------------------------------------------------
00000000
00000000 ; @0x004047B0
00000000 struc_1_VT      struc ; (sizeof=0x10)
00000000 sub_40101E      dd ?                    ; sub_40101E
00000004 j___RTC_NumErrors dd ?                  ; j___RTC_NumErrors
00000008 sub_401023      dd ?                    ; sub_401023
0000000C sub_401073      dd ?                    ; sub_401073
00000010 struc_1_VT      ends



the type of "struc_1.VT" is "struc_1_VT*"

When asked for vtableaddress I gave it 0x004047B0.

This enables jumps in hexrays to virtual function.



IDC functionality
=================

my plugins add these idc functions:
reset_alt_calls
---------------
I messed up my idb database and this was a cure:

static void reset_alt_calls(ea_t ea)
{
	static const char * nname;
	if ( ph.id == PLFM_MIPS )
		nname = "$ mips";
	else if ( ph.id == PLFM_ARM )
		nname = " $arm";
	else
		nname = "$ vmm functions";
	netnode n(nname);
	for(nodeidx_t idx= n.alt1st(); idx != BADNODE; idx = n.altnxt(idx))
	{
		if(n.altval(idx)-1 == ea)
		{
			n.altdel(idx);
			noUsed(idx);                 // reanalyze the current instruction
			recalc_spd(idx);
		}	
		//n.altdel_all(atag);
	}
}


structs_of_size(num)
-------------------
Just calls "Which structure has size num?".

Graph of structures inside structures.
======================================
structures_graph_0.png, see structures_graph.png
menu View/graphs/show structures graph


Milan Bohacek

More Repositories

1

ScyllaHide

C++
232
star
2

IDA_Signsrch

IDA Signsrch
C
145
star
3

IDA-IDC-Scripts

Varoius IDC-scripts I've collected during the years.
Python
130
star
4

idastealth

C
98
star
5

IDA_ClassInformer

IDA ClassInformer PlugIn
C++
62
star
6

GUID-Finder

C++
50
star
7

IDASimulator

IDASimulator is a plugin that extends IDA's conditional breakpoint support, making it easy to augment / replace complex executable code inside a debugged process with Python code. Specifically, IDASimulator makes use of conditional breakpoints in the IDA debugger to hijack the execution flow of a process and invoke Python handler functions whenever particular code blocks are executed. With support for multiple target architectures, it handles details such as register initialization, memory allocation, pointers, function arguments and return values seamlessly and transparently, making it easy to replace, modify and subvert existing functionality (or lack thereof) in the target process. IDASimulator also includes the IDASim python module, on which IDASimulator is based. This allows for all of the features of IDASimulator to be integrated into more complex IDAPython scripts. IDASimulator currently supports the x86, x86_64, ARM and MIPS32 architectures. Porting to other architectures is very easy.
Python
46
star
8

ida-pro-swf

C++
29
star
9

IDA_FunctionStringAssociate_PlugIn

IDA FunctionStringAssociate PlugIn
C++
27
star
10

idascope

Python
26
star
11

IDA_COM_Plugin

C++
25
star
12

Fast_IDB2Sig_and_LoadMap_IDA_plugins

C++
20
star
13

optimice

Python
17
star
14

arm-thumb-decompiler-plugin

C++
17
star
15

idapathfinder

Python
15
star
16

IndirectCalls

C++
15
star
17

IDA_Extrapass

IDA ExtraPass PlugIn
C
14
star
18

detpdb

C++
14
star
19

desquirr

C++
14
star
20

idatools

Tools for IDA
JavaScript
13
star
21

IDAProBoschME7

Siemens Bosch ME7.x Disassembler Helper for IDA Pro
C
13
star
22

ida-x86emu-QT

C++
12
star
23

bios_parse

Python
12
star
24

PPCAltivec

C++
12
star
25

idaplugs

Plugins for IDA Pro by servil
C++
11
star
26

uberstealth

C
11
star
27

IDA2PAT_Reloaded

C++
10
star
28

turbodiff

C++
10
star
29

CommentViewer

C++
9
star
30

patchdiff3

Continuation of the popular patchdiff IDA plugin
C++
9
star
31

idastruct

C++
8
star
32

jeb2-plugin-macho

Mach-O Object Plugin for JEB2 https://www.pnfsoftware.com
Java
8
star
33

HeapTracer

C++
8
star
34

ida-libbfd-loader

IDA Pro libbfd based loader for misc formats that IDA cannot handle, like IRIX ECOFF etc.
CMake
7
star
35

bflt-utils

C
7
star
36

ida-plugins-collection

Python
7
star
37

ida-unicode-string-convert

C++
7
star
38

WhatAPIs

IDA WhatAPIs PlugIn
C++
7
star
39

RECPP

RECPP is a IDA plugin / API for reversing C++ applications based on Igor Skochinsky articles and scripts (http://www.openrce.org/articles/full_view/21)
C++
7
star
40

ida-sync-plugin

C++
6
star
41

ida-pro-plugin-wizard-for-vs2013

JavaScript
6
star
42

garmin-ida-loader

C++
6
star
43

StructDump

C++
6
star
44

axis-cris-idp

IDA Pro CPU plugin for the AXIS CRIS architecture
C++
6
star
45

idainject

C++
6
star
46

arm-helper

C++
6
star
47

IDA-CC

http://forum.exetools.com/showthread.php?t=13569&page=3
6
star
48

binarydiffer

C++
6
star
49

processstalker

C++
6
star
50

Cypress-M8-IDA-Processor-Module

C++
6
star
51

analyzecore

C++
6
star
52

IDA-omf2pat

IDA FLAIR helpers for making .SIG files from Borland sources by servil
C++
5
star
53

IDA-rails

C++
5
star
54

IDA-pinlog

C
5
star
55

findStrcpy

C++
5
star
56

fujitsu-fr30-idp

IDA Pro CPU plugin for the Fujitsu FR30 architecture
C++
5
star
57

cyrplw

C
5
star
58

findMemcpy

C++
5
star
59

bignum-dumper

C++
5
star
60

findMalloc

C++
4
star
61

get-asm-code

C++
4
star
62

Automated-Generic-Function-Naming

Python
4
star
63

MIPSJT

MIPS JT fixup for IDA PRO
C++
4
star
64

rsrcExtractor

C++
4
star
65

IdaThingy

C++
4
star
66

ppc2

C++
4
star
67

krypton

Python
4
star
68

gerbay1

C++
4
star
69

ida-dbdump

C++
4
star
70

tree-cbass

Python
4
star
71

ida-x86emu

C++
4
star
72

IDAWinHelpViewer

C++
3
star
73

depload

C++
3
star
74

ppchelper

C++
3
star
75

ida_objectivec_plugins

C++
3
star
76

IDA_MarkRefCnt

IDA MarkRefCount PlugIn
C++
3
star
77

idaplugininfo

This is a little utility to dump information about installed IDA Pro plugins. The key parts of the IDA PLUGIN export "plugin_t" struct data.
C#
3
star
78

REDB

Python
3
star
79

IDA_WaitBoxEx

IDA WaitBoxEx
C++
3
star
80

CopyAndPast

Binary Copy and Paste
C++
2
star
81

idaocaml

C
2
star
82

idapatchwork

https://bitbucket.org/daniel_plohmann/idapatchwork
Python
2
star
83

ncoverage

C#
2
star
84

ida_load_all_dump_load

C++
2
star
85

vctaxo

C++
2
star
86

malflare

C++
2
star
87

ParseBinTree

take IDA PRO memory lines and print binary tree node.
Python
2
star
88

IDACSharp

C# 'Scripts' for IDA 6.6+ based on https://idacsharp.codeplex.com/
2
star
89

IDA-auto-declaration

IDA PRO plugin for automatic type declaration like char, byte, float, double wchar etc...
2
star
90

mynav

Python
2
star
91

wwcd2

Ida pro What Would Capstone Decode by Stefan Esser
C++
2
star
92

Hotch

C++
2
star
93

rails

C++
1
star
94

ida-vs2005templates

C++
1
star
95

classinformer

https://sourceforge.net/projects/classinformer/ partially adapted for ida64
1
star
96

ida_plugin_depack_aplib_and_lzma

Assembly
1
star
97

CLU

C
1
star
98

idastruct-1

Script helper in working with ida structures
Python
1
star
99

COSA-IDA

Comprehensive Static Analyzer For Android Application (COSA with IDA Pro)
Java
1
star
100

lltd-osx

LLTD (LLD2D) for OS X
C
1
star