def mkenu32(self): global myenum32 if myenum32 is None: myenum32 = "ARM32_SYSREG_aenum" enu = idaapi.add_enum(0, myenum32, 0) for i in regs32.keys(): idaapi.add_enum_member(enu, regs32[i], i) return myenum32
def mkenu64(self): global myenum64 if myenum64 is None: myenum64 = "ARM64_SYSREG_aenum" enu = idaapi.add_enum(0, myenum64, 0) for i in regs64.keys(): idaapi.add_enum_member(enu, regs64[i], i) return myenum64
def add(cls, enum, name, value, **bitmask): """Add an enumeration member `name` with the specified `value` to the enumeration `enum`. If the int, `bitmask`, is specified then used it as the bitmask for the enumeration. """ eid = by(enum) bmask = bitmask.get('bitmask', idaapi.BADADDR & mask(eid)) res = interface.tuplename(name) if isinstance(name, tuple) else name ok = idaapi.add_enum_member(eid, utils.string.to(res), value, bmask) err = { getattr(idaapi, item): item for item in [ 'ENUM_MEMBER_ERROR_NAME', 'ENUM_MEMBER_ERROR_VALUE', 'ENUM_MEMBER_ERROR_ENUM', 'ENUM_MEMBER_ERROR_MASK', 'ENUM_MEMBER_ERROR_ILLV' ] } if ok in err.keys(): raise E.DisassemblerError( u"{:s}.add({:#x}, {!r}, {:#x}{:s}) : Unable to add member to enumeration due to error {:s}({:d})." .format( '.'.join([__name__, cls.__name__]), eid, name, value, u", {:s}".format(utils.string.kwargs(bitmask)) if bitmask else '', err[ok], ok)) return eid
def add(cls, enum, name, value, **kwds): '''Given a valid enum id, add the specified /name/ and /value/ to it''' bmask = kwds.get('mask', -1&mask(enum)) res = idaapi.add_enum_member(enum, name, value, bmask) if res in (idaapi.ENUM_MEMBER_ERROR_NAME, idaapi.ENUM_MEMBER_ERROR_VALUE, idaapi.ENUM_MEMBER_ERROR_ENUM, idaapi.ENUM_MEMBER_ERROR_MASK, idaapi.ENUM_MEMBER_ERROR_ILLV): raise Exception, "enum.member.add(%x, %r, %r, %r):Unable to add enum member"%(enum, name, value, kwds) return cls.byValue(enum, value)
def init(self): # Some initialization global hexnight_cb_info, hexnight_cb, inttype if idaapi.init_hexrays_plugin() and idaapi.ph_get_id( ) == idaapi.PLFM_ARM and idaapi.BADADDR > 0xFFFFFFFF: inttype = idaapi.get_int_type_by_width_and_sign(4, True) enu = idaapi.add_enum(0, myenum, 0) for i in regs.keys(): idaapi.add_enum_member(enu, regs[i], i) hexnight_cb_info = hexrays_callback_info() hexnight_cb = hexnight_cb_info.event_callback if idaapi.install_hexrays_callback(hexnight_cb): print "Hexnight plugin installed" addon = idaapi.addon_info_t() addon.id = "org.xerub.hexnight" addon.name = "Hexnight" addon.producer = "xerub" addon.url = "https://twitter.com/xerub" addon.version = "6.95" idaapi.register_addon(addon) return idaapi.PLUGIN_KEEP print "Hexnight plugin failed" return idaapi.PLUGIN_SKIP
def add(cls, enum, name, value, **bitmask): """Add an enumeration member `name` with the specified `value` to the enumeration `enum`. If the int, `bitmask`, is specified then used it as the bitmask for the enumeration. """ eid = by(enum) bmask = bitmask.get('bitmask', idaapi.BADADDR & mask(eid)) res = interface.tuplename(name) if isinstance(name, tuple) else name ok = idaapi.add_enum_member(eid, utils.string.to(res), value, bmask) err = {getattr(idaapi, n) : n for n in ('ENUM_MEMBER_ERROR_NAME', 'ENUM_MEMBER_ERROR_VALUE', 'ENUM_MEMBER_ERROR_ENUM', 'ENUM_MEMBER_ERROR_MASK', 'ENUM_MEMBER_ERROR_ILLV')} if ok in err.viewkeys(): raise E.DisassemblerError(u"{:s}.add({:#x}, {!r}, {:#x}{:s}) : Unable to add member to enumeration due to error {:s}({:d}).".format('.'.join((__name__, cls.__name__)), eid, name, value, u", {:s}".format(utils.string.kwargs(bitmask)) if bitmask else '', err[ok], ok)) return eid
def add_magnumdb_entry(self, name, value): enum_id = self.ensure_magnumdb_enum_type() serial = 0 enum_memberid = idaapi.get_enum_member(enum_id, value, serial, 0) while enum_memberid != 0xffffffffffffffff: if idaapi.get_enum_member_name(enum_memberid) == name: return enum_memberid, serial serial += 1 enum_memberid = idaapi.get_enum_member(enum_id, value, serial, 0) if enum_memberid == 0xffffffffffffffff: enum_memberid = idaapi.add_enum_member(enum_id, name, value) return enum_memberid, serial
def add(cls, enum, name, value, **bitmask): """Add an enumeration member ``name`` with the specified ``value`` to the enumeration identified by ``enum``. If the int, ``bitmask``, is specified then used it as the bitmask for the enumeration. """ eid = by(enum) bmask = bitmask.get('bitmask', -1 & mask(eid)) res = interface.tuplename(name) if isinstance(name, tuple) else name ok = idaapi.add_enum_member(eid, res, value, bmask) if ok in (idaapi.ENUM_MEMBER_ERROR_NAME, idaapi.ENUM_MEMBER_ERROR_VALUE, idaapi.ENUM_MEMBER_ERROR_ENUM, idaapi.ENUM_MEMBER_ERROR_MASK, idaapi.ENUM_MEMBER_ERROR_ILLV): raise ValueError( "{:s}.add({:x}, {!r}, {:x}, bitmask={!r}) : Unable to add member to enumeration." .format('.'.join((__name__, cls.__name__)), eid, name, value, bitmask)) return cls.by_value(eid, value)
def add_magnumdb_entry(self, name, value): enum_id = self.ensure_magnumdb_enum_type() # idaapi.add_enum_member accept only str (Py3) if type(name) == type(b''): name = name.decode('utf-8') serial = 0 enum_memberid = idaapi.get_enum_member(enum_id, value, serial, 0) while enum_memberid != 0xffffffffffffffff: if idaapi.get_enum_member_name(enum_memberid) == name: return enum_memberid, serial serial += 1 enum_memberid = idaapi.get_enum_member(enum_id, value, serial, 0) if enum_memberid == 0xffffffffffffffff: enum_memberid = idaapi.add_enum_member(enum_id, name, value) return enum_memberid, serial
def add(cls, enum, name, value, **bitmask): """Add an enumeration member `name` with the specified `value` to the enumeration `enum`. If the int, `bitmask`, is specified then used it as the bitmask for the enumeration. """ eid = by(enum) bmask = bitmask.get('bitmask', idaapi.BADADDR & mask(eid)) res = interface.tuplename(name) if isinstance(name, tuple) else name ok = idaapi.add_enum_member(eid, res, value, bmask) err = { getattr(idaapi, n): n for n in ('ENUM_MEMBER_ERROR_NAME', 'ENUM_MEMBER_ERROR_VALUE', 'ENUM_MEMBER_ERROR_ENUM', 'ENUM_MEMBER_ERROR_MASK', 'ENUM_MEMBER_ERROR_ILLV') } if ok in err.viewkeys(): raise E.DisassemblerError( "{:s}.add({:#x}, {!r}, {:#x}, bitmask={!r}) : Unable to add member to enumeration due to error {:s}({:d})." .format('.'.join((__name__, cls.__name__)), eid, name, value, bitmask, err[ok], ok)) return eid
def _add_enum_member(enum, name, value, bitmask=DEFMASK): """Add an enum member.""" error = idaapi.add_enum_member(enum, name, value, bitmask) if error: raise _enum_member_error(error, enum, name, value, bitmask)
def __call__(self): idaapi.add_enum_member(self.id, self.name.encode('utf-8'), self.value, self.bmask)
def __call__(self): idaapi.add_enum_member(self.id, self.name, self.value, self.bmask)