moveax41h

StartFinder

Dec 6th, 2017
1,521
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.40 KB | None | 0 0
  1. # 1. Start in a function
  2. # 2. Enum the func instructions and look for pattern of "heads"
  3. # 3. print the instruction 2 before the beginning of the pattern
  4. # 3. look for the same pattern elsewhere in the file
  5.  
  6. def main():
  7.     FUNCTION_NAME = 'start' #Change this to whatever func you want to look for. May have to change to _start in some cases or code your own logic
  8.  
  9.     print "===Welcome to StartFinder v0.1 by moveax41h==="
  10.     cursor = 0
  11.     real_names = []
  12.     addresses = []
  13.     names = idautils.Names()
  14.     # Populate the two above lists with their respective data from the list of tuples returned by idautils.Names()
  15.     for n in names:
  16.         real_names.append(n[1]) # real_names[30] ------> addresses[30]
  17.         addresses.append(n[0])
  18.     # search for a 'start' name in the names list and if it is there, set cursor to the address of beginning of it
  19.     for rn in real_names:
  20.         if rn == FUNCTION_NAME:
  21.             cursor = addresses[int(real_names.index(FUNCTION_NAME))]
  22.             break
  23.     if cursor: #if a start was found, assign it to the cursor and then
  24.         myFunc = idaapi.get_func(cursor)
  25.         while cursor < myFunc.endEA:
  26.             print "%s" % idc.GetDisasm(cursor)
  27.             if idc.GetMnem(cursor) == 'call' and idc.GetMnem(idc.prev_head(cursor)) == 'jmp':
  28.                 idc.MakeComm(cursor, 'This is a call after a jump!')
  29.             cursor = idc.next_head(cursor,myFunc.endEA) # MaxEA()
  30.     print "===StartFinder end. Thanks for using==="
  31.  
  32. if __name__ == "__main__":
  33.     main()
Advertisement
Add Comment
Please, Sign In to add comment