def cmt_changed(self, ea, repeatable): self.pre_hook() if LOG_IDB_EVENTS: self.debug_event("cmt_changed (0x%.016X, %x)" % (ea, repeatable)) hooks.ida.comment_changed(ea) if (idc.LineA(ea, 0) is None) and (idc.LineB(ea, 0) is None): return idaapi.IDB_Hooks.cmt_changed(self, ea, repeatable) return 0
def get_import_module_name(address): global module_names global idata_seg_start global idata_seg_end segment_eas = list(idautils.Segments()) # This hasn't been initialized yet... # if module_names is None: module_names = list() for idata_seg_start in segment_eas: print "Going through segment %08X" % idata_seg_start segment = idaapi.getseg(idata_seg_start) if segment.type != idaapi.SEG_XTRN: continue print "Found idata segment" idata_seg_end = idc.SegEnd(idata_seg_start) parse = re.compile('.*Imports\s+from\s+([\w\d]+\.[\w\d]+).*', re.IGNORECASE) # save the address/module name combinations we discover # modules = list() # Scan the .idata segment looking for the imports from # string and get the address ranges where it applies # for head in idautils.Heads(idata_seg_start, idata_seg_end): for line_id in range(100): line = idc.LineA(head, line_id) if line and 'imports from' in line.lower(): res = parse.match(line) if res: print 'Found import line [%s][%s]' % (line, res.group(1)) modules.append((head, res.group(1).lower())) modules.append((idata_seg_end, None)) for idx in range(len(modules) - 1): mod = modules[idx] module_names.append(((mod[0], modules[idx + 1][0]), mod[1])) for addr_range, module_name in module_names: if addr_range[0] <= address < addr_range[1]: return module_name return None
def yacheck_data_comments(self): eas = yaunit.load('data_comments') i = 0 for offset in range(0, 3): for cmt, rpt, post, ant in tests_data: ea = eas[i] logger.debug( "checking data comment at 0x%08X : %r, %r, %r, %r" % (ea, cmt, rpt, post, ant)) i += 1 if cmt != None: self.assertEqual(idc.GetCommentEx(ea, False), cmt) if rpt != None: self.assertEqual(idc.GetCommentEx(ea, True), rpt) if post != None: for j, txt in enumerate(post.split('\n')): self.assertEqual(idc.LineB(ea, j), txt) if ant != None: for j, txt in enumerate(ant.split('\n')): self.assertEqual(idc.LineA(ea, j), txt)
def anterior(self): """Anterior Comment""" lines = (idc.LineA(self._ea, index) for index in count()) return "\n".join(iter(lines.next, None))