joxeankoret

Simple script to patch any appearance of a specific call

Feb 19th, 2021 (edited)
420
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.75 KB | None | 0 0
  1. #
  2. # Simple script to patch any appearance of a specific call
  3. # The script was used in the following Youtube video:
  4. #
  5. # https://www.youtube.com/watch?v=mlEcfRlw9rU
  6. #
  7. # By Joxean Koret
  8. #
  9. # Public Domain
  10. #
  11.  
  12. import idc
  13. import idaapi
  14. import ida_idp
  15.  
  16. text_to_search = "call    CreateMenu"
  17. start_ea = idc.get_inf_attr(idc.INF_MIN_EA)
  18. end_ea   = idc.get_inf_attr(idc.INF_MAX_EA)
  19.  
  20. ea = start_ea
  21. while ea < end_ea and ea != BADADDR:
  22.   ea = idc.find_text(ea+1, idc.SEARCH_DOWN, 0, 0, text_to_search)
  23.   if ea != BADADDR:
  24.     size = idc.get_item_size(ea)
  25.     if size == 5:
  26.       ida_idp.assemble(ea, 0, ea, True, "mov eax, 1")
  27.  
  28.       # Alternatively, you can NOP the whole instruction by uncommenting this
  29.       #idaapi.patch_bytes(ea, b"\x90"*size)
  30.  
Add Comment
Please, Sign In to add comment