{"id":7369,"date":"2020-07-31T23:12:30","date_gmt":"2020-07-31T23:12:30","guid":{"rendered":"https:\/\/www.hexacorn.com\/blog\/?p=7369"},"modified":"2020-07-31T23:24:15","modified_gmt":"2020-07-31T23:24:15","slug":"ida-colonoscopy","status":"publish","type":"post","link":"https:\/\/www.hexacorn.com\/blog\/2020\/07\/31\/ida-colonoscopy\/","title":{"rendered":"IDA colonoscopy"},"content":{"rendered":"\n<p>One of the most annoying things I come across during analysis are &#8230; function names. It&#8217;s great to have many of them resolved either via flirt of symbols, but the length of some of these function names is making it really hard to read code.<\/p>\n\n\n\n<p>It is especially important with &#8216;basic&#8217; string functions that hide behind constructs like:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">std::basic_string,std::allocator,_STL70&gt;::assign\n(std::basic_string,std::allocator,_STL70&gt; const &amp;,uint,uint)<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">std::basic_string,std::allocator,_STL70&gt;::operator=(ushort const *)<\/pre>\n\n\n\n<p>Why not simple &#8216;assign&#8217; and &#8216;operator&#8217;?<\/p>\n\n\n\n<p>It&#8217;s because it&#8217;s puristic and accurate, that&#8217;s why \ud83d\ude42<\/p>\n\n\n\n<p>Reading code listings relying on these functions is difficult, and it involves a lot of mental processing to find the actual method name in these long strings.<\/p>\n\n\n\n<p>I got bored doing so and coded a very badly written idapython script that replaces these names with a shorter version. Again, this is a blasphemy to both IDA and IDAPython so you have been warned.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import idaapi\nimport idc\nimport types\nimport os\nimport pprint\nimport random\n\nmask = idc.GetLongPrm(idc.INF_SHORT_DN)\n\nfor func_ea in idautils.Functions():\n    function_name = idc.GetFunctionName(func_ea)\n    function_name_dem = idc.Demangle(function_name, mask)\n    if function_name_dem != None:\n       function_name = function_name_dem\n    <code>m=re.search(r'hex_',function_name,re.IGNORECASE) <\/code>\n    <code>if not m:<\/code>\n       <code>print function_name <\/code>\n       <code>m=re.search(r'basic_string.*?::([^:=]+)\\(',function_name,re.IGNORECASE) <\/code>\n       <code>if m: <\/code>\n          <code>short_fun = m.group(1) <\/code>\n          <code>short_fun1 = re.sub('[\\(=&lt; ~\\'\\\"\\+\\`-].+$','',short_fun) <\/code>\n          <code>cnt=0 <\/code>\n          <code>while True: <\/code>\n             <code>short_fun = 'hex_string_' + short_fun1 + \"_\" + str(cnt) <\/code>\n             <code>res = MakeName(func_ea,short_fun) <\/code>\n             <code>if res: <\/code>\n                <code>print short_fun <\/code>\n                <code>break <\/code>\n             <code>cnt = cnt + 1 <\/code>\n             <code>if cnt>1000: <\/code>\n                <code>break<\/code><\/pre>\n\n\n\n<p>The result:<\/p>\n\n\n\n<p>before<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><a href=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2020\/07\/hex_strings_before.png\"><img decoding=\"async\" src=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2020\/07\/hex_strings_before-1024x391.png\" alt=\"\" class=\"wp-image-7377\" width=\"500\" srcset=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2020\/07\/hex_strings_before-1024x391.png 1024w, https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2020\/07\/hex_strings_before-300x114.png 300w, https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2020\/07\/hex_strings_before-768x293.png 768w, https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2020\/07\/hex_strings_before.png 1428w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>after<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2020\/07\/hex_strings-1.png\"><img decoding=\"async\" loading=\"lazy\" width=\"399\" height=\"244\" src=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2020\/07\/hex_strings-1.png\" alt=\"\" class=\"wp-image-7375\" srcset=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2020\/07\/hex_strings-1.png 399w, https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2020\/07\/hex_strings-1-300x183.png 300w, https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2020\/07\/hex_strings-1-80x50.png 80w\" sizes=\"(max-width: 399px) 100vw, 399px\" \/><\/a><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>One of the most annoying things I come across during analysis are &#8230; function names. It&#8217;s great to have many of them resolved either via flirt of symbols, but the length of some of these function names is making it &hellip; <a href=\"https:\/\/www.hexacorn.com\/blog\/2020\/07\/31\/ida-colonoscopy\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[85],"tags":[],"_links":{"self":[{"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts\/7369"}],"collection":[{"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/comments?post=7369"}],"version-history":[{"count":6,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts\/7369\/revisions"}],"predecessor-version":[{"id":7378,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts\/7369\/revisions\/7378"}],"wp:attachment":[{"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/media?parent=7369"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/categories?post=7369"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/tags?post=7369"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}