@Override protected List<SourceInfo> doInBackground(String... params) { List<SourceInfo> historyItems = new ArrayList<>(); File showJavaDir = new File(Environment.getExternalStorageDirectory() + "/ShowJava/"); showJavaDir.mkdirs(); File nomedia = new File(showJavaDir, ".nomedia"); if (!nomedia.exists() || !nomedia.isFile()) { try { nomedia.createNewFile(); } catch (IOException e) { Ln.d(e); } } File dir = new File(Environment.getExternalStorageDirectory() + "/ShowJava/sources"); if (dir.exists()) { File[] files = dir.listFiles(); for (File file : files) { if (Utils.sourceExists(file)) { historyItems.add(Utils.getSourceInfoFromSourcePath(file)); } else { if (!Utils.isProcessorServiceRunning(baseContext)) { try { if (file.exists()) { if (file.isDirectory()) { FileUtils.deleteDirectory(file); } else { file.delete(); } } } catch (Exception e) { Ln.d(e); } } if (file.exists() && !file.isDirectory()) { file.delete(); } } } } return historyItems; }
private ArrayList<PackageInfoHolder> getInstalledApps(ApplicationLoader task) { ArrayList<PackageInfoHolder> res = new ArrayList<>(); List<PackageInfo> packages = getPackageManager().getInstalledPackages(0); int totalPackages = packages.size(); for (int i = 0; i < totalPackages; i++) { PackageInfo p = packages.get(i); if (!isSystemPackage(p)) { ApplicationInfo appInfo = null; try { appInfo = getPackageManager().getApplicationInfo(p.packageName, 0); } catch (PackageManager.NameNotFoundException e) { Ln.e(e); } int count = i + 1; int progressVal = (count / totalPackages) * 100; final PackageInfoHolder newInfo = new PackageInfoHolder(); newInfo.packageLabel = p.applicationInfo.loadLabel(getPackageManager()).toString(); task.doProgress( "Loading application " + count + " of " + totalPackages + " (" + newInfo.packageLabel + ")"); newInfo.packageName = p.packageName; newInfo.packageVersion = p.versionName; if (appInfo != null) { newInfo.packageFilePath = appInfo.publicSourceDir; } newInfo.packageIcon = p.applicationInfo.loadIcon(getPackageManager()); res.add(newInfo); } } Comparator<PackageInfoHolder> AppNameComparator = new Comparator<PackageInfoHolder>() { public int compare(PackageInfoHolder o1, PackageInfoHolder o2) { return o1.getPackageLabel().compareTo(o2.getPackageLabel()); } }; Collections.sort(res, AppNameComparator); return res; }
private void cleanOldSources() { File dir = new File(Environment.getExternalStorageDirectory() + "/ShowJava"); if (dir.exists()) { File[] files = dir.listFiles(); for (File file : files) { if (!file.getName().equalsIgnoreCase("sources")) { try { if (file.exists()) { if (file.isDirectory()) { FileUtils.deleteDirectory(file); } else { file.delete(); } } } catch (Exception e) { Ln.d(e); } } } } else { dir.mkdirs(); } }
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == FILE_PICKER) { if (data != null) { Uri uri = data.getData(); File apkFile = new File(uri.getPath()); final String PackageDir = apkFile.getAbsolutePath(); Ln.d(PackageDir); final String PackageName; final String PackageId; if (FilenameUtils.isExtension(PackageDir, "apk")) { PackageManager pm = getPackageManager(); PackageInfo info = pm.getPackageArchiveInfo(PackageDir, PackageManager.GET_ACTIVITIES); if (info != null) { ApplicationInfo appInfo = info.applicationInfo; if (Build.VERSION.SDK_INT >= 8) { appInfo.sourceDir = PackageDir; appInfo.publicSourceDir = PackageDir; } PackageName = info.applicationInfo.loadLabel(getPackageManager()).toString(); PackageId = info.packageName; } else { PackageName = ""; PackageId = ""; } if (!prefs.getBoolean("hide_decompiler_select", false)) { final CharSequence[] items = {"CFR 0.102", "JaDX 0.6.1"}; AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Pick a decompiler"); builder.setItems( items, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { Intent i = new Intent(getApplicationContext(), AppProcessActivity.class); i.putExtra("package_id", PackageId); i.putExtra("package_label", PackageName); i.putExtra("package_file_path", PackageDir); i.putExtra("decompiler", (item == 1 ? "jadx" : "cfr")); startActivity(i); overridePendingTransition(R.anim.fadein, R.anim.fadeout); } }); AlertDialog alert = builder.create(); alert.show(); } else { Intent i = new Intent(getApplicationContext(), AppProcessActivity.class); i.putExtra("package_id", PackageId); i.putExtra("package_label", PackageName); i.putExtra("package_file_path", PackageDir); i.putExtra("decompiler", prefs.getString("decompiler", "cfr")); startActivity(i); overridePendingTransition(R.anim.fadein, R.anim.fadeout); } } } } }