def gen_goto_code(self, attrib, instr_offsets, dst): """Generate C code for a potential destination @dst @attrib: instruction Attributes @instr_offsets: instructions offsets list @dst: potential instruction destination""" out = [] if is_expr(dst): out += self.gen_post_code(attrib, "DST_value") out.append('BlockDst->address = DST_value;') out += self.gen_post_instr_checks(attrib) out.append('\t\treturn JIT_RET_NO_EXCEPTION;') return out assert isinstance(dst, LocKey) offset = self.lifter.loc_db.get_location_offset(dst) if offset is None: # Generate goto for local labels return ['goto %s;' % dst] if (offset > attrib.instr.offset and offset in instr_offsets): # Only generate goto for next instructions. # (consecutive instructions) out += self.gen_post_code(attrib, "0x%x" % offset) out += self.gen_post_instr_checks(attrib) out.append('goto %s;' % dst) else: out += self.gen_post_code(attrib, "0x%x" % offset) out.append('BlockDst->address = DST_value;') out += self.gen_post_instr_checks(attrib) out.append('\t\treturn JIT_RET_NO_EXCEPTION;') return out
def fromstring(self, text, loc_db, parser_result=None): if parser_result: e, start, stop = parser_result[self.parser] else: try: e, start, stop = next(self.parser.scanString(text)) except StopIteration: return None, None if e == [None]: return None, None assert (m2_expr.is_expr(e)) self.expr = e return start, stop
def __str__(self): """Return the mnemonic as a string. Note: - it is not mandatory as the instruction class already implement it. It used to get rid of the padding between the opcode and the arguments. - most of this code is copied from miasm/core/cpu.py """ o = "%s" % self.name # if self.name in [ # "MOV", "ADD", "SUB", # "MUL", "DIV", "MOD", # "AND", "OR", "XOR"]: # if self.args[0].is_int(): # o += " %s" % self.arg2str(self.args[0]) # o += ", %s" % hex(int(self.args[1])) # else: # o += " %s" % self.arg2str(self.args[0]) # o += ", %s" % self.arg2str(self.args[1]) # elif self.name in ['JNE', 'JE', 'JGE', 'JL']: # o += " %s" % hex(int(self.args[2])) # o += ", %s" % self.arg2str(self.args[0]) # o += ", %s" % self.arg2str(self.args[1]) # else: args = [] if self.args: o += " " for i, arg in enumerate(self.args): if not is_expr(arg): raise ValueError('zarb arg type') x = self.arg2str(arg, pos=i) args.append(x) o += self.gen_args(args) return o
def dst_to_c(self, src): """Translate Expr @src into C code""" if not is_expr(src): src = ExprInt(src, self.PC.size) return self.id_to_c(src)