本文整理汇总了Python中miasm2.ir.translators.Translator类的典型用法代码示例。如果您正苦于以下问题:Python Translator类的具体用法?Python Translator怎么用?Python Translator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Translator类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, expr):
"@expr: Expr instance"
# Init
self.languages = list(Translator.available_languages())
self.expr = expr
# Initial translation
text = Translator.to_language(self.languages[0]).from_expr(self.expr)
# Create the Form
idaapi.Form.__init__(self, r"""STARTITEM 0
Python Expression
{FormChangeCb}
<Language:{cbLanguage}>
<Translation:{result}>
""", {
'result': idaapi.Form.MultiLineTextControl(text=text,
flags=translatorForm.flags),
'cbLanguage': idaapi.Form.DropdownListControl(
items=self.languages,
readonly=True,
selval=0),
'FormChangeCb': idaapi.Form.FormChangeCb(self.OnFormChange),
})
开发者ID:chubbymaggie,项目名称:miasm,代码行数:25,代码来源:utils.py
示例2: emul
def emul(self, ctx=None, step=False):
# Init
ctx_init = self._ira.arch.regs.regs_init
if ctx is not None:
ctx_init.update(ctx)
solver = z3.Solver()
symb_exec = SymbolicExecutionEngine(self._ira, ctx_init)
history = self.history[::-1]
history_size = len(history)
translator = Translator.to_language("z3")
size = self._ira.IRDst.size
for hist_nb, label in enumerate(history, 1):
if hist_nb == history_size and label == self.initial_state.label:
line_nb = self.initial_state.line_nb
else:
line_nb = None
irb = self.irblock_slice(self._ira.blocks[label], line_nb)
# Emul the block and get back destination
dst = symb_exec.emulbloc(irb, step=step)
# Add constraint
if hist_nb < history_size:
next_label = history[hist_nb]
expected = symb_exec.eval_expr(m2_expr.ExprId(next_label,
size))
solver.add(
self._gen_path_constraints(translator, dst, expected))
# Save the solver
self._solver = solver
# Return only inputs values (others could be wrongs)
return {element: symb_exec.eval_expr(element)
for element in self.inputs}
开发者ID:carolineLe,项目名称:miasm,代码行数:35,代码来源:depgraph.py
示例3: test_ExprOp_toC
def test_ExprOp_toC(self):
from miasm2.expression.expression import ExprInt32, ExprOp
from miasm2.ir.translators.C import Translator
args = [ExprInt32(i) for i in xrange(9)]
translator = Translator.to_language("C")
# Unary operators
self.translationTest(
ExprOp('parity', *args[:1]), r'parity(0x0&0xffffffff)')
self.translationTest(
ExprOp('!', *args[:1]), r'(~ 0x0)&0xffffffff')
self.translationTest(
ExprOp('hex2bcd', *args[:1]), r'hex2bcd_32(0x0)')
self.translationTest(ExprOp('fabs', *args[:1]), r'fabs(0x0)')
self.assertRaises(NotImplementedError, translator.from_expr,
ExprOp('X', *args[:1]))
# Binary operators
self.translationTest(
ExprOp('==', *args[:2]), r'(((0x0&0xffffffff) == (0x1&0xffffffff))?1:0)')
self.translationTest(
ExprOp('%', *args[:2]), r'(((0x0&0xffffffff)%(0x1&0xffffffff))&0xffffffff)')
self.translationTest(
ExprOp('-', *args[:2]), r'(((0x0&0xffffffff) - (0x1&0xffffffff))&0xffffffff)')
self.translationTest(
ExprOp('bsr', *args[:1]), r'x86_bsr(0x0, 0x20)')
self.translationTest(
ExprOp('cpuid0', *args[:2]), r'cpuid0(0x0, 0x1)')
self.translationTest(
ExprOp('fcom0', *args[:2]), r'fcom0(0x0, 0x1)')
self.translationTest(
ExprOp('fadd', *args[:2]), r'fadd(0x0, 0x1)')
self.translationTest(
ExprOp('segm', *args[:2]), r'segm2addr(jitcpu, 0x0, 0x1)')
self.translationTest(
ExprOp('imod', *args[:2]), r'imod32((vm_cpu_t*)jitcpu->cpu, 0x0, 0x1)')
self.translationTest(
ExprOp('bcdadd', *args[:2]), r'bcdadd_32(0x0, 0x1)')
self.assertRaises(NotImplementedError, translator.from_expr,
ExprOp('X', *args[:2]))
# Ternary operators
self.translationTest(
ExprOp('div8', *args[:3]), r'(div_op(32, 0x0, 0x1, 0x2) &0xffffffff)')
# Other cases
self.translationTest(
ExprOp('+', *args[:3]), r'(((0x0&0xffffffff)+(0x1&0xffffffff)+(0x2&0xffffffff))&0xffffffff)')
self.assertRaises(NotImplementedError, translator.from_expr,
ExprOp('X', *args[:3]))
开发者ID:CaineQT,项目名称:miasm,代码行数:51,代码来源:ir2C.py
示例4: __init__
def __init__(self, machine, produce_solution=True, **kwargs):
"""Init a DSEPathConstraint
@machine: Machine of the targeted architecture instance
@produce_solution: (optional) if set, new solutions will be computed"""
super(DSEPathConstraint, self).__init__(machine, **kwargs)
# Dependency check
assert z3 is not None
# Init PathConstraint specifics structures
self.produce_solution = produce_solution
self.cur_solver = z3.Solver()
self.new_solutions = {} # destination -> set of model
self.z3_trans = Translator.to_language("z3")
开发者ID:carolineLe,项目名称:miasm,代码行数:14,代码来源:dse.py
示例5: OnFormChange
def OnFormChange(self, fid):
if fid == self.cbLanguage.id:
# Display the Field (may be hide)
self.ShowField(self.result, True)
# Translate the expression
dest_lang = self.languages[self.GetControlValue(self.cbLanguage)]
try:
text = Translator.to_language(dest_lang).from_expr(self.expr)
except Exception, error:
self.ShowField(self.result, False)
return -1
# Update the form
self.SetControlValue(self.result,
idaapi.textctrl_info_t(text=str(text),
flags=translatorForm.flags))
开发者ID:chubbymaggie,项目名称:miasm,代码行数:17,代码来源:utils.py
示例6: __init__
def __init__(self, machine, produce_solution=PRODUCE_SOLUTION_CODE_COV,
known_solutions=None,
**kwargs):
"""Init a DSEPathConstraint
@machine: Machine of the targeted architecture instance
@produce_solution: (optional) if set, new solutions will be computed"""
super(DSEPathConstraint, self).__init__(machine, **kwargs)
# Dependency check
assert z3 is not None
# Init PathConstraint specifics structures
self.cur_solver = z3.Solver()
self.new_solutions = {} # solution identifier -> solution's model
self._known_solutions = set() # set of solution identifiers
self.z3_trans = Translator.to_language("z3")
self._produce_solution_strategy = produce_solution
self._previous_addr = None
self._history = None
if produce_solution == self.PRODUCE_SOLUTION_PATH_COV:
self._history = [] # List of addresses in the current path
开发者ID:guedou,项目名称:miasm,代码行数:21,代码来源:dse.py
示例7: emul
def emul(self, ctx=None, step=False):
# Init
ctx_init = self._ira.arch.regs.regs_init
if ctx is not None:
ctx_init.update(ctx)
depnodes = self.relevant_nodes
solver = z3.Solver()
sb = symbexec(self._ira, ctx_init)
temp_label = asm_label("Temp")
history = self.relevant_labels[::-1]
history_size = len(history)
for hist_nb, label in enumerate(history):
# Build block with relevant lines only
affected_lines = set(depnode.line_nb for depnode in depnodes
if depnode.label == label)
irs = self._ira.blocs[label].irs
affects = []
for line_nb in sorted(affected_lines):
affects.append(irs[line_nb])
# Emul the block and get back destination
dst = sb.emulbloc(irbloc(temp_label, affects), step=step)
# Add constraint
if hist_nb + 1 < history_size:
next_label = history[hist_nb + 1]
expected = sb.eval_expr(m2_expr.ExprId(next_label, 32))
constraint = m2_expr.ExprAff(dst, expected)
solver.add(Translator.to_language("z3").from_expr(constraint))
# Save the solver
self._solver = solver
# Return only inputs values (others could be wrongs)
return {depnode.element: sb.symbols[depnode.element]
for depnode in self.input}
开发者ID:0xf1sh,项目名称:miasm,代码行数:38,代码来源:depgraph.py
示例8: init_arch_C
import miasm2.expression.expression as m2_expr
from miasm2.expression.simplifications import expr_simp
from miasm2.core import asmbloc
from miasm2.ir.translators import Translator
import logging
log_to_c_h = logging.getLogger("ir_helper")
console_handler = logging.StreamHandler()
console_handler.setFormatter(logging.Formatter("%(levelname)-5s: %(message)s"))
log_to_c_h.addHandler(console_handler)
log_to_c_h.setLevel(logging.WARN)
# Miasm to C translator
translator = Translator.to_language("C")
prefetch_id = []
prefetch_id_size = {}
for size in [8, 16, 32, 64]:
prefetch_id_size[size] = []
for i in xrange(20):
name = 'pfmem%.2d_%d' % (size, i)
c = m2_expr.ExprId(name, size)
globals()[name] = c
prefetch_id.append(c)
prefetch_id_size[size].append(c)
def init_arch_C(arch):
arch.id2Cid = {}
for x in arch.regs.all_regs_ids + prefetch_id:
arch.id2Cid[x] = m2_expr.ExprId('((vm_cpu_t*)jitcpu->cpu)->' + str(x), x.size)
开发者ID:winchester1887,项目名称:miasm,代码行数:31,代码来源:ir2C.py
示例9: translationTest
def translationTest(self, expr, expected):
from miasm2.ir.translators import Translator
translator = Translator.to_language("C")
self.assertEqual(translator.from_expr(expr), expected)
开发者ID:CaineQT,项目名称:miasm,代码行数:5,代码来源:ir2C.py
示例10: Attributes
"""
Module to generate C code for a given native @block
"""
import miasm2.expression.expression as m2_expr
from miasm2.ir.ir import IRBlock, AssignBlock
from miasm2.ir.translators import Translator
from miasm2.core.asmblock import expr_is_label, AsmBlockBad, AsmLabel
# Miasm to C translator
TRANSLATOR = Translator.to_language("C")
SIZE_TO_MASK = {x: 2**x - 1 for x in (1, 2, 3, 7, 8, 16, 32, 64)}
MASK_INT = 0xffffffffffffffff
class Attributes(object):
"""
Store an irblock attributes
"""
def __init__(self, log_mn=False, log_regs=False):
self.mem_read = False
self.mem_write = False
self.set_exception = False
self.log_mn = log_mn
self.log_regs = log_regs
self.instr = None
开发者ID:chubbymaggie,项目名称:miasm,代码行数:30,代码来源:codegen.py
示例11: ExprRandom_OpSubRange
random.seed(0)
class ExprRandom_OpSubRange(ExprRandom):
operations_by_args_number = {1: ["-"],
2: ["<<", ">>",],
"2+": ["+", "*", "&", "|", "^"],
}
print "[+] Compute a random expression:"
expr = ExprRandom_OpSubRange.get(depth=8)
print "-> %s" % expr
print
target_exprs = {lang:Translator.to_language(lang).from_expr(expr)
for lang in Translator.available_languages()}
for target_lang, target_expr in target_exprs.iteritems():
print "[+] Translate in %s:" % target_lang
print target_expr
print
print "[+] Eval in Python:"
def memory(addr, size):
ret = random.randint(0, (1 << size) - 1)
print "Memory access: @0x%x -> 0x%x" % (addr, ret)
return ret
for expr_id in expr.get_r(mem_read=True):
if isinstance(expr_id, ExprId):
value = random.randint(0, (1 << expr_id.size) - 1)
开发者ID:CaineQT,项目名称:miasm,代码行数:30,代码来源:expr_translate.py
示例12: ExprId
from miasm2.expression.expression import *
from miasm2.analysis.expression_range import expr_range
from miasm2.ir.translators import Translator
import z3
trans = Translator.to_language("z3")
a = ExprId("a", 8)
b = ExprId("b", 32)
for expr in [
a,
b,
b[4:6],
a + ExprInt(4, 8),
ExprInt(5, 8) + ExprInt(4, 8),
a.zeroExtend(32) + ExprInt(0x100, 32),
(a.zeroExtend(32) * ExprInt(3, 32)) + ExprInt(0x100, 32),
(a.zeroExtend(32) + ExprInt(0x80, 32)) * ExprInt(3, 32),
ExprCond(b, a.zeroExtend(32) + ExprInt(0x100, 32),
a.zeroExtend(32) + ExprInt(0x500, 32)),
ExprCond(b[1:2], a.zeroExtend(32), a.zeroExtend(32) + ExprInt(0x1000, 32)) + \
ExprCond(b[0:1], a.zeroExtend(32) + ExprInt(0x5000, 32), a.zeroExtend(32) + ExprInt(0x10000, 32)),
- a,
- ExprInt(4, 8),
b[:8].zeroExtend(16) - ExprInt(4, 16),
a[4:6].zeroExtend(32) + ExprInt(-1, 32),
a >> ExprInt(4, 8),
a << ExprInt(4, 8),
ExprOp("a>>", a, ExprInt(4, 8)),
ExprInt(4, 8) >> a,
ExprInt(4, 8) << a,
开发者ID:carolineLe,项目名称:miasm,代码行数:31,代码来源:range.py
注:本文中的miasm2.ir.translators.Translator类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论