Hex-Rays v7.2 vs. v7.1 Decompiler Comparison Page

Below you will find side-by-side comparisons of v7.1 and v7.2 decompilations. Please maximize the window too see both columns simultaneously.

The following examples are displayed on this page:

NOTE: these are just some selected examples that can be illustrated as side-by-side differences. There are many other improvements and new features that are not mentioned on this page.


Magic divisions in 64-bit code

In the past the Decompiler was able to recognize magic divisions in 32-bit code. We now support magic divisions in 64-bit code too.

return 21600 * (t / 21600);

More aggressive 'if' to 'boolean' folding

More aggressive folding of if_one_else_zero constructs; the output is much shorter and easier to grasp.

return a1 << 28 != 0 && (a1 & (unsigned __int8)(a1 - 1)) == 0;

Better type of 'this' argument

The decompiler tries to guess the type of the first argument of a constructor. This leads to improved listing.

XImage *__fastcall XImage::setHotSpot(XImage *this, int a2, int a3)
{
  LOWORD(this->height) = a2;
  HIWORD(this->height) = a3;
  return this;
}

Improved union field selection

The decompiler has a better algorithm to find the correct union field. This reduces the number of casts in the output.

float __fastcall ret4f(__n128 a1)
{
  return a1.n128_f32[2];
}

Improved recognition of 'for' loops

We improved recognition of 'for' loops, they are shorter and much easier to understand.

  for ( i = 0; i < 16; ++i )
  {
    printf("%x", *(unsigned __int8 *)(i + v2) >> 4);
    printf("%x", *(_BYTE *)(i + v2) & 0xF);
  }

Added support for shifted pointers

Please note that the code on the left is completely illegible; the assembler code is probably easier to work with in this case. However, the code on the right is very neat. JFYI, below is the class hierarchy for this example:

struct __cppobj B1
{
  B1_vtbl *__vftable /*VFT*/;
  char d1[4];
};
struct __cppobj B2
{
  B2_vtbl *__vftable /*VFT*/;
  char d2[4];
};
struct __cppobj A : B1, B2
{
  char d3[4];
};
  

Also please note that the source code had

A::a2(A *this)

but at the assembler level we have

A::a2(B2 *this)

Visual Studio plays such tricks.

int __thiscall A::a2(B2 *__shifted(A,8) this)
{
  printf("A::a2 %p\n", ADJ(this));
  printf("A::d2 %p\n", ADJ(this)->d2);
  return ADJ(this)->d3[0];
}

Better recognition of inlined standard functions

Yes, the code on the left and on the right do the same. We prefer the right side, very much.

if ( !memcmp(i + 10, "AMIBIOSC", 8u) )
      return i + 10;

Improved application of pre-increment and pre-decrement

Minor stuff, one would say, and we'd completely agree. However, these minor details make reading the output a pleasure.

    v5 = *++v4;
    result = --a4;

Added support for RRX addressing mode in ARM

This is a rare addressing mode that is nevertheless used by compilers. Now we support it nicely.

__int64 __fastcall sar64(__int64 a1)
{
  return a1 >> 1;
}

Improved constant propagation in global memory

The new decompiler managed to disentangle the obfuscation code and convert it into a nice strcpy()

strcpy((char *)&dword_1005DF9A, "basic_string");

Added support for Objective C blocks

The new version knows about ObjC blocks and can represent them correctly in the output. See Edit, Other, Objective-C submenu in IDA, it contains the necessary actions to analyze the blocks.

__int64 __fastcall sub_181450634(__int64 a1, __int64 a2, __int64 a3)
{
  Block_layout_18145064C blk; // [xsp+0h] [xbp-30h]

  blk.isa = _NSConcreteStackBlock;
  *(_QWORD *)&blk.flags = 0x42000000LL;
  blk.invoke = sub_181450694;
  blk.descriptor = (Block_descriptor_1 *)&unk_1B0668958;
  blk.lvar1 = *(_QWORD *)(a1 + 32);
  blk.lvar2 = a3;
  return sub_18144BD0C(a2, &blk);
}

Improved recognition of 64-bit comparisons

We continue to improve recognition of 64-bit arithmetics. While it is impossible to handle all cases, we do not give up.

  gettimeofday(&tv, 0);
  v0 = 90 * (v3 / 1000 + 1000LL * *(_QWORD *)&tv);
  if ( v0 < 0xFFFFFFFFFFFFFFFFLL )
    stamp = 90 * (v3 / 1000 + 1000LL * *(_QWORD *)&tv);

Merged common code in 'if' branches

Yet another optimization rule that lifts common code from 'if' branches. We made it even more aggressive.

    mywcscpy();
    if ( a3 < 0 )
      v4 = -a3;

Added forced stack variables

Sometimes compilers reuse the same stack slot for different purposes. Many our users asked us to add a feature to handle this situation. The new decompiler addresses this issue by adding a command to force creation of a new variable at the specified point. Currently we support only aliasable stack variables because this is the most common case.

In the sample above the slot of the p_data_format variable is reused. Initially it holds a pointer to an integer (data_format) and then it holds a simple integer (errcode). Previous versions of the decompiler could not handle this situation nicely and the output would necessarily have casts and quite difficult to read. The two different uses of the slot would be represented just by one variable. You can see it in the left listing.

The new version produces clean code and displays two variables. Naturally it happens after applying the force new variable command.

    data_format = *p_data_format;
    if ( *p_data_format < 0 || data_format > 13 )
    {
      errcode = 2;
      SetError(&this->status, &errcode, "format not one of accepted types");
    }

Added support for virtual calls

Well, these listings require no comments, the new version apparently wins!

void __cdecl test3(D7 *a1)
{
  a1->f1(&a1->A1);
  a1->f2(&a1->D3);
  a1->f3(&a1->D5);
  a1->f4(&a1->A4);
  a1->f5(a1);
  a1->f6(a1);
  a1->g0(&a1->D5);
  a1->g5(&a1->D5);
  a1->g7(a1);
  if ( a1 )
    a1->~D7(a1);
}

Last updated