Esempio n. 1
0
 def print(self, o, tab=0):
     o.print_commented_jump(self.orig_jump, self.fused_inst, tab)
     if self.prefetch is not None:
         o.print_inst(self.prefetch, tab)
     print_tabbed_no_end(color_keyword("and ") + color_keyword("if "), tab)
     o.print_if_cond(self.cond_id, self.fused_inst)
     print()
Esempio n. 2
0
 def print(self, o, tab=0):
     if self.is_infinite:
         print_tabbed(color_keyword("for") + " (;;) {", tab)
     else:
         print_tabbed(color_keyword("loop") + " {", tab)
     self.branch.print(o, tab+1)
     print_tabbed("}", tab)
Esempio n. 3
0
 def print(self, o, tab=0):
     o.print_commented_jump(self.orig_jump, self.fused_inst, tab)
     if self.prefetch is not None:
         o.print_inst(self.prefetch, tab)
     print_tabbed_no_end(color_keyword("and ") + color_keyword("if "), tab)
     o.print_if_cond(self.cond_id, self.fused_inst)
     print()
Esempio n. 4
0
 def print(self, o, tab=0):
     if self.is_infinite:
         print_tabbed(color_keyword("for") + " (;;) {", tab)
     else:
         print_tabbed(color_keyword("loop") + " {", tab)
     self.branch.print(o, tab+1)
     print_tabbed("}", tab)
Esempio n. 5
0
 def print(self, o, tab=0):
     o.print_commented_jump(self.orig_jump, self.fused_inst, tab)
     if self.prefetch is not None:
         o.print_inst(self.prefetch, tab)
     print_tabbed_no_end(color_keyword("if "), tab)
     o.print_if_cond(self.cond_id, self.fused_inst)
     print_no_end(color_keyword("  goto "))
     print(color_addr(self.addr_jump, False))
Esempio n. 6
0
 def print(self, o, tab=0):
     o.print_commented_jump(self.orig_jump, self.fused_inst, tab)
     if self.prefetch is not None:
         o.print_inst(self.prefetch, tab)
     print_tabbed_no_end(color_keyword("if "), tab)
     o.print_if_cond(self.cond_id, self.fused_inst)
     print_no_end(color_keyword("  goto "))
     print(color_addr(self.addr_jump, False))
Esempio n. 7
0
 def print(self, o, tab=0):
     if self.is_infinite:
         print_tabbed(color_keyword("infiniteloop") + " {", tab)
     else:
         print_tabbed(color_keyword("loop") + " {", tab)
     self.branch.print(o, tab + 1)
     print_tabbed("}", tab)
     if self.epilog != None:
         self.epilog.print(o, tab)
Esempio n. 8
0
 def print(self, o, tab=0):
     if self.is_infinite:
         print_tabbed(color_keyword("infiniteloop") + " {", tab)
     else:
         print_tabbed(color_keyword("loop") + " {", tab)
     self.branch.print(o, tab+1)
     print_tabbed("}", tab)
     if self.epilog != None:
         self.epilog.print(o, tab)
Esempio n. 9
0
 def print_rep_end():
     nonlocal tab
     if i.prefix[0] in REP_PREFIX:
         print()
         print_label_or_addr(i.address, tab)
         print("rcx--")
         if i.prefix[0] == X86_PREFIX_REPNE:
             print_tabbed_no_end(color_keyword("if"), tab)
             print_no_end(" (!Z) ")
             print(color_keyword("break"))
         tab -= 1
         print_tabbed_no_end("}", tab)
Esempio n. 10
0
 def print_rep_end():
     nonlocal tab
     if i.prefix[0] in REP_PREFIX:
         print()
         print_label_or_addr(i.address, tab)
         print("rcx--")
         if i.prefix[0] == X86_PREFIX_REPNE:
             print_tabbed_no_end(color_keyword("if"), tab)
             print_no_end(" (!Z) ")
             print(color_keyword("break"))
         tab -= 1
         print_tabbed_no_end("}", tab)
Esempio n. 11
0
 def print_ast(self, entry, ast):
     print_no_end(color_keyword("function "))
     print_no_end(self.binary.reverse_symbols.get(entry, hex(entry)))
     print(" {")
     self.print_vars_type()
     ast.print(self, 1)
     print("}")
Esempio n. 12
0
 def print_ast(self, entry, ast):
     print_no_end(color_keyword("function "))
     print_no_end(self.binary.reverse_symbols.get(entry, hex(entry)))
     print(" {")
     self.print_vars_type()
     ast.print(self, 1)
     print("}")
Esempio n. 13
0
 def print_rep_begin():
     nonlocal tab
     if i.prefix[0] in REP_PREFIX:
         print_tabbed_no_end(color_keyword("while"), tab)
         # TODO: for 16 and 32 bits
         print_no_end(" (!rcx)")
         print(") {")
         tab += 1
Esempio n. 14
0
 def print_rep_begin():
     nonlocal tab
     if i.prefix[0] in REP_PREFIX:
         print_tabbed_no_end(color_keyword("while"), tab)
         # TODO: for 16 and 32 bits
         print_no_end(" (!rcx)")
         print(") {")
         tab += 1
Esempio n. 15
0
 def print_ast(self, entry, ast):
     print_no_end(color_keyword("function "))
     print_no_end(self.binary.reverse_symbols.get(entry, hex(entry)))
     sec_name, _ = self.binary.is_address(entry)
     if sec_name is not None:
         print(" (%s) {" % color_section(sec_name))
     else:
         print(" {")
     self.print_vars_type()
     ast.print(self, 1)
     print("}")
Esempio n. 16
0
 def print_ast(self, entry, ast):
     print_no_end(color_keyword("function "))
     print_no_end(self.binary.reverse_symbols.get(entry, hex(entry)))
     sec_name, _ = self.binary.is_address(entry)
     if sec_name is not None:
         print(" (%s) {" % color_section(sec_name))
     else:
         print(" {")
     self.print_vars_type()
     ast.print(self, 1)
     print("}")
Esempio n. 17
0
    def print(self, o, tab=0):
        o.print_commented_jump(None, self.fused_inst, tab)
        print_tabbed_no_end(color_keyword("if "), tab)
        o.print_if_cond(self.cond_id, self.fused_inst)

        # If it contains only one instruction
        if self.fused_inst == None and len(self.br.nodes) == 1 and \
                len(self.br.nodes[0]) == 1 and isinstance(self.br.nodes[0], list):
            print_no_end(" :  ")
            o.print_inst(self.br.nodes[0][0], 0)
        else:
            print(" {")
            self.br.print(o, tab+1)
            print_tabbed("}", tab)
Esempio n. 18
0
    def print(self, o, tab=0):
        o.print_commented_jump(None, self.fused_inst, tab)
        print_tabbed_no_end(color_keyword("if "), tab)
        o.print_if_cond(self.cond_id, self.fused_inst)

        # If it contains only one instruction
        if self.fused_inst == None and len(self.br.nodes) == 1 and \
                len(self.br.nodes[0]) == 1 and isinstance(self.br.nodes[0], list):
            print_no_end(" :  ")
            o.print_inst(self.br.nodes[0][0], 0)
        else:
            print(" {")
            self.br.print(o, tab + 1)
            print_tabbed("}", tab)
Esempio n. 19
0
 def print(self, tab=0):
     print_cmp_jump_commented(self.cmp_inst, self.orig_jump, tab)
     print_tabbed_no_end(color_keyword("if "), tab)
     print_if_cond(self.cmp_inst, self.cond_id)
     print_no_end(color_keyword("  goto "))
     print_addr(self.addr_jump)
Esempio n. 20
0
 def print(self, o, tab=0):
     print_tabbed_no_end(color_keyword("goto "), tab)
     print(color_addr(self.addr_jump, False))
Esempio n. 21
0
    def print(self, o, tab=0, print_else_keyword=False):
        ARCH_UTILS = o.ctx.libarch.utils

        #
        # if cond {
        # } else {
        #   ...
        # }
        #
        # become
        #
        # if !cond {
        #   ...
        # }
        #

        br_next = self.br_next
        br_next_jump = self.br_next_jump
        inv_if = False

        if len(self.br_next.nodes) == 0:
            br_next, br_next_jump = br_next_jump, br_next
            inv_if = True

        o.print_commented_jump(self.jump_inst, self.fused_inst, tab)

        if print_else_keyword:
            print_tabbed_no_end(color_keyword("else if "), tab)
        else:
            print_tabbed_no_end(color_keyword("if "), tab)

        # jump_inst is the condition to go to the else-part
        if inv_if:
            o.print_if_cond(ARCH_UTILS.get_cond(self.jump_inst),
                            self.fused_inst)
        else:
            o.print_if_cond(ARCH_UTILS.invert_cond(self.jump_inst),
                            self.fused_inst)

        print(" {")

        # if-part
        br_next.print(o, tab + 1)

        # else-part
        if len(br_next_jump.nodes) > 0:
            print_tabbed_no_end("} ", tab)

            #
            # if {
            #   ...
            # } else {
            #   if {
            #     ...
            #   }
            # }
            #
            # become :
            #
            # if {
            #   ...
            # }
            # else if {
            #   ...
            # }
            #

            br = br_next_jump

            if len(br.nodes) == 1 and isinstance(br.nodes[0], Ast_Ifelse):
                print()
                br.nodes[0].print(o, tab, True)
                return

            if len(br.nodes) == 2 and isinstance(br.nodes[0], list) and \
                  len(br.nodes[0]) == 1 and ARCH_UTILS.is_cmp(br.nodes[0][0]) and \
                  isinstance(br.nodes[1], Ast_Ifelse):
                print()
                br.nodes[1].print(o, tab, True)
                return

            print(color_keyword("else ") + "{")
            br.print(o, tab + 1)

        print_tabbed("}", tab)
Esempio n. 22
0
 def print(self, o, tab=0):
     print_tabbed_no_end(color_keyword("goto "), tab)
     print(color_addr(self.addr_jump, False))
Esempio n. 23
0
    def print(self, o, tab=0, print_else_keyword=False):
        ARCH_UTILS = o.ctx.libarch.utils

        #
        # if cond {
        # } else {
        #   ...
        # }
        #
        # become
        #
        # if !cond {
        #   ...
        # }
        #

        br_next = self.br_next
        br_next_jump = self.br_next_jump
        inv_if = False

        if len(self.br_next.nodes) == 0:
            br_next, br_next_jump = br_next_jump, br_next
            inv_if = True
            
        o.print_commented_jump(self.jump_inst, self.fused_inst, tab)

        if self.prefetch is not None:
            o.print_inst(self.prefetch, tab)

        if print_else_keyword:
            print_tabbed_no_end(color_keyword("else if "), tab)
        else:
            print_tabbed_no_end(color_keyword("if "), tab)

        # jump_inst is the condition to go to the else-part
        if inv_if:
            o.print_if_cond(ARCH_UTILS.get_cond(self.jump_inst),
                            self.fused_inst)
        else:
            o.print_if_cond(ARCH_UTILS.invert_cond(self.jump_inst),
                            self.fused_inst)

        print(" {")

        # if-part
        br_next.print(o, tab+1)

        # else-part
        if len(br_next_jump.nodes) > 0:
            print_tabbed_no_end("} ", tab)
            
            # 
            # if {
            #   ...
            # } else {
            #   if {
            #     ...
            #   }
            # }
            #
            # become :
            #
            # if {
            #   ...
            # }
            # else if {
            #   ...
            # }
            #

            br = br_next_jump

            if len(br.nodes) == 1 and isinstance(br.nodes[0], Ast_Ifelse):
                print()
                br.nodes[0].print(o, tab, True)
                return

            if len(br.nodes) == 2 and isinstance(br.nodes[0], list) and \
                  len(br.nodes[0]) == 1 and ARCH_UTILS.is_cmp(br.nodes[0][0]) and \
                  isinstance(br.nodes[1], Ast_Ifelse):
                print()
                br.nodes[1].print(o, tab, True)
                return

            print(color_keyword("else ") + "{")
            br.print(o, tab+1)

        print_tabbed("}", tab)
Esempio n. 24
0
    def print(self, tab=0, print_else_keyword=False):

        #
        # if cond {
        # } else {
        #   ...
        # }
        #
        # become
        #
        # if !cond {
        #   ...
        # }
        #

        br_next = self.br_next
        br_next_jump = self.br_next_jump
        inv_if = False

        if len(self.br_next.nodes) == 0:
            br_next, br_next_jump = br_next_jump, br_next
            inv_if = True
            
        print_cmp_jump_commented(self.cmp_inst, self.jump_inst, tab)

        if print_else_keyword:
            print_tabbed_no_end(color_keyword("else if "), tab)
        else:
            print_tabbed_no_end(color_keyword("if "), tab)

        # jump_inst is the condition to go to the else-part
        if inv_if:
            print_if_cond(self.cmp_inst, self.jump_inst.id)
        else:
            print_if_cond(self.cmp_inst, invert_cond(self.jump_inst.id))

        print(" {")

        # if-part
        br_next.print(tab+1)

        # else-part
        if len(br_next_jump.nodes) > 0:
            print_tabbed_no_end("} ", tab)
            
            # 
            # if {
            #   ...
            # } else {
            #   if {
            #     ...
            #   }
            # }
            #
            # become :
            #
            # if {
            #   ...
            # }
            # else if {
            #   ...
            # }
            #

            br = br_next_jump

            if len(br.nodes) == 1 and isinstance(br.nodes[0], Ast_Ifelse):
                print()
                br.nodes[0].print(tab, True)
                return

            if len(br.nodes) == 2 and isinstance(br.nodes[0], list) and \
                  len(br.nodes[0]) == 1 and br.nodes[0][0].id == X86_INS_CMP and \
                  isinstance(br.nodes[1], Ast_Ifelse):
                print()
                br.nodes[1].print(tab, True)
                return

            print(color_keyword("else ") + "{")
            br.print(tab+1)

        print_tabbed("}", tab)
Esempio n. 25
0
 def print(self, tab=0):
     print_cmp_jump_commented(self.cmp_inst, self.orig_jump, tab)
     print_tabbed_no_end(color_keyword("and ") + color_keyword("if "), tab)
     print_if_cond(self.cmp_inst, self.cond_id)
     print()