本文整理汇总了Python中miasm2.core.interval.interval函数的典型用法代码示例。如果您正苦于以下问题:Python interval函数的具体用法?Python interval怎么用?Python interval使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了interval函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
}
示例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)
示例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
示例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)
示例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
示例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
示例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)])
示例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)])
示例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
示例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
示例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)])
示例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)
示例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
示例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)
示例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,
)