def export_apps_to_format( a, output, dot=None, _format=None ) : output_name = output if output_name[-1] != "/" : output_name = output_name + "/" for vm in a.get_vms() : x = analysis.VMAnalysis( vm ) for method in vm.get_methods() : filename = output_name + valid_class_name( method.get_class_name() ) if filename[-1] != "/" : filename = filename + "/" descriptor = method.get_descriptor() descriptor = descriptor.replace(";", "") descriptor = descriptor.replace(" ", "") descriptor = descriptor.replace("(", "-") descriptor = descriptor.replace(")", "-") descriptor = descriptor.replace("/", "_") filename = filename + method.get_name() + descriptor buff = method2dot( x.get_method( method ) ) if dot : fd = open( filename + ".dot", "w") fd.write( buff ) fd.close() if _format : method2format( filename + "." + _format, _format, raw = buff )
def export_apps_to_format(a, output, dot=None, _format=None): output_name = output if output_name[-1] != "/": output_name = output_name + "/" for vm in a.get_vms(): x = analysis.VMAnalysis(vm) for method in vm.get_methods(): filename = output_name + valid_class_name(method.get_class_name()) if filename[-1] != "/": filename = filename + "/" descriptor = method.get_descriptor() descriptor = descriptor.replace(";", "") descriptor = descriptor.replace(" ", "") descriptor = descriptor.replace("(", "-") descriptor = descriptor.replace(")", "-") descriptor = descriptor.replace("/", "_") filename = filename + method.get_name() + descriptor buff = method2dot(x.get_method(method)) if dot: fd = open(filename + ".dot", "w") fd.write(buff) fd.close() if _format: method2format(filename + "." + _format, _format, raw=buff)
def get_method_graphs(self): # get _the_ androguard ``Analysis`` object that contains our current class dx = self.mainwin.session.get_analysis(self.current_class) # we're going to fill this svgs array with one svg graph per method svgs = [] # m is of type ``EncodedMethod``` for m in self.current_class.get_methods(): # get a ``MethodAnalysis`` object for our method m mx = dx.get_method(m) # get a graph of our method in dot format buff_dot = method2dot(mx) # unpack the returned graph list because we expect a single graph (graph, ) = self.create_graph(buff_dot, str(m.get_name())) graph.write("crash.dot", format='raw') # render svg svg = graph.create_svg() svgs.append(svg) return svgs
def export_apps_to_format(filename, s, output, methods_filter=None, jar=None, decompiler_type=None, form=None): from androguard.misc import clean_file_name from androguard.core.bytecodes import dvm from androguard.core.bytecode import method2dot, method2format from androguard.decompiler import decompiler print("Dump information {} in {}".format(filename, output)) if not os.path.exists(output): print("Create directory %s" % output) os.makedirs(output) else: print("Clean directory %s" % output) androconf.rrmdir(output) os.makedirs(output) methods_filter_expr = None if methods_filter: methods_filter_expr = re.compile(methods_filter) dump_classes = [] for _, vm, vmx in s.get_objects_dex(): print("Decompilation ...", end=' ') sys.stdout.flush() if decompiler_type == "dex2jad": vm.set_decompiler(decompiler.DecompilerDex2Jad(vm, androconf.CONF["BIN_DEX2JAR"], androconf.CONF["BIN_JAD"], androconf.CONF["TMP_DIRECTORY"])) elif decompiler_type == "dex2winejad": vm.set_decompiler(decompiler.DecompilerDex2WineJad(vm, androconf.CONF["BIN_DEX2JAR"], androconf.CONF["BIN_WINEJAD"], androconf.CONF["TMP_DIRECTORY"])) elif decompiler_type == "ded": vm.set_decompiler(decompiler.DecompilerDed(vm, androconf.CONF["BIN_DED"], androconf.CONF["TMP_DIRECTORY"])) elif decompiler_type == "dex2fernflower": vm.set_decompiler(decompiler.DecompilerDex2Fernflower(vm, androconf.CONF["BIN_DEX2JAR"], androconf.CONF["BIN_FERNFLOWER"], androconf.CONF["OPTIONS_FERNFLOWER"], androconf.CONF["TMP_DIRECTORY"])) print("End") if jar: print("jar ...", end=' ') filenamejar = decompiler.Dex2Jar(vm, androconf.CONF["BIN_DEX2JAR"], androconf.CONF["TMP_DIRECTORY"]).get_jar() shutil.move(filenamejar, os.path.join(output, "classes.jar")) print("End") for method in vm.get_methods(): if methods_filter_expr: msig = "{}{}{}".format(method.get_class_name(), method.get_name(), method.get_descriptor()) if not methods_filter_expr.search(msig): continue # Current Folder to write to filename_class = valid_class_name(str(method.get_class_name())) filename_class = os.path.join(output, filename_class) create_directory(filename_class) print("Dump {} {} {} ...".format(method.get_class_name(), method.get_name(), method.get_descriptor()), end=' ') filename = clean_file_name(os.path.join(filename_class, method.get_short_string())) buff = method2dot(vmx.get_method(method)) # Write Graph of method if form: print("%s ..." % form, end=' ') method2format(filename + "." + form, form, None, buff) # Write the Java file for the whole class if str(method.get_class_name()) not in dump_classes: print("source codes ...", end=' ') current_class = vm.get_class(method.get_class_name()) current_filename_class = valid_class_name(str(current_class.get_name())) current_filename_class = os.path.join(output, current_filename_class + ".java") with open(current_filename_class, "w") as fd: fd.write(current_class.get_source()) dump_classes.append(method.get_class_name()) # Write SMALI like code print("bytecodes ...", end=' ') bytecode_buff = dvm.get_bytecodes_method(vm, vmx, method) with open(filename + ".ag", "w") as fd: fd.write(bytecode_buff) print()
def export_apps_to_format(filename, a, output, methods_filter=None, jar=None, decompiler_type=None, format=None): print "Dump information %s in %s" % (filename, output) if not os.path.exists(output): print "Create directory %s" % output os.makedirs(output) else: print "Clean directory %s" % output androconf.rrmdir(output) os.makedirs(output) methods_filter_expr = None if methods_filter: methods_filter_expr = re.compile(methods_filter) output_name = output if output_name[-1] != "/": output_name = output_name + "/" dump_classes = [] for vm in a.get_vms(): print "Analysis ...", sys.stdout.flush() vmx = analysis.VMAnalysis(vm) print "End" print "Decompilation ...", sys.stdout.flush() if not decompiler_type: vm.set_decompiler(decompiler.DecompilerDAD(vm, vmx)) elif decompiler_type == "dex2jad": vm.set_decompiler( decompiler.DecompilerDex2Jad(vm, androconf.CONF["PATH_DEX2JAR"], androconf.CONF["BIN_DEX2JAR"], androconf.CONF["PATH_JAD"], androconf.CONF["BIN_JAD"], androconf.CONF["TMP_DIRECTORY"])) elif decompiler_type == "dex2winejad": vm.set_decompiler( decompiler.DecompilerDex2WineJad( vm, androconf.CONF["PATH_DEX2JAR"], androconf.CONF["BIN_DEX2JAR"], androconf.CONF["PATH_JAD"], androconf.CONF["BIN_WINEJAD"], androconf.CONF["TMP_DIRECTORY"])) elif decompiler_type == "ded": vm.set_decompiler( decompiler.DecompilerDed(vm, androconf.CONF["PATH_DED"], androconf.CONF["BIN_DED"], androconf.CONF["TMP_DIRECTORY"])) elif decompiler_type == "dex2fernflower": vm.set_decompiler( decompiler.DecompilerDex2Fernflower( vm, androconf.CONF["PATH_DEX2JAR"], androconf.CONF["BIN_DEX2JAR"], androconf.CONF["PATH_FERNFLOWER"], androconf.CONF["BIN_FERNFLOWER"], androconf.CONF["OPTIONS_FERNFLOWER"], androconf.CONF["TMP_DIRECTORY"])) else: raise ("invalid decompiler !") print "End" if options.jar: print "jar ...", filenamejar = decompiler.Dex2Jar( vm, androconf.CONF["PATH_DEX2JAR"], androconf.CONF["BIN_DEX2JAR"], androconf.CONF["TMP_DIRECTORY"]).get_jar() shutil.move(filenamejar, output + "classes.jar") print "End" for method in vm.get_methods(): if methods_filter_expr: msig = "%s%s%s" % (method.get_class_name(), method.get_name(), method.get_descriptor()) if not methods_filter_expr.search(msig): continue filename_class = valid_class_name(method.get_class_name()) create_directory(filename_class, output) print "Dump %s %s %s ..." % (method.get_class_name(), method.get_name(), method.get_descriptor()), filename_class = output_name + filename_class if filename_class[-1] != "/": filename_class = filename_class + "/" descriptor = method.get_descriptor() descriptor = descriptor.replace(";", "") descriptor = descriptor.replace(" ", "") descriptor = descriptor.replace("(", "-") descriptor = descriptor.replace(")", "-") descriptor = descriptor.replace("/", "_") filename = filename_class + method.get_name() + descriptor if len(method.get_name() + descriptor) > 250: all_identical_name_methods = vm.get_methods_descriptor( method.get_class_name(), method.get_name()) pos = 0 for i in all_identical_name_methods: if i.get_descriptor() == method.get_descriptor(): break pos += 1 filename = filename_class + method.get_name() + "_%d" % pos buff = method2dot(vmx.get_method(method)) if format: print "%s ..." % format, method2format(filename + "." + format, format, None, buff) if method.get_class_name() not in dump_classes: print "source codes ...", current_class = vm.get_class(method.get_class_name()) current_filename_class = valid_class_name( current_class.get_name()) create_directory(filename_class, output) current_filename_class = output_name + current_filename_class + ".java" fd = open(current_filename_class, "w") fd.write(current_class.get_source()) fd.close() dump_classes.append(method.get_class_name()) print "bytecodes ...", bytecode_buff = dvm.get_bytecodes_method(vm, vmx, method) fd = open(filename + ".ag", "w") fd.write(bytecode_buff) fd.close() print
def export_apps_to_format(filename, s, output, methods_filter=None, jar=None, decompiler_type=None, form=None): print("Dump information %s in %s" % (filename, output)) if not os.path.exists(output): print("Create directory %s" % output) os.makedirs(output) else: print("Clean directory %s" % output) androconf.rrmdir(output) os.makedirs(output) methods_filter_expr = None if methods_filter: methods_filter_expr = re.compile(methods_filter) dump_classes = [] for _, vm, vmx in s.get_objects_dex(): print("Decompilation ...", end=' ') sys.stdout.flush() if decompiler_type == "dex2jad": vm.set_decompiler(decompiler.DecompilerDex2Jad(vm, androconf.CONF["BIN_DEX2JAR"], androconf.CONF["BIN_JAD"], androconf.CONF["TMP_DIRECTORY"])) elif decompiler_type == "dex2winejad": vm.set_decompiler(decompiler.DecompilerDex2WineJad(vm, androconf.CONF["BIN_DEX2JAR"], androconf.CONF["BIN_WINEJAD"], androconf.CONF["TMP_DIRECTORY"])) elif decompiler_type == "ded": vm.set_decompiler(decompiler.DecompilerDed(vm, androconf.CONF["BIN_DED"], androconf.CONF["TMP_DIRECTORY"])) elif decompiler_type == "dex2fernflower": vm.set_decompiler(decompiler.DecompilerDex2Fernflower(vm, androconf.CONF["BIN_DEX2JAR"], androconf.CONF["BIN_FERNFLOWER"], androconf.CONF["OPTIONS_FERNFLOWER"], androconf.CONF["TMP_DIRECTORY"])) print("End") if jar: print("jar ...", end=' ') filenamejar = decompiler.Dex2Jar(vm, androconf.CONF["BIN_DEX2JAR"], androconf.CONF["TMP_DIRECTORY"]).get_jar() shutil.move(filenamejar, os.path.join(output, "classes.jar")) print("End") for method in vm.get_methods(): if methods_filter_expr: msig = "%s%s%s" % (method.get_class_name(), method.get_name(), method.get_descriptor()) if not methods_filter_expr.search(msig): continue # Current Folder to write to filename_class = valid_class_name(method.get_class_name()) filename_class = os.path.join(output, filename_class) create_directory(filename_class) print("Dump %s %s %s ..." % (method.get_class_name(), method.get_name(), method.get_descriptor()), end=' ') filename = clean_file_name(os.path.join(filename_class, method.get_short_string())) buff = method2dot(vmx.get_method(method)) # Write Graph of method if form: print("%s ..." % form, end=' ') method2format(filename + "." + form, form, None, buff) # Write the Java file for the whole class if method.get_class_name() not in dump_classes: print("source codes ...", end=' ') current_class = vm.get_class(method.get_class_name()) current_filename_class = valid_class_name(current_class.get_name()) current_filename_class = os.path.join(output, current_filename_class + ".java") with open(current_filename_class, "w") as fd: fd.write(current_class.get_source()) dump_classes.append(method.get_class_name()) # Write SMALI like code print("bytecodes ...", end=' ') bytecode_buff = dvm.get_bytecodes_method(vm, vmx, method) with open(filename + ".ag", "w") as fd: fd.write(bytecode_buff) print()
def export_apps_to_format(filename, a, output, methods_filter=None, jar=None, decompiler_type=None, format=None): print "Dump information %s in %s" % (filename, output) if not os.path.exists(output): print "Create directory %s" % output os.makedirs(output) else: print "Clean directory %s" % output androconf.rrmdir(output) os.makedirs(output) methods_filter_expr = None if methods_filter: methods_filter_expr = re.compile(methods_filter) output_name = output if output_name[-1] != "/": output_name = output_name + "/" dump_classes = [] for vm in a.get_vms(): print "Analysis ...", sys.stdout.flush() vmx = analysis.VMAnalysis(vm) print "End" print "Decompilation ...", sys.stdout.flush() if not decompiler_type: vm.set_decompiler(decompiler.DecompilerDAD(vm, vmx)) elif decompiler_type == "dex2jad": vm.set_decompiler(decompiler.DecompilerDex2Jad( vm, androconf.CONF["PATH_DEX2JAR"], androconf.CONF["BIN_DEX2JAR" ], androconf.CONF["PATH_JAD"], androconf.CONF["BIN_JAD"], androconf.CONF["TMP_DIRECTORY"])) elif decompiler_type == "dex2winejad": vm.set_decompiler(decompiler.DecompilerDex2WineJad( vm, androconf.CONF["PATH_DEX2JAR"], androconf.CONF["BIN_DEX2JAR" ], androconf.CONF["PATH_JAD"], androconf.CONF["BIN_WINEJAD"], androconf.CONF["TMP_DIRECTORY"])) elif decompiler_type == "ded": vm.set_decompiler(decompiler.DecompilerDed( vm, androconf.CONF["PATH_DED"], androconf.CONF["BIN_DED"], androconf.CONF["TMP_DIRECTORY"])) elif decompiler_type == "dex2fernflower": vm.set_decompiler(decompiler.DecompilerDex2Fernflower( vm, androconf.CONF["PATH_DEX2JAR"], androconf.CONF[ "BIN_DEX2JAR" ], androconf.CONF["PATH_FERNFLOWER"], androconf.CONF[ "BIN_FERNFLOWER" ], androconf.CONF["OPTIONS_FERNFLOWER" ], androconf.CONF["TMP_DIRECTORY"])) else: raise ("invalid decompiler !") print "End" if options.jar: print "jar ...", filenamejar = decompiler.Dex2Jar( vm, androconf.CONF["PATH_DEX2JAR"], androconf.CONF["BIN_DEX2JAR"], androconf.CONF["TMP_DIRECTORY"]).get_jar() shutil.move(filenamejar, output + "classes.jar") print "End" for method in vm.get_methods(): if methods_filter_expr: msig = "%s%s%s" % (method.get_class_name(), method.get_name(), method.get_descriptor()) if not methods_filter_expr.search(msig): continue filename_class = valid_class_name(method.get_class_name()) create_directory(filename_class, output) print "Dump %s %s %s ..." % (method.get_class_name(), method.get_name(), method.get_descriptor()), filename_class = output_name + filename_class if filename_class[-1] != "/": filename_class = filename_class + "/" descriptor = method.get_descriptor() descriptor = descriptor.replace(";", "") descriptor = descriptor.replace(" ", "") descriptor = descriptor.replace("(", "-") descriptor = descriptor.replace(")", "-") descriptor = descriptor.replace("/", "_") filename = filename_class + method.get_name() + descriptor if len(method.get_name() + descriptor) > 250: all_identical_name_methods = vm.get_methods_descriptor( method.get_class_name(), method.get_name()) pos = 0 for i in all_identical_name_methods: if i.get_descriptor() == method.get_descriptor(): break pos += 1 filename = filename_class + method.get_name() + "_%d" % pos buff = method2dot(vmx.get_method(method)) if format: print "%s ..." % format, method2format(filename + "." + format, format, None, buff) if method.get_class_name() not in dump_classes: print "source codes ...", current_class = vm.get_class(method.get_class_name()) current_filename_class = valid_class_name( current_class.get_name()) create_directory(filename_class, output) current_filename_class = output_name + current_filename_class + ".java" with open(current_filename_class, "w") as fd: fd.write(current_class.get_source()) dump_classes.append(method.get_class_name()) print "bytecodes ...", bytecode_buff = dvm.get_bytecodes_method(vm, vmx, method) with open(filename + ".ag", "w") as fd: fd.write(bytecode_buff) print