uroboros-diversification/src/analysis/reassemble_symbol_get.py
def v_exp2(self, exp, instr, f, chk):
        """
        Analyze expression and determine if it represent an address.
        If so substitute if with a corresponding symbolic expression using labels
        :param exp: expression
        :param instr: instruction tuple to which the expression belongs to
        :param f: unused
        :param chk: True if instruction is TEST (x86)
        :return: modified expression if matching, original one otherwise
        """
        if isinstance(exp, Types.Const):
            if isinstance(exp, Types.Normal) and chk: return exp
            s = self.check_sec(exp)
            if s is not None:
                self.insert_data(s.sec_name, exp)
                return Types.Label(self.build_symbol(exp))
            if self.check_text(exp):
                if ELF_utils.elf_arm(): exp = type(exp)(exp & (-2))
                s_label = self.build_symbol(exp)
                self.insert_text(s_label, exp)
                return Types.Label(s_label)
            if self.check_plt(exp):
                return Types.Label(self.build_plt_symbol(exp))
        elif isinstance(exp, Types.Symbol):
            if isinstance(exp, Types.JumpDes):
                if self.check_text(exp):
                    s_label = 'S_' + dec_hex(exp)
                    self.insert_text(s_label, exp)
                    return Types.Label(s_label)
                elif self.check_plt(exp) and exp in self.plt_hash:
                    return Types.Label(self.plt_hash[exp])
            elif isinstance(exp, Types.StarDes):
                return Types.StarDes(self.v_exp2(exp.content, instr, f, chk))
            elif isinstance(exp, Types.CallDes):
                if exp.func_name.startswith('S_0'):
                    addr = int(exp.func_name[2:], 16)
                    if self.check_text(addr):
                        s_label = 'S_' + dec_hex(addr)
                        self.insert_text(s_label, addr)
                        return Types.Label(s_label)
                    elif self.check_plt(addr):
                        off = 0
                        while not self.plt_hash.get(addr - off, None): off += 2
                        return Types.Label(self.plt_hash[addr - off])
                else: self.symbol_list.insert(0, exp.func_begin_addr)
        elif isinstance(exp, Types.Ptr):
            if isinstance(exp, (Types.BinOP_PLUS, Types.BinOP_MINUS)):
                r, addr = exp
                s = self.check_sec(addr)
                if s is not None:
                    s_label = 'S_' + dec_hex(addr)
                    self.insert_data(s.sec_name, addr)
                    return Types.BinOP_PLUS_S((r, s_label)) \
                        if isinstance(exp, Types.BinOP_PLUS) \
                        else Types.BinOP_MINUS_S((r, s_label))
            elif isinstance(exp, (Types.FourOP_PLUS, Types.FourOP_MINUS)):
                r1, r2, off, addr = exp
                s = self.check_sec(addr)
                if s is not None:
                    s_label = 'S_' + dec_hex(addr)
                    self.insert_data(s.sec_name, addr)
                    return Types.FourOP_PLUS_S((r1,r2,off,s_label)) \
                        if isinstance(exp, Types.FourOP_PLUS) \
                        else Types.FourOP_MINUS_S((r1,r2,off,s_label))
            elif isinstance(exp, Types.JmpTable_PLUS):
                addr, r, off = exp
                s = self.check_sec(addr)
                if s is not None:
                    s_label = 'S_' + dec_hex(addr)
                    self.insert_data(s.sec_name, addr)
                    return Types.JmpTable_PLUS_S((s_label, r, off))
                if self.check_text(addr):
                    s_label = 'S_' + dec_hex(addr)
                    self.insert_text(s_label, addr)
                    return Types.JmpTable_PLUS_S((s_label, r, off))
            elif isinstance(exp, Types.JmpTable_MINUS):
                addr, r, off = exp
                s = self.check_sec(addr)
                if s is not None:
                    s_label = '-S_' + dec_hex(addr)
                    self.insert_data(s.sec_name, addr)
                    return Types.JmpTable_MINUS_S((s_label, r, off))
                if self.check_text(addr):
                    s_label = '-S_' + dec_hex(addr)
                    self.insert_text(s_label, addr)
                    return Types.JmpTable_MINUS_S((s_label, r, off))
        return exp

        Analyze expression and determine if it represent an address.
        If so substitute if with a corresponding symbolic expression using labels
        :param exp: expression
        :param instr: instruction tuple to which the expression belongs to
        :param f: unused
        :param chk: True if instruction is TEST (x86)
        :return: modified expression if matching, original one otherwise
        
Analyze expression and determine if it represent an address.
If so substitute if with a corresponding symbolic expression using labels
Analyze expression and determine if it represent an address . If so substitute if with a corresponding symbolic expression using labels
def v_exp2(self, exp, instr, f, chk):
        if isinstance(exp, Types.Const):
            if isinstance(exp, Types.Normal) and chk: return exp
            s = self.check_sec(exp)
            if s is not None:
                self.insert_data(s.sec_name, exp)
                return Types.Label(self.build_symbol(exp))
            if self.check_text(exp):
                if ELF_utils.elf_arm(): exp = type(exp)(exp & (-2))
                s_label = self.build_symbol(exp)
                self.insert_text(s_label, exp)
                return Types.Label(s_label)
            if self.check_plt(exp):
                return Types.Label(self.build_plt_symbol(exp))
        elif isinstance(exp, Types.Symbol):
            if isinstance(exp, Types.JumpDes):
                if self.check_text(exp):
                    s_label = 'S_' + dec_hex(exp)
                    self.insert_text(s_label, exp)
                    return Types.Label(s_label)
                elif self.check_plt(exp) and exp in self.plt_hash:
                    return Types.Label(self.plt_hash[exp])
            elif isinstance(exp, Types.StarDes):
                return Types.StarDes(self.v_exp2(exp.content, instr, f, chk))
            elif isinstance(exp, Types.CallDes):
                if exp.func_name.startswith('S_0'):
                    addr = int(exp.func_name[2:], 16)
                    if self.check_text(addr):
                        s_label = 'S_' + dec_hex(addr)
                        self.insert_text(s_label, addr)
                        return Types.Label(s_label)
                    elif self.check_plt(addr):
                        off = 0
                        while not self.plt_hash.get(addr - off, None): off += 2
                        return Types.Label(self.plt_hash[addr - off])
                else: self.symbol_list.insert(0, exp.func_begin_addr)
        elif isinstance(exp, Types.Ptr):
            if isinstance(exp, (Types.BinOP_PLUS, Types.BinOP_MINUS)):
                r, addr = exp
                s = self.check_sec(addr)
                if s is not None:
                    s_label = 'S_' + dec_hex(addr)
                    self.insert_data(s.sec_name, addr)
                    return Types.BinOP_PLUS_S((r, s_label)) \
                        if isinstance(exp, Types.BinOP_PLUS) \
                        else Types.BinOP_MINUS_S((r, s_label))
            elif isinstance(exp, (Types.FourOP_PLUS, Types.FourOP_MINUS)):
                r1, r2, off, addr = exp
                s = self.check_sec(addr)
                if s is not None:
                    s_label = 'S_' + dec_hex(addr)
                    self.insert_data(s.sec_name, addr)
                    return Types.FourOP_PLUS_S((r1,r2,off,s_label)) \
                        if isinstance(exp, Types.FourOP_PLUS) \
                        else Types.FourOP_MINUS_S((r1,r2,off,s_label))
            elif isinstance(exp, Types.JmpTable_PLUS):
                addr, r, off = exp
                s = self.check_sec(addr)
                if s is not None:
                    s_label = 'S_' + dec_hex(addr)
                    self.insert_data(s.sec_name, addr)
                    return Types.JmpTable_PLUS_S((s_label, r, off))
                if self.check_text(addr):
                    s_label = 'S_' + dec_hex(addr)
                    self.insert_text(s_label, addr)
                    return Types.JmpTable_PLUS_S((s_label, r, off))
            elif isinstance(exp, Types.JmpTable_MINUS):
                addr, r, off = exp
                s = self.check_sec(addr)
                if s is not None:
                    s_label = '-S_' + dec_hex(addr)
                    self.insert_data(s.sec_name, addr)
                    return Types.JmpTable_MINUS_S((s_label, r, off))
                if self.check_text(addr):
                    s_label = '-S_' + dec_hex(addr)
                    self.insert_text(s_label, addr)
                    return Types.JmpTable_MINUS_S((s_label, r, off))
        return exp
def v_exp2 ( self , exp , instr , f , chk ) : if isinstance ( exp , Types . Const ) : if isinstance ( exp , Types . Normal ) and chk : return exp s = self . check_sec ( exp ) if s is not None : self . insert_data ( s . sec_name , exp ) return Types . Label ( self . build_symbol ( exp ) ) if self . check_text ( exp ) : if ELF_utils . elf_arm ( ) : exp = type ( exp ) ( exp & ( - 2 ) ) s_label = self . build_symbol ( exp ) self . insert_text ( s_label , exp ) return Types . Label ( s_label ) if self . check_plt ( exp ) : return Types . Label ( self . build_plt_symbol ( exp ) ) elif isinstance ( exp , Types . Symbol ) : if isinstance ( exp , Types . JumpDes ) : if self . check_text ( exp ) : s_label = 'S_' + dec_hex ( exp ) self . insert_text ( s_label , exp ) return Types . Label ( s_label ) elif self . check_plt ( exp ) and exp in self . plt_hash : return Types . Label ( self . plt_hash [ exp ] ) elif isinstance ( exp , Types . StarDes ) : return Types . StarDes ( self . v_exp2 ( exp . content , instr , f , chk ) ) elif isinstance ( exp , Types . CallDes ) : if exp . func_name . startswith ( 'S_0' ) : addr = int ( exp . func_name [ 2 : ] , 16 ) if self . check_text ( addr ) : s_label = 'S_' + dec_hex ( addr ) self . insert_text ( s_label , addr ) return Types . Label ( s_label ) elif self . check_plt ( addr ) : off = 0 while not self . plt_hash . get ( addr - off , None ) : off += 2 return Types . Label ( self . plt_hash [ addr - off ] ) else : self . symbol_list . insert ( 0 , exp . func_begin_addr ) elif isinstance ( exp , Types . Ptr ) : if isinstance ( exp , ( Types . BinOP_PLUS , Types . BinOP_MINUS ) ) : r , addr = exp s = self . check_sec ( addr ) if s is not None : s_label = 'S_' + dec_hex ( addr ) self . insert_data ( s . sec_name , addr ) return Types . BinOP_PLUS_S ( ( r , s_label ) ) if isinstance ( exp , Types . BinOP_PLUS ) else Types . BinOP_MINUS_S ( ( r , s_label ) ) elif isinstance ( exp , ( Types . FourOP_PLUS , Types . FourOP_MINUS ) ) : r1 , r2 , off , addr = exp s = self . check_sec ( addr ) if s is not None : s_label = 'S_' + dec_hex ( addr ) self . insert_data ( s . sec_name , addr ) return Types . FourOP_PLUS_S ( ( r1 , r2 , off , s_label ) ) if isinstance ( exp , Types . FourOP_PLUS ) else Types . FourOP_MINUS_S ( ( r1 , r2 , off , s_label ) ) elif isinstance ( exp , Types . JmpTable_PLUS ) : addr , r , off = exp s = self . check_sec ( addr ) if s is not None : s_label = 'S_' + dec_hex ( addr ) self . insert_data ( s . sec_name , addr ) return Types . JmpTable_PLUS_S ( ( s_label , r , off ) ) if self . check_text ( addr ) : s_label = 'S_' + dec_hex ( addr ) self . insert_text ( s_label , addr ) return Types . JmpTable_PLUS_S ( ( s_label , r , off ) ) elif isinstance ( exp , Types . JmpTable_MINUS ) : addr , r , off = exp s = self . check_sec ( addr ) if s is not None : s_label = '-S_' + dec_hex ( addr ) self . insert_data ( s . sec_name , addr ) return Types . JmpTable_MINUS_S ( ( s_label , r , off ) ) if self . check_text ( addr ) : s_label = '-S_' + dec_hex ( addr ) self . insert_text ( s_label , addr ) return Types . JmpTable_MINUS_S ( ( s_label , r , off ) ) return exp
Analyze expression and determine if it represent an address.
Analyze expression and determine if it represent an address .
"""
        Analyze expression and determine if it represent an address.
        If so substitute if with a corresponding symbolic expression using labels
        :param exp: expression
        :param instr: instruction tuple to which the expression belongs to
        :param f: unused
        :param chk: True if instruction is TEST (x86)
        :return: modified expression if matching, original one otherwise
        """
modified expression if matching, original one otherwise
modified expression if matching original one otherwise
self
exp
None
instr
instruction tuple to which the expression belongs to
instruction tuple to which the expression belongs to
f
None
chk
True if instruction is TEST (x86)
True if instruction is TEST ( x86 )