def mask(cls, mid): '''Return the bitmask for the enumeration member `mid`.''' if not interface.node.is_identifier(mid): raise E.MemberNotFoundError( u"{:s}.mask({:#x}) : Unable to locate member by the specified identifier." .format('.'.join([__name__, cls.__name__]), mid)) return idaapi.get_enum_member_bmask(mid)
def by_identifier(cls, enum, mid): '''Return the member of the enumeration specified by `enum` and its `mid`.''' eid = by(enum) if member.parent(mid) != eid: raise E.MemberNotFoundError( u"{:s}.by_identifier({:#x}, {:d}) : Unable to locate member by the specified identifier." .format('.'.join([__name__, cls.__name__]), eid, mid)) return mid
def name(cls, mid): '''Return the name of the enumeration member `mid`.''' if not interface.node.is_identifier(mid): raise E.MemberNotFoundError( u"{:s}.name({:#x}) : Unable to locate member by the specified identifier." .format('.'.join([__name__, cls.__name__]), mid)) res = idaapi.get_enum_member_name(mid) return utils.string.of(res)
def by_value(cls, enum, value): '''Return the member identifier for the member of the enumeration `enum` with the specified `value`.''' eid = by(enum) bmask = idaapi.BADADDR & mask(eid) res, _ = idaapi.get_first_serial_enum_member(eid, value, bmask) if res == idaapi.BADADDR: raise E.MemberNotFoundError(u"{:s}.by_value({:#x}, {:d}) : Unable to locate member by value.".format('.'.join((__name__, cls.__name__)), eid, value)) return res
def value(cls, mid, value, **bitmask): """Set the `value` for the enumeration `member` belonging to `enum`. If the integer `bitmask` is specified, then use it as a bitmask. Otherwise assume all bits are set. """ if not interface.node.is_identifier(mid): raise E.MemberNotFoundError(u"{:s}.value({:#x}, {:#x}) : Unable to locate member by the specified identifier.".format('.'.join((__name__, cls.__name__)), mid, value)) bmask = bitmask.get('bitmask', idaapi.BADADDR & cls.mask(mid)) return idaapi.set_enum_member_value(mid, value, bmask)
def comment(cls, mid, comment, **repeatable): """Set the comment for the enumeration member id `mid` to `comment`. If the bool `repeatable` is specified, then set the repeatable comment. """ if not interface.node.is_identifier(mid): raise E.MemberNotFoundError(u"{:s}.comment({:#x}, {!r}) : Unable to locate member by the specified identifier.".format('.'.join((__name__, cls.__name__)), mid, comment)) res = utils.string.to(comment) return idaapi.set_enum_member_cmt(mid, res, repeatable.get('repeatable', True))
def by_index(cls, enum, index): '''Return the member identifier for the member of the enumeration `enum` at the specified `index`.''' eid = by(enum) try: return next(mid for i, mid in enumerate(cls.iterate(eid)) if i == index) except StopIteration: pass raise E.MemberNotFoundError( u"{:s}.by_index({:#x}, {:d}) : Unable to locate member by index.". format('.'.join([__name__, cls.__name__]), eid, index))
def comment(cls, mid, **repeatable): """Return the comment for the enumeration member `mid`. If the bool `repeatable` is specified, then return the repeatable comment. """ if not interface.node.is_identifier(mid): raise E.MemberNotFoundError( u"{:s}.comment({:#x}) : Unable to locate member by the specified identifier." .format('.'.join([__name__, cls.__name__]), mid)) res = idaapi.get_enum_member_cmt(mid, repeatable.get('repeatable', True)) return utils.string.of(res)
def serial(cls, mid): '''Return the serial of the enumeration member `mid`.''' if not interface.node.is_identifier(mid): raise E.MemberNotFoundError(u"{:s}.serial({:#x}) : Unable to locate member by the specified identifier.".format('.'.join((__name__, cls.__name__)), mid)) return idaapi.get_enum_member_serial(mid)