def get_bitmasks(enumid): """ Return list of bitmasks used in enum. """ bmasks = [] bid = idc.GetFirstBmask(enumid) while bid != idaapi.BADADDR: bmasks.append(bid) bid = idc.GetNextBmask(enumid, bid) return bmasks
def enum_member_iterate_bitfield(enum_id): # bitfield bmask = idc.GetFirstBmask(enum_id) while bmask != idc.BADADDR: const_value = idc.GetFirstConst(enum_id, bmask) while const_value != idc.BADADDR: # TODO must implement serial for bitfield const_id = idc.GetConstEx(enum_id, const_value, 0, bmask) yield (const_id, const_value, bmask) const_value = idc.GetNextConst(enum_id, const_value, bmask) bmask = idc.GetNextBmask(enum_id, bmask)
def walk_enum(eid): def get_enums(bmask): value = idc.GetFirstConst(eid, bmask) while value != idaapi.BADADDR: yield value, bmask value = idc.GetNextConst(eid, value, bmask) # iterate on every bmask bmask = idc.GetFirstBmask(eid) while bmask != idaapi.BADADDR: for v, m in get_enums(bmask): yield v, m bmask = idc.GetNextBmask(eid, bmask) # iterate on regular constants for v, m in get_enums(-1): yield v, m
def getConsts(self, reload=False): if self._vals and not reload: return self._vals res = {} bm = idc.GetFirstBmask(self.id) while True: if bm not in res: res[bm] = {} c = idc.GetFirstConst(self.id, bm) while c != idc.BADADDR: cid = idc.GetConstEx(self.id, c, 0, bm) res[bm][c] = cid c = idc.GetNextConst(self.id, c, bm) if bm == idc.BADADDR: self._vals = res return res bm = idc.GetNextBmask(self.id, bm)
def enum_member_iterate_all(enum_id): const_value = idc.GetFirstConst(enum_id, -1) while const_value != idc.BADADDR: serial = 0 const_id = idc.GetConstEx(enum_id, const_value, serial, -1) while const_id != idc.BADADDR: yield (const_id, const_value, idc.BADADDR) serial += 1 const_id = idc.GetConstEx(enum_id, const_value, serial, -1) const_value = idc.GetNextConst(enum_id, const_value, -1) enum_member_iterate_bitfield(enum_id) bmask = idc.GetFirstBmask(enum_id) while bmask != idc.BADADDR: const_value = idc.GetFirstConst(enum_id, bmask) while const_value != idc.BADADDR: # TODO must implement serial for bitfield const_id = idc.GetConstEx(enum_id, const_value, 0, bmask) yield (const_id, const_value, bmask) const_value = idc.GetNextConst(enum_id, const_value, bmask) bmask = idc.GetNextBmask(enum_id, bmask)