def run(self, swf_filename): print('parsing original source files in {0} ...'.format( self._paths['src'] )) self._builder = asdox.asBuilder.Builder() if self.is_move_source_codes: print('clean up {0} ...'.format(self._paths['dst'])) if os.path.exists(self._paths['dst']): shutil.rmtree(self._paths['dst']) os.makedirs(self._paths['dst']) # 收集混淆包名, 类名 self._reproduce_module(self._paths['src'], self._paths['dst']) self._names_map['module'] = self._module_generator.names_map self._names_map['module'][''] = '' self._names_map['class'] = self._classname_generator.names_map # 收集源代码信息 self._packages = self._builder.packages del self._builder print('generating new infos ...') for pkg in self._packages.values(): for cls in pkg.classes.values(): cls.fuzzy, method_names_map = FuzzyClassGenerator.generate( pkg.name, cls, self._names_map['class'] ) self._names_map['method'][cls.full_name] = method_names_map for interface in pkg.interfaces.values(): interface.fuzzy, method_names_map = FuzzyClassGenerator.generate( pkg.name, interface, self._names_map['class'] ) self._names_map['method'][interface.full_name] = method_names_map # 记录映射关系 print(json.dumps(self._names_map, indent=4)) with open('names_map.json', 'w') as outfile: print(json.dumps(self._names_map, indent=4), file=outfile) pydata_filename = swf_filename.split(os.sep)[2] dump_filename = 'self.' + pydata_filename + '.pydata' import cPickle as pickle with open(dump_filename, 'w') as outfile: pickle.dump(self, outfile) print('dumped `self` to `{0}`....'.format(dump_filename)) print('Analysing swf file:{0} ...'.format(swf_filename)) replacer = SWFFileReplacer(self._packages, self._names_map) name, ext = os.path.splitext(swf_filename) out_filename = name + '.obfused' + ext replacer.replace(swf_filename, out_filename) print('Replacing SWF file {0} -> {1}'.format(swf_filename, out_filename)) return None
def debug(self, swf_filename): pydata_filename = swf_filename.split(os.sep)[2] dump_filename = 'self.' + pydata_filename + '.pydata' print('>>debug<< restore self from {0}'.format( 'self.' + pydata_filename + '.pydata' )) import cPickle as pickle with open(dump_filename, 'r') as infile: self = pickle.load(infile) print('Analysing swf file:{0} ...'.format(swf_filename)) replacer = SWFFileReplacer(self._packages, self._names_map) name, ext = os.path.splitext(swf_filename) out_filename = name + '.obfused' + ext replacer.replace(swf_filename, out_filename) print('Replacing SWF file {0} -> {1}'.format(swf_filename, out_filename)) return None