<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>Hex blog</title>
    <link rel="alternate" type="text/html" href="http://hexblog.com/" />
    <link rel="self" type="application/atom+xml" href="http://hexblog.com/atom.xml" />
   <id>tag:hexblog.com,2009://1</id>
    <updated>2009-06-19T20:33:02Z</updated>
    <subtitle>About IDA Pro, decompilation, programming, binary program analysis, information security.</subtitle>
    <generator uri="http://www.sixapart.com/movabletype/">Movable Type 3.2</generator>
 
<entry>
    <title>Function call graph plugin sample</title>
    <link rel="alternate" type="text/html" href="http://hexblog.com/2009/06/function_call_graph_plugin_sam.html" />
    <id>tag:hexblog.com,2009://1.96</id>
    <published>2009-06-19T20:02:48Z</published>
    <updated>2009-06-19T20:33:02Z</updated>
    
    <summary>IDA Pro already has a function call graph facility, nonetheless it employs WinGraph32....</summary>
    <author>
        <name>Elias Bachaalany</name>
        
    </author>
            <category term="IDA Pro" />
    
    <content type="html" xml:lang="en" xml:base="http://hexblog.com/">
        <![CDATA[<p>IDA Pro already has a function call graph facility, nonetheless it employs WinGraph32.</p>]]>
        <![CDATA[<p>Although it is helpful, it is not very useful just because it lacks interactivity.</p>

<p><img alt="Wingraph function call graph" src="http://hexblog.com/ida_pro/pix/fcg_wg32.jpg" width="400" height="300" /></p>

<p>For demonstration purposes, we created a sample plugin that uses the graph functions from the SDK to achieve the same thing but with a bit more of interactivity: double-click to jump to a node, search node by name (also search next), etc...<br />
One can easily modify the plugin to also add a navigation stack or perhaps more filters.</p>

<p><img alt="plugin function call graph" src="http://hexblog.com/ida_pro/pix/fcg_cg.jpg" width="400" height="300" /></p>

<p>After the plugin is installed it will create a new menu item in Views / Subviews / Function call graph, also make sure you right-click in the graph to see the options and hotkeys.</p>

<p>To recompile the plugin you need IDA Pro SDK version 5.5</p>

<p>Hope you find it useful!</p>

<p><a href="http://hexblog.com/ida_pro/pix/fcg_v1.zip">Click here to download the plugin</a></p>]]>
    </content>
</entry>
<entry>
    <title>IDA Pro 5.5 and Hex-Rays 1.1 have been released!</title>
    <link rel="alternate" type="text/html" href="http://hexblog.com/2009/06/ida_pro_55_and_hexrays_11_have.html" />
    <id>tag:hexblog.com,2009://1.95</id>
    <published>2009-06-15T16:30:59Z</published>
    <updated>2009-06-15T16:35:24Z</updated>
    
    <summary>IDA Pro 5.5 We are happy to announce a new version of IDA Pro! The major news is the new docking user interface. There are many other improvements: processor modules, file formats, analysis tweaks, well, the usual stuff. There is...</summary>
    <author>
        <name>Ilfak Guilfanov</name>
        
    </author>
    
    <content type="html" xml:lang="en" xml:base="http://hexblog.com/">
        <![CDATA[<h3>IDA Pro 5.5</h3>

We are happy to announce a new version of IDA Pro! The major news is the
new docking user interface. There are many other improvements: processor modules,
file formats, analysis tweaks, well, the usual stuff. There is a new MS Windows
Crash Dump Loader and improved Bochs debugger. The complete list of new
features and bug fixes is available here
<p>
<a href="http://www.hex-rays.com/idapro/55/index.htm">http://www.hex-rays.com/idapro/55/index.htm</a>


<h3>Hex-Rays 1.1</h3>


We also release a new version of our decompiler: now with the floating point
support. It was a technically challenging task and required lots of testing, but
we are very happy with the end result. It can really handle floating point
computations and generates reliable output. All subtle nuances, like conversion
rules, fpu stack state, predefined compiler helper functions, are all taken care of.
<p>
The decompiler uses debug information if it is available: in this case, even local
variable names and types will be restored. If there is no debug information, the
decompiler will still generate correct and precise output. In fact, it is designed
to work without debug information, which means that virtually any
compiler-generated executable can be analyzed and turned into C output.


<h3>New pricing and support plans</h3>

With this release, we update the pricing of IDA Pro and Hex-Rays Decompiler.
While the initial purchase prices are increased, upgrade prices go down.
In order to streamline the upgrade process, we will use the same rules for
all our products: now a support plan is renewable any time while it is active
and also three months after its expiration. The new support period is counted from
the expiration date of the previous support period.
<p>
If you upgraded your IDA/Hex-Rays copy the last month with older prices,
do not worry. For you, we will add a month of support for the IDA license,
and three months of support for Hex-Rays Decompiler.
<p>
We will continue to accept old-style upgrade orders until 12 October 2009.


<h3>How to request the new versions</h3>

As usual, the new versions are free for users whose licenses are within active
support plan. Submit your ida.key to
<p>
<a href="https://www.hex-rays.com/updida.shtm">https://www.hex-rays.com/updida.shtm</a>l
<p>
and expect a message from us within 5-10 minutes. Sometimes we do not have your
email in the database, so please specify it (otherwise we will have no means of
communicating with you).
<p>
To request the new version of the decompiler, please use Edit, Plugins, Hex-Rays,
Check for updates in IDA.


<h3>Is your key too old?</h3>

If your key is too old for a free update, you might still be
eligible for a discounted upgrade. Until 12 October 2009 we offer the upgrade
prices for all purchases made two years ago or less. The order forms can be
found here:
<p>
<a href="http://www.hex-rays.com/idapro/idaorder.htm">http://www.hex-rays.com/idapro/idaorder.htm</a>
<p>
We will arrange an electronic delivery to existing customers.
<p>
That's all folks! Enjoy the release.

]]>
        
    </content>
</entry>
<entry>
    <title>IDA Pro 5.5 goes alpha </title>
    <link rel="alternate" type="text/html" href="http://hexblog.com/2009/06/ida_pro_55_goes_alpha.html" />
    <id>tag:hexblog.com,2009://1.94</id>
    <published>2009-06-02T14:12:44Z</published>
    <updated>2009-06-02T14:47:52Z</updated>
    
    <summary>After many months of work, IDA Pro 5.5 is now in alpha stage and this week the beta will be out for testing....</summary>
    <author>
        <name>Elias Bachaalany</name>
        
    </author>
            <category term="IDA Pro" />
    
    <content type="html" xml:lang="en" xml:base="http://hexblog.com/">
        After many months of work, IDA Pro 5.5 is now in alpha stage and this week the beta will be out for testing.
        <![CDATA[In this version many small and big improvements took place, here is a partial change list:<ul>

<li>PC module improvements
<li>PE loader improvements
<li>ARM processor module improvements
<li>Improved Hex-View:<ul> <li>Edit support   <li>Data display format: words, dwords, doubles, ...  <li>Unicode or custom codepages </ul>
<li>Bochsrc file loader: load a bochsrc file and start debugging the disk image
<li>Windows Crash dump support: IDA now accepts MS Windows Crash dump files. Load the crash dump file and IDA Pro will create a database with the memory contents of the crash (if they were included). You can also run the Windbg debugger module and issue commands to the debugger engine to investigate more about the crash
<li>Docking interface: all windows are now dockable, allowing you to make optimal use of the desktop space.
</ul>

<p>This is for example how a desktop configuration could look like:</p>

<a href="/ida_pro/pix/main55.gif"><img border="0" alt="main interface example" src="/ida_pro/pix/main55-thumb.gif" width="480" height="285" /></a>

<p>And this is another desktop configuration for the debugger:</p>

<a href="/ida_pro/pix/dbg55.gif"><img border="0" alt="debugger interface example" src="/ida_pro/pix/dbg55-thumb.gif" width="480" height="285" /></a>]]>
    </content>
</entry>
<entry>
    <title>Decompiling floating point</title>
    <link rel="alternate" type="text/html" href="http://hexblog.com/2009/05/decompiling_floating_point.html" />
    <id>tag:hexblog.com,2009://1.93</id>
    <published>2009-05-05T12:13:32Z</published>
    <updated>2009-05-05T12:18:40Z</updated>
    
    <summary>It is a nice feeling, when, after long debugging nights, your software finally runs and produces meaningful results. Another hallmark is when other users start to use it and obtain useful results. Usually this period is very busy: lots of...</summary>
    <author>
        <name>Ilfak Guilfanov</name>
        
    </author>
            <category term="Decompilation" />
    
    <content type="html" xml:lang="en" xml:base="http://hexblog.com/">
        <![CDATA[It is a nice feeling, when, after long debugging nights, your software
finally runs and produces meaningful results. Another hallmark is when other users
start to use it and obtain useful results. Usually this period is very busy: lots
of new bugs are discovered and fixed, unforeseen corner cases are handled.
Then another period starts: when users come back
for more copies,with more ideas, request more functionality, etc. This is what is happening
with the decompiler now and I feel it is time to update you with the latest news.
<p>
]]>
        <![CDATA[In short, things go well. We currently can handle floating point instructions
for Borland and Visual Studio, and some GCC generated stuff. Problems remain (especially with optimized code)but we advance well. Below are a couple of samples. The first one is very simple. The following assembly function:
<p>
<div style="background:#DDEEFF;border:1px solid;white-space:pre; font-family: andale, courier, monospace"><span>_my_sincos      proc near                                                    </span>
<span>                                                                             </span>
<span><span style="color:green">arg_0           </span><span style="color:navy">= qword ptr  </span><span style="color:#008040">8                                               </span></span>
<span>                                                                             </span>
<span>                <span style="color:navy">push    ebp                                                  </span></span>
<span>                <span style="color:navy">mov     ebp, esp                                             </span></span>
                <span style="color:navy">fld     [ebp+</span><span style="color:green">arg_0</span><span style="color:navy">]
                fsincos
                fxch    st(1)
                fmul    st, st
                fxch    st(1)
                fmul    st, st
                faddp   st(1), st
                fsqrt
                mov     esp, ebp
                <span style="color:navy">pop     ebp                                                  </span></span>
                <span style="color:navy">retn
</span>_my_sincos      endp
</div>
<p>
is converted into the following one-liner:
<p>
<div style="background:#DDFFDD;border:1px solid;white-space:pre; font-family: andale, courier, monospace"><span style="color:gray">long double __cdecl my_sincos(double a1)
</span><span style="color:navy">{
  return </span>sqrt<span style="color:navy">(</span>sin<span style="color:navy">(</span><span style="color:#8080ff">a1</span><span style="color:navy">) * </span>sin<span style="color:navy">(</span><span style="color:#8080ff">a1</span><span style="color:navy">) + </span>cos<span style="color:navy">(</span><span style="color:#8080ff">a1</span><span style="color:navy">) * </span>cos<span style="color:navy">(</span><span style="color:#8080ff">a1</span><span style="color:navy">));
</span><span style="background:navy"></span><span style="color:navy">}
</div>
<p>
Pretty simple, you may say... Well, here's a longer one (sorry for the length of the assembler listing, please scroll down):
<p>
<div style="background:#DDEEFF;border:1px solid;white-space:pre; font-family: andale, courier, monospace"><span>?ld_ull_test@@YAOO_K@Z proc near                                             </span>
<span>                                                                             </span>
<span><span style="color:green">var_40          </span><span style="color:navy">= qword ptr </span><span style="color:#008040">-40h                                             </span></span>
<span><span style="color:green">var_38          </span><span style="color:navy">= qword ptr </span><span style="color:#008040">-38h                                             </span></span>
<span><span style="color:green">var_30          </span><span style="color:navy">= qword ptr </span><span style="color:#008040">-30h                                             </span></span>
<span><span style="color:green">var_28          </span><span style="color:navy">= qword ptr </span><span style="color:#008040">-28h                                             </span></span>
<span><span style="color:green">var_20          </span><span style="color:navy">= qword ptr </span><span style="color:#008040">-20h                                             </span></span>
<span><span style="color:green">var_18          </span><span style="color:navy">= qword ptr </span><span style="color:#008040">-18h                                             </span></span>
<span><span style="color:green">var_10          </span><span style="color:navy">= qword ptr </span><span style="color:#008040">-10h                                             </span></span>
<span><span style="color:green">var_8           </span><span style="color:navy">= qword ptr </span><span style="color:#008040">-8                                               </span></span>
<span><span style="color:green">arg_0           </span><span style="color:navy">= qword ptr  </span><span style="color:#008040">8                                               </span></span>
<span><span style="color:green">arg_8           </span><span style="color:navy">= qword ptr  </span><span style="color:#008040">10h                                             </span></span>
<span>                                                                             </span>
<span>                <span style="color:navy">push    ebp                                                  </span></span>
<span>                <span style="color:navy">mov     ebp, esp                                             </span></span>
<span>                <span style="color:navy">sub     esp, </span><span style="color:green">28h                                             </span></span>
                <span style="color:navy">mov     eax, dword ptr [ebp+</span><span style="color:green">arg_8</span><span style="color:navy">+</span><span style="color:green">4</span><span style="color:navy">]
                push    eax             </span>; int
                <span style="color:navy">mov     ecx, dword ptr [ebp+</span><span style="color:green">arg_8</span><span style="color:navy">]
                push    ecx             </span>; int
                <span style="color:navy">sub     esp, </span><span style="color:green">8
                </span><span style="color:navy">fld     [ebp+</span><span style="color:green">arg_0</span><span style="color:navy">]
                fstp    [esp+</span><span style="color:green">38h</span><span style="color:navy">+</span><span style="color:green">var_38</span><span style="color:navy">]
                call    </span>?ld_ull_add@@YAOO_K@Z <span style="color:gray">
                </span><span style="color:navy">add     esp, </span><span style="color:green">10h
                </span><span style="color:navy">fstp    [ebp+</span><span style="color:green">arg_0</span><span style="color:navy">]
                sub     esp, </span><span style="color:green">8
                </span><span style="color:navy">fld     [ebp+</span><span style="color:green">arg_0</span><span style="color:navy">]
                fstp    [esp+</span><span style="color:green">30h</span><span style="color:navy">+</span><span style="color:green">var_30</span><span style="color:navy">]
                call    </span>?ld_ull_cvt@@YA_KO@Z <span style="color:gray">
                </span><span style="color:navy">add     esp, </span><span style="color:green">8
                </span><span style="color:navy">mov     dword ptr [ebp+</span><span style="color:green">arg_8</span><span style="color:navy">], eax
                mov     dword ptr [ebp+</span><span style="color:green">arg_8</span><span style="color:navy">+</span><span style="color:green">4</span><span style="color:navy">], edx
                mov     edx, dword ptr [ebp+</span><span style="color:green">arg_8</span><span style="color:navy">+</span><span style="color:green">4</span><span style="color:navy">]
                push    edx             </span>; int
                <span style="color:navy">mov     eax, dword ptr [ebp+</span><span style="color:green">arg_8</span><span style="color:navy">]
                push    eax             </span>; int
                <span style="color:navy">sub     esp, </span><span style="color:green">8
                </span><span style="color:navy">fld     [ebp+</span><span style="color:green">arg_0</span><span style="color:navy">]
                fstp    [esp+</span><span style="color:green">38h</span><span style="color:navy">+</span><span style="color:green">var_38</span><span style="color:navy">]
                call    </span>?ld_ull_sub@@YAOO_K@Z <span style="color:gray">
                </span><span style="color:navy">add     esp, </span><span style="color:green">10h
                </span><span style="color:navy">fstp    [ebp+</span><span style="color:green">arg_0</span><span style="color:navy">]
                mov     ecx, dword ptr [ebp+</span><span style="color:green">arg_8</span><span style="color:navy">+</span><span style="color:green">4</span><span style="color:navy">]
                push    ecx             </span>; int
                <span style="color:navy">mov     edx, dword ptr [ebp+</span><span style="color:green">arg_8</span><span style="color:navy">]
                push    edx             </span>; int
                <span style="color:navy">sub     esp, </span><span style="color:green">8
                </span><span style="color:navy">fld     [ebp+</span><span style="color:green">arg_0</span><span style="color:navy">]
                fstp    [esp+</span><span style="color:green">38h</span><span style="color:navy">+</span><span style="color:green">var_38</span><span style="color:navy">]
                call    </span>?ld_ull_mul@@YAOO_K@Z <span style="color:gray">
                </span><span style="color:navy">add     esp, </span><span style="color:green">10h
                </span><span style="color:navy">fstp    [ebp+</span><span style="color:green">arg_0</span><span style="color:navy">]
                mov     eax, dword ptr [ebp+</span><span style="color:green">arg_8</span><span style="color:navy">]
                mov     ecx, dword ptr [ebp+</span><span style="color:green">arg_8</span><span style="color:navy">+</span><span style="color:green">4</span><span style="color:navy">]
                mov     dword ptr [ebp+</span><span style="color:green">var_8</span><span style="color:navy">], eax
                mov     dword ptr [ebp+</span><span style="color:green">var_8</span><span style="color:navy">+</span><span style="color:green">4</span><span style="color:navy">], ecx
                mov     edx, dword ptr [ebp+</span><span style="color:green">var_8</span><span style="color:navy">+</span><span style="color:green">4</span><span style="color:navy">]
                mov     dword ptr [ebp+</span><span style="color:green">var_10</span><span style="color:navy">+</span><span style="color:green">4</span><span style="color:navy">], edx
                and     dword ptr [ebp+</span><span style="color:green">var_8</span><span style="color:navy">+</span><span style="color:green">4</span><span style="color:navy">], </span><span style="color:green">7FFFFFFFh
                </span><span style="color:navy">fild    [ebp+</span><span style="color:green">var_8</span><span style="color:navy">]
                and     dword ptr [ebp+</span><span style="color:green">var_10</span><span style="color:navy">+</span><span style="color:green">4</span><span style="color:navy">], </span><span style="color:green">80000000h
                </span><span style="color:navy">mov     dword ptr [ebp+</span><span style="color:green">var_10</span><span style="color:navy">], </span><span style="color:green">0
                </span><span style="color:navy">fild    [ebp+</span><span style="color:green">var_10</span><span style="color:navy">]
                fchs
                faddp   st(1), st
                fcomp   [ebp+</span><span style="color:green">arg_0</span><span style="color:navy">]
                fnstsw  ax
                test    ah, </span><span style="color:green">41h
                </span><span style="color:navy">jnz     short loc_F0A
                mov     eax, dword ptr [ebp+</span><span style="color:green">arg_8</span><span style="color:navy">+</span><span style="color:green">4</span><span style="color:navy">]
                push    eax             </span>; int
                <span style="color:navy">mov     ecx, dword ptr [ebp+</span><span style="color:green">arg_8</span><span style="color:navy">]
                push    ecx             </span>; int
                <span style="color:navy">sub     esp, </span><span style="color:green">8
                </span><span style="color:navy">fld     [ebp+</span><span style="color:green">arg_0</span><span style="color:navy">]
                fstp    [esp+</span><span style="color:green">38h</span><span style="color:navy">+</span><span style="color:green">var_38</span><span style="color:navy">]
                call    </span>?ld_ull_div@@YAOO_K@Z <span style="color:gray">
                </span><span style="color:navy">add     esp, </span><span style="color:green">10h
                </span><span style="color:navy">fstp    [ebp+</span><span style="color:green">arg_0</span><span style="color:navy">]
                jmp     short loc_F2D
</span><span style="color:gray">; ---------------------------------------------------------------------------

</span><span style="color:navy">loc_F0A:                                </span>; int
                <span style="color:navy">push    </span><span style="color:green">0
                </span><span style="color:navy">push    </span><span style="color:#ff8000">4D2h            </span>; int
                <span style="color:navy">mov     edx, dword ptr [ebp+</span><span style="color:green">arg_8</span><span style="color:navy">+</span><span style="color:green">4</span><span style="color:navy">]
                push    edx             </span>; int
                <span style="color:navy">mov     eax, dword ptr [ebp+</span><span style="color:green">arg_8</span><span style="color:navy">]
                push    eax             </span>; int
                <span style="color:navy">sub     esp, </span><span style="color:green">8
                </span><span style="color:navy">fld     [ebp+</span><span style="color:green">arg_0</span><span style="color:navy">]
                fstp    [esp+</span><span style="color:green">40h</span><span style="color:navy">+</span><span style="color:green">var_40</span><span style="color:navy">]
                call    </span>?ld_ull_calc@@YAOO_K0@Z <span style="color:gray">
                </span><span style="color:navy">add     esp, </span><span style="color:green">18h
                </span><span style="color:navy">fstp    [ebp+</span><span style="color:green">arg_0</span><span style="color:navy">]

loc_F2D:
                mov     ecx, dword ptr [ebp+</span><span style="color:green">arg_8</span><span style="color:navy">+</span><span style="color:green">4</span><span style="color:navy">]
                push    ecx             </span>; int
                <span style="color:navy">mov     edx, dword ptr [ebp+</span><span style="color:green">arg_8</span><span style="color:navy">]
                push    edx             </span>; int
                <span style="color:navy">sub     esp, </span><span style="color:green">8
                </span><span style="color:navy">fld     [ebp+</span><span style="color:green">arg_0</span><span style="color:navy">]
                fstp    [esp+</span><span style="color:green">38h</span><span style="color:navy">+</span><span style="color:green">var_38</span><span style="color:navy">]
                call    </span>?ld_ull_cmpeq@@YA_NO_K@Z <span style="color:gray">
                </span><span style="color:navy">add     esp, </span><span style="color:green">10h
                </span><span style="color:navy">movzx   eax, al
                test    eax, eax
                jz      short loc_F83
                mov     ecx, dword ptr [ebp+</span><span style="color:green">arg_8</span><span style="color:navy">]
                mov     edx, dword ptr [ebp+</span><span style="color:green">arg_8</span><span style="color:navy">+</span><span style="color:green">4</span><span style="color:navy">]
                mov     dword ptr [ebp+</span><span style="color:green">var_18</span><span style="color:navy">], ecx
                mov     dword ptr [ebp+</span><span style="color:green">var_18</span><span style="color:navy">+</span><span style="color:green">4</span><span style="color:navy">], edx
                mov     eax, dword ptr [ebp+</span><span style="color:green">var_18</span><span style="color:navy">+</span><span style="color:green">4</span><span style="color:navy">]
                mov     dword ptr [ebp+</span><span style="color:green">var_20</span><span style="color:navy">+</span><span style="color:green">4</span><span style="color:navy">], eax
                and     dword ptr [ebp+</span><span style="color:green">var_18</span><span style="color:navy">+</span><span style="color:green">4</span><span style="color:navy">], </span><span style="color:green">7FFFFFFFh
                </span><span style="color:navy">fild    [ebp+</span><span style="color:green">var_18</span><span style="color:navy">]
                and     dword ptr [ebp+</span><span style="color:green">var_20</span><span style="color:navy">+</span><span style="color:green">4</span><span style="color:navy">], </span><span style="color:green">80000000h
                </span><span style="color:navy">mov     dword ptr [ebp+</span><span style="color:green">var_20</span><span style="color:navy">], </span><span style="color:green">0
                </span><span style="color:navy">fild    [ebp+</span><span style="color:green">var_20</span><span style="color:navy">]
                fchs
                faddp   st(1), st
                fstp    [ebp+</span><span style="color:green">var_28</span><span style="color:navy">]
                jmp     short loc_F89
</span><span style="color:gray">; ---------------------------------------------------------------------------

</span><span style="color:navy">loc_F83:
                fld     [ebp+</span><span style="color:green">arg_0</span><span style="color:navy">]
                fstp    [ebp+</span><span style="color:green">var_28</span><span style="color:navy">]

loc_F89:
                fld     [ebp+</span><span style="color:green">var_28</span><span style="color:navy">]
                <span style="color:navy">mov     esp, ebp                                             </span></span>
                <span style="color:navy">pop     ebp                                                  </span>
                <span style="color:navy">retn
</span>?ld_ull_test@@YAOO_K@Z endp
</div>
<p>
The above code is translated into:
<p>
<div style="background:#DDFFDD;border:1px solid;white-space:pre; font-family: andale, courier, monospace"><span style="color:gray">double __cdecl ld_ull_test(double a1, __int64 a2)
</span><span style="color:navy">{
  </span><span style="color:gray">double v2</span><span style="color:navy">; </span><span style="color:gray">// </span><span style="color:#8080ff">st7@1
  </span><span style="color:gray">double v4</span><span style="color:navy">; </span><span style="color:gray">// </span><span style="color:#8080ff">[sp+18h] [bp-28h]@5
  </span><span style="color:gray">double v5</span><span style="color:navy">; </span><span style="color:gray">// </span><span style="color:#8080ff">[sp+48h] [bp+8h]@1
  </span><span style="color:gray">double v6</span><span style="color:navy">; </span><span style="color:gray">// </span><span style="color:#8080ff">[sp+48h] [bp+8h]@1
  </span><span style="color:gray">double v7</span><span style="color:navy">; </span><span style="color:gray">// </span><span style="color:#8080ff">[sp+48h] [bp+8h]@2
  </span><span style="color:gray">unsigned __int64 v8</span><span style="color:navy">; </span><span style="color:gray">// </span><span style="color:#8080ff">[sp+50h] [bp+10h]@1

  v6 </span><span style="color:navy">= </span>ld_ull_add<span style="color:navy">(</span><span style="color:#8080ff">a1</span><span style="color:navy">, </span><span style="color:#8080ff">a2</span><span style="color:navy">);
  </span><span style="color:#8080ff">v8 </span><span style="color:navy">= </span>ld_ull_cvt<span style="color:navy">(</span><span style="color:#8080ff">v6</span><span style="color:navy">);
  </span><span style="color:#8080ff">v2 </span><span style="color:navy">= </span>ld_ull_sub<span style="color:navy">(</span><span style="color:#8080ff">v6</span><span style="color:navy">, </span><span style="color:#8080ff">v8</span><span style="color:navy">);
  </span><span style="color:#8080ff">v5 </span><span style="color:navy">= </span>ld_ull_mul<span style="color:navy">(</span><span style="color:#8080ff">v2</span><span style="color:navy">, </span><span style="color:#8080ff">v8</span><span style="color:navy">);
  if ( (</span><span style="color:gray">double</span><span style="color:navy">)</span><span style="color:#8080ff">v8 &lt;</span><span style="color:navy">= </span><span style="color:#8080ff">v5 </span><span style="color:navy">)
    </span><span style="color:#8080ff">v7 </span><span style="color:navy">= </span>ld_ull_calc<span style="color:navy">(</span><span style="color:#8080ff">v5</span><span style="color:navy">, </span><span style="color:#8080ff">v8</span><span style="color:navy">, 1234i64);
  else
    </span><span style="color:#8080ff">v7 </span><span style="color:navy">= </span>ld_ull_div<span style="color:navy">(</span><span style="color:#8080ff">v5</span><span style="color:navy">, </span><span style="color:#8080ff">v8</span><span style="color:navy">);
  if ( </span>ld_ull_cmpeq<span style="color:navy">(</span><span style="color:#8080ff">v7</span><span style="color:navy">, </span><span style="color:#8080ff">v8</span><span style="color:navy">) )
    </span><span style="color:#8080ff">v4 </span><span style="color:navy">= (</span><span style="color:gray">double</span><span style="color:navy">)</span><span style="color:#8080ff">v8</span><span style="color:navy">;
  else
    </span><span style="color:#8080ff">v4 </span><span style="color:navy">= </span><span style="color:#8080ff">v7</span><span style="color:navy">;
  return </span><span style="color:#8080ff">v4</span><span style="color:navy">;
</span><span style="background:#8080ff"></span><span style="color:navy">}
</div>
<p>
I strongly prefer the second listing to the first. In fact, the more I use
the decompiler, the less I want to return to the assembly level (this means that
you may expect source level debugging and other similar improvements in the future ;)
<p>
In order to handle floating point, we also had to improve many other aspects
of the decompiler. Here are the things I remember offhand:
<ul>
<li>We changed the stack variable allocation mechanism to use data flow information.
In practice this means that reused stack frame slots are recognized and multiple
variables are created for them. No more funny casts because of a stack slot reuse!
<li>The stack variables are considered as first class citizens by the propagation and
other algorithms. Previous versions of the decompiler were optimizing registers
but stack variables were not optimized much. In practice: shorter and cleaner output.
This improvement, combined with the previous one, allows us to handle reused
function stack arguments very smoothly. It goes without saying that aliased
stack variables are still not optimized (unfortunately, it can not be done
automatically)
<li>Made the optimization rules more robust and more efficient
<li>Added more rules to remove unnecessary casts
<li>Add a new algorithm to recognize call arguments
<li>Better user interface (as usual, improving ui is always a good idea ;)
</ul>

This list could go on with more details but let's stop here.
Since there are some substantial changes, we will make a beta testing for the next
release. It is not that far away now - probably even this month!
]]>
    </content>
</entry>
<entry>
    <title>IDA v5.4 demo</title>
    <link rel="alternate" type="text/html" href="http://hexblog.com/2009/04/ida_v54_demo.html" />
    <id>tag:hexblog.com,2009://1.92</id>
    <published>2009-04-17T16:01:55Z</published>
    <updated>2009-04-17T16:05:52Z</updated>
    
    <summary>Just a quick note for interested parties: we prepared the new demo version of IDA Pro. The new demo includes the bochs debugger. The debugger is fully functional with just one limitation: it will become inactive after a number of...</summary>
    <author>
        <name>Ilfak Guilfanov</name>
        
    </author>
            <category term="IDA Pro" />
    
    <content type="html" xml:lang="en" xml:base="http://hexblog.com/">
        <![CDATA[<p>Just a quick note for interested parties: we prepared the new demo version of IDA Pro. The new demo includes the bochs debugger. The debugger is fully functional with just one limitation: it will become inactive after a number of commands. I prefer to tell you this in advance rather than this limitation to be discovered in the middle of a heavy debugging session ;)</p>

<p>Here's the download link:</p>

<p><a href="http://www.hex-rays.com/idapro/idadowndemo.htm">http://www.hex-rays.com/idapro/idadowndemo.htm</a></p>

<p>Enjoy!</p>]]>
        
    </content>
</entry>
<entry>
    <title>Advanced Windows Kernel Debugging with VMWare and IDA&apos;s GDB debugger</title>
    <link rel="alternate" type="text/html" href="http://hexblog.com/2009/02/advanced_windows_kernel_debugg.html" />
    <id>tag:hexblog.com,2009://1.91</id>
    <published>2009-02-19T13:21:04Z</published>
    <updated>2009-02-19T21:15:14Z</updated>
    
    <summary>We have already published short tutorial on Windows kernel debugging with IDA and VMWare on our site, but the debugging experience can still be improved. VMWare&apos;s GDB stub is very basic, it doesn&apos;t know anything about processes or threads (for...</summary>
    <author>
        <name>Igor Skochinsky</name>
        <uri>ilfak</uri>
    </author>
            <category term="IDA Pro" />
    
    <content type="html" xml:lang="en" xml:base="http://hexblog.com/">
        <![CDATA[<P>We have already published <a href="http://www.hex-rays.com/idapro/debugger/gdb_vmware_winkernel.pdf">short tutorial</a> on Windows kernel debugging
with IDA and VMWare on our site, but the debugging experience can
still be improved.</P>
<P>VMWare's GDB stub is very basic, it doesn't know anything about processes or
threads (for Windows guests), so for anything high-level we'll need
to do some extra work. We will show how to get the loaded module list
and load symbols for all them using IDAPython.</P>
]]>
        <![CDATA[<H4>Preparing VM for debugging</H4>
<P>Let's assume that you already have a VM with
Windows (32-bit) installed. Before starting the debugging, copy files
for which you want to see symbols to the host. If you're not sure,
copy nt*.exe and hal.dll from System32, and the whole
System32\drivers directory.</P>
<P>Edit the VM's .vmx file to enable GDB debugger
stub:</P>
<IMG SRC="http://www.hexblog.com/ida_pro/pix/gdb-vmware-winkernel2_htm_91f1c9c.png" NAME="graphics28" ALIGN=LEFT WIDTH=494 HEIGHT=398 BORDER=0>
<BR CLEAR=LEFT><P>
Add these lines to the file:</P>
<PRE>debugStub.listen.guest32 = &quot;TRUE&quot;
debugStub.hideBreakpoints= &quot;TRUE&quot;</PRE>
<P>Save the file.</P>
<P></P>
<P>In VMWare, click &quot;Power on this virtual machine&quot; or click the
green Play button on the toolbar.</P>
<P><IMG SRC="http://www.hexblog.com/ida_pro/pix/gdb-vmware-winkernel2_htm_100c5d47.png" NAME="graphics7" ALIGN=LEFT WIDTH=576 HEIGHT=418 BORDER=0><BR CLEAR=LEFT><BR>
</P>
<P>Wait until the VM boots.</P>
<H4>Debugging in IDA</H4>
<P>Start IDA.</P>
<P><IMG SRC="http://www.hexblog.com/ida_pro/pix/gdb-vmware-winkernel2_htm_m20f96fb6.gif" NAME="graphics8" ALIGN=BOTTOM WIDTH=323 HEIGHT=273 BORDER=0></P>
<P>If you get the welcome dialog, choose &quot;Go&quot;.</P>
<P><IMG SRC="http://www.hexblog.com/ida_pro/pix/gdb-vmware-winkernel2_htm_519c4c2f.gif" NAME="graphics32" ALIGN=BOTTOM WIDTH=801 HEIGHT=505 BORDER=0></P>
<P>Choose Debugger | Attach | Remote GDB debugger.</P>
<P></P>
<P><IMG SRC="http://www.hexblog.com/ida_pro/pix/gdb-vmware-winkernel2_htm_6b9e4a85.gif" NAME="graphics33" ALIGN=BOTTOM WIDTH=378 HEIGHT=201 BORDER=0></P>
<P>Enter &quot;localhost&quot; for hostname and 8832 for the port number.</P>
<P><IMG SRC="http://www.hexblog.com/ida_pro/pix/gdb-vmware-winkernel2_htm_m104fe357.gif" NAME="graphics34" ALIGN=BOTTOM WIDTH=400 HEIGHT=174 BORDER=0></P>
<P>Choose &lt;attach to the process started on target&gt; and click OK.</P>

<P><IMG SRC="http://www.hexblog.com/ida_pro/pix/gdb-vmware-winkernel2_htm_m15202098.png" NAME="graphics9" ALIGN=BOTTOM WIDTH=545 HEIGHT=475 BORDER=0></P>
<P>The execution should stop somewhere in the kernel (address above
0x80000000). You can step through the code, but it's not very
convenient without any names. Let's try to gather some more
information.</P>
<H4>Getting the module list</H4>
<P>The list of kernel modules is
stored in the list pointed to by the <CODE>PsLoadedModuleList</CODE>
symbol in the kernel. To find its address, we will use the so-called
&quot;KPCR trick&quot;. KPCR stands for Kernel Processor Control
Region. It is used by the kernel to store various information about
each processor. It is placed at the base of the segment pointed to by
the <CODE>fs</CODE>
register (similar to TEB in user mode). One of the fields in it is
<CODE>KdVersionBlock</CODE>
which points to a structure used by  the kernel debugger. It, in
turn, has various pointers to kernel structures, including
<CODE>PsLoadedModuleList</CODE>.</P>
<P>Definition of the KPCR
structure can be found in many places, including IDA's ntddk.til. 
Right now we just need to know that <CODE>KdVersionBlock</CODE>
field is situated at offset 0x34 from the start of KPCR. It points to
<CODE>DBGKD_GET_VERSION64</CODE>,
which has <CODE>PsLoadedModuleList</CODE>
pointer at offset 0x18.</P>
<P>Let's write a small Python function
to find the value of that pointer.
To retrieve the base of the segment pointed to by
fs, we can use the VMWare's debug monitor &quot;r&quot; command. GDB
debugger plugin registers an IDC function <CODE>SendGDBMonitor()</CODE>
to send commands to the monitor, and we can use IDAPython's <CODE>Eval()</CODE>
function to call it:</P>
<PRE>fs_str = Eval('SendGDBMonitor(&quot;r fs&quot;)')</PRE>
<P>Returned string has the following
format:</P>
<PRE>fs 0x30 base 0x82744a00 limit 0x00002008 type 0x3 s 1 dpl 0 p 1 db 1</PRE>
<P>We need the address specified after
&quot;base&quot;:</P>
<PRE>kpcr = int(fs_str[13:23], 16) #extract and convert as base 16 (hexadecimal) number</PRE>
<P>Then get the value of <CODE>KdVersionBlock</CODE>:</P>
<PRE>kdversionblock = Dword(kpcr+0x34)</PRE>
<P>And finally <CODE>PsLoadedModuleList</CODE>:</P>
<P><CODE>PsLoadedModuleList = Dword(kdversionblock+0x18)</CODE></P>

<H4>Walking the module list</H4>

<P><CODE>PsLoadedModuleList</CODE>
is declared as <CODE>PLIST_ENTRY</CODE>. <CODE>LIST_ENTRY</CODE> is a
structure which represents a member of a double-linked list:</P>
<PRE>typedef struct _LIST_ENTRY
{
     PLIST_ENTRY Flink;
     PLIST_ENTRY Blink;
} LIST_ENTRY, *PLIST_ENTRY;</PRE>
<P>So, we just need to follow the <CODE>Flink</CODE> pointer until we come
back to where we started. A single entry of the list has the
following structure:</P>
<PRE>struct LDR_MODULE
{
  LIST_ENTRY InLoadOrderModuleList;
  LIST_ENTRY InMemoryOrderModuleList;
  LIST_ENTRY InInitializationOrderModuleList;
  PVOID BaseAddress;
  PVOID EntryPoint;
  ULONG SizeOfImage;
  UNICODE_STRING FullDllName;
  UNICODE_STRING BaseDllName;
  ULONG Flags;
  SHORT LoadCount;
  SHORT TlsIndex;
  LIST_ENTRY HashTableEntry;
  ULONG TimeDateStamp;
};</PRE>
<P>Now we can write a small function to walk this list and create a segment
for each module:</P>

<PRE>
#get the first module
cur_mod = Dword(PsLoadedModuleList)
while cur_mod != PsLoadedModuleList and cur_mod != BADADDR:
  BaseAddress  = Dword(cur_mod+0x18)
  SizeOfImage  = Dword(cur_mod+0x20)
  FullDllName  = get_unistr(cur_mod+0x24)
  BaseDllName  = get_unistr(cur_mod+0x2C)
  #create a segment for the module
  SegCreate(BaseAddress, BaseAddress+SizeOfImage, 0, 1, saRelByte, scPriv)
  #set its name
  SegRename(BaseAddress, BaseDllName)
  #get next entry
  cur_mod = Dword(cur_mod)</PRE>
<H4>Loading symbols</H4>
<P>Having the module list is nice, but not very useful without symbols. We can
load the symbols manually for each module using File | Load File |
PDB file... command, but it would be better to automate it.</P>
<P>For that we can use the PDB plugin. From looking at its sources
(available in the SDK), we can see that it supports three &quot;call
codes&quot;:</P>
<PRE>//call_code==0: user invoked 'load pdb' command, load pdb for the input file
//call_code==1: ida decided to call the plugin itself
//call_code==2: load pdb for an additional exe/dll
//              load_addr: netnode(&quot;$ pdb&quot;).altval(0)
//              dll_name:  netnode(&quot;$ pdb&quot;).supstr(0)</PRE>

<P>Call code 2 looks just like what we need. However, current IDAPython
includes a rather basic implementation of netnode class and it is not
possible to set supvals from Python. However, if we look at handling
of the other call codes, we can see that the plugin retrieves module
base from <CODE>&quot;$ PE header&quot;</CODE> netnode and module
path using <CODE>get_input_file_path()</CODE> function. IDAPython's
<CODE>netnode.altset()</CODE> function does work, and we can use
set_root_filename() to set the input file path. Also, if we pass a
call code 3, we will avoid the &quot;Do you want to load the
symbols?&quot; prompt.</P>

<PRE>#new netnode instance
penode = idaapi.netnode()
#create netnode the in database if necessary
penode.create(&quot;$PE header&quot;)
#set the imagebase (-2 == 0xFFFFFFFE)
penode.altset(0xFFFFFFFE, BaseAddress)
#set the module filename
idaapi.set_root_filename(filename)
#run the plugin
RunPlugin(&quot;pdb&quot;,3)</PRE>
<P>However, we need to replace the kernel-mode path by the local path beforehand:</P>
<PRE>#path to the local copy of System32 directory
local_sys32 = r&quot;D:\VmWareShared\w7\System32&quot;
if FullDllName.lower().startswith(r&quot;\systemroot\system32&quot;):
#translate into local filename
filename = local_sys32 + FullDllName[20:]</PRE>

<P>Now we can gather all pieces into a single script. Download it <a href="http://hexblog.com/idapro/vmware_modules.py">here</a></P>
<P>After running it, you should have a nice memory map:</P>
<P>
<IMG SRC="http://www.hexblog.com/ida_pro/pix/gdb-vmware-winkernel2_htm_m17b305f6.gif" NAME="graphics1" ALIGN=LEFT WIDTH=713 HEIGHT=393 BORDER=0><BR CLEAR=LEFT><BR>
</P>
<P>
...and name list:</P>
<P>
<IMG SRC="http://www.hexblog.com/ida_pro/pix/gdb-vmware-winkernel2_htm_65b4d822.gif" NAME="graphics2" ALIGN=LEFT WIDTH=400 HEIGHT=352 BORDER=0><BR CLEAR=LEFT><BR>
</P>
<P>Looks much better now. Happy debugging!</P>]]>
    </content>
</entry>
<entry>
    <title>IDA Pro has 9 debugger modules</title>
    <link rel="alternate" type="text/html" href="http://hexblog.com/2009/02/ida_pro_has_9_debugger_modules.html" />
    <id>tag:hexblog.com,2009://1.90</id>
    <published>2009-02-05T18:43:41Z</published>
    <updated>2009-02-05T18:55:19Z</updated>
    
    <summary> Since the number of debugger modules in IDA surpassed the magical number seven plus or minus two, we created a small table describing what is available and what is not: http://www.hex-rays.com/idapro/debugger/index.htm Direct links to tutorials are available here: http://www.hex-rays.com/idapro/idasupport.htm...</summary>
    <author>
        <name>Ilfak Guilfanov</name>
        
    </author>
            <category term="IDA Pro" />
    
    <content type="html" xml:lang="en" xml:base="http://hexblog.com/">
        <![CDATA[<p><a href="http://www.hex-rays.com/idapro/54/index.htm"><img src="http://www.hex-rays.com/idapro/debugger/debuggers_logo_small.gif" align=left border=0 /></a> Since the number of debugger modules in IDA surpassed <a href="http://en.wikipedia.org/wiki/The_Magical_Number_Seven,_Plus_or_Minus_Two">the magical number seven plus or minus two</a>, we created a small table describing what is available and what is not:</p>

<p><a href="http://www.hex-rays.com/idapro/debugger/index.htm">http://www.hex-rays.com/idapro/debugger/index.htm</a></p>

<p>Direct links to tutorials are available here:</p>

<p><a href="http://www.hex-rays.com/idapro/idasupport.htm">http://www.hex-rays.com/idapro/idasupport.htm</a></p>

<p>I know, I know - we need to add 64-bit support for all platforms, port the Bochs debugger module to Linux, and... any other suggestions? I personally would love to have source level debugging, yet it requires some substantial changes to the kernel. We probably will move in this direction, sooner or later...</p>]]>
        
    </content>
</entry>
<entry>
    <title>Kernel debugging with IDA</title>
    <link rel="alternate" type="text/html" href="http://hexblog.com/2009/01/kernel_debugging_with_ida.html" />
    <id>tag:hexblog.com,2009://1.89</id>
    <published>2009-01-30T13:02:18Z</published>
    <updated>2009-01-30T14:55:31Z</updated>
    
    <summary>When IDA introduced debugging facilities years ago, the task of analyzing hostile code became more enriched: no more looking at static code and figuring out what it does, instead just run the malware in a virtual machine and debug it...</summary>
    <author>
        <name>Elias Bachaalany</name>
        
    </author>
            <category term="IDA Pro" />
    
    <content type="html" xml:lang="en" xml:base="http://hexblog.com/">
        <![CDATA[<p>When IDA introduced debugging facilities years ago, the task of analyzing hostile code became more enriched: no more looking at static code and figuring out what it does, instead just run the malware in a virtual machine and debug it remotely, even debug just a small code snippet from the database (Bochs based debugger plugin).</p>]]>
        <![CDATA[<p>With IDA 5.4 release, in addition to the Bochs and GDB plugins, we also introduced a debugger plugin based on <a href="http://www.microsoft.com/whdc/DevTools/Debugging/default.mspx">Microsoft's Debugger Engine</a> (the same engine used by Windbg, cdb and kd). With this addition to IDA you can now debug live kernel targets as well.</p>

<p>For user mode debugging the Windbg debugger plugin beats the win32 debugger plugin, by providing you access to a wide range of extensions that ship with the debugging tools from Microsoft.<br />
For kernel debugging, you can use Bochs/Disk Image loader or GDB plugin to debug the whole operating system from Bios code and on.<br />
However when Windbg plugin is used, you get the raw power of the debugging engine (extensions / built-in commands, symbols, ...).</p>

<p>We prepared a video showing how to debug kernel mode and user mode at the same time with full symbolic information (provided from the PDB files).<br />
The video also demonstrates how to set breakpoints on user mode APIs and see them get triggered when any application in the system uses those APIs.</p>

<p>Before viewing the video, for those willing to experiment with the Windbg debugger plugin to debug kernel mode and user mode at the same time, here is how to prepare a database:</p>

<ol>
<li>If you never used the Windbg debugger plugin before please visit the <a href="http://www.hex-rays.com/idapro/debugger/windbg_tut.pdf">Windbg plugin tutorial</a> page
<li>Setup a process server inside the VM and attach to it from IDA to debug just any user mode application
<li>Once attached, go to desired segments (kernel32, user32, advapi32, gdi32, etc...) and convert them to loader segments
<li>If symbol retrieval mechanism was properly configured then most system DLLs will have symbol information, otherwise only exported names will available
<li>Now we have a database with all user mode components we wish to inspect from the live kernel debugging session
<li>Using the same database, change the connection string so that it connects to the same VM for the purpose of live kernel debugging this time
<li>Once attached to the kernel, IDA will present loaded drivers and kernel mode modules in the debugger / modules list
<li>It is possible to convert to loader segments the kernel mode components of interest
<li>That's it! The database is now suited for kernel debugging, yet contains names and addresses of user mode components
</ol>

<p>The <a href="http://hex-rays.com/video/windbg_video_1.htm">video</a> will put everything into perspective!</p>]]>
    </content>
</entry>
<entry>
    <title>IDA v5.4 release is not that far away</title>
    <link rel="alternate" type="text/html" href="http://hexblog.com/2009/01/ida_v54_release_is_not_that_fa.html" />
    <id>tag:hexblog.com,2009://1.88</id>
    <published>2009-01-20T00:29:01Z</published>
    <updated>2009-01-20T03:01:51Z</updated>
    
    <summary>I&apos;m happy to inform you that we are entering the beta stage of IDA v5.4! In addition to numerous small and not that small improvements, the new version will have three debugger modules: bochs, gdb, and windbg, selectable on the...</summary>
    <author>
        <name>Ilfak Guilfanov</name>
        
    </author>
            <category term="IDA Pro" />
    
    <content type="html" xml:lang="en" xml:base="http://hexblog.com/">
        <![CDATA[<p>I'm happy to inform you that we are entering the beta stage of IDA v5.4!</p>

<p>In addition to numerous small and not that small improvements, the new version will have three debugger modules: <strong>bochs, gdb, and windbg</strong>, selectable on the fly (the active debugger session will be closed, though ;))<br />
<ul><br />
<li> With the bochs debugger, we offer three different worlds:<strong> run-any-code-snippet</strong> facility, <strong>windows-like-environment</strong> for PE files, and <strong>any-bochs-image</strong> bare-bone machine emulation mode. You can read more about this module in our blog: <a href="http://hexblog.com/2008/11/bochs_plugin_goes_alpha.html">http://hexblog.com/2008/11/bochs_plugin_goes_alpha.html</a><br />
<li> With gdb, <strong>x86 </strong>and <strong>arm </strong>targets are supported. Among other things, it is possible to connect IDA to <strong>QEMU </strong>or debug a virtual machine inside <strong>VMWare</strong>. We tried it <strong>iPhone </strong>as well. However, while it works in some curcimstances, there were some problems on the gdbserver side.<br />
<li> With windbg, <strong>user </strong>and <strong>kernel </strong>mode debugging is available. The debugger engine from Microsoft, which is currently the only choice for driver and kernel mode debugging, can be used from IDA. It can automatically load required <strong>PDB </strong>files and populate the listing with meaningful names, types, etc. Speaking of PDB files, IDA imports more information from them: local function variables and types are retrieved too, c++ base classes are handled, etc.<br />
</ul></p>

<p>The gdb and windbg debugger modules support local and remote debugging. We tried to make the debugger modules as open as possible: target-specific commands can be sent to all backend engines in a very easy and user-friendly way.</p>

<p>As usual, better analysis and many minor changes have been made. If you spend plenty of time analyzing gcc generated binaries, you'll certainly appreciate that IDA handles its weird way of preparing outgoing function arguments. Now it can trace and find arguments copies to the stack with <strong>mov </strong>statements.</p>

<p>The new IDA will support <strong>Python </strong>out of box, thanks to Gergely Erdelyi, who kindly agreed the <a href="http://www.d-dome.net/idapython/">Python plugin</a> to be included in the official distribution. In fact, the main IDA window will have a command line to enter any python (or other language) expressions and immediately get a result in the message window.</p>

<p>We will prepare the detailed list of improvements later this week.</p>]]>
        
    </content>
</entry>
<entry>
    <title>IDA and MIPS</title>
    <link rel="alternate" type="text/html" href="http://hexblog.com/2008/11/ida_and_mips.html" />
    <id>tag:hexblog.com,2008://1.87</id>
    <published>2008-11-21T12:54:43Z</published>
    <updated>2008-11-21T13:27:47Z</updated>
    
    <summary>If you analyze MIPS binaries, you may find useful the following addition to IDA: http://www.binary-art.net/?p=1002 This is MIPS emulator for Linux. It can generate an IDC script after emulation, which then can be applied to the database and make it...</summary>
    <author>
        <name>Ilfak Guilfanov</name>
        
    </author>
            <category term="IDA Pro" />
    
    <content type="html" xml:lang="en" xml:base="http://hexblog.com/">
        <![CDATA[<p>If you analyze MIPS binaries, you may find useful the following addition to IDA:</p>

<p><a href="http://www.binary-art.net/?p=1002">http://www.binary-art.net/?p=1002</a></p>

<p>This is MIPS emulator for Linux. It can generate an IDC script after emulation, which then can be applied to the database and make it more readable.</p>

<p> </p>]]>
        
    </content>
</entry>
<entry>
    <title>Bochs plugin goes alpha</title>
    <link rel="alternate" type="text/html" href="http://hexblog.com/2008/11/bochs_plugin_goes_alpha.html" />
    <id>tag:hexblog.com,2008://1.86</id>
    <published>2008-11-07T11:51:41Z</published>
    <updated>2008-11-07T14:46:30Z</updated>
    
    <summary> Bochs debugger plugin is in alpha stage now, all of the 3 loaders mentioned in the previous blog entry, are now complete....</summary>
    <author>
        <name>Elias Bachaalany</name>
        
    </author>
            <category term="IDA Pro" />
    
    <content type="html" xml:lang="en" xml:base="http://hexblog.com/">
        <![CDATA[<p><a href="http://bochs.sourceforge.net/"><img valign="top" border="0" src="http://www.hexblog.com/ida_pro/pix/bochs.jpg" alt="Bochs emulator" align="left" style="padding-right:5px"/></a><br />
Bochs debugger plugin is in alpha stage now, all of the 3 loaders mentioned in the <a href="http://hexblog.com/2008/10/bochs_emulator_and_ida.html#more">previous blog entry</a>, are now complete.</p>]]>
        <![CDATA[<p> Since we demonstrated briefly the IDB loader last time, we will demonstrate the PE loader this time, which will allow you to debug PE executables.<br />
For this we continue using the same malware however using the PE loader instead.</p>

<p>Throughout the video you will see numerous tricks used by this malware and you will see how the debugger works smoothly with them. </p>

<p>Here are some of the features supported by it:</p>

<p><li> SEH support: we try to mimic Windows as much as possible, for example the ICEBP instruction is a privileged instruction, but Windows report back a single step exception. Similarly Windows does not distinguish between 0xCC and 0xCD 0x03, so when an exception occurs, it reports that the exception address is always one byte before the trap. So if it was an INT 0x3 (CD03) then exception address will point to the 0x03 (in the middle of the instruction). We behave the same as Windows.</p>

<p><li> TLS callbacks: TLS callbacks are normally parsed by IDA and presented as entry points (ctrl+E), so you can put breakpoints there and run your program.</p>

<p><li> Extendible API emulation: you can provide implementation of a given API using scripting facilities, for example, in the video you see a call to GlobalAlloc, here is how it is actually implemented:</p>

<p>(from api_kernel32.idc)<br />
<blockquote><br />
///func=GlobalAlloc entry=k32_GlobalAlloc purge=8<br />
static k32_GlobalAlloc()<br />
{<br />
  eax = BochsVirtAlloc(0, BX_GETPARAM(2), 1);<br />
  return 0;<br />
}</p>

<p>///func=GlobalFree entry=k32_GlobalFree purge=4<br />
static k32_GlobalFree()<br />
{<br />
  eax = BochsVirtFree(BX_GETPARAM(1), 0);<br />
  return 0;<br />
}<br />
</blockquote><br />
A simple MessageBoxA replacement can be:</p>

<p>(from api_user32.idc)</p>

<blockquote>
///func=MessageBoxA entry=messagebox purge=0x10
static messagebox()
{
  auto param2;
  
  param2 = BX_GETPARAM(2);

<p>  Message("I am messagebox function; %s\n", GetString(param2, -1, ASCSTR_C));</p>

<p>  eax = 1;</p>

<p>  // continue execution<br />
  return 0;<br />
}<br />
</blockquote></p>

<p><li> Use your own code: You can also write your own DLL and map it into the process' space. You can then redirect existing APIs to your own functionality, for example:<br />
///func=GetProcAddress entry=bochsys.BxGetProcAddress purge=8<br />
///func=ExitProcess entry=bochsys.BxExitProcess purge=4<br />
///func=GetModuleFileNameA entry=bochsys.BxGetModuleFileNameA purge=12<br />
///func=GetModuleHandleA entry=bochsys.BxGetModuleHandleA purge=4</p>

<p>We redirect some functions to bochsys.dll which will do the job inside the process' space.</p>

<p><li> Less demanding PE loader: By that you can for example load any PE file, including system drivers or dlls. Given that you emulate the API calls, you can theoretically trace such targets too.</p>

<p><li> Dependency resolution: You don't have to emulate all APIs to use this plugin, by default if an API is not present, then a stub will be generated for it. For example, you can define a stub that will always return 0 for CreateFileA call, as:</p>

<p>///func=CreateFileA retval=0</p>

<p>Since CreateFileA is recognized by IDA's IDS files, no need to specify the "purge" value, otherwise a full definition would look like:</p>

<p>///func=FuncName purge=N_bytes retval=VALUE</p>

<p><li> NT structures emulation: Some malware don't use GetProcAddress or GetModuleHandle() for example, instead they try to parse the system structures and deduce these values.<br />
For this we also provide and build the basic structure of PEB and PEB_LDR_DATA, LDR_MODULE(s) and RTL_USER_PROCESS_PARAMETERS.</p>

<p>If you need to inspect PEB structure of Win32 programs, then remember to grab the <a href="http://www.hex-rays.com/idapro/freefiles/ldrmodules.idc">ldrmodule.idc</a> script from IDA's download area.</p>

<p>Here's the video: <br />
<center><br />
<a href="http://hex-rays.com/video/bochs_video_2.html"><img src="http://www.hexblog.com/ida_pro/pix/bochs_video2_thumb.jpg"/></a></center></p>]]>
    </content>
</entry>
<entry>
    <title>From simple to complex</title>
    <link rel="alternate" type="text/html" href="http://hexblog.com/2008/10/from_simple_to_complex.html" />
    <id>tag:hexblog.com,2008://1.85</id>
    <published>2008-10-10T17:22:30Z</published>
    <updated>2008-10-10T17:48:25Z</updated>
    
    <summary>The last week Elias ran a sample malware in the Bochs emulator and I was curious to see what it exactly does. So I took the unpacked version of the malware and fed it into the decompiler. It turned out...</summary>
    <author>
        <name>Ilfak Guilfanov</name>
        
    </author>
            <category term="Decompilation" />
    
    <content type="html" xml:lang="en" xml:base="http://hexblog.com/">
        <![CDATA[The last week Elias ran a sample malware in the <a href="http://hexblog.com/2008/10/bochs_emulator_and_ida.html">Bochs emulator</a> and I was curious to see what it exactly does. 

So I took the unpacked version of the malware and fed it into the decompiler. It turned out to be a pretty short downloadler (different AV vendors give it different names: <em>Lighty</em> 
after the compression method, or <em>FraudLoad</em>, or <em>FakeAlert</em>, etc). Such simple code is very easy to decompile. I renamed some functions and added some 
comments to it. The final text looks like this:
]]>
        <![CDATA[<p>
<pre style="border: 1px">
  download_winivstr();  <font color="#0000ff">// Download a program from the internet</font>
                        <font color="#0000ff">// It will be launched later</font>
                        <font color="#0000ff">// Create a thread to scare the user</font>
  icon_thread = CreateThread(<font color="#ff00ff">0</font>, <font color="#ff00ff">0</font>, icon_thread_entry, <font color="#ff00ff">0</font>, <font color="#ff00ff">0</font>, &amp;Data);
  Sleep(<font color="#ff00ff">1000u</font>);         <font color="#0000ff">// 1 second</font>
  <font color="#a52829"><b>while</b></font> ( <font color="#ff00ff">1</font> )
  {
    <font color="#a52829"><b>if</b></font> ( check_security_guards() == GUARD_EXISTS )
      SendMessageA(main_hwnd, WM_DESTROY, <font color="#ff00ff">0</font>, <font color="#ff00ff">0</font>);
    <font color="#a52829"><b>else</b></font>
      scare_user();    <font color="#0000ff">// Tell the user that his computer is infected</font>
    Sleep(<font color="#ff00ff">180000u</font>);    <font color="#0000ff">// 3 minutes</font>
  }
</pre>

The original listing is 118KB and the decompilation result is 23KB. the difference is <em>5 times</em>, which is a good ratio for such a simple program. The assember listing and the 

decompilation output can be downloaded here:
<p>
<a href="http://www.hexblog.com/decompilation/files/lighty_fraudload.zip">http://www.hex-rays.com/decompilation/files/lighty_fraudload.zip</a>
<p>
The next time I'll try to find something more complicated to show you more advanced features of the decompiler. Something really difficult to understand even for seasoned reverse engineers. 

For example, can you make sense out the following code? How much time does it take for you?
<p>
<span style="white-space: pre; font-family: ProggyTinySZ; color: blue; background: white">
                <span style="color:navy">push    ebp
                mov     ebp, esp
                sub     esp, </span><span style="color:green">8
                </span><span style="color:navy">mov     edx, [ebp+</span><span style="color:green">arg_C</span><span style="color:navy">]
                mov     eax, [ebp+</span><span style="color:green">arg_8</span><span style="color:navy">]
                push    edx
                push    eax
                fild    [esp+</span><span style="color:green">10h</span><span style="color:navy">+</span><span style="color:green">var_10</span><span style="color:navy">]
                add     esp, </span><span style="color:green">8
                </span><span style="color:navy">test    edx, edx
                js      short loc_2A23
                fstp    [ebp+</span><span style="color:green">var_8</span><span style="color:navy">]
                fld     [ebp+</span><span style="color:green">var_8</span><span style="color:navy">]
                fld     [ebp+</span><span style="color:green">arg_0</span><span style="color:navy">]
                leave
                fucompp
                fnstsw  ax
                sahf
                setnz   al
                setp    dl
                or      al, dl
                movzx   eax, al
                retn

</span><span style="color:navy">loc_2A23:                               </span>
                <span style="color:navy">fadd    ds:flt_AEEC
                fstp    [ebp+</span><span style="color:green">var_8</span><span style="color:navy">]
                fld     [ebp+</span><span style="color:green">var_8</span><span style="color:navy">]
                fld     [ebp+</span><span style="color:green">arg_0</span><span style="color:navy">]
                leave
                fucompp
                fnstsw  ax
                sahf
                setnz   al
                setp    dl
                or      al, dl
                movzx   eax, al
                retn
</span></span>
<p>
This mess was originally a one-line statement:
<span style="white-space: pre; font-family: ProggyTinySZ; color: gray; background: white">

bool <span style="color:navy">cmpeq_double_longlong</span>(double <span style="color:black">a</span>, unsigned __int64 <span style="color:navy">b</span>)
{
  return <span style="color:black">a == b</span>;
}
</span>
<p>
(you knew that it would be that simple, didn't you? ;)
<p>
As you see, we are playing with the floating point arithmetic now. Who knows, maybe the decompiler will handle it in the nearest future. Do not hold your breath yet: there is a long way 

ahead and many problems to solve. The above listing is from our sample test file. The test file has ~750 trivial functions and we compile it with 3 different compilers in optimized and  

non-optimized modes. So we 'just' need to make sure that all <em>750*3*2=4500</em> functions decompile correctly and we will have the first decompilation step over. Then we will need to 

make sure that all possible combinations of integer and floating point arithmetic decompile well, type conversions do not spoil the result, and the output is generated correctly. For integer 

arithmetic, a similar test file took more than one month, I bet that floating point will take longer... But we will eventually be there, with a good result (it must be portable too, since we do 
not plan to stay forever with x86). Stay tuned! :)
]]>
    </content>
</entry>
<entry>
    <title>Bochs Emulator and IDA?</title>
    <link rel="alternate" type="text/html" href="http://hexblog.com/2008/10/bochs_emulator_and_ida.html" />
    <id>tag:hexblog.com,2008://1.84</id>
    <published>2008-10-02T23:11:14Z</published>
    <updated>2008-10-02T23:50:49Z</updated>
    
    <summary> The next version of IDA will be released with a bochs debugger plugin, and what is nice about is that you will be able to use it easily by just downloading bochs executables and telling IDA where to find...</summary>
    <author>
        <name>Elias Bachaalany</name>
        
    </author>
            <category term="IDA Pro" />
    
    <content type="html" xml:lang="en" xml:base="http://hexblog.com/">
        <![CDATA[<p><a href="http://bochs.sourceforge.net/"><img valign="top" border="0" src="http://www.hexblog.com/ida_pro/pix/bochs.jpg" alt="Bochs emulator" align="left" style="padding-right:5px"/></a><br />
The next version of IDA will be released with a bochs debugger plugin, and what is nice about is that you will be able to use it easily by just downloading bochs executables and telling IDA where to find it.</p>]]>
        <![CDATA[<p>IDA's bochs debugger is a plugin that allow you to use bochs' emulation/debugger inside IDA's interface, but not just only that, but to make your debugging experience easier.</p>

<p>The plugin will come with three of the what we dubbed as "bochs loaders", so here is a brief explanation:</p>

<p>The first loader, disk image loader, is probably the most simple but yet the most powerful one. It allows you to debug any bochs image of your choice. For example, you could debug boot sector, 16 bit code, and perhaps debug 32 bit code all in the same debugging session. We actually use this bochs loader to debug other bochs loaders!</p>

<p>The second, idb loader, is a 32bit mode loader that allow you to debug anything within the database. The database will be your input file, thus whatever segments exist in the database, will be loaded and mapped into bochs' virtual memory. The idb loader understands and catches raw cpu exceptions and allows you to specify the startup stack segment's size.</p>

<p>Finally comes the pe loader, which is a specialized bochs loader, that will read your PE file and create a virtual environment similar to windows environment, trying to mimic basic demands for a PE file (import resolution, SEH, api emulation backed by IDC scripts).</p>

<p>This plugin is still under development, however we put a small video demonstrating the IDB loader.</p>

<p>Here's a small video: <br />
<center><br />
<a href="http://hex-rays.com/video/bochs_video_1.html"><img src="http://www.hexblog.com/ida_pro/pix/bochs_video_thumb.jpg"/></a></center></p>]]>
    </content>
</entry>
<entry>
    <title>BITS used as a covert channel</title>
    <link rel="alternate" type="text/html" href="http://hexblog.com/2008/09/bits_used_as_a_covert_channel.html" />
    <id>tag:hexblog.com,2008://1.83</id>
    <published>2008-09-25T22:12:18Z</published>
    <updated>2008-09-26T00:12:49Z</updated>
    
    <summary> The idea to use BITS to download files from the internet is not new. If you check the corresponding page from Wikipedia, you will find that Background Intelligent Transfer Service (BITS) is a component of modern Microsoft Windows operating...</summary>
    <author>
        <name>Ilfak Guilfanov</name>
        
    </author>
            <category term="Decompilation" />
    
    <content type="html" xml:lang="en" xml:base="http://hexblog.com/">
        <![CDATA[<div style=" background-image: url(/decompilation/pix/redcables.jpg);background-repeat: no-repeat">
The idea to use BITS to download files from the internet is not new. If you check the corresponding page from Wikipedia, you will find that

<p><a href="http://en.wikipedia.org/wiki/Background_Intelligent_Transfer_Service">Background Intelligent Transfer Service (BITS) is a component of modern Microsoft Windows operating systems that facilitates prioritized, throttled, and asynchronous transfer of files between machines using idle network bandwidth.</a></p>

<p>The web page ends with a list of third-party applications that use BITS. However, as any technical method, it can be used for evil purposes as well. Eric Landuyt analyzed a malware that exploits it for bad:</p>

<p><a href="http://www.datarescue.com/laboratory/trojan2008/index.html">http://www.datarescue.com/laboratory/trojan2008/index.html</a></p>

<p>I liked the "proof of concept" WinDbg script that runs the malware in a controlled manner. Breakpoints with actions are very powerful, indeed.</p>

<p>Nice work, Eric! <img src="/decompilation/pix/thumbsup.gif" /><br />
</div></p>]]>
        
    </content>
</entry>
<entry>
    <title>The IDA Pro book</title>
    <link rel="alternate" type="text/html" href="http://hexblog.com/2008/08/the_ida_pro_book_1.html" />
    <id>tag:hexblog.com,2008://1.82</id>
    <published>2008-08-26T17:53:07Z</published>
    <updated>2008-08-27T01:16:37Z</updated>
    
    <summary> This is not the first book about IDA Pro. However, this is the first book I recommend to anyone using IDA Pro because of the following points: Comprehensive: it describes all major IDA features by starting at the beginning...</summary>
    <author>
        <name>Ilfak Guilfanov</name>
        
    </author>
            <category term="IDA Pro" />
    
    <content type="html" xml:lang="en" xml:base="http://hexblog.com/">
        <![CDATA[<center>
<a href="http://nostarch.com/idapro.htm">
<img src="http://www.hexblog.com/ida_pro/pix/idabook.jpg">
</a>
</center>
<p>
This is not the first book about IDA Pro. However, this is the first
book I recommend to anyone using IDA Pro because of the following points:
<ul>
<li><b>Comprehensive</b>: it describes all major IDA features
by starting at the beginning and going all the way to the end.
Experienced users may be tempted to skip the first few chapters; resist this
temptation and you will discover something new (I did :)

<li><b>Accurate</b>: it is very difficult to be detailed and precise when describing
such a complex product. Chris does it excellently well.

<li><b>Real</b>: handles real world malware, packers, and obfuscated code

<li><b>No fillers</b>: it is direct and concise

<li><b>Profound</b>: this is not just a collection of recipes or tricks, but will give
you a better understanding of the IDA architecture, thus saving you
from unnecessary frustration. Knowing the limitations of your tool is just as
important as knowing its capabilities.


</ul>
It comes tons of code snippets, scripts, and sample modules. Programming for IDA Pro is covered
too: from simple plugins to processor modules.
<p>
If you want to use IDA efficiently, get your copy from <a href="http://nostarch.com/idapro.htm">No Starch Press</a>!
<p>
<small>
UPD for numerologists: the book has exactly 640 pages, no less, no more!
</small>]]>
        
    </content>
</entry>

</feed> 

