Merge pull request #2605 from IgorEisberg/master

Determine minSdkVersion with baksmali for JARs + don't compress webp
This commit is contained in:
Connor Tumbleson 2021-07-04 09:19:28 -04:00 committed by GitHub
commit a36be82c48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 14 deletions

View File

@ -32,6 +32,10 @@ import brut.androlib.src.SmaliDecoder;
import brut.common.BrutException; import brut.common.BrutException;
import brut.directory.*; import brut.directory.*;
import brut.util.*; 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.io.*;
import java.util.*; import java.util.*;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -41,25 +45,21 @@ import java.util.zip.ZipEntry;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
public class Androlib { public class Androlib {
private final AndrolibResources mAndRes = new AndrolibResources(); private final AndrolibResources mAndRes = new AndrolibResources();
protected final ResUnknownFiles mResUnknownFiles = new ResUnknownFiles(); protected final ResUnknownFiles mResUnknownFiles = new ResUnknownFiles();
public ApkOptions apkOptions; public ApkOptions apkOptions;
private int mMinSdkVersion = 0; private int mMinSdkVersion = 0;
public Androlib() {
this(new ApkOptions());
}
public Androlib(ApkOptions apkOptions) { public Androlib(ApkOptions apkOptions) {
this.apkOptions = apkOptions; this.apkOptions = apkOptions;
mAndRes.apkOptions = apkOptions; mAndRes.apkOptions = apkOptions;
} }
public Androlib() {
this.apkOptions = new ApkOptions();
mAndRes.apkOptions = this.apkOptions;
}
public ResTable getResTable(ExtFile apkFile) public ResTable getResTable(ExtFile apkFile)
throws AndrolibException { throws AndrolibException {
return mAndRes.getResTable(apkFile, true); return mAndRes.getResTable(apkFile, true);
@ -70,6 +70,10 @@ public class Androlib {
return mAndRes.getResTable(apkFile, loadMainPkg); return mAndRes.getResTable(apkFile, loadMainPkg);
} }
public int getMinSdkVersion() {
return mMinSdkVersion;
}
public void decodeSourcesRaw(ExtFile apkFile, File outDir, String filename) public void decodeSourcesRaw(ExtFile apkFile, File outDir, String filename)
throws AndrolibException { throws AndrolibException {
try { try {
@ -92,7 +96,11 @@ public class Androlib {
OS.rmdir(smaliDir); OS.rmdir(smaliDir);
smaliDir.mkdirs(); smaliDir.mkdirs();
LOGGER.info("Baksmaling " + filename + "..."); LOGGER.info("Baksmaling " + filename + "...");
SmaliDecoder.decode(apkFile, smaliDir, filename, bakDeb, 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) { } catch (BrutException ex) {
throw new AndrolibException(ex); throw new AndrolibException(ex);
} }
@ -809,5 +817,5 @@ public class Androlib {
"lib", "libs", "assets", "META-INF", "kotlin" }; "lib", "libs", "assets", "META-INF", "kotlin" };
private final static Pattern NO_COMPRESS_PATTERN = Pattern.compile("(" + private final static Pattern NO_COMPRESS_PATTERN = Pattern.compile("(" +
"jpg|jpeg|png|gif|wav|mp2|mp3|ogg|aac|mpg|mpeg|mid|midi|smf|jet|rtttl|imy|xmf|mp4|" + "jpg|jpeg|png|gif|wav|mp2|mp3|ogg|aac|mpg|mpeg|mid|midi|smf|jet|rtttl|imy|xmf|mp4|" +
"m4a|m4v|3gp|3gpp|3g2|3gpp2|amr|awb|wma|wmv|webm|mkv)$"); "m4a|m4v|3gp|3gpp|3g2|3gpp2|amr|awb|wma|wmv|webm|webp|mkv)$");
} }

View File

@ -332,6 +332,8 @@ public class ApkDecoder {
putVersionInfo(meta); putVersionInfo(meta);
putSharedLibraryInfo(meta); putSharedLibraryInfo(meta);
putSparseResourcesInfo(meta); putSparseResourcesInfo(meta);
} else {
putMinSdkInfo(meta);
} }
putUnknownInfo(meta); putUnknownInfo(meta);
putFileCompressionInfo(meta); putFileCompressionInfo(meta);
@ -386,6 +388,15 @@ public class ApkDecoder {
} }
} }
private void putMinSdkInfo(MetaInfo meta) {
int minSdkVersion = mAndrolib.getMinSdkVersion();
if (minSdkVersion > 0) {
Map<String, String> sdkInfo = new LinkedHashMap<>();
sdkInfo.put("minSdkVersion", Integer.toString(minSdkVersion));
meta.sdkInfo = sdkInfo;
}
}
private void putPackageInfo(MetaInfo meta) throws AndrolibException { private void putPackageInfo(MetaInfo meta) throws AndrolibException {
String renamed = mResTable.getPackageRenamed(); String renamed = mResTable.getPackageRenamed();
String original = mResTable.getPackageOriginal(); String original = mResTable.getPackageOriginal();

View File

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