(self, comments=False, symbolized=True)
return "\n".join(contents)
:return:
def assembly(self, comments=False, symbolized=True):
        """

        :return:
        """

        if comments:
            dbg_comments = self.dbg_comments()
        else:
            dbg_comments = ""

        labels = "\n".join([ str(lbl) for lbl in self.labels ])

        inserted_asm_before_label = ""
        if self.addr in self.binary.inserted_asm_before_label:
            # put all assembly code there
            if comments:
                inserted_asm_before_label += "\t# Inserted assembly code (before label):\n"
            inserted_asm_before_label = "\n".join(self.binary.inserted_asm_before_label[self.addr])
            inserted_asm_before_label += "\n"

        inserted_asm_after_label = ""
        if self.addr in self.binary.inserted_asm_after_label:
            # put all assembly code there
            if comments:
                inserted_asm_after_label += "\t# Inserted assembly code (after label):\n"
            inserted_asm_after_label = "\n".join(self.binary.inserted_asm_after_label[self.addr])
            inserted_asm_after_label += "\n"

        not_symbolized = "\t%s\t%s" % (self.mnemonic, self.op_str)
        if not symbolized:
            asm = not_symbolized

        elif not any([ operand.symbolized for operand in self.operands ]):
            # No label is involved
            asm = not_symbolized

        elif not self.operands:
            # There is no operand
            asm = not_symbolized

        else:
            # Now it's the tricky part. capstone doesn't give us anyway to print individual operand. We gotta parse it
            # by ourselves
            # Remove the address
            #capstone_str = capstone_str[capstone_str.find('\t') + 1 : ]

            all_operands = [ operand.operand_str for operand in self.operands]
            mnemonic = self.mnemonic

            for i, op in enumerate(self.operands):
                op_asm = op.assembly()
                if op_asm is not None:
                    if op.type in (OP_TYPE_IMM, OP_TYPE_MEM):
                        all_operands[i] = op_asm
                    else:
                        raise BinaryError("Unsupported operand type %d." % op.type)

                    if self.capstone_operand_types[i] == capstone.CS_OP_IMM:
                        if mnemonic.startswith('j') or mnemonic.startswith('call') or mnemonic.startswith('loop'):
                            pass
                        else:
                            # mark the size of the variable
                            if op.is_dataref:
                                op.label.var_size = op.size
                            if self.binary.syntax == 'at&t':
                                all_operands[i] = "$" + all_operands[i]
                            else:
                                all_operands[i] = 'OFFSET FLAT:' + all_operands[i]

            asm = "\t%s%s" % (mnemonic, "\t" + ", ".join(all_operands))

        if self.addr in self.binary._removed_instructions:
            contents = [dbg_comments, inserted_asm_before_label, labels, inserted_asm_after_label]
        else:
            contents = [ dbg_comments, inserted_asm_before_label, labels, inserted_asm_after_label, asm ]
        contents = [ a for a in contents if a ]

        return "\n".join(contents)
def assembly ( self , comments = False , symbolized = True ) : if comments : dbg_comments = self . dbg_comments ( ) else : dbg_comments = "" labels = "\n" . join ( [ str ( lbl ) for lbl in self . labels ] ) inserted_asm_before_label = "" if self . addr in self . binary . inserted_asm_before_label : # put all assembly code there if comments : inserted_asm_before_label += "\t# Inserted assembly code (before label):\n" inserted_asm_before_label = "\n" . join ( self . binary . inserted_asm_before_label [ self . addr ] ) inserted_asm_before_label += "\n" inserted_asm_after_label = "" if self . addr in self . binary . inserted_asm_after_label : # put all assembly code there if comments : inserted_asm_after_label += "\t# Inserted assembly code (after label):\n" inserted_asm_after_label = "\n" . join ( self . binary . inserted_asm_after_label [ self . addr ] ) inserted_asm_after_label += "\n" not_symbolized = "\t%s\t%s" % ( self . mnemonic , self . op_str ) if not symbolized : asm = not_symbolized elif not any ( [ operand . symbolized for operand in self . operands ] ) : # No label is involved asm = not_symbolized elif not self . operands : # There is no operand asm = not_symbolized else : # Now it's the tricky part. capstone doesn't give us anyway to print individual operand. We gotta parse it # by ourselves # Remove the address #capstone_str = capstone_str[capstone_str.find('\t') + 1 : ] all_operands = [ operand . operand_str for operand in self . operands ] mnemonic = self . mnemonic for i , op in enumerate ( self . operands ) : op_asm = op . assembly ( ) if op_asm is not None : if op . type in ( OP_TYPE_IMM , OP_TYPE_MEM ) : all_operands [ i ] = op_asm else : raise BinaryError ( "Unsupported operand type %d." % op . type ) if self . capstone_operand_types [ i ] == capstone . CS_OP_IMM : if mnemonic . startswith ( 'j' ) or mnemonic . startswith ( 'call' ) or mnemonic . startswith ( 'loop' ) : pass else : # mark the size of the variable if op . is_dataref : op . label . var_size = op . size if self . binary . syntax == 'at&t' : all_operands [ i ] = "$" + all_operands [ i ] else : all_operands [ i ] = 'OFFSET FLAT:' + all_operands [ i ] asm = "\t%s%s" % ( mnemonic , "\t" + ", " . join ( all_operands ) ) if self . addr in self . binary . _removed_instructions : contents = [ dbg_comments , inserted_asm_before_label , labels , inserted_asm_after_label ] else : contents = [ dbg_comments , inserted_asm_before_label , labels , inserted_asm_after_label , asm ] contents = [ a for a in contents if a ] return "\n" . join ( contents )