def dex_2_smali(app_dir, tools_dir):
    """Run dex2smali."""
    try:
        logger.info('DEX -> SMALI')
        dexes = get_dex_files(app_dir)
        for dex_path in dexes:
            logger.info('Converting %s to Smali Code',
                        filename_from_path(dex_path))
            if (len(settings.BACKSMALI_BINARY) > 0
                    and is_file_exists(settings.BACKSMALI_BINARY)):
                bs_path = settings.BACKSMALI_BINARY
            else:
                bs_path = os.path.join(tools_dir, 'baksmali-2.5.2.jar')
            output = os.path.join(app_dir, 'smali_source/')
            smali = [
                find_java_binary(),
                '-jar',
                bs_path,
                'd',
                dex_path,
                '-o',
                output,
            ]
            trd = threading.Thread(target=subprocess.call, args=(smali, ))
            trd.daemon = True
            trd.start()
    except Exception:
        logger.exception('Converting DEX to SMALI')
    def get_embedded_classes(self):
        """
        Get the list of Java classes from all DEX files.

        :return: list of Java classes
        """
        if self.classes is not None:
            return self.classes
        for dex_file in glob.iglob(os.path.join(self.apk_dir, '*.dex')):
            if (len(settings.BACKSMALI_BINARY) > 0
                    and is_file_exists(settings.BACKSMALI_BINARY)):
                bs_path = settings.BACKSMALI_BINARY
            else:
                bs_path = os.path.join(self.tools_dir, 'baksmali-2.5.2.jar')
            args = [
                find_java_binary(), '-jar', bs_path, 'list', 'classes',
                dex_file
            ]
            classes = subprocess.check_output(
                args, universal_newlines=True).splitlines()
            if self.classes is not None:
                self.classes = self.classes + classes
            else:
                self.classes = classes
        return self.classes
def win_fix_java(tools_dir):
    """Run JAVA path fix in Windows."""
    try:
        logger.info('Running JAVA path fix in Windows')
        dmy = os.path.join(tools_dir, 'd2j2/d2j_invoke.tmp')
        org = os.path.join(tools_dir, 'd2j2/d2j_invoke.bat')
        dat = ''
        with open(dmy, 'r') as file_pointer:
            dat = file_pointer.read().replace('[xxx]', find_java_binary())
        with open(org, 'w') as file_pointer:
            file_pointer.write(dat)
    except Exception:
        logger.exception('Running JAVA path fix in Windows')