Skip to content

Commit

Permalink
idapython: add get_item_end, get_byte, get_word, get_dword, get_qword.
Browse files Browse the repository at this point in the history
get_item_end code is similar to idc.ItemSize but 1) doesn't force ea to
be head 2) check if ea is within a segment. IDA specifications say
get_item_end must return 1 on unexplored bytes.
  • Loading branch information
invano authored and imbillow committed Aug 20, 2020
1 parent 9ed6ac9 commit b0ad896
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions idb/idapython.py
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,37 @@ def next_not_tail(self, ea):
def next_inited(self, ea, maxea):
return self.next_that(ea, maxea, lambda flags: ida_bytes.has_value(flags))

def get_item_end(self, ea):
ea += 1
flags = self.api.idc.GetFlags(ea)
while flags is not None and not self.api.ida_bytes.is_head(flags) and self.api.idc.SegEnd(ea):
ea += 1
flags = self.api.idc.GetFlags(ea)
return ea

def get_byte(self, ea):
return ord(self.get_bytes(ea, 1))

def get_word(self, ea):
if self.api.idaapi.get_inf_structure().is_be:
fmt = ">H"
else:
fmt = "<H"
return struct.unpack(fmt, self.get_bytes(ea, 2))[0]

def get_dword(self, ea):
if self.api.idaapi.get_inf_structure().is_be:
fmt = ">I"
else:
fmt = "<I"
return struct.unpack(fmt, self.get_bytes(ea, 4))[0]

def get_qword(self, ea):
if self.api.idaapi.get_inf_structure().is_be:
fmt = ">Q"
else:
fmt = "<Q"
return struct.unpack(fmt, self.get_bytes(ea, 8))[0]

class ida_nalt:
def __init__(self, db, api):
Expand Down

0 comments on commit b0ad896

Please sign in to comment.