Ejemplo n.º 1
0
 def _replace_multiname(self, packagename, classname):
     for index, multiname in enumerate(self._get_original_multiname_all()):
         if index == 0:
             continue
         print(self.abcfile.const_pool.get_multiname_string(index))
         # 只处理QName/QNameA的 multiname
         if multiname.kind not in (StMultiname.QName, StMultiname.QNameA):
             continue
         info = self.abcfile.const_pool.get_multiname(index)
         if info['namespace'] == joinPackageClassName(packagename, classname):
             # 私有方法/私有成员变量
             if info['name'] in self.abcclass.methods:
                 new_method_name = self.abcclass.fuzzy.methods[info['name']].name
                 self._set_new_string(multiname.name, new_method_name)
                 print(u'Replace by {0}({1})'.format(new_method_name, multiname.name))
             elif info['name'] in self.abcclass.variables:
                 new_var_name = self.abcclass.fuzzy.variables[info['name']].name
                 self._set_new_string(multiname.name, new_var_name)
                 print(u'Replace by {0}({1})'.format(new_var_name, multiname.name))
         elif info['namespace'] == '':
             # 根package中其他文件中定义的类
             if info['name'] in self.packages[''].classes:
                 other_class = self.packages[''].classes[info['name']]
                 new_classname = other_class.fuzzy.name
                 self._set_new_string(multiname.name, new_classname)
                 print('Replace by {0}({1})'.format(new_classname, multiname.name))
         elif info['namespace'] in self.names_map['module']:
             if not is_class_in_packages(self.packages, info['namespace'], info['name']):
                 continue
             # 其他文件中定义的类
             other_class = get_class_from_packages(
                 self.packages,
                 info['namespace'], info['name']
             )
             # 替换为混淆后的类名
             new_classname = other_class.fuzzy.name
             self._set_new_string(multiname.name, new_classname)
             # 替换为混淆后的包名
             new_namespace = self.names_map['module'][info['namespace']]
             self._set_new_namespace(multiname.ns, new_namespace)
             print(u'Replace by {0}({1}) {2}({3})'.format(
                 new_classname, multiname.name,
                 new_namespace, self.abcfile.const_pool.namespaces[multiname.ns]
             ))
Ejemplo n.º 2
0
 def get_new_package_class_name(self, package, cls):
     new_package = self.names_map['module'][package]
     return joinPackageClassName(new_package, cls.fuzzy.name)