def assign_colors(ctx, ast): if isinstance(ast, Ast_Branch): for n in ast.nodes: if isinstance(n, list): if is_uncond_jump(n[0]) and n[0].operands[0].type == MIPS_OP_IMM and \ n[0].address in ctx.gph.link_out: nxt = ctx.gph.link_out[n[0].address][BRANCH_NEXT] pick_color(nxt) else: # ast assign_colors(ctx, n) elif isinstance(ast, Ast_IfGoto) or isinstance(ast, Ast_Goto): pick_color(ast.addr_jump) elif isinstance(ast, Ast_Ifelse): assign_colors(ctx, ast.br_next_jump) assign_colors(ctx, ast.br_next) elif isinstance(ast, Ast_Loop): assign_colors(ctx, ast.branch) elif isinstance(ast, Ast_If_cond): assign_colors(ctx, ast.br)
def _sub_asm_inst(self, i, tab=0, prefix=""): if is_ret(i): self._retcall(self.get_inst_str(i)) return False if is_call(i): self._retcall(i.mnemonic) self._add(" ") if self.gctx.sectionsname: op = i.operands[0] if op.type == MIPS_OP_IMM: s = self._binary.get_section(op.value.imm) if s is not None: self._add("(") self._section(s.name) self._add(") ") self._operand(i, 0, hexa=True, force_dont_print_data=True) return False # Here we can have conditional jump with the option --dump if is_jump(i): if len(i.operands) == 0: self._add(i.mnemonic) return False self._add(i.mnemonic + " ") for num in range(len(i.operands)-1): self._operand(i, num) self._add(", ") if i.operands[-1].type != MIPS_OP_IMM: self._operand(i, -1, force_dont_print_data=True) self.inst_end_here() if is_uncond_jump(i) and not self.ctx.is_dump \ and not i.address in self._dis.jmptables: self._add(" ") self._comment("# STOPPED") return False self._operand(i, -1, hexa=True, force_dont_print_data=True) return False modified = False if self.gctx.capstone_string: if i.id in LD_CHECK: self._operand(i, 0) self._add(" = (") self._type(LD_TYPE[i.id]) self._add(") ") self._operand(i, 1) modified = True elif i.id in ST_CHECK: self._operand(i, 1) self._add(" = (") self._type(ST_TYPE[i.id]) self._add(") ") self._operand(i, 0) modified = True elif i.id in INST_CHECK: if i.id == MIPS_INS_LUI: self._add("(load upper) ") self._operand(i, 0) self._add(" = ") self._operand(i, 1) elif i.id == MIPS_INS_MOVE: self._operand(i, 0) self._add(" = ") if i.operands[1].value.reg == MIPS_REG_ZERO: self._add("0") else: self._operand(i, 1) else: self._operand(i, 0) if i.operands[0].type == i.operands[1].type == MIPS_OP_REG and \ i.operands[0].value.reg == i.operands[1].value.reg: self._add(" " + inst_symbol(i) + "= ") else: self._add(" = ") self._operand(i, 1) self._add(" " + inst_symbol(i) + " ") self._operand(i, 2) modified = True if not modified: self._add("%s " % i.mnemonic) if len(i.operands) > 0: modified = self._operand(i, 0) k = 1 while k < len(i.operands): self._add(", ") modified |= self._operand(i, k) k += 1 return modified
def _sub_asm_inst(self, i, tab=0, prefix=""): if is_ret(i): self._retcall(self.get_inst_str(i)) return False if is_call(i): self._retcall(i.mnemonic) self._add(" ") if self.gctx.sectionsname: op = i.operands[0] if op.type == MIPS_OP_IMM: s = self._binary.get_section(op.value.imm) if s is not None: self._add("(") self._section(s.name) self._add(") ") self._operand(i, 0, hexa=True, force_dont_print_data=True) return False # Here we can have conditional jump with the option --dump if is_jump(i): if len(i.operands) == 0: self._add(i.mnemonic) return False self._add(i.mnemonic + " ") for num in range(len(i.operands) - 1): self._operand(i, num) self._add(", ") if i.operands[-1].type != MIPS_OP_IMM: self._operand(i, -1, force_dont_print_data=True) self.inst_end_here() if is_uncond_jump(i) and not self.ctx.is_dump \ and not i.address in self._dis.jmptables: self._add(" ") self._comment("# STOPPED") return False self._operand(i, -1, hexa=True, force_dont_print_data=True) return False modified = False if self.gctx.capstone_string == 0: if i.id in LD_CHECK: self._operand(i, 0) self._add(" = (") self._type(LD_TYPE[i.id]) self._add(") ") self._operand(i, 1) modified = True elif i.id in ST_CHECK: self._operand(i, 1) self._add(" = (") self._type(ST_TYPE[i.id]) self._add(") ") self._operand(i, 0) modified = True elif i.id in INST_CHECK: if i.id == MIPS_INS_LUI: self._add("(load upper) ") self._operand(i, 0) self._add(" = ") self._operand(i, 1) elif i.id == MIPS_INS_MOVE: self._operand(i, 0) self._add(" = ") if i.operands[1].value.reg == MIPS_REG_ZERO: self._add("0") else: self._operand(i, 1) else: self._operand(i, 0) if i.operands[0].type == i.operands[1].type == MIPS_OP_REG and \ i.operands[0].value.reg == i.operands[1].value.reg: self._add(" " + inst_symbol(i) + "= ") else: self._add(" = ") self._operand(i, 1) self._add(" " + inst_symbol(i) + " ") self._operand(i, 2) modified = True if not modified: self._add("%s " % i.mnemonic) if len(i.operands) > 0: modified = self._operand(i, 0) k = 1 while k < len(i.operands): self._add(", ") modified |= self._operand(i, k) k += 1 return modified