Skip to content

Commit

Permalink
Implement decompiling individual "DEX" files
Browse files Browse the repository at this point in the history
Signed-off-by: apk-editor <[email protected]>
  • Loading branch information
apk-editor committed Nov 26, 2023
1 parent b9b6895 commit b28be96
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
Expand Down Expand Up @@ -30,6 +31,7 @@
import com.apk.editor.utils.APKEditorUtils;
import com.apk.editor.utils.APKExplorer;
import com.apk.editor.utils.Common;
import com.apk.editor.utils.DexToSmali;
import com.apk.editor.utils.tasks.DeleteFile;
import com.apk.editor.utils.tasks.DeleteProject;
import com.apk.editor.utils.tasks.ExportToStorage;
Expand Down Expand Up @@ -197,13 +199,13 @@ public void onPostExecute() {
Intent imageView = new Intent(requireActivity(), ImageViewActivity.class);
imageView.putExtra(ImageViewActivity.PATH_INTENT, APKExplorer.getData(getFilesList(), true, requireActivity()).get(position));
startActivity(imageView);
} else if (APKExplorer.getData(getFilesList(), true, requireActivity()).get(position).endsWith(".dex") || APKExplorer.getData(getFilesList(), true,
requireActivity()).get(position).endsWith("resources.arsc")) {
} else if (APKExplorer.getData(getFilesList(), true, requireActivity()).get(position).endsWith(".dex")) {
decompileDexToSmali(new File(APKExplorer.getData(getFilesList(), true, requireActivity()).get(position))).execute();
} else if (APKExplorer.getData(getFilesList(), true, requireActivity()).get(position).equalsIgnoreCase("resources.arsc")) {
new MaterialAlertDialogBuilder(requireActivity())
.setIcon(R.mipmap.ic_launcher)
.setTitle(R.string.unsupported_file)
.setMessage(getString(APKExplorer.getData(getFilesList(), true, requireActivity()).get(position).endsWith("resources.arsc") ?
R.string.unsupported_file_arsc :R.string.unsupported_file_dex))
.setMessage(R.string.unsupported_file_arsc)
.setPositiveButton(getString(R.string.cancel), (dialog, id) -> {
}).show();
} else {
Expand Down Expand Up @@ -254,6 +256,48 @@ public void handleOnBackPressed() {
return mRootView;
}

private sExecutor decompileDexToSmali(File inputFile) {
return new sExecutor() {
private ProgressDialog mProgressDialog;
private File mBackUpPath, mExplorePath;
private String mDexName = null;

@SuppressLint("StringFormatInvalid")
@Override
public void onPreExecute() {
mProgressDialog = new ProgressDialog(requireActivity());
mProgressDialog.setMessage("\n" + getString(R.string.decompiling, inputFile.getName()));
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
mProgressDialog.setIcon(R.mipmap.ic_launcher);
mProgressDialog.setTitle(R.string.app_name);
mProgressDialog.setIndeterminate(true);
mProgressDialog.setCancelable(false);
mProgressDialog.show();
mExplorePath = inputFile.getParentFile();
mBackUpPath = new File(mExplorePath,".aeeBackup");
mDexName = inputFile.getName();
}

@Override
public void doInBackground() {
sFileUtils.mkdir(mBackUpPath);
sFileUtils.copy(inputFile, new File(mBackUpPath, inputFile.getName()));
sFileUtils.delete(inputFile);
sFileUtils.mkdir(new File(mExplorePath, mDexName));
new DexToSmali(false, new File(mBackUpPath, inputFile.getName()), new File(mExplorePath, mDexName), 0, mDexName).execute();
}

@Override
public void onPostExecute() {
try {
mProgressDialog.dismiss();
} catch (IllegalArgumentException ignored) {
}
reload(requireActivity());
}
};
}

private void retainDialog() {
if (sCommonUtils.getString("projectAction", null, requireActivity()) == null) {
new MaterialAlertDialogBuilder(requireActivity())
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/com/apk/editor/utils/DexToSmali.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
public class DexToSmali {

private final boolean mDebugInfo;
private final File mApkFile, mOutDir;
private final File mInputFile, mOutDir;
private final int mAPI;
private final String mDEXName;

public DexToSmali(boolean debugInfo, File apkFile, File outDir, int api, String dexName) {
public DexToSmali(boolean debugInfo, File inputFile, File outDir, int api, String dexName) {
this.mDebugInfo = debugInfo;
this.mApkFile = apkFile;
this.mInputFile = inputFile;
this.mOutDir = outDir;
this.mAPI = api;
this.mDEXName = dexName;
Expand All @@ -51,7 +51,7 @@ public void execute() {
jobs = 6;
}
// create the container
MultiDexContainer<? extends DexBackedDexFile> container = DexFileFactory.loadDexContainer(mApkFile, Opcodes.forApi(mAPI));
MultiDexContainer<? extends DexBackedDexFile> container = DexFileFactory.loadDexContainer(mInputFile, Opcodes.forApi(mAPI));
MultiDexContainer.DexEntry<? extends DexBackedDexFile> dexEntry;
DexBackedDexFile dexFile;
// If we have 1 item, ignore the passed file. Pull the DexFile we need.
Expand Down

0 comments on commit b28be96

Please sign in to comment.