コード例 #1
0
 def v_exp2(self, exp, instr, f, chk):
     # TODO: create subfunctions to simplify this mess
     # check_test_condition = lambda l,c: not (isinstance(l, Types.Normal) and c)
     if isinstance(exp, Types.Const):
         if isinstance(exp, Types.Normal) and chk: return exp
         l1 = self.parse_const(exp)
         s = self.check_sec(l1)
         if s is not None:
             s_label = self.build_symbol(exp)
             loc1 = get_loc(instr)
             if not self.has_data(l1):
                 reassemble.data_set[l1] = ''
                 self.label.insert(0, (s.sec_name, l1))
             self.c2d_addr.insert(0, loc1.loc_addr)
             return Types.Label(s_label)
         if self.check_text(l1):
             s_label = self.build_symbol(exp)
             loc1 = get_loc(instr)
             if not self.has_text(l1):
                 reassemble.text_set[l1] = ''
                 self.deslist.insert(0, s_label)
             self.deslist_reloc.insert(0, loc1.loc_addr)
             return Types.Label(s_label)
         if self.check_plt(l1):
             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)
                 if not self.has_text(exp):
                     reassemble.text_set[exp] = ''
                     self.deslist.insert(0, s_label)
                 return Types.Label(s_label)
         elif isinstance(exp, Types.StarDes):
             return Types.StarDes(self.v_exp2(exp.content, instr, f, chk))
         elif isinstance(exp, Types.CallDes):
             fn = exp.func_name[2:]
             is_dig_loc = False
             try:
                 addr = int(fn, 16)
                 is_dig_loc = True
             except:
                 self.symbol_list.insert(0, exp.func_begin_addr)
             if is_dig_loc:
                 if self.check_text(addr):
                     s_label = 'S_' + dec_hex(addr)
                     if not self.has_text(addr):
                         reassemble.text_set[addr] = ''
                         self.deslist.insert(0, s_label)
                     return Types.Label(s_label)
     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)
                 loc1 = get_loc(instr)
                 if not self.has_data(addr):
                     reassemble.data_set[addr] = ''
                     self.label.insert(0, (s.sec_name, addr))
                 self.c2d_addr.insert(0, loc1.loc_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)
                 loc1 = get_loc(instr)
                 if not self.has_data(addr):
                     reassemble.data_set[addr] = ''
                     self.label.insert(0, (s.sec_name, addr))
                 self.c2d_addr.insert(0, loc1.loc_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)
                 loc1 = get_loc(instr)
                 if not self.has_data(addr):
                     reassemble.data_set[addr] = ''
                     self.label.insert(0, (s.sec_name, addr))
                 self.c2d_addr.insert(0, loc1.loc_addr)
                 return Types.JmpTable_PLUS_S((s_label, r, off))
             if self.check_text(addr):
                 s_label = 'S_' + dec_hex(addr)
                 loc1 = get_loc(instr)
                 if not self.has_text(addr):
                     reassemble.text_set[addr] = ''
                     self.deslist.insert(0, s_label)
                 self.deslist_reloc.insert(0, loc1.loc_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)
                 loc1 = get_loc(instr)
                 if not self.has_data(addr):
                     reassemble.data_set[addr] = ''
                     self.label.insert(0, (s.sec_name, addr))
                 self.c2d_addr.insert(0, loc1.loc_addr)
                 return Types.JmpTable_MINUS_S((s_label, r, off))
             if self.check_text(addr):
                 s_label = '-S_' + dec_hex(addr)
                 loc1 = get_loc(instr)
                 if not self.has_text(addr):
                     reassemble.text_set[addr] = ''
                     self.deslist.insert(0, s_label)
                 self.deslist_reloc.insert(0, loc1.loc_addr)
                 return Types.JmpTable_MINUS_S((s_label, r, off))
     return exp