Example #1
0
def get_bytecodes_class(dex_object, ana_object, class_obj):
    i_buffer = ""

    for i in class_obj.get_methods():
        i_buffer += dvm.get_bytecodes_method(dex_object, ana_object, i)

    return i_buffer
Example #2
0
    def run(self):
        self.view = self.window.active_view()

        if self.view.id() in AG_METHOD_ID:
            dex_object, ana_object = AG_DEX_VIEW[AG_DEX_VIEW_LINK[self.view.id()]]

            self.view.sel().clear()
            if not AG_SC[self.view.id()]:
                self.view.set_syntax_file("Packages/Java/Java.tmLanguage")
                i_buffer = get_sourcecode_method(dex_object, ana_object, AG_METHOD_ID[self.view.id()])
            else:
                self.view.set_syntax_file("Packages/ag-st/agbytecodes.tmLanguage")
                i_buffer = dvm.get_bytecodes_method(dex_object, ana_object, AG_METHOD_ID[self.view.id()])

            self.view.set_read_only(False)
            edit = self.view.begin_edit()
            self.view.replace(edit, sublime.Region(0, self.view.size()), i_buffer)
            self.view.end_edit(edit)
            AG_SC[self.view.id()] = not AG_SC[self.view.id()]

        elif self.view.id() in AG_CLASS_ID:
            dex_object, ana_object = AG_DEX_VIEW[AG_DEX_VIEW_LINK[self.view.id()]]

            self.view.sel().clear()

            if not AG_SC[self.view.id()]:
                self.view.set_syntax_file("Packages/Java/Java.tmLanguage")
                i_buffer = AG_CLASS_ID[self.view.id()].get_source()
            else:
                self.view.set_syntax_file("Packages/ag-st/agbytecodes.tmLanguage")
                i_buffer = get_bytecodes_class(dex_object, ana_object, AG_CLASS_ID[self.view.id()])

            self.view.set_read_only(False)
            edit = self.view.begin_edit()
            self.view.replace(edit, sublime.Region(0, self.view.size()), i_buffer)
            self.view.end_edit(edit)

            AG_SC[self.view.id()] = not AG_SC[self.view.id()]

        elif self.view.id() in AG_AXML_ID:
            apk_object = AG_AXML_ID[self.view.id()]

            self.view.sel().clear()

            if not AG_SC[self.view.id()]:
                i_buffer = apk_object.get_android_manifest_xml().toprettyxml()
                self.view.set_syntax_file("Packages/XML/XML.tmLanguage")
            else:
                i_buffer = get_axml_info(apk_object)

            self.view.set_read_only(False)
            edit = self.view.begin_edit()
            self.view.replace(edit, sublime.Region(0, self.view.size()), i_buffer)
            self.view.end_edit(edit)

            AG_SC[self.view.id()] = not AG_SC[self.view.id()]
Example #3
0
    def __init__(self, orig_id, method):
        self.view = sublime.active_window().new_file()
        self.dex_object, self.ana_object = AG_DEX_VIEW[orig_id]
        AG_DEX_VIEW_LINK[self.view.id()] = orig_id
        AG_REVERT_METHODS[method] = self.view

        self.view.set_name("%s-%s-%s.mag" % (method.get_class_name(), method.get_name(), method.get_descriptor()))
        self.view.set_syntax_file("Packages/ag-st/agbytecodes.tmLanguage")

        self.view.set_scratch(True)
        edit = self.view.begin_edit()

        i_buffer = dvm.get_bytecodes_method(self.dex_object, self.ana_object, method)
        AG_METHOD_ID[self.view.id()] = method

        self.view.replace(edit, sublime.Region(0, self.view.size()), i_buffer)
        self.view.end_edit(edit)
        self.view.sel().clear()

        if self.view.id() not in AG_SC:
            AG_SC[self.view.id()] = False
Example #4
0
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()
Example #5
0
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
Example #6
0
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
Example #7
0
    def run(self):
        self.view = self.window.active_view()

        if self.view.id() in AG_METHOD_ID:
            dex_object, ana_object = AG_DEX_VIEW[AG_DEX_VIEW_LINK[
                self.view.id()]]

            self.view.sel().clear()
            if not AG_SC[self.view.id()]:
                self.view.set_syntax_file("Packages/Java/Java.tmLanguage")
                i_buffer = get_sourcecode_method(dex_object, ana_object,
                                                 AG_METHOD_ID[self.view.id()])
            else:
                self.view.set_syntax_file(
                    "Packages/ag-st/agbytecodes.tmLanguage")
                i_buffer = dvm.get_bytecodes_method(
                    dex_object, ana_object, AG_METHOD_ID[self.view.id()])

            self.view.set_read_only(False)
            edit = self.view.begin_edit()
            self.view.replace(edit, sublime.Region(0, self.view.size()),
                              i_buffer)
            self.view.end_edit(edit)
            AG_SC[self.view.id()] = not AG_SC[self.view.id()]

        elif self.view.id() in AG_CLASS_ID:
            dex_object, ana_object = AG_DEX_VIEW[AG_DEX_VIEW_LINK[
                self.view.id()]]

            self.view.sel().clear()

            if not AG_SC[self.view.id()]:
                self.view.set_syntax_file("Packages/Java/Java.tmLanguage")
                i_buffer = AG_CLASS_ID[self.view.id()].get_source()
            else:
                self.view.set_syntax_file(
                    "Packages/ag-st/agbytecodes.tmLanguage")
                i_buffer = get_bytecodes_class(dex_object, ana_object,
                                               AG_CLASS_ID[self.view.id()])

            self.view.set_read_only(False)
            edit = self.view.begin_edit()
            self.view.replace(edit, sublime.Region(0, self.view.size()),
                              i_buffer)
            self.view.end_edit(edit)

            AG_SC[self.view.id()] = not AG_SC[self.view.id()]

        elif self.view.id() in AG_AXML_ID:
            apk_object = AG_AXML_ID[self.view.id()]

            self.view.sel().clear()

            if not AG_SC[self.view.id()]:
                i_buffer = apk_object.get_android_manifest_xml().toprettyxml()
                self.view.set_syntax_file("Packages/XML/XML.tmLanguage")
            else:
                i_buffer = get_axml_info(apk_object)

            self.view.set_read_only(False)
            edit = self.view.begin_edit()
            self.view.replace(edit, sublime.Region(0, self.view.size()),
                              i_buffer)
            self.view.end_edit(edit)

            AG_SC[self.view.id()] = not AG_SC[self.view.id()]
Example #8
0
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()
Example #9
0
def method_info_index(apk_vm_serial, output):
    methods_filter_expr = None

    method_dict = {
    }  #method_dict = {method_name: method_info[[invoke_info], CFG_Hash]}
    method_name_list = []
    dump_classes = []
    classes_list = []

    #get vm_list from apk_vm_serial
    for vm_list in apk_vm_serial:
        vm = vm_list[0]
        vmx = vm_list[1]
        for method in vm.get_methods():
            method_info = []  #method_info = [set([invoke_info]), CFG_Hash]
            invoke_info = []
            method_opcode_str = ""
            filename_class = valid_class_name(method.get_class_name())
            if filename_class.find("android/support/v4") != -1:
                continue
            create_directory(filename_class, output)

            #        print "Dump %s %s %s ..." % (method.get_class_name(),
            #                                     method.get_name(),
            #                                     method.get_descriptor()),

            output_dir = output
            if output_dir[-1] != "/":
                output_dir = output_dir + "/"
            filename_class = output_dir + 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

            if method.get_class_name() not in dump_classes:
                #class's name-content pair --> [name, content]
                cls_nc_pair = []

                #print "source codes ...",
                current_class = vm.get_class(method.get_class_name())
                current_filename_clas = valid_class_name(
                    current_class.get_name())
                # create_directory(filename_class, output)

                #                current_filename_class = output_dir + current_filename_clas + ".java"
                #                with open(current_filename_class, "w") as fd:
                #                    fd.write(current_class.get_source())
                dump_classes.append(method.get_class_name())
                #fileclassname = output_dir+current_filename_clas
                fileclassname = "L" + current_filename_clas
                cls_nc_pair.append(fileclassname)
                #cls_nc_pair.append(current_class.get_source())
                classes_list.append(cls_nc_pair)

            bytecode_buff = dvm.get_bytecodes_method(vm, vmx, method)
            line_s = bytecode_buff.split("\n")

            #two procedures for each line
            for line in line_s:

                if line.startswith("\t"):

                    #1st: find 'invoke' information
                    if line.find("invoke") != -1:
                        #invoke relation Lcom/xxx/yyy;->Lcom/sss/uuu;
                        #invokelist = [Lcom/xxx/yyy, "->", Lcom/sss/uuu]
                        invoke_rel = ""
                        tempstr1 = ""
                        tempstr2 = ""
                        ir = line[line.find("L"):]
                        #print "line:", line
                        #print "ir:", ir
                        if ir.find("->") != -1:
                            cls_rels = ir.split("->")

                            tempstr1 = cls_rels[0][
                                cls_rels[0].find("L"):cls_rels[0].find(";")]

                            if cls_rels[1].find("/") != -1 and cls_rels[
                                    1][:cls_rels[1].find("/")].rfind(
                                        "L") != -1:
                                pos = cls_rels[1][:cls_rels[1].
                                                  find("/")].rfind("L")
                                tempstr2 = cls_rels[1][pos:cls_rels[1].find(";"
                                                                            )]

                            if not (tempstr1.startswith("Ljava")
                                    or tempstr1.startswith("Landroid")
                                    or tempstr2.startswith("Ljava")
                                    or tempstr2.startswith("Landroid")
                                    or tempstr1 == tempstr2):
                                if len(tempstr2) != 0:
                                    invoke_rel += tempstr1
                                    invoke_rel += "->"
                                    invoke_rel += tempstr2

                            if invoke_rel != "":
                                invoke_info.append(invoke_rel)

                if line.startswith("\t"):
                    #2nd: computing the HASH Value of mthod
                    #line = line.strip()
                    line = line.strip()
                    tttt = line.find(")")
                    templine = line[tttt + 2:]
                    #if the method contain opcode like:
                    #    goto target, goto/16 target, goto/32 target
                    #    if-xx xx,xx,target
                    if templine.startswith("if") or templine.startswith(
                            "goto"):
                        if templine.rfind(" ") != -1:
                            spcpos = templine.find(" ")
                            rspcpos = templine.rfind(" ")
                            dvmopcode = templine[:spcpos] + templine[rspcpos:]
                    elif templine.find("switch") != -1:
                        if templine.rfind(", ") != -1:
                            spcpos = templine.find(" ")
                            rspcpos = templine.rfind(", ")
                            dvmopcode = templine[:spcpos] + templine[rspcpos +
                                                                     2:]
                    else:
                        rightposition = templine.find(" ")
                        #print templine[:rightposition]
                        dvmopcode = templine[:rightposition]
                    #print dvmopcode
                    method_opcode_str += dvmopcode

            #compute the Hash value of each method
            methodmd5 = hashlib.md5()
            methodmd5.update(method_opcode_str)
            method_md5_index = methodmd5.hexdigest()

            method_name_list.append(filename)
            set_invoke_info = set(invoke_info)
            method_info.append(set_invoke_info)
            method_info.append(method_md5_index)

            method_dict[filename] = method_info

    return method_dict, classes_list