<commit_before>require_relative 'apk_to_java/pretty_printer'

module ApkToJava
  include ApkToJava::PrettyPrinter
  DEX_TO_JAR = '/usr/local/Cellar/dex2jar/2.0/bin/d2j-dex2jar'
  JADX = '/usr/local/Cellar/jadx/bin/jadx-gui'

  module Setup
    def install_dex2jar
      print_info("installing dex2jar..")
      `ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null && brew install dex2jar`
      print_success "done!"
    end

    def install_jadx
      print_info("installing jadx..")
      `cd /usr/local/Cellar && wget https://github.com/skylot/jadx/releases/download/v0.6.0/jadx-0.6.0.zip && unzip jadx-0.6.0.zip -d jadx/ && rm jadx-0.6.0.zip && cd -`
      print_success "done!"
    end

    def jadx_installed?
      !`ls #{ApkToJava::JADX}`.empty?
    end

    def dex_to_jar_installed?
      !`ls #{ApkToJava::DEX_TO_JAR}`.empty?
    end

    def env_setup?
      dex_to_jar_installed? && jadx_installed?
    end

    def initialize_setup
      print_info("Initializing setup!!")
      install_dex2jar if !dex_to_jar_installed?
      install_jadx if !jadx_installed?
      print_success("setup done :)")
    end
  end

  module Operations
    def convert_to_dex(apk)
      print_info "Converting to dex.."
      `mkdir apkToJava`
      `cp #{apk} apkToJava/`
      apk_name = apk.split('/').last.split('.').first
      apk = "apkToJava/#{apk_name}"
      `mv apkToJava/#{apk_name}.apk apkToJava/#{apk_name}.zip`
      `unzip apkToJava/#{apk_name}.zip -d apkTojava/`
      `#{ApkToJava::DEX_TO_JAR} apkTojava/classes.dex`
      print_success "done!"
      `pwd`.chomp + "/apkTojava/classes.dex"
    end

    def dex_to_jar(apk)
      dex_file = convert_to_dex apk
      print_info "Converting dex to jar"
      command = ApkToJava::DEX_TO_JAR + " #{dex_file}"
      `#{command}`
      print_success "done!"
      `pwd`.chomp + '/classes-dex2jar.jar'
    end

    def clean_up
      print_info "cleaning the mess.."
      `rm -rf apkToJava`
      'rm classes-dex2jar.jar'
      print_success "done!"
    end

    def view_as_java_code(apk)
      jar_file = dex_to_jar apk
      clean_up
      print_info "Opening in gui interface.."

      command = ApkToJava::JADX + " #{jar_file} &"
      print_success "Please be patience, apkToJava might take some time to load your project in gui interface"
      `#{command}`
    end
  end
end<commit_msg>fixing cleanup<commit_after>require_relative 'apk_to_java/pretty_printer'

module ApkToJava
  include ApkToJava::PrettyPrinter
  DEX_TO_JAR = '/usr/local/Cellar/dex2jar/2.0/bin/d2j-dex2jar'
  JADX = '/usr/local/Cellar/jadx/bin/jadx-gui'

  module Setup
    def install_dex2jar
      print_info("installing dex2jar..")
      `ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null && brew install dex2jar`
      print_success "done!"
    end

    def install_jadx
      print_info("installing jadx..")
      `cd /usr/local/Cellar && wget https://github.com/skylot/jadx/releases/download/v0.6.0/jadx-0.6.0.zip && unzip jadx-0.6.0.zip -d jadx/ && rm jadx-0.6.0.zip && cd -`
      print_success "done!"
    end

    def jadx_installed?
      !`ls #{ApkToJava::JADX}`.empty?
    end

    def dex_to_jar_installed?
      !`ls #{ApkToJava::DEX_TO_JAR}`.empty?
    end

    def env_setup?
      dex_to_jar_installed? && jadx_installed?
    end

    def initialize_setup
      print_info("Initializing setup!!")
      install_dex2jar if !dex_to_jar_installed?
      install_jadx if !jadx_installed?
      print_success("setup done :)")
    end
  end

  module Operations
    def convert_to_dex(apk)
      print_info "Converting to dex.."
      `mkdir apkToJava`
      `cp #{apk} apkToJava/`
      apk_name = apk.split('/').last.split('.').first
      apk = "apkToJava/#{apk_name}"
      `mv apkToJava/#{apk_name}.apk apkToJava/#{apk_name}.zip`
      `unzip apkToJava/#{apk_name}.zip -d apkTojava/`
      `#{ApkToJava::DEX_TO_JAR} apkTojava/classes.dex`
      print_success "done!"
      `pwd`.chomp + "/apkTojava/classes.dex"
    end

    def dex_to_jar(apk)
      dex_file = convert_to_dex apk
      print_info "Converting dex to jar"
      command = ApkToJava::DEX_TO_JAR + " #{dex_file}"
      `#{command}`
      print_success "done!"
      `pwd`.chomp + '/classes-dex2jar.jar'
    end

    def clean_up
      print_info "cleaning the mess.."
      `rm -rf apkToJava`
      print_success "done!"
    end

    def view_as_java_code(apk)
      jar_file = dex_to_jar apk
      clean_up
      print_info "Opening in gui interface.."

      command = ApkToJava::JADX + " #{jar_file} &"
      print_success "Please be patience, apkToJava might take some time to load your project in gui interface"
      `#{command}`
    end
  end
end
{'fraction_non_alphanumeric': 0.12640801001251564, 'fraction_numerical': 0.00980392156862745, 'mean_word_length': 2.7755905511811023, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6842703', 'n_tokens_mistral': 1897, 'n_tokens_neox': 1798, 'n_words': 348}