Log in

View Full Version : Post your favorite IDC scripts here


Kayaker
June 28th, 2011, 23:42

Hi All,



I was going to post this handy little IDC script I found, then I thought we might be able to expand it into a thread where people could add any useful scripts they've created, found, adapted, ripped off, or otherwise made use of.



If not, then consider it a chance to get the creative reversing juices working and come up with a new one!  Could be for a one-off use situation, but that doesn't matter, it's just to throw around some ideas.





Here's one I found recently by "deobfuscated" which adds a hot key to simplify colorizing lines in IDA.  I may adapt it to add a couple of different colors for different uses, making it a little easier to keep track of important lines as you scroll around a disassembly.



http://deobfuscated.blogspot.com/2011/06/coloring-junk-code-in-ida-pro.html





<div style="margin:20px; margin-top:5px; "><div class="smallfont" style="margin-bottom:2px">Quote:</div><table cellpadding="6" cellspacing="0" border="1" width="90%"><tr><td class="alt2" style="border:1px inset"><i>Coloring junk code in IDA Pro 



 Especially when reversing malware, junk code is always a pain.

 For the sake of readability, I often color junk code with some dark color.

 This makes the disassembly much more readable as shown below.



 However, coloring instructions in IDA Pro is not very handy.

 One has to go through menus (&quot;Edit&quot;-&gt;&quot;Other&quot;-&gt;&quot;Color instruction...&quot and pick up a color for every single block to be colored.



 That's why I wrote a very simple IDC script which can help with this and save some time. It simply colors the current instruction (at the cursor location) or the selected instructions, if any.

 Running the script on an instruction that's been colored already sets its color back to the default value.

 Also, a new hotkey (&quot;j&quot; in this case) is defined. 

</i></td></tr></table></div>



#include &lt;idc.idc&gt;  

  

#define JUNK_COLOR 0x7f5555  

  

static ColorJunkCode()  

{  

 auto start, end;  

 if ((start = SelStart()) == BADADDR)  

  start = end = ScreenEA();  

 else  

  end = SelEnd();  

 do {  

  if (GetColor(start, CIC_ITEM) == JUNK_COLOR)  

   SetColor(start, CIC_ITEM, DEFCOLOR);  

  else  

   SetColor(start, CIC_ITEM, JUNK_COLOR);  

  start = NextAddr (start);  

 } while (start &lt; end);  

 Refresh();  

}  

  

static main()  

{  

 AddHotkey (&quot;j&quot;, &quot;ColorJunkCode&quot;  

}  







 <div style="margin:20px; margin-top:5px; "><div class="smallfont" style="margin-bottom:2px">Quote:</div><table cellpadding="6" cellspacing="0" border="1" width="90%"><tr><td class="alt2" style="border:1px inset"><i>Run the script in IDA (&quot;File&quot;-&gt;&quot;Script file...&quot and you're ready to go.

 Hitting &lt;j&gt; will now color current/selected instructions.



 If you want IDA to load this script automatically, follow these steps:

 - Store this script in IDA/idc (not mandatory but it makes sense to keep all scripts in the same directory)

 - Edit IDA/idc/ida.idc:



Add the line &quot;#include &lt;colorjunk.idc&gt;&quot; (or whatever filename you like) at the top of the file

Copy/paste the AddHotkey instruction into the function &quot;main&quot;



 - Remove the function &quot;main&quot; from colorjunk.idc</i></td></tr></table></div>





Any other good IDC scripts?



Cheers,

Kayaker