Advertisement
Guest User

Untitled

a guest
Apr 25th, 2021
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.07 KB | None | 0 0
  1. import sys, re, struct
  2. import  idaapi, idc
  3.  
  4. def parseFile(filename):
  5.     pattern = "eax=([0-9a-z]{8}) ebx=([0-9a-z]{8}) ecx=([0-9a-z]{8}) edx=([0-9a-z]{8}) esi=([0-9a-z]{8}) edi=([0-9a-z]{8})[^\n]*\neip=([0-9a-z]{8}) esp=([0-9a-z]{8}) ebp=([0-9a-z]{8})[^\n]*\n[^\n]*\n[^\n]*\n(.*)"
  6.  
  7.     pattern = re.compile(pattern)
  8.     text = open(filename).read()
  9.     matches = re.findall(pattern, text)
  10.     ret = []
  11.     for match in matches:
  12.         eax, ebx, ecx, edx, esi, edi, eip, esp, ebp, last_line = match
  13.         ret.append( {'eax':eax, 'ebx':ebx, 'ecx':ecx, 'edx':edx, 'esi':esi, 'edi':edi, 'esp':esp, 'ebp':ebp, 'last_line':last_line} )
  14.     return ret
  15.  
  16. def fillInGraph(matches):
  17.     regs_pattern = '(eax|ebx|ecx|edx|esi|edi|esp|ebp)'
  18.     regs_pattern = re.compile(regs_pattern)
  19.  
  20.     for match in matches:
  21.         comment = []
  22.  
  23.         regs = re.findall(regs_pattern, match['last_line'])
  24.         for reg in regs:
  25.             comment.append( "%s=%s;" % (reg, match[reg]))
  26.        
  27.         last_line = match['last_line'].split()
  28.         addr = int(last_line[0], 16)
  29.         if len(last_line) > 4:
  30.             if comment:
  31.                 comment.append('*'+last_line[-1].split(':')[-1])
  32.             else:
  33.                 comment.append(last_line[-1].split(':')[-1])
  34.  
  35.         idc.SetColor(addr, CIC_ITEM, 0x7f0000) # blue
  36.         if comment:
  37.             idc.MakeComm(addr, '\n'.join(comment))
  38.  
  39. class myplugin_t(idaapi.plugin_t):
  40.     flags = idaapi.PLUGIN_UNL
  41.     comment = "This is a comment"
  42.     help = "This is help"
  43.     wanted_name = "My Python plugin"
  44.     wanted_hotkey = "Alt-F7"
  45.  
  46.     def init(self):
  47.         idaapi.msg("плагин загрузился")
  48.         return idaapi.PLUGIN_OK
  49.  
  50.     def run(self, arg):
  51.             filename = idaapi.askfile_c(False, "*.*", "Pin log file");
  52.             matches = parseFile(filename)
  53.             fillInGraph(matches)
  54.  
  55.     def term(self):
  56.         idaapi.msg("term() called!\n")
  57.  
  58. def PLUGIN_ENTRY():
  59.     try:
  60.         return myplugin_t()
  61.     except:
  62.         print("Unexpected error:", sys.exc_info()[0])
  63.         raise
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement