• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python interval.interval函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中miasm2.core.interval.interval函数的典型用法代码示例。如果您正苦于以下问题:Python interval函数的具体用法?Python interval怎么用?Python interval使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了interval函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: __init__

    def __init__(self, ir_arch, bs=None):
        """Initialise a JitCore instance.
        @ir_arch: ir instance for current architecture
        @bs: bitstream
        """

        self.ir_arch = ir_arch
        self.bs = bs
        self.known_blocs = {}
        self.lbl2jitbloc = BoundedDict(self.jitted_block_max_size,
                                       delete_cb=self.jitted_block_delete_cb)
        self.lbl2bloc = {}
        self.log_mn = False
        self.log_regs = False
        self.log_newbloc = False
        self.segm_to_do = set()
        self.job_done = set()
        self.jitcount = 0
        self.addr2obj = {}
        self.addr2objref = {}
        self.blocs_mem_interval = interval()
        self.disasm_cb = None
        self.split_dis = set()
        self.addr_mod = interval()

        self.options = {"jit_maxline": 50  # Maximum number of line jitted
                        }
开发者ID:CaineQT,项目名称:miasm,代码行数:27,代码来源:jitcore.py


示例2: __init__

    def __init__(self, ir_arch, bs=None):
        """Initialise a JitCore instance.
        @ir_arch: ir instance for current architecture
        @bs: bitstream
        """

        self.ir_arch = ir_arch
        self.bs = bs
        self.known_blocs = {}
        self.lbl2jitbloc = BoundedDict(self.jitted_block_max_size,
                                       delete_cb=self.jitted_block_delete_cb)
        self.lbl2bloc = {}
        self.log_mn = False
        self.log_regs = False
        self.log_newbloc = False
        self.segm_to_do = set()
        self.job_done = set()
        self.jitcount = 0
        self.addr2obj = {}
        self.addr2objref = {}
        self.blocs_mem_interval = interval()
        self.disasm_cb = None
        self.split_dis = set()
        self.addr_mod = interval()

        self.options = {"jit_maxline": 50  # Maximum number of line jitted
                        }

        self.mdis = asmbloc.disasmEngine(ir_arch.arch, ir_arch.attrib, bs,
                                         lines_wd=self.options["jit_maxline"],
                                         symbol_pool=ir_arch.symbol_pool,
                                         follow_call=False,
                                         dontdis_retcall=False,
                                         split_dis=self.split_dis,
                                         dis_bloc_callback=self.disasm_cb)
开发者ID:Junraa,项目名称:miasm,代码行数:35,代码来源:jitcore.py


示例3: asm_resolve_final

def asm_resolve_final(mnemo, blocks, symbol_pool, dst_interval=None):
    """Resolve and assemble @blocks using @symbol_pool into interval
    @dst_interval"""

    sanity_check_blocks(blocks)

    guess_blocks_size(mnemo, blocks)
    blockChains = group_constrained_blocks(symbol_pool, blocks)
    resolved_blockChains = resolve_symbol(blockChains, symbol_pool, dst_interval)

    asmbloc_final(mnemo, blocks, resolved_blockChains, symbol_pool)
    patches = {}
    output_interval = interval()

    for block in blocks:
        offset = block.label.offset
        for instr in block.lines:
            if not instr.data:
                # Empty line
                continue
            assert len(instr.data) == instr.l
            patches[offset] = instr.data
            instruction_interval = interval([(offset, offset + instr.l-1)])
            if not (instruction_interval & output_interval).empty:
                raise RuntimeError("overlapping bytes %X" % int(offset))
            instr.offset = offset
            offset += instr.l
    return patches
开发者ID:avelik,项目名称:miasm,代码行数:28,代码来源:asmbloc.py


示例4: _range_shift_uniq

    def _range_shift_uniq(self, x_min, x_max, shift, op):
        """Bounds interval for x @op @shift with
         - x of size self.size
         - @x_min <= x <= @x_max
         - operations are considered unsigned
         - shift <= self.size
        """
        assert shift <= self.size
        # Shift operations are monotonic, and overflow results in 0
        max_bound = self.mask

        if op == "<<":
            obtain_max = x_max << shift
            if obtain_max > max_bound:
                # Overflow at least on max, best-effort
                # result '0' often happen, include it
                return interval([(0, 0), ((1 << shift) - 1, max_bound)])
            else:
                return interval([(x_min << shift, obtain_max)])
        elif op == ">>":
            return interval([((x_min >> shift) & max_bound,
                              (x_max >> shift) & max_bound)])
        elif op == "a>>":
            # The Miasm2 version (Expr or ModInt) could have been used, but
            # introduce unnecessary dependencies for this module
            # Python >> is the arithmetic one
            ashr = lambda x, y: self._signed2unsigned(self._unsigned2signed(x) >> y)
            end_min, end_max = ashr(x_min, shift), ashr(x_max, shift)
            end_min, end_max = min(end_min, end_max), max(end_min, end_max)
            return interval([(end_min, end_max)])
        else:
            raise ValueError("%s is not a shifter" % op)
开发者ID:carolineLe,项目名称:miasm,代码行数:32,代码来源:modularintervals.py


示例5: blocks_to_memrange

    def blocks_to_memrange(self, blocks):
        """Return an interval instance standing for blocks addresses
        @blocks: list of AsmBlock instances
        """

        mem_range = interval()

        for block in blocks:
            mem_range += interval([(block.ad_min, block.ad_max - 1)])

        return mem_range
开发者ID:commial,项目名称:miasm,代码行数:11,代码来源:jitcore.py


示例6: blocs2memrange

    def blocs2memrange(self, blocs):
        """Return an interval instance standing for blocs addresses
        @blocs: list of asm_bloc instances
        """

        mem_range = interval()

        for b in blocs:
            mem_range += interval([(b.ad_min, b.ad_max - 1)])

        return mem_range
开发者ID:jbcayrou,项目名称:miasm,代码行数:11,代码来源:jitcore.py


示例7: _range_mul

 def _range_mul(self, x_min, x_max, y_min, y_max):
     """Interval bounds for x * y, with
      - x, y of size self.size
      - @x_min <= x <= @x_max
      - @y_min <= y <= @y_max
      - operations are considered unsigned
     This is a naive version, going to TOP on overflow"""
     max_bound = self.mask
     if y_max * x_max > max_bound:
         return interval([(0, max_bound)])
     else:
         return interval([(x_min * y_min, x_max * y_max)])
开发者ID:carolineLe,项目名称:miasm,代码行数:12,代码来源:modularintervals.py


示例8: _range_minus_uniq

 def _range_minus_uniq(self, x_min, x_max):
     """Bounds interval for -x, with
      - x of size self.size
      - @x_min <= x <= @x_max
      - operations are considered unsigned
     From Hacker's Delight: Chapter 4
     """
     max_bound = self.mask
     if (x_min == 0 and x_max != 0):
         # HD returns 0, max_bound; see _range_add
         return interval([(0, 0), ((- x_max) & max_bound, max_bound)])
     else:
         return interval([((- x_max) & max_bound, (- x_min) & max_bound)])
开发者ID:carolineLe,项目名称:miasm,代码行数:13,代码来源:modularintervals.py


示例9: get_blockchains_address_interval

def get_blockchains_address_interval(blockChains, dst_interval):
    """Compute the interval used by the pinned @blockChains
    Check if the placed chains are in the @dst_interval"""

    allocated_interval = interval()
    for chain in blockChains:
        if not chain.pinned:
            continue
        chain_interval = interval([(chain.offset_min, chain.offset_max-1)])
        if chain_interval not in dst_interval:
            raise ValueError('Chain placed out of destination interval')
        allocated_interval += chain_interval
    return allocated_interval
开发者ID:avelik,项目名称:miasm,代码行数:13,代码来源:asmbloc.py


示例10: mmap

    def mmap(self, addr, len_, prot, flags, fd, off, vmmngr):
        """Stub for 'mmap' syscall

        'mmap2' must be implemented by calling this function with off * 4096
        """
        if addr == 0:
            addr = self.mmap_current
            self.mmap_current += (len_ + 0x1000) & ~0xfff

        all_mem = vmmngr.get_all_memory()
        mapped = interval([(start, start + info["size"] - 1)
                           for start, info in all_mem.iteritems()])

        MAP_FIXED = 0x10
        if flags & MAP_FIXED:
            # Alloc missing and override
            missing = interval([(addr, addr + len_ - 1)]) - mapped
            for start, stop in missing:
                vmmngr.add_memory_page(start, PAGE_READ|PAGE_WRITE,
                                          "\x00" * (stop - start + 1),
                                          "mmap allocated")
        else:
            # Find first candidate segment nearby addr
            for start, stop in mapped:
                if stop < addr:
                    continue
                rounded = (stop + 1 + 0x1000) & ~0xfff
                if (interval([(rounded, rounded + len_)]) & mapped).empty:
                    addr = rounded
                    break
            else:
                assert (interval([(addr, addr + len_)]) & mapped).empty

            vmmngr.add_memory_page(addr, PAGE_READ|PAGE_WRITE, "\x00" * len_,
                                      "mmap allocated")


        if fd == 0xffffffff:
            if off != 0:
                raise RuntimeError("Not implemented")
            data = "\x00" * len_
        else:
            fdesc = self.file_descriptors[fd]
            cur_pos = fdesc.tell()
            fdesc.seek(off)
            data = fdesc.read(len_)
            fdesc.seek(cur_pos)

        vmmngr.set_mem(addr, data)
        return addr
开发者ID:commial,项目名称:miasm,代码行数:50,代码来源:environment.py


示例11: _range_mod_uniq

 def _range_mod_uniq(self, x_min, x_max, mod):
     """Interval bounds for x % @mod, with
      - x, @mod of size self.size
      - @x_min <= x <= @x_max
      - operations are considered unsigned
     """
     if (x_max - x_min) >= mod:
         return interval([(0, mod - 1)])
     x_max = x_max % mod
     x_min = x_min % mod
     if x_max < x_min:
         return interval([(0, x_max), (x_min, mod - 1)])
     else:
         return interval([(x_min, x_max)])
开发者ID:carolineLe,项目名称:miasm,代码行数:14,代码来源:modularintervals.py


示例12: _interval_shift

 def _interval_shift(self, operation, shifter):
     """Apply the shifting operation @operation with a shifting
     ModularIntervals @shifter on the current instance"""
     # Work on a copy of shifter intervals
     shifter = interval(shifter.intervals)
     if (shifter.hull()[1] >= self.size):
         shifter += interval([(self.size, self.size)])
     shifter &= interval([(0, self.size)])
     ret = interval()
     for shift_range in shifter:
         for shift in xrange(shift_range[0], shift_range[1] + 1):
             for x_min, x_max in self.intervals:
                 ret += self._range_shift_uniq(x_min, x_max, shift, operation)
     return self.__class__(self.size, ret)
开发者ID:carolineLe,项目名称:miasm,代码行数:14,代码来源:modularintervals.py


示例13: retrieve_stack_accesses

def retrieve_stack_accesses(ir_arch_a, ssa):
    """
    Walk the ssa graph and find stack based variables.
    Return a dictionnary linking stack base address to its size/name
    @ir_arch_a: ira instance
    @ssa: SSADiGraph instance
    """
    stack_vars = set()
    for block in ssa.graph.blocks.itervalues():
        for assignblk in block:
            for dst, src in assignblk.iteritems():
                stack_vars.update(get_stack_accesses(ir_arch_a, dst))
                stack_vars.update(get_stack_accesses(ir_arch_a, src))
    stack_vars = filter(lambda expr: check_expr_below_stack(ir_arch_a, expr), stack_vars)

    base_to_var = {}
    for var in stack_vars:
        base_to_var.setdefault(var.ptr, set()).add(var)


    base_to_interval = {}
    for addr, vars in base_to_var.iteritems():
        var_interval = interval()
        for var in vars:
            offset = expr_simp(addr - ir_arch_a.sp)
            if not offset.is_int():
                # skip non linear stack offset
                continue

            start = int(offset)
            stop = int(expr_simp(offset + ExprInt(var.size / 8, offset.size)))
            mem = interval([(start, stop-1)])
            var_interval += mem
        base_to_interval[addr] = var_interval
    if not base_to_interval:
        return {}
    # Check if not intervals overlap
    _, tmp = base_to_interval.popitem()
    while base_to_interval:
        addr, mem = base_to_interval.popitem()
        assert (tmp & mem).empty
        tmp += mem

    base_to_info = {}
    for addr, vars in base_to_var.iteritems():
        name = "var_%d" % (len(base_to_info))
        size = max([var.size for var in vars])
        base_to_info[addr] = size, name
    return base_to_info
开发者ID:commial,项目名称:miasm,代码行数:49,代码来源:data_flow.py


示例14: add_block_to_mem_interval

    def add_block_to_mem_interval(self, vm, block):
        "Update vm to include block addresses in its memory range"
        self.blocks_mem_interval += interval([(block.ad_min, block.ad_max - 1)])

        vm.reset_code_bloc_pool()
        for a, b in self.blocks_mem_interval:
            vm.add_code_bloc(a, b + 1)
开发者ID:commial,项目名称:miasm,代码行数:7,代码来源:jitcore.py


示例15: __init__

    def __init__(self, ir_arch, bin_stream):
        """Initialise a JitCore instance.
        @ir_arch: ir instance for current architecture
        @bin_stream: bin_stream instance
        """
        # Arch related
        self.ir_arch = ir_arch
        self.ircfg = self.ir_arch.new_ircfg()
        self.arch_name = "%s%s" % (self.ir_arch.arch.name, self.ir_arch.attrib)

        # Structures for block tracking
        self.offset_to_jitted_func = BoundedDict(self.jitted_block_max_size,
                                       delete_cb=self.jitted_block_delete_cb)
        self.loc_key_to_block = {}
        self.blocks_mem_interval = interval()

        # Logging & options
        self.log_mn = False
        self.log_regs = False
        self.log_newbloc = False
        self.options = {"jit_maxline": 50,  # Maximum number of line jitted
                        "max_exec_per_call": 0 # 0 means no limit
                        }

        # Disassembly Engine
        self.split_dis = set()
        self.mdis = disasmEngine(
            ir_arch.arch, ir_arch.attrib, bin_stream,
            lines_wd=self.options["jit_maxline"],
            loc_db=ir_arch.loc_db,
            follow_call=False,
            dontdis_retcall=False,
            split_dis=self.split_dis,
        )
开发者ID:commial,项目名称:miasm,代码行数:34,代码来源:jitcore.py


示例16: vm_load_elf

def vm_load_elf(vm, fdata, **kargs):
    """
    Very dirty elf loader
    TODO XXX: implement real loader
    """
    #log.setLevel(logging.DEBUG)
    e = elf_init.ELF(fdata, **kargs)
    i = interval()
    all_data = {}
    for p in e.ph.phlist:
        if p.ph.type != 1:
            continue
        log.debug('0x%x 0x%x 0x%x 0x%x', p.ph.vaddr, p.ph.memsz, p.ph.offset,
                  p.ph.filesz)
        data_o = e._content[p.ph.offset:p.ph.offset + p.ph.filesz]
        addr_o = p.ph.vaddr
        a_addr = addr_o & ~0xFFF
        b_addr = addr_o + max(p.ph.memsz, p.ph.filesz)
        b_addr = (b_addr + 0xFFF) & ~0xFFF
        all_data[addr_o] = data_o
        # -2: Trick to avoid merging 2 consecutive pages
        i += [(a_addr, b_addr-2)]
    for a, b in i.intervals:
        #print hex(a), hex(b)
        vm.add_memory_page(a, PAGE_READ | PAGE_WRITE, "\x00"*(b+2-a))

    #vm.dump_memory_page_pool()

    for r_vaddr, data in all_data.items():
        vm.set_mem(r_vaddr, data)
    return e
开发者ID:AmesianX,项目名称:miasm,代码行数:31,代码来源:elf.py


示例17: updt_automod_code

 def updt_automod_code(self, vm):
     """Remove code jitted in range self.addr_mod
     @vm: VmMngr instance
     """
     for addr_start, addr_stop in self.addr_mod:
         self.del_bloc_in_range(addr_start, addr_stop + 1)
     self.__updt_jitcode_mem_range(vm)
     self.addr_mod = interval()
开发者ID:CaineQT,项目名称:miasm,代码行数:8,代码来源:jitcore.py


示例18: resolve_symbol

def resolve_symbol(blockChains, symbol_pool, dst_interval=None):
    """Place @blockChains in the @dst_interval"""

    log_asmbloc.info('resolve_symbol')
    if dst_interval is None:
        dst_interval = interval([(0, 0xFFFFFFFFFFFFFFFF)])

    forbidden_interval = interval(
        [(-1, 0xFFFFFFFFFFFFFFFF + 1)]) - dst_interval
    allocated_interval = get_blockchains_address_interval(blockChains,
                                                          dst_interval)
    log_asmbloc.debug('allocated interval: %s', allocated_interval)

    pinned_chains = [chain for chain in blockChains if chain.pinned]

    # Add wedge in forbidden intervals
    for start, stop in forbidden_interval.intervals:
        wedge = BlockChainWedge(
            symbol_pool, offset=start, size=stop + 1 - start)
        pinned_chains.append(wedge)

    # Try to place bigger blockChains first
    pinned_chains.sort(key=lambda x: x.offset_min)
    blockChains.sort(key=lambda x: -x.max_size)

    fixed_chains = list(pinned_chains)

    log_asmbloc.debug("place chains")
    for chain in blockChains:
        if chain.pinned:
            continue
        fixed = False
        for i in xrange(1, len(fixed_chains)):
            prev_chain = fixed_chains[i - 1]
            next_chain = fixed_chains[i]

            if prev_chain.offset_max + chain.max_size < next_chain.offset_min:
                new_chains = prev_chain.merge(chain)
                fixed_chains[i - 1:i] = new_chains
                fixed = True
                break
        if not fixed:
            raise RuntimeError('Cannot find enough space to place blocks')

    return [chain for chain in fixed_chains if isinstance(chain, BlockChain)]
开发者ID:mattermon,项目名称:miasm,代码行数:45,代码来源:asmbloc.py


示例19: brk

    def brk(self, addr, vmmngr):
        """Stub for 'brk' syscall"""
        if addr == 0:
            addr = self.brk_current
        else:
            all_mem = vmmngr.get_all_memory()
            mapped = interval([(start, start + info["size"] - 1)
                               for start, info in all_mem.iteritems()])

            # Alloc missing and override
            missing = interval([(self.brk_current, addr)]) - mapped
            for start, stop in missing:
                vmmngr.add_memory_page(start, PAGE_READ|PAGE_WRITE,
                                       "\x00" * (stop - start + 1),
                                       "BRK")

            self.brk_current = addr
        return addr
开发者ID:commial,项目名称:miasm,代码行数:18,代码来源:environment.py


示例20: ret_func

 def ret_func(self, target):
     if isinstance(target, (int, long)):
         target = ModularIntervals(self.size, interval([(target, target)]))
     if not isinstance(target, ModularIntervals):
         raise TypeError("Unsupported operation with %s" % target.__class__)
     if target.size != self.size:
         raise TypeError("Size are not the same: %s vs %s" % (self.size,
                                                              target.size))
     return func(self, target)
开发者ID:carolineLe,项目名称:miasm,代码行数:9,代码来源:modularintervals.py



注:本文中的miasm2.core.interval.interval函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python parse_asm.parse_txt函数代码示例发布时间:2022-05-27
下一篇:
Python graph.DiGraph类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap