Miasm2
 All Classes Namespaces Files Functions Variables Typedefs Properties Macros
Public Member Functions | Static Public Attributes | Static Private Attributes | List of all members
miasm2.ir.translators.miasm.TranslatorMiasm Class Reference
+ Inheritance diagram for miasm2.ir.translators.miasm.TranslatorMiasm:
+ Collaboration diagram for miasm2.ir.translators.miasm.TranslatorMiasm:

Public Member Functions

def from_ExprId
 
def from_ExprInt
 
def from_ExprCond
 
def from_ExprSlice
 
def from_ExprOp
 
def from_ExprCompose
 
def from_ExprAff
 
def from_ExprMem
 
def register
 
def to_language
 
def available_languages
 
def from_expr
 

Static Public Attributes

list available_translators = []
 

Static Private Attributes

string __LANG__ = "Miasm"
 

Detailed Description

Definition at line 4 of file miasm.py.

Member Function Documentation

def miasm2.ir.translators.translator.Translator.available_languages (   cls)
inherited

Definition at line 34 of file translator.py.

34 
35  def available_languages(cls):
36  "Return the list of registered languages"
37  return [translator.__LANG__ for translator in cls.available_translators]
def miasm2.ir.translators.translator.Translator.from_expr (   self,
  expr 
)
inherited
Translate an expression according to its type
@expr: expression to translate

Definition at line 92 of file translator.py.

92 
93  def from_expr(self, expr):
94  """Translate an expression according to its type
95  @expr: expression to translate
96  """
97  # Use cache
98  if expr in self._cache:
99  return self._cache[expr]
100 
101  # Handle Expr type
102  handlers = {m2_expr.ExprInt: self.from_ExprInt,
103  m2_expr.ExprId: self.from_ExprId,
104  m2_expr.ExprCompose: self.from_ExprCompose,
105  m2_expr.ExprSlice: self.from_ExprSlice,
106  m2_expr.ExprOp: self.from_ExprOp,
107  m2_expr.ExprMem: self.from_ExprMem,
108  m2_expr.ExprAff: self.from_ExprAff,
109  m2_expr.ExprCond: self.from_ExprCond
110  }
111  for target, handler in handlers.iteritems():
112  if isinstance(expr, target):
113  ## Compute value and update the internal cache
114  ret = handler(expr)
115  self._cache[expr] = ret
116  return ret
117  raise ValueError("Unhandled type for %s" % expr)
118 

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

def miasm2.ir.translators.miasm.TranslatorMiasm.from_ExprAff (   self,
  expr 
)

Definition at line 34 of file miasm.py.

34 
35  def from_ExprAff(self, expr):
36  return "ExprAff(%s, %s)" % (self.from_expr(expr.dst),
37  self.from_expr(expr.src))

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

def miasm2.ir.translators.miasm.TranslatorMiasm.from_ExprCompose (   self,
  expr 
)

Definition at line 29 of file miasm.py.

29 
30  def from_ExprCompose(self, expr):
31  args = ["(%s, %d, %d)" % (self.from_expr(arg), start, stop)
32  for arg, start, stop in expr.args]
33  return "ExprCompose([%s])" % ", ".join(args)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

def miasm2.ir.translators.miasm.TranslatorMiasm.from_ExprCond (   self,
  expr 
)

Definition at line 15 of file miasm.py.

15 
16  def from_ExprCond(self, expr):
17  return "ExprCond(%s, %s, %s)" % (self.from_expr(expr.cond),
18  self.from_expr(expr.src1),
19  self.from_expr(expr.src2))

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

def miasm2.ir.translators.miasm.TranslatorMiasm.from_ExprId (   self,
  expr 
)

Definition at line 9 of file miasm.py.

9 
10  def from_ExprId(self, expr):
11  return "ExprId(%s, size=%d)" % (repr(expr.name), expr.size)

+ Here is the caller graph for this function:

def miasm2.ir.translators.miasm.TranslatorMiasm.from_ExprInt (   self,
  expr 
)

Definition at line 12 of file miasm.py.

12 
13  def from_ExprInt(self, expr):
14  return "ExprInt(0x%x, %d)" % (int(expr.arg), expr.size)

+ Here is the caller graph for this function:

def miasm2.ir.translators.miasm.TranslatorMiasm.from_ExprMem (   self,
  expr 
)

Definition at line 38 of file miasm.py.

38 
39  def from_ExprMem(self, expr):
40  return "ExprMem(%s, size=%d)" % (self.from_expr(expr.arg), expr.size)
41 
42 
43 # Register the class
44 Translator.register(TranslatorMiasm)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

def miasm2.ir.translators.miasm.TranslatorMiasm.from_ExprOp (   self,
  expr 
)

Definition at line 25 of file miasm.py.

25 
26  def from_ExprOp(self, expr):
27  return "ExprOp(%s, %s)" % (repr(expr.op),
28  ", ".join(map(self.from_expr, expr.args)))

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

def miasm2.ir.translators.miasm.TranslatorMiasm.from_ExprSlice (   self,
  expr 
)

Definition at line 20 of file miasm.py.

20 
21  def from_ExprSlice(self, expr):
22  return "ExprSlice(%s, %d, %d)" % (self.from_expr(expr.arg),
23  expr.start,
24  expr.stop)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

def miasm2.ir.translators.translator.Translator.register (   cls,
  translator 
)
inherited
Register a translator
@translator: Translator sub-class

Definition at line 14 of file translator.py.

14 
15  def register(cls, translator):
16  """Register a translator
17  @translator: Translator sub-class
18  """
19  cls.available_translators.append(translator)
def miasm2.ir.translators.translator.Translator.to_language (   cls,
  target_lang,
  args,
  kwargs 
)
inherited
Return the corresponding translator instance
@target_lang: str (case insensitive) wanted language
Raise a NotImplementedError in case of unmatched language

Definition at line 21 of file translator.py.

21 
22  def to_language(cls, target_lang, *args, **kwargs):
23  """Return the corresponding translator instance
24  @target_lang: str (case insensitive) wanted language
25  Raise a NotImplementedError in case of unmatched language
26  """
27  target_lang = target_lang.lower()
28  for translator in cls.available_translators:
29  if translator.__LANG__.lower() == target_lang:
30  return translator(*args, **kwargs)
31 
32  raise NotImplementedError("Unknown target language: %s" % target_lang)
tuple translator
Definition: ir2C.py:15

Member Data Documentation

string miasm2.ir.translators.miasm.TranslatorMiasm.__LANG__ = "Miasm"
staticprivate

Definition at line 7 of file miasm.py.

list miasm2.ir.translators.translator.Translator.available_translators = []
staticinherited

Definition at line 9 of file translator.py.


The documentation for this class was generated from the following file: