コード例 #1
0
 def deleting_enum_member(self, id, cid):
     ename = idaapi.get_enum_name(id)
     value = idaapi.get_enum_member_value(cid)
     serial = idaapi.get_enum_member_serial(cid)
     bmask = idaapi.get_enum_member_bmask(cid)
     self._send_event(EnumMemberDeletedEvent(ename, value, serial, bmask))
     return 0
コード例 #2
0
ファイル: enum.py プロジェクト: k273811702/idascripts
def by(**type):
    """Search through all the enumerations within the database and return the first result.

    like = glob match
    regex = regular expression
    index = particular index
    identifier or id = internal id number
    """
    searchstring = ', '.join("{:s}={!r}".format(k, v)
                             for k, v in type.iteritems())

    res = __builtin__.list(iterate(**type))
    if len(res) > 1:
        map(logging.info, ("[{:d}] {:s} & {:#x} ({:d} members){:s}".format(
            idaapi.get_enum_idx(n), idaapi.get_enum_name(n), mask(n),
            len(__builtin__.list(members(n))),
            " // {:s}".format(comment(n)) if comment(n) else '')
                           for i, n in enumerate(res)))
        logging.warn(
            "{:s}.search({:s}) : Found {:d} matching results, returning the first one."
            .format(__name__, searchstring, len(res)))

    res = next(iter(res), None)
    if res is None:
        raise LookupError(
            "{:s}.search({:s}) : Found 0 matching results.".format(
                __name__, searchstring))
    return res
コード例 #3
0
 def enum_member_created(self, id, cid):
     ename = idaapi.get_enum_name(id)
     name = idaapi.get_enum_member_name(cid)
     value = idaapi.get_enum_member_value(cid)
     bmask = idaapi.get_enum_member_bmask(cid)
     self._send_event(EnumMemberCreatedEvent(ename, name, value, bmask))
     return 0
コード例 #4
0
def list(**type):
    '''List all of the enumerations within the database that match the keyword specified by `type`.'''
    res = [item for item in iterate(**type)]

    maxindex = max(builtins.map(idaapi.get_enum_idx, res) if res else [1])
    maxname = max(
        builtins.map(utils.fcompose(idaapi.get_enum_name, len), res
                     ) if res else [0])
    maxsize = max(builtins.map(size, res) if res else [0])
    cindex = math.floor(1 + math.log(maxindex or 1) / math.log(10))
    try:
        cmask = max(len("{:x}".format(mask(item)))
                    for item in res) if res else database.config.bits() / 4.0
    except Exception:
        cmask = 0

    for item in res:
        name = idaapi.get_enum_name(item)
        six.print_(
            u"{:<{:d}s} {:>{:d}s} & {:<#{:d}x} ({:d} members){:s}".format(
                "[{:d}]".format(idaapi.get_enum_idx(item)),
                2 + math.trunc(cindex), utils.string.of(name), maxname,
                mask(item), 2 + math.trunc(cmask),
                len(builtins.list(members(item))),
                u" // {:s}".format(comment(item)) if comment(item) else ''))
    return
コード例 #5
0
ファイル: enum.py プロジェクト: youngjun-chang/Sark
def _enum_member_error(err, eid, name, value, bitmask):
    """Format enum member error."""
    exception, msg = ENUM_ERROR_MAP[err]
    enum_name = idaapi.get_enum_name(eid)
    return exception(
        ('add_enum_member(enum="{}", member="{}", value={}, bitmask=0x{:08X}) '
         'failed: {}').format(enum_name, name, value, bitmask, msg))
コード例 #6
0
ファイル: enum.py プロジェクト: k273811702/idascripts
def list(**type):
    """List all the enumerations within the database.

    Search type can be identified by providing a named argument.
    like = glob match
    regex = regular expression
    index = particular index
    identifier = particular id number
    pred = function predicate
    """
    res = __builtin__.list(iterate(**type))

    maxindex = max(__builtin__.map(idaapi.get_enum_idx, res))
    maxname = max(
        __builtin__.map(utils.compose(idaapi.get_enum_name, len), res))
    maxsize = max(__builtin__.map(size, res))
    cindex = math.ceil(math.log(maxindex or 1) / math.log(10))
    cmask = max(
        __builtin__.map(
            utils.compose(mask, math.log,
                          functools.partial(operator.mul, 1.0 / math.log(16)),
                          math.ceil), res) or [database.config.bits() / 4.0])

    for n in res:
        print("[{:{:d}d}] {:>{:d}s} & {:#<{:d}x} ({:d} members){:s}".format(
            idaapi.get_enum_idx(n), int(cindex), idaapi.get_enum_name(n),
            maxname, mask(n), int(cmask), len(__builtin__.list(members(n))),
            " // {:s}".format(comment(n)) if comment(n) else ''))
    return
コード例 #7
0
def list(**type):
    '''List all of the enumerations within the database that match the keyword specified by `type`.'''
    res = [item for item in iterate(**type)]

    maxindex = max(builtins.map(idaapi.get_enum_idx, res) if res else [1])
    maxname = max(
        builtins.map(utils.fcompose(idaapi.get_enum_name, len), res
                     ) if res else [0])
    maxsize = max(builtins.map(size, res) if res else [0])
    cindex = math.ceil(math.log(maxindex or 1) / math.log(10))
    try:
        cmask = max(
            builtins.map(
                utils.fcompose(
                    mask,
                    utils.fcondition(utils.fpartial(operator.eq, 0))
                    (utils.fconstant(1), utils.fidentity), math.
                    log, functools.partial(operator.mul, 1.0 /
                                           math.log(8)), math.ceil), res
            ) if res else [database.config.bits() / 4.0])
    except:
        cmask = 0

    for item in res:
        name = idaapi.get_enum_name(item)
        six.print_(
            u"[{:{:d}d}] {:>{:d}s} & {:<{:d}x} ({:d} members){:s}".format(
                idaapi.get_enum_idx(item), int(cindex), utils.string.of(name),
                maxname, mask(item), int(cmask),
                len(builtins.list(members(item))),
                u" // {:s}".format(comment(item)) if comment(item) else ''))
    return
コード例 #8
0
 def renaming_enum(self, id, is_enum, newname):
     extra = {}
     if is_enum:
         oldname = idaapi.get_enum_name(id)
     else:
         oldname = idaapi.get_enum_member_name(id)
     self._send_event(EnumRenamedEvent(oldname, newname, is_enum))
     return 0
コード例 #9
0
ファイル: YaToolIDATools.py プロジェクト: tmcmil/YaCo
def tid_is_enum(tid):
    # get_enum_name return name for struc or enum
    tid_name = idaapi.get_enum_name(tid)

    if idaapi.get_enum(tid_name) != idc.BADADDR:
        return True

    return False
コード例 #10
0
ファイル: YaToolIDAHooks.py プロジェクト: tmcmil/YaCo
    def rename(self, ea, new_name):
        """
        This function only records information about the element *before* it is renamed
        """
        if idaapi.is_member_id(ea):
            name = idaapi.get_member_fullname(ea)
        elif idaapi.get_struc(ea) is not None:
            name = idaapi.get_struc_name(ea)
        elif idaapi.get_enum_idx(ea) != idc.BADADDR:
            name = idaapi.get_enum_name(ea)
        elif idaapi.get_enum_idx(idaapi.get_enum_member_enum(ea)) != idc.BADADDR:
            # this is an enum member id
            enum_id = idaapi.get_enum_member_enum(ea)
            name = idaapi.get_enum_name(enum_id) + "." + idaapi.get_enum_member_name(ea)
        else:
            name = idc.Name(ea)

        hooks.current_rename_infos[ea] = name

        return 0
コード例 #11
0
ファイル: enum.py プロジェクト: OfficialMan/Sark
def _enum_member_error(err, eid, name, value, bitmask):
    """Format enum member error."""
    exception, msg = ENUM_ERROR_MAP[err]
    enum_name = idaapi.get_enum_name(eid)
    return exception(('add_enum_member(enum="{}", member="{}", value={}, bitmask=0x{:08X}) '
                      'failed: {}').format(
        enum_name,
        name,
        value,
        bitmask,
        msg
    ))
コード例 #12
0
ファイル: enumeration.py プロジェクト: arizvisa/idascripts
def list(**type):
    '''List all of the enumerations within the database that match the keyword specified by `type`.'''
    res = builtins.list(iterate(**type))

    maxindex = max(builtins.map(idaapi.get_enum_idx, res) or [1])
    maxname = max(builtins.map(utils.fcompose(idaapi.get_enum_name, len), res) or [0])
    maxsize = max(builtins.map(size, res) or [0])
    cindex = math.ceil(math.log(maxindex or 1)/math.log(10))
    try: cmask = max(builtins.map(utils.fcompose(mask, utils.fcondition(utils.fpartial(operator.eq, 0))(utils.fconstant(1), utils.fidentity), math.log, functools.partial(operator.mul, 1.0/math.log(8)), math.ceil), res) or [database.config.bits()/4.0])
    except: cmask = 0

    for n in res:
        name = idaapi.get_enum_name(n)
        six.print_(u"[{:{:d}d}] {:>{:d}s} & {:<{:d}x} ({:d} members){:s}".format(idaapi.get_enum_idx(n), int(cindex), utils.string.of(name), maxname, mask(n), int(cmask), len(builtins.list(members(n))), u" // {:s}".format(comment(n)) if comment(n) else ''))
    return
コード例 #13
0
def by(**type):
    '''Return the identifier for the first enumeration matching the keyword specified by `type`.'''
    searchstring = utils.string.kwargs(type)

    res = builtins.list(iterate(**type))
    if len(res) > 1:
        map(logging.info, (u"[{:d}] {:s} & {:#x} ({:d} members){:s}".format(
            idaapi.get_enum_idx(n), idaapi.get_enum_name(n), mask(n),
            len(builtins.list(members(n))),
            u" // {:s}".format(comment(n)) if comment(n) else '')
                           for i, n in enumerate(res)))
        logging.warn(
            u"{:s}.search({:s}) : Found {:d} matching results. Returning the first enumeration {:#x}."
            .format(__name__, searchstring, len(res), res[0]))

    res = next(iter(res), None)
    if res is None:
        raise E.SearchResultsError(
            u"{:s}.search({:s}) : Found 0 matching results.".format(
                __name__, searchstring))
    return res
コード例 #14
0
def by(**type):
    '''Return the identifier for the first enumeration matching the keyword specified by `type`.'''
    searchstring = utils.string.kwargs(type)

    listable = [item for item in iterate(**type)]
    if len(listable) > 1:
        messages = (u"[{:d}] {:s} & {:#x} ({:d} members){:s}".format(
            idaapi.get_enum_idx(item), idaapi.get_enum_name(item), mask(item),
            len(builtins.list(members(item))),
            u" // {:s}".format(comment(item)) if comment(item) else '')
                    for i, item in enumerate(listable))
        [logging.info(msg) for msg in messages]
        logging.warning(
            u"{:s}.search({:s}) : Found {:d} matching results. Returning the first enumeration {:#x}."
            .format(__name__, searchstring, len(listable), listable[0]))

    iterable = (item for item in listable)
    res = next(iterable, None)
    if res is None:
        raise E.SearchResultsError(
            u"{:s}.search({:s}) : Found 0 matching results.".format(
                __name__, searchstring))
    return res
コード例 #15
0
def name(enum):
    '''Return the name of the enumeration `enum`.'''
    eid = by(enum)
    res = idaapi.get_enum_name(eid)
    return utils.string.of(res)
コード例 #16
0
ファイル: enum.py プロジェクト: boogie1337/Sark
 def name(self):
     """Name of the enum"""
     return idaapi.get_enum_name(self.eid)
コード例 #17
0
 def deleting_enum(self, id):
     self._send_event(EnumDeletedEvent(idaapi.get_enum_name(id)))
     return 0
コード例 #18
0
def name(enum):
    '''Return the name of the enumeration `enum`.'''
    eid = by(enum)
    return idaapi.get_enum_name(eid)
コード例 #19
0
 def enum_bf_changed(self, id):
     bf_flag = 1 if idc.IsBitfield(id) else 0
     self._send_event(EnumBfChangedEvent(idaapi.get_enum_name(id), bf_flag))
     return 0
コード例 #20
0
ファイル: enumeration.py プロジェクト: arizvisa/idascripts
def by(**type):
    '''Return the identifier for the first enumeration matching the keyword specified by `type`.'''
    searchstring = utils.string.kwargs(type)

    res = builtins.list(iterate(**type))
    if len(res) > 1:
        map(logging.info, (u"[{:d}] {:s} & {:#x} ({:d} members){:s}".format(idaapi.get_enum_idx(n), idaapi.get_enum_name(n), mask(n), len(builtins.list(members(n))), u" // {:s}".format(comment(n)) if comment(n) else '') for i,n in enumerate(res)))
        logging.warn(u"{:s}.search({:s}) : Found {:d} matching results. Returning the first enumeration {:#x}.".format(__name__, searchstring, len(res), res[0]))

    res = next(iter(res), None)
    if res is None:
        raise E.SearchResultsError(u"{:s}.search({:s}) : Found 0 matching results.".format(__name__, searchstring))
    return res
コード例 #21
0
ファイル: enumeration.py プロジェクト: arizvisa/idascripts
def name(enum):
    '''Return the name of the enumeration `enum`.'''
    eid = by(enum)
    res = idaapi.get_enum_name(eid)
    return utils.string.of(res)
コード例 #22
0
ファイル: enum.py プロジェクト: stevemk14ebr/idascripts-2
def name(identifier, name=None):
    '''Given an enum id, get/set it's /name/'''
    if name is None:
        return idaapi.get_enum_name(identifier)
    return idaapi.set_enum_name(identifier, name)
コード例 #23
0
 def enum_cmt_changed(self, tid, repeatable_cmt):
     cmt = idaapi.get_enum_cmt(tid, repeatable_cmt)
     emname = idaapi.get_enum_name(tid)
     self._send_event(EnumCmtChangedEvent(emname, cmt, repeatable_cmt))
     return 0
コード例 #24
0
ファイル: hooks.py プロジェクト: snyiu100/IDAConnect
 def enum_renamed(self, tid):
     new_name = idaapi.get_enum_name(tid)
     self._send_event(EnumRenamedEvent(tid, new_name))
     return 0
コード例 #25
0
ファイル: enum.py プロジェクト: k273811702/idascripts
def name(enum):
    '''Return the name of the enumeration identified by ``enum``.'''
    eid = by(enum)
    return idaapi.get_enum_name(eid)