コード例 #1
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
コード例 #2
0
def rebase(info):
    functions, globals = map(utils.fcompose(sorted, list), (database.functions(), internal.netnode.alt.fiter(internal.comment.tagging.node())))

    p = ui.Progress()
    p.update(current=0, title=u"Rebasing tagcache...", min=0, max=len(functions)+len(globals))
    fcount = gcount = 0

    scount = info.size() + 1
    six.print_(u"{:s}.rebase({!s}) : Rebasing tagcache for {:d} segments.".format(__name__, utils.string.repr(info), scount))

    # for each segment
    p.open()
    for si in six.moves.range(scount):
        msg = u"Rebasing tagcache for segment {:d} of {:d} : {:#x} ({:+#x}) -> {:#x}".format(si, scount, info[si]._from, info[si].size, info[si].to)
        p.update(title=msg), six.print_(msg)

        # for each function (using target address because ida moved the netnodes for us)
        res = [n for n in functions if info[si].to <= n < info[si].to + info[si].size]
        for i, fn in __rebase_function(info[si]._from, info[si].to, info[si].size, iter(res)):
            text = u"Function {:d} of {:d} : {:#x}".format(i + fcount, len(functions), fn)
            p.update(value=sum((fcount, gcount, i)), text=text)
            ui.navigation.procedure(fn)
        fcount += len(res)

        # for each global
        res = [(ea, count) for ea, count in globals if info[si]._from <= ea < info[si]._from + info[si].size]
        for i, ea in __rebase_globals(info[si]._from, info[si].to, info[si].size, iter(res)):
            text = u"Global {:d} of {:d} : {:#x}".format(i + gcount, len(globals), ea)
            p.update(value=sum((fcount, gcount, i)), text=text)
            ui.navigation.analyze(ea)
        gcount += len(res)
    p.close()
コード例 #3
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
コード例 #4
0
ファイル: segment.py プロジェクト: perfectswpuboy1/ida-minsc
def list(**type):
    '''List all of the segments in the database that match the keyword specified by `type`.'''
    res = builtins.list(__iterate__(**type))

    maxindex = max(builtins.map(operator.attrgetter('index'), res) or [1])
    maxaddr = max(builtins.map(operator.attrgetter('endEA'), res) or [1])
    maxsize = max(builtins.map(operator.methodcaller('size'), res) or [1])
    maxname = max(
        builtins.map(utils.fcompose(idaapi.get_true_segm_name, len), res)
        or [1])
    cindex = math.ceil(math.log(maxindex or 1) / math.log(10))
    caddr = math.ceil(math.log(maxaddr or 1) / math.log(16))
    csize = math.ceil(math.log(maxsize or 1) / math.log(16))

    for seg in res:
        comment = idaapi.get_segment_cmt(seg, 0) or idaapi.get_segment_cmt(
            seg, 1)
        six.print_(
            u"[{:{:d}d}] {:#0{:d}x}<>{:#0{:d}x} : {:<+#{:d}x} : {:>{:d}s} : sel:{:04x} flags:{:02x}{:s}"
            .format(
                seg.index, int(cindex), seg.startEA, 2 + int(caddr), seg.endEA,
                2 + int(caddr), seg.size(), 3 + int(csize),
                utils.string.of(idaapi.get_true_segm_name(seg)),
                maxname, seg.sel, seg.flags, u"// {:s}".format(
                    utils.string.of(comment)) if comment else ''))
    return
コード例 #5
0
 def list(cls, enum):
     '''List all the members belonging to the enumeration identified by `enum`.'''
     # FIXME: make this consistent with every other .list using the matcher class
     eid = by(enum)
     res = builtins.list(cls.iterate(eid))
     maxindex = max(builtins.map(utils.first, enumerate(res)) or [1])
     maxvalue = max(builtins.map(utils.fcompose(member.value, "{:#x}".format, len), res) or [1])
     for i, mid in enumerate(res):
          six.print_(u"[{:d}] 0x{:>0{:d}x} {:s}".format(i, member.value(mid), maxvalue, member.name(mid)))
     return
コード例 #6
0
ファイル: enumeration.py プロジェクト: arizvisa/idascripts
 def list(cls, enum):
     '''List all the members belonging to the enumeration identified by `enum`.'''
     # FIXME: make this consistent with every other .list using the matcher class
     eid = by(enum)
     res = builtins.list(cls.iterate(eid))
     maxindex = max(builtins.map(utils.first, enumerate(res)) or [1])
     maxvalue = max(builtins.map(utils.fcompose(member.value, "{:#x}".format, len), res) or [1])
     for i, mid in enumerate(res):
          six.print_(u"[{:d}] 0x{:>0{:d}x} {:s}".format(i, member.value(mid), maxvalue, member.name(mid)))
     return
コード例 #7
0
 def list(cls, enum):
     '''List all the members belonging to the enumeration identified by `enum`.'''
     # FIXME: make this consistent with every other .list using the matcher class
     eid = by(enum)
     listable = [item for item in cls.iterate(eid)]
     maxindex = max(
         len("[{:d}]".format(index))
         for index, _ in enumerate(listable)) if listable else 1
     maxvalue = max(
         builtins.map(utils.fcompose(member.value, "{:#x}".format, len
                                     ), listable) if listable else [1])
     for i, mid in enumerate(listable):
         six.print_(u"{:<{:d}s} {:#0{:d}x} {:s}".format(
             "[{:d}]".format(i), maxindex, member.value(mid), 2 + maxvalue,
             member.name(mid)))
     return
コード例 #8
0
ファイル: segment.py プロジェクト: arizvisa/idascripts
def list(**type):
    '''List all of the segments in the database that match the keyword specified by `type`.'''
    res = builtins.list(__iterate__(**type))

    maxindex = max(builtins.map(operator.attrgetter('index'), res) or [1])
    maxaddr = max(builtins.map(operator.attrgetter('endEA'), res) or [1])
    maxsize = max(builtins.map(operator.methodcaller('size'), res) or [1])
    maxname = max(builtins.map(utils.fcompose(idaapi.get_true_segm_name,len), res) or [1])
    cindex = math.ceil(math.log(maxindex or 1)/math.log(10))
    caddr = math.ceil(math.log(maxaddr or 1)/math.log(16))
    csize = math.ceil(math.log(maxsize or 1)/math.log(16))

    for seg in res:
        comment = idaapi.get_segment_cmt(seg, 0) or idaapi.get_segment_cmt(seg, 1)
        six.print_(u"[{:{:d}d}] {:#0{:d}x}<>{:#0{:d}x} : {:<+#{:d}x} : {:>{:d}s} : sel:{:04x} flags:{:02x}{:s}".format(seg.index, int(cindex), seg.startEA, 2+int(caddr), seg.endEA, 2+int(caddr), seg.size(), 3+int(csize), utils.string.of(idaapi.get_true_segm_name(seg)), maxname, seg.sel, seg.flags, u"// {:s}".format(utils.string.of(comment)) if comment else ''))
    return
コード例 #9
0
import functools, operator, itertools, types
import os, logging
import math, re, fnmatch

import database
import ui, internal
from internal import utils, interface, exceptions as E

import idaapi

## enumerating
__matcher__ = utils.matcher()
__matcher__.boolean(
    'regex', re.search,
    utils.fcompose(
        idaapi.get_segm_name if hasattr(idaapi, 'get_segm_name') else
        idaapi.get_true_segm_name, utils.string.of))
__matcher__.attribute('index', 'index')
__matcher__.attribute('identifier',
                      'name'), __matcher__.attribute('id', 'name')
__matcher__.attribute('selector', 'sel')
__matcher__.boolean(
    'like', lambda v, n: fnmatch.fnmatch(n, v),
    utils.fcompose(
        idaapi.get_segm_name if hasattr(idaapi, 'get_segm_name') else
        idaapi.get_true_segm_name, utils.string.of))
__matcher__.boolean(
    'name', operator.eq,
    utils.fcompose(
        idaapi.get_segm_name if hasattr(idaapi, 'get_segm_name') else
        idaapi.get_true_segm_name, utils.string.of))
コード例 #10
0
            member.comment(item, repeatable=True)
            or member.comment(item, repeatable=False))
           for item in members.iterate(eid)]
    aligned = max([len(item) for item, _, _, _ in res] if res else [0])
    return "<type 'enum'> {:s}{:s}\n".format(
        name(eid), " // {:s}".format(cmt) if cmt else '') + '\n'.join(
            "[{:d}] {:<{align}s} : {:#0{width}x} & {:#0{width}x}".format(
                i, name, value, bmask, width=w + 2, align=aligned) +
            (" // {:s}".format(comment) if comment else '')
            for i, (name, value, bmask, comment) in enumerate(res))


__matcher__ = utils.matcher()
__matcher__.attribute('index', idaapi.get_enum_idx)
__matcher__.boolean('regex', re.search,
                    utils.fcompose(idaapi.get_enum_name, utils.string.of))
__matcher__.boolean('like', lambda v, n: fnmatch.fnmatch(n, v),
                    utils.fcompose(idaapi.get_enum_name, utils.string.of))
__matcher__.boolean('name', operator.eq,
                    utils.fcompose(idaapi.get_enum_name, utils.string.of))
__matcher__.attribute('id')
__matcher__.attribute('identifier')
__matcher__.predicate('pred')
__matcher__.predicate('predicate')


def __iterate__():
    '''Yield the identifier of each enumeration within the database.'''
    for item in range(idaapi.get_enum_qty()):
        yield idaapi.getn_enum(item)
    return
コード例 #11
0
    '''Return the bitmask for the enumeration `enum`.'''
    eid = by(enum)
    res = size(eid)
    return 2**res-1 if res > 0 else idaapi.BADADDR

def repr(enum):
    '''Return a printable summary of the enumeration `enum`.'''
    eid = by(enum)
    w = size(eid)*2
    res = [(member.name(n), member.value(n), member.mask(n), member.comment(n)) for n in members.iterate(eid)]
    aligned = max([len(n) for n, _, _, _ in res] or [0])
    return "<type 'enum'> {:s}\n".format(name(eid)) + '\n'.join(("[{:d}] {:<{align}s} : {:#0{width}x} & {:#0{width}x}".format(i, name, value, bmask, width=w+2, align=aligned)+((' // '+comment) if comment else '') for i,(name,value,bmask,comment) in enumerate(res)))   # XXX

__matcher__ = utils.matcher()
__matcher__.attribute('index', idaapi.get_enum_idx)
__matcher__.boolean('regex', re.search, utils.fcompose(idaapi.get_enum_name, utils.string.of))
__matcher__.boolean('like', lambda v, n: fnmatch.fnmatch(n, v), utils.fcompose(idaapi.get_enum_name, utils.string.of))
__matcher__.boolean('name', operator.eq, utils.fcompose(idaapi.get_enum_name, utils.string.of))
__matcher__.attribute('id')
__matcher__.attribute('identifier')
__matcher__.predicate('pred')
__matcher__.predicate('predicate')

def __iterate__():
    '''Yield the identifier of each enumeration within the database.'''
    for n in six.moves.range(idaapi.get_enum_qty()):
        yield idaapi.getn_enum(n)
    return

@utils.string.decorate_arguments('regex', 'like', 'name')
def iterate(**type):
コード例 #12
0
import functools, operator, itertools, types
import os, logging
import math, re, fnmatch

import database
import ui, internal
from internal import utils, interface, exceptions as E

import idaapi

## enumerating
__matcher__ = utils.matcher()
__matcher__.combinator(
    'regex',
    utils.fcompose(utils.fpartial(re.compile, flags=re.IGNORECASE),
                   operator.attrgetter('match')), idaapi.get_segm_name
    if hasattr(idaapi, 'get_segm_name') else idaapi.get_true_segm_name,
    utils.string.of)
__matcher__.attribute('index', 'index')
__matcher__.attribute('identifier',
                      'name'), __matcher__.attribute('id', 'name')
__matcher__.attribute('selector', 'sel')
__matcher__.combinator(
    'like',
    utils.fcompose(fnmatch.translate,
                   utils.fpartial(re.compile, flags=re.IGNORECASE),
                   operator.attrgetter('match')), idaapi.get_segm_name
    if hasattr(idaapi, 'get_segm_name') else idaapi.get_true_segm_name,
    utils.string.of)
__matcher__.boolean(
    'name', lambda name, item: name.lower() == item.lower(),
コード例 #13
0
ファイル: enumeration.py プロジェクト: arizvisa/idascripts
    '''Return the bitmask for the enumeration `enum`.'''
    eid = by(enum)
    res = size(eid)
    return 2**res-1 if res > 0 else idaapi.BADADDR

def repr(enum):
    '''Return a printable summary of the enumeration `enum`.'''
    eid = by(enum)
    w = size(eid)*2
    res = [(member.name(n), member.value(n), member.mask(n), member.comment(n)) for n in members.iterate(eid)]
    aligned = max([len(n) for n, _, _, _ in res] or [0])
    return "<type 'enum'> {:s}\n".format(name(eid)) + '\n'.join(("[{:d}] {:<{align}s} : {:#0{width}x} & {:#0{width}x}".format(i, name, value, bmask, width=w+2, align=aligned)+((' // '+comment) if comment else '') for i,(name,value,bmask,comment) in enumerate(res)))   # XXX

__matcher__ = utils.matcher()
__matcher__.attribute('index', idaapi.get_enum_idx)
__matcher__.boolean('regex', re.search, utils.fcompose(idaapi.get_enum_name, utils.string.of))
__matcher__.boolean('like', lambda v, n: fnmatch.fnmatch(n, v), utils.fcompose(idaapi.get_enum_name, utils.string.of))
__matcher__.boolean('name', operator.eq, utils.fcompose(idaapi.get_enum_name, utils.string.of))
__matcher__.attribute('id')
__matcher__.attribute('identifier')
__matcher__.predicate('pred')
__matcher__.predicate('predicate')

def __iterate__():
    '''Yield the identifier of each enumeration within the database.'''
    for n in six.moves.range(idaapi.get_enum_qty()):
        yield idaapi.getn_enum(n)
    return

@utils.string.decorate_arguments('regex', 'like', 'name')
def iterate(**type):
コード例 #14
0
ファイル: segment.py プロジェクト: perfectswpuboy1/ida-minsc
from six.moves import builtins

import functools, operator, itertools, types
import os, logging
import math, re, fnmatch

import database
import ui, internal
from internal import utils, interface, exceptions as E

import idaapi

## enumerating
__matcher__ = utils.matcher()
__matcher__.boolean('regex', re.search,
                    utils.fcompose(idaapi.get_true_segm_name, utils.string.of))
__matcher__.attribute('index', 'index')
__matcher__.attribute('identifier',
                      'name'), __matcher__.attribute('id', 'name')
__matcher__.attribute('selector', 'sel')
__matcher__.boolean('like', lambda v, n: fnmatch.fnmatch(n, v),
                    utils.fcompose(idaapi.get_true_segm_name, utils.string.of))
__matcher__.boolean('name', operator.eq,
                    utils.fcompose(idaapi.get_true_segm_name, utils.string.of))
__matcher__.boolean('greater', operator.le,
                    'endEA'), __matcher__.boolean('gt', operator.lt, 'endEA')
__matcher__.boolean('less', operator.ge,
                    'startEA'), __matcher__.boolean('lt', operator.gt,
                                                    'startEA')
__matcher__.predicate('predicate'), __matcher__.predicate('pred')