Thursday, July 16, 2020

IDAPython beginning, review Hex operand

Just me experimenting with IDAPython
grabbing an operand that is hex and converting/displaying it in multiple ways

# review a hex parameter in assembly
def hexParamReview(addressHex, paramNumber):
 # get line address to pass to idapython
 address = int(addressHex)
 # display what segment its in
 print "segment: %s" % idc.get_segm_name(address)
 # get the assembly command
 print "command: %s" % GetMnem(address)
 # get the assembly 1st parameter
 print "param %d: %s" % (paramNumber, GetOpnd(address, paramNumber))
 # convert parameter from string to hex
 hexAsString = ( GetOpnd(address ,paramNumber)[:-1] )
 print "hex(param 0): 0x%s" % hexAsString
 # convert parameter from hex to int
  print "int(param 0): %d" % int(hexAsString, 16)
  print "int(param 0): invalid hex"
 # convert parameter from hex to string
  print "str(param 0): %s" % hexAsString[2:].decode("hex")
  print "str(param 0): undefined"

hexParamReview(0x100048C3, 0)
hexParamReview(here(), 0)

# example:
#  0x100048C3 push 4141h
# output:
#  segment: .text
#  command: push
#  param 0: 4141h
#  hex(param 0): 0x4141
#  int(param 0): 16705
#  str(param 0): AA

1 comment:

  1. I want to thank Dr Emu a very powerful spell caster who help me to bring my husband back to me, few month ago i have a serious problem with my husband, to the extend that he left the house, and he started dating another woman and he stayed with the woman, i tried all i can to bring him back, but all my effort was useless until the day my friend came to my house and i told her every thing that had happened between me and my husband, then she told me of a powerful spell caster who help her when she was in the same problem I then contact Dr Emu and told him every thing and he told me not to worry my self again that my husband will come back to me after he has cast a spell on him, i thought it was a joke, after he had finish casting the spell, he told me that he had just finish casting the spell, to my greatest surprise within 48 hours, my husband really came back begging me to forgive him, if you need his help you can contact him with via email: or add him up on his whatsapp +2347012841542 is willing to help any body that need his help.