<?xml version="1.0"?>
<rss version="2.0">
    <channel>
        <title>OpenRCE: Blog</title>
        <link>http://www.openrce.org/rss/feeds/blog</link>
        <description>OpenRCE: The Open Reverse Code Engineering Community</description>
                <item>
            <title>IDAPython 0.8.0 patch</title>
                            <pubDate>Fri, 01 Sep 2006 12:46:15 -0500</pubDate>
                                        <link>https://www.openrce.org/blog/view/405/IDAPython_0.8.0_patch</link>
                                        <author>PSUJobu &lt;email-suppressed@example.com&gt;</author>
                                                    <description>Pedram asked for an article, but since I don't feel this is article-worthy...&amp;nbsp;&amp;nbsp;;-)&lt;br /&gt;
&lt;br /&gt;
I started a &lt;a href=&quot;http://www.datarescue.com/ubb/ultimatebb.php?/topic/4/398.html&quot;&gt;topic&lt;/a&gt; on the IDA Pro bulletin board about an IDAPython loader module. Though I have not had the time to finish that little experiment, I tried out the few unknowns (I have written loader modules before, and know what I need to do).&lt;br /&gt;
&lt;br /&gt;
Question #1: Can you call mem2base() from outside of a loader?&amp;nbsp;&amp;nbsp;Answer: IDAPython does not wrap mem2base()&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Building IDAPython&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
So, I figured out how to build IDAPython and how Gergo wanted the directory structure set up:&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;
&amp;lt;some_dir&amp;gt;/&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;idapython&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;idasdk-versions/&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;4.9/&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;swigsdk-versions/&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;4.9/&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
I added cygwin/bin to my PATH, opened an NT command prompt, and ran vcvars32.bat from my Visual C++ install.&amp;nbsp;&amp;nbsp;Then you do 'make dist IDAVERSION=4.9' and voila - I had a plugin.&amp;nbsp;&amp;nbsp;Well, not quite.&amp;nbsp;&amp;nbsp;I had to edit the makefile to force the SYSTEM to be WindowsNT, since Cygwin 'uname' reports 'CygwinNT', and I had to tweak the paths and add a new environment variable FIND to provide the complete path.&amp;nbsp;&amp;nbsp;Gergo obviously has some &amp;quot;environmental&amp;quot; differences.&amp;nbsp;&amp;nbsp;C'est la vie.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Modifying IDAPython&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Actually, I really only had to modify the IDA SDK - the version beneath swigsdk-versions/4.9.&amp;nbsp;&amp;nbsp;In loader.hpp, I moved #ifdef's around to export mem2base() to Python via SWIG.&amp;nbsp;&amp;nbsp;Rebuild, and &amp;quot;Bam!&amp;quot; - IDAPython kicked up a notch...&lt;br /&gt;
&lt;br /&gt;
...until you try to call idaapi.mem2base() with the logical arguments - a Python string and three integers.&amp;nbsp;&amp;nbsp;You get a TypeError exception because of the first argument.&amp;nbsp;&amp;nbsp;Apparently Python strings do not match 'void', which is how SWIG translates the &amp;quot;const void *&amp;quot; argument.&lt;br /&gt;
&lt;br /&gt;
In the end, I changed &amp;quot;const void *&amp;quot; to &amp;quot;const char *&amp;quot; and everyone was happy.&lt;br /&gt;
&lt;br /&gt;
Question #1 (again): Can you call mem2base() from outside of a loader?&amp;nbsp;&amp;nbsp;Answer: Yes!&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Other Possibilities&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Why not expose file2base()?&amp;nbsp;&amp;nbsp;I didn't look into it, but it should be possible.&amp;nbsp;&amp;nbsp;I only cared about Python strings, since I want to decompress firmware from a source file and disassemble &lt;b&gt;that&lt;/b&gt; rather than the compressed stuff.&amp;nbsp;&amp;nbsp;Python with its &amp;quot;batteries included&amp;quot; mentality already supports a bunch of compression routines, so it is a ready-made solution to my problem.&lt;br /&gt;
&lt;br /&gt;
The same &amp;quot;const void *&amp;quot; to &amp;quot;const char *&amp;quot; change would probably allow patch_many_bytes() to be exposed, too.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Disclaimer&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
I did not complete the experiment, so I didn't even bother checking segment creation from IDAPython (not that I doubt that &lt;b&gt;those&lt;/b&gt; APIs are exposed).&amp;nbsp;&amp;nbsp;I created a segment by hand in an existing IDB and used Alt+8 to write the two lines of Python required to generate some bogus data and write it into the new segment.&lt;br /&gt;
&lt;br /&gt;
YMMV!&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Files&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
I put the &lt;a href=&quot;https://www.openrce.org/repositories/users/PSUJobu/idapython-0.8.2.patch&quot;&gt;patch&lt;/a&gt; to IDAPython's 4.9.patch in my repository.&amp;nbsp;&amp;nbsp;You need to apply the patch to 0.8.0 and rebuild.&amp;nbsp;&amp;nbsp;I do not want to supply the binary for several reasons:&lt;br /&gt;
&lt;br /&gt;
1. That's Gergely's &amp;quot;job&amp;quot; - I have no desire to take over IDAPython.&amp;nbsp;&amp;nbsp;:)&lt;br /&gt;
&lt;br /&gt;
2. Datarescue frowns upon distribution of plugin binaries for anything but the latest IDA Pro revision. Perhaps the SDK freeze makes this a non-issue (for 4.9+), but I would prefer not to help any illicit users of IDA Pro.&amp;nbsp;&amp;nbsp;It is an excellent tool and well worth the money, IMHO.&lt;br /&gt;
&lt;br /&gt;
3. See #1 - I had enough trouble creating a patch for a patch (timestamp differences cause bogus differences)&lt;br /&gt;
&lt;br /&gt;
Of course, you could just wait for Gergely to release the update.&amp;nbsp;&amp;nbsp;I only provided the info to demonstrate the ease of enhancing IDAPython.&amp;nbsp;&amp;nbsp;Despite the lengthy posting, the bulk of the time to make this change was spent figuring out the build environment.&amp;nbsp;&amp;nbsp;The real work (after this was): edit the SWIG version of the IDA SDK, rebuild, and test.&amp;nbsp;&amp;nbsp;Were it not for my inexperience with SWIG, it would have taken about 2 minutes...</description>
                    </item>
            </channel>
</rss>
