Advertisement
Guest User

Untitled

a guest
May 2nd, 2022
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. import re as regular_expression
  2. import idaapi as ida_interface
  3. import idautils as ida_utilities
  4. import idc as idc_interface
  5. import ida_typeinf as ida_type
  6. import ida_search
  7. import ida_lines
  8. import ida_hexrays
  9. import ida_bytes
  10.  
  11. def GetCfunc(ea):
  12. f = idaapi.get_func(ea)
  13. if f is None:
  14. return None
  15.  
  16. # Decompile the function.
  17. cfunc = None
  18. try:
  19. cfunc = idaapi.decompile(f)
  20. finally:
  21. return cfunc
  22.  
  23. def ChangeVariableType(func_ea, lvar, tif):
  24. lsi = ida_hexrays.lvar_saved_info_t()
  25. lsi.ll = lvar
  26. lsi.type = ida_typeinf.tinfo_t(tif)
  27. if not ida_hexrays.modify_user_lvar_info(func_ea, ida_hexrays.MLI_TYPE, lsi):
  28. print("[E] Could not modify lvar type for %s" % lvar.name)
  29. return False
  30. return True
  31.  
  32. def decompile_function( function_location ):
  33. decompile_handle = ida_hexrays.open_pseudocode( function_location, 0 )
  34.  
  35. for local_variable in GetCfunc( function_location ).lvars:
  36. type_info = local_variable.type()
  37.  
  38. if ida_type.is_type_ptr( type_info.get_decltype() ):
  39. dword_type = ida_type.tinfo_t()
  40. ida_type.parse_decl( dword_type, ida_type.get_idati(), "_DWORD;", ida_type.PT_TYP )
  41.  
  42. ChangeVariableType( function_location, local_variable, dword_type )
  43.  
  44. decompile_handle.refresh_view(True)
  45.  
  46. decompile_function( 0xDEADBEEF ) # put your own function here
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement