DST

search-for-instructions.py

DST
Sep 25th, 2017
1,100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.41 KB | None | 0 0
  1. # Didier Stevens 2017/09/25
  2.  
  3. def GenerateInstructionList(address_start, address_end):
  4.     instructions = []
  5.     address = address_start
  6.     while address <= end and address != BADADDR:
  7.         instruction = GetMnem(address)
  8.         if instruction != '':
  9.             instructions.append([instruction, address])
  10.         address = NextAddr(address)
  11.     return instructions
  12.  
  13. def CompareInstructions(segment_instructions, instructions_to_compare):
  14.     while instructions_to_compare != [] and segment_instructions != [] and instructions_to_compare[0] == segment_instructions[0][0]:
  15.         segment_instructions = segment_instructions[1:]
  16.         instructions_to_compare = instructions_to_compare[1:]
  17.     return instructions_to_compare == []
  18.  
  19. def SearchForInstructions(sequence):
  20.     print('Searching for: %s' % sequence)
  21.     instructions_to_search_for = sequence.split(' ')
  22.     segment_instructions = GenerateInstructionList(SegStart(ScreenEA()), SegEnd(ScreenEA()))
  23.     while segment_instructions != []:
  24.         if CompareInstructions(segment_instructions, instructions_to_search_for):
  25.             print('%s:0x%08x: %s' % (SegName(segment_instructions[0][1]), segment_instructions[0][1], ' | '.join(map(GetDisasm, [i[1] for i in segment_instructions[0:len(instructions_to_search_for)]]))))
  26.         segment_instructions = segment_instructions[1:]
  27.  
  28. SearchForInstructions('pop pop retn')
  29. SearchForInstructions('call mov mov')
Advertisement
Add Comment
Please, Sign In to add comment