Hex-Rays v1.1 vs. v1.0 Decompiler Comparison Page

Hex-Rays v1.1 vs. v1.0 Decompiler Comparison Page

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

The following examples are displayed on this page:

NOTE: The new decompiler can use comparison instructions (and other clues) to determine possible variable values. In the example above, it is clear that the result variable is equal to zero within the if-block. This knowledge allows for more optimizations and makes the code more readable.


More aggressive variable elimination

We improved the decompiler engine to eliminate more variables. This means less useless assignments, shorter and more readable code.

HRESULT __stdcall AtlMarshalPtrInProc(LPUNKNOWN pUnk,
                                      const IID *riid,
                                      LPSTREAM *ppstm)

{
  HRESULT v3; // edi@1

  v3 = CreateStreamOnHGlobal(0, 1, ppstm);
  if ( v3 >= 0 )
  {
    v3 = CoMarshalInterface(*ppstm, riid, pUnk, 3u, 0, 1u);
    if ( v3 < 0 )
    {
      (*ppstm)->lpVtbl->Release(*ppstm);
      *ppstm = 0;
    }
  }
  return v3;
}

More for-loops

For-loops are easier to read than while- or do-loops. The decompiler prefers to generate for loops now. Again, note the difference in size and readability!


      for ( j = 0; j < 5; ++j )
      {
        v3 = 1 << j;
        tbl2[j + 5 * i] = ((1 << j) & v1) == 1 << j;
      }

Better recognition of 64-bit idioms

While we still do not recognize all 64-bit idioms (perfections is out of question in binary analysis) we do much better now. Above is just one of many possible examples (v10 on the left and v21 on the right are 64-bit variables.

      v21 += v22;
      *(_DWORD *)&v8 = GetShortField(v21, (int)"IMAGE_DEBUG_DIRECTORY", 1);
      if ( v8 )
        break;

Better recognition of 64-bit idioms, example 2

Yet one more illustration of 64-bit arithmetics.

qword_6992C7E0 += PageSize * a6 - a2;

Floating point instructions

One could say that this comparison is not fair and we would agree. Previous versions of the decompiler could not handle floating point instruction at all, and the new version knows all about them, including conversion intricacies and other subtle details.

bool __cdecl ld_ull_cmpge(long double a1, unsigned __int64 a2)
{
  return a1 >= (long double)a2;
}

Better recognition of built-in functions

While there is a lot to do, the new version copes better with inline memcpy(), strlen(), and similar functions.

      memcpy(v99 - 1, v100, v96);
      v109 += 4;
      v111 = (const char **)v109;

More aggressive value propagation

Thanks to the more aggressive propagation algorithm, the output becomes simpler.

signed __int64 __cdecl smodushort(signed __int64 a1, unsigned __int16 a2)
{
  return a1 % a2;
}

New algorithm to detect function arguments

We switched to a new heuristic algorithm to detect arguments of unknown function calls. While it is not perfect, it loses less arguments and tends to produce more reliable output. Please note that this algorithm is required to determine the types of only unknown calls: once the user specifies the function prototype, it will be used by the decompiler.

  result = sub_100270F(0);
  if ( result )
  {
    dword_100A480 = sub_15F0000(byte_1009628, -2147483648, 3, 0, 3, 128, 0);

Implicit value propagation

      result = sub_402EE0(v3);
      if ( !result )
      {
        v10 = 0;
        v7 = v3->pchar4;
        if ( v3->dword0 <= 0u )

Last updated