Exemple #1
0
def add_enum(name=None, index=None, flags=idaapi.hexflag(), bitfield=False):
    """Create a new enum.

    Args:
        name: Name of the enum to create.
        index: The index of the enum. Leave at default to append the enum as the last enum.
        flags: Enum type flags.
        bitfield: Is the enum a bitfield.

    Returns:
        An `Enum` object.
    """
    if name is not None:
        with ignored(exceptions.EnumNotFound):
            _get_enum(name)
            raise exceptions.EnumAlreadyExists()

    if index is None or index < 0:
        index = idaapi.get_enum_qty()

    eid = idaapi.add_enum(index, name, flags)

    if eid == idaapi.BADADDR:
        raise exceptions.EnumCreationFailed('Failed creating enum "{}"'.format(name))

    if bitfield:
        idaapi.set_enum_bf(eid, bitfield)

    return Enum(eid=eid)
Exemple #2
0
def new(name, flags=0):
    '''Create an enumeration with the specified `name` and `flags` using ``idaapi.add_enum``.'''
    idx = count()
    res = idaapi.add_enum(idx, utils.string.to(name), flags)
    if res == idaapi.BADADDR:
        raise E.DisassemblerError(u"{:s}.new({!r}, flags={:d}) : Unable to create enumeration named \"{:s}\".".format(__name__, name, flags, utils.string.escape(name, '"')))
    return res
Exemple #3
0
def add_enum(name=None, index=None, flags=idaapi.hex_flag(), bitfield=False):
    """Create a new enum.

    Args:
        name: Name of the enum to create.
        index: The index of the enum. Leave at default to append the enum as the last enum.
        flags: Enum type flags.
        bitfield: Is the enum a bitfield.

    Returns:
        An `Enum` object.
    """
    if name is not None:
        with suppress(exceptions.EnumNotFound):
            _get_enum(name)
            raise exceptions.EnumAlreadyExists()

    if index is None or index < 0:
        index = idaapi.get_enum_qty()

    eid = idaapi.add_enum(index, name, flags)

    if eid == idaapi.BADADDR:
        raise exceptions.EnumCreationFailed(
            'Failed creating enum "{}"'.format(name))

    if bitfield:
        idaapi.set_enum_bf(eid, bitfield)

    return Enum(eid=eid)
Exemple #4
0
def new(name, flags=0):
    '''Create an enumeration with the specified `name` and `flags` using ``idaapi.add_enum``.'''
    idx = count()
    res = idaapi.add_enum(idx, utils.string.to(name), flags)
    if res == idaapi.BADADDR:
        raise E.DisassemblerError(u"{:s}.new({!r}, flags={:d}) : Unable to create enumeration named \"{:s}\".".format(__name__, name, flags, utils.string.escape(name, '"')))
    return res
Exemple #5
0
def create(name, flags=0):
    '''Create an enumeration with the specified /name/'''
    idx = count()
    res = idaapi.add_enum(idx, name, flags)
    if res == 0xffffffff:
        raise Exception, "Unable to create enum"
    return res
    def ensure_magnumdb_enum_type(self):
        """Ensure we have a valid MAGNUMDB enum"""

        enum_id = idaapi.get_enum("_IDA_MAGNUMDB")
        if enum_id == 0xffffffffffffffff:
            enum_id = idaapi.add_enum(idaapi.BADADDR, "_IDA_MAGNUMDB", 0)

        return enum_id
Exemple #7
0
 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
Exemple #8
0
 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
Exemple #9
0
def new(name, flags=0):
    '''Create an enumeration with the specified ``name`` and ``flags`` using `idaapi.add_enum`.'''
    idx = count()
    res = idaapi.add_enum(idx, name, flags)
    if res == idaapi.BADADDR:
        raise E.DisassemblerError(
            "{:s}.new({!r}, flags={:d}) : Unable to create enumeration named {:s}."
            .format(__name__, name, flags, name))
    return res
Exemple #10
0
def new(name, flags=0):
    '''Create an enumeration with the specified ``name``.'''
    idx = count()
    res = idaapi.add_enum(idx, name, flags)
    if res == idaapi.BADADDR:
        raise ValueError(
            "{:s}.create : Unable to create enumeration named {:s}".format(
                __name__, name))
    return res
Exemple #11
0
def add_enum(name=None, index=idaapi.BADADDR, flags=idaapi.hexflag(), bitfield=False):
    """Create a new enum."""
    if name is not None:
        with ignored(exceptions.EnumNotFound):
            _get_enum(name)
            raise exceptions.EnumAlreadyExists()

    eid = idaapi.add_enum(index, name, flags)

    if eid == idaapi.BADADDR:
        raise exceptions.EnumCreationFailed('Failed creating enum "{}"'.format(name))

    if bitfield:
        idaapi.set_enum_bf(eid, bitfield)

    return Enum(eid=eid)
Exemple #12
0
    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