style: return DexFile interface from SmaliDecoder

This commit is contained in:
IgorEisberg 2021-07-04 14:12:38 +03:00
parent 6cfa79e456
commit fad2f99541
2 changed files with 14 additions and 10 deletions

View File

@ -32,6 +32,10 @@ import brut.androlib.src.SmaliDecoder;
import brut.common.BrutException;
import brut.directory.*;
import brut.util.*;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.jf.dexlib2.iface.DexFile;
import java.io.*;
import java.util.*;
import java.util.logging.Logger;
@ -41,9 +45,6 @@ import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipOutputStream;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
public class Androlib {
private final AndrolibResources mAndRes = new AndrolibResources();
protected final ResUnknownFiles mResUnknownFiles = new ResUnknownFiles();
@ -95,9 +96,10 @@ public class Androlib {
OS.rmdir(smaliDir);
smaliDir.mkdirs();
LOGGER.info("Baksmaling " + filename + "...");
apiLevel = SmaliDecoder.decode(apkFile, smaliDir, filename, bakDeb, apiLevel);
if (mMinSdkVersion == 0 || mMinSdkVersion > apiLevel) {
mMinSdkVersion = apiLevel;
DexFile dexFile = SmaliDecoder.decode(apkFile, smaliDir, filename, bakDeb, apiLevel);
int minSdkVersion = dexFile.getOpcodes().api;
if (mMinSdkVersion == 0 || mMinSdkVersion > minSdkVersion) {
mMinSdkVersion = minSdkVersion;
}
} catch (BrutException ex) {
throw new AndrolibException(ex);

View File

@ -24,6 +24,7 @@ import org.jf.dexlib2.Opcodes;
import org.jf.dexlib2.dexbacked.DexBackedDexFile;
import org.jf.dexlib2.dexbacked.DexBackedOdexFile;
import org.jf.dexlib2.analysis.InlineMethodResolver;
import org.jf.dexlib2.iface.DexFile;
import org.jf.dexlib2.iface.MultiDexContainer;
import java.io.File;
@ -31,7 +32,7 @@ import java.io.IOException;
public class SmaliDecoder {
public static int decode(File apkFile, File outDir, String dexName, boolean bakDeb, int apiLevel)
public static DexFile decode(File apkFile, File outDir, String dexName, boolean bakDeb, int apiLevel)
throws AndrolibException {
return new SmaliDecoder(apkFile, outDir, dexName, bakDeb, apiLevel).decode();
}
@ -44,7 +45,7 @@ public class SmaliDecoder {
mApiLevel = apiLevel;
}
private int decode() throws AndrolibException {
private DexFile decode() throws AndrolibException {
try {
final BaksmaliOptions options = new BaksmaliOptions();
@ -67,7 +68,8 @@ public class SmaliDecoder {
}
// create the container
MultiDexContainer<? extends DexBackedDexFile> container = DexFileFactory.loadDexContainer(mApkFile, mApiLevel > 0 ? Opcodes.forApi(mApiLevel) : null);
MultiDexContainer<? extends DexBackedDexFile> container =
DexFileFactory.loadDexContainer(mApkFile, mApiLevel > 0 ? Opcodes.forApi(mApiLevel) : null);
MultiDexContainer.DexEntry<? extends DexBackedDexFile> dexEntry;
DexBackedDexFile dexFile;
@ -97,7 +99,7 @@ public class SmaliDecoder {
Baksmali.disassembleDexFile(dexFile, mOutDir, jobs, options);
return dexFile.getOpcodes().api;
return dexFile;
} catch (IOException ex) {
throw new AndrolibException(ex);
}