mirror of
https://github.com/revanced/Apktool.git
synced 2024-11-06 12:47:03 +01:00
Refactor into common config object. (#3100)
* extract Config * extract Config * style: linting --------- Co-authored-by: Slava Volkov <sv99@inbox.ru>
This commit is contained in:
parent
25509a7498
commit
10495cbe96
@ -21,9 +21,9 @@ import brut.androlib.exceptions.AndrolibException;
|
||||
import brut.androlib.exceptions.CantFindFrameworkResException;
|
||||
import brut.androlib.exceptions.InFileNotFoundException;
|
||||
import brut.androlib.exceptions.OutDirExistsException;
|
||||
import brut.androlib.options.BuildOptions;
|
||||
import brut.common.BrutException;
|
||||
import brut.directory.DirectoryException;
|
||||
import brut.directory.ExtFile;
|
||||
import brut.util.AaptManager;
|
||||
import brut.util.OSDetection;
|
||||
import org.apache.commons.cli.*;
|
||||
@ -74,25 +74,28 @@ public class Main {
|
||||
setAdvanceMode();
|
||||
}
|
||||
|
||||
Config config = Config.getDefaultConfig();
|
||||
initConfig(commandLine, config);
|
||||
|
||||
boolean cmdFound = false;
|
||||
for (String opt : commandLine.getArgs()) {
|
||||
if (opt.equalsIgnoreCase("d") || opt.equalsIgnoreCase("decode")) {
|
||||
cmdDecode(commandLine);
|
||||
cmdDecode(commandLine, config);
|
||||
cmdFound = true;
|
||||
} else if (opt.equalsIgnoreCase("b") || opt.equalsIgnoreCase("build")) {
|
||||
cmdBuild(commandLine);
|
||||
cmdBuild(commandLine, config);
|
||||
cmdFound = true;
|
||||
} else if (opt.equalsIgnoreCase("if") || opt.equalsIgnoreCase("install-framework")) {
|
||||
cmdInstallFramework(commandLine);
|
||||
cmdInstallFramework(commandLine, config);
|
||||
cmdFound = true;
|
||||
} else if (opt.equalsIgnoreCase("empty-framework-dir")) {
|
||||
cmdEmptyFrameworkDirectory(commandLine);
|
||||
cmdEmptyFrameworkDirectory(commandLine, config);
|
||||
cmdFound = true;
|
||||
} else if (opt.equalsIgnoreCase("list-frameworks")) {
|
||||
cmdListFrameworks(commandLine);
|
||||
cmdListFrameworks(commandLine, config);
|
||||
cmdFound = true;
|
||||
} else if (opt.equalsIgnoreCase("publicize-resources")) {
|
||||
cmdPublicizeResources(commandLine);
|
||||
cmdPublicizeResources(commandLine, config);
|
||||
cmdFound = true;
|
||||
}
|
||||
}
|
||||
@ -108,54 +111,55 @@ public class Main {
|
||||
}
|
||||
}
|
||||
|
||||
private static void cmdDecode(CommandLine cli) throws AndrolibException {
|
||||
ApkDecoder decoder = new ApkDecoder();
|
||||
private static void initConfig(CommandLine cli, Config config) {
|
||||
if (cli.hasOption("p") || cli.hasOption("frame-path")) {
|
||||
config.frameworkDirectory = cli.getOptionValue("p");
|
||||
}
|
||||
if (cli.hasOption("t") || cli.hasOption("tag")) {
|
||||
config.frameworkTag = cli.getOptionValue("t");
|
||||
}
|
||||
if (cli.hasOption("api") || cli.hasOption("api-level")) {
|
||||
config.apiLevel = Integer.parseInt(cli.getOptionValue("api"));
|
||||
}
|
||||
}
|
||||
|
||||
int paraCount = cli.getArgList().size();
|
||||
String apkName = cli.getArgList().get(paraCount - 1);
|
||||
File outDir;
|
||||
private static void cmdDecode(CommandLine cli, Config config) throws AndrolibException {
|
||||
String apkName = getLastArg(cli);
|
||||
|
||||
// check for options
|
||||
// check decode options
|
||||
if (cli.hasOption("s") || cli.hasOption("no-src")) {
|
||||
decoder.setDecodeSources(ApkDecoder.DECODE_SOURCES_NONE);
|
||||
config.setDecodeSources(Config.DECODE_SOURCES_NONE);
|
||||
}
|
||||
if (cli.hasOption("only-main-classes")) {
|
||||
decoder.setDecodeSources(ApkDecoder.DECODE_SOURCES_SMALI_ONLY_MAIN_CLASSES);
|
||||
config.setDecodeSources(Config.DECODE_SOURCES_SMALI_ONLY_MAIN_CLASSES);
|
||||
}
|
||||
if (cli.hasOption("d") || cli.hasOption("debug")) {
|
||||
System.err.println("SmaliDebugging has been removed in 2.1.0 onward. Please see: https://github.com/iBotPeaches/Apktool/issues/1061");
|
||||
System.exit(1);
|
||||
}
|
||||
if (cli.hasOption("b") || cli.hasOption("no-debug-info")) {
|
||||
decoder.setBaksmaliDebugMode(false);
|
||||
}
|
||||
if (cli.hasOption("t") || cli.hasOption("frame-tag")) {
|
||||
decoder.setFrameworkTag(cli.getOptionValue("t"));
|
||||
config.baksmaliDebugMode = false;
|
||||
}
|
||||
if (cli.hasOption("f") || cli.hasOption("force")) {
|
||||
decoder.setForceDelete(true);
|
||||
config.forceDelete = true;
|
||||
}
|
||||
if (cli.hasOption("r") || cli.hasOption("no-res")) {
|
||||
decoder.setDecodeResources(ApkDecoder.DECODE_RESOURCES_NONE);
|
||||
config.setDecodeResources(Config.DECODE_RESOURCES_NONE);
|
||||
}
|
||||
if (cli.hasOption("force-manifest")) {
|
||||
decoder.setForceDecodeManifest(ApkDecoder.FORCE_DECODE_MANIFEST_FULL);
|
||||
config.setForceDecodeManifest(Config.FORCE_DECODE_MANIFEST_FULL);
|
||||
}
|
||||
if (cli.hasOption("no-assets")) {
|
||||
decoder.setDecodeAssets(ApkDecoder.DECODE_ASSETS_NONE);
|
||||
config.setDecodeAssets(Config.DECODE_ASSETS_NONE);
|
||||
}
|
||||
if (cli.hasOption("k") || cli.hasOption("keep-broken-res")) {
|
||||
decoder.setKeepBrokenResources(true);
|
||||
}
|
||||
if (cli.hasOption("p") || cli.hasOption("frame-path")) {
|
||||
decoder.setFrameworkDir(cli.getOptionValue("p"));
|
||||
config.keepBrokenResources = true;
|
||||
}
|
||||
if (cli.hasOption("m") || cli.hasOption("match-original")) {
|
||||
decoder.setAnalysisMode(true);
|
||||
}
|
||||
if (cli.hasOption("api") || cli.hasOption("api-level")) {
|
||||
decoder.setApiLevel(Integer.parseInt(cli.getOptionValue("api")));
|
||||
config.analysisMode = true;
|
||||
}
|
||||
|
||||
File outDir;
|
||||
if (cli.hasOption("o") || cli.hasOption("output")) {
|
||||
outDir = new File(cli.getOptionValue("o"));
|
||||
} else {
|
||||
@ -169,8 +173,8 @@ public class Main {
|
||||
outDir = new File(outName);
|
||||
}
|
||||
|
||||
ApkDecoder decoder = new ApkDecoder(config, new ExtFile(apkName));
|
||||
decoder.setOutDir(outDir);
|
||||
decoder.setApkFile(new File(apkName));
|
||||
|
||||
try {
|
||||
decoder.decode();
|
||||
@ -204,54 +208,48 @@ public class Main {
|
||||
}
|
||||
}
|
||||
|
||||
private static void cmdBuild(CommandLine cli) {
|
||||
private static void cmdBuild(CommandLine cli, Config config) {
|
||||
String[] args = cli.getArgs();
|
||||
String appDirName = args.length < 2 ? "." : args[1];
|
||||
File outFile;
|
||||
BuildOptions buildOptions = new BuildOptions();
|
||||
|
||||
// check for build options
|
||||
if (cli.hasOption("f") || cli.hasOption("force-all")) {
|
||||
buildOptions.forceBuildAll = true;
|
||||
config.forceBuildAll = true;
|
||||
}
|
||||
if (cli.hasOption("d") || cli.hasOption("debug")) {
|
||||
buildOptions.debugMode = true;
|
||||
config.debugMode = true;
|
||||
}
|
||||
if (cli.hasOption("n") || cli.hasOption("net-sec-conf")) {
|
||||
buildOptions.netSecConf = true;
|
||||
config.netSecConf = true;
|
||||
}
|
||||
if (cli.hasOption("v") || cli.hasOption("verbose")) {
|
||||
buildOptions.verbose = true;
|
||||
config.verbose = true;
|
||||
}
|
||||
if (cli.hasOption("a") || cli.hasOption("aapt")) {
|
||||
buildOptions.aaptPath = cli.getOptionValue("a");
|
||||
config.aaptPath = cli.getOptionValue("a");
|
||||
}
|
||||
if (cli.hasOption("c") || cli.hasOption("copy-original")) {
|
||||
System.err.println("-c/--copy-original has been deprecated. Removal planned for v3.0.0 (#2129)");
|
||||
buildOptions.copyOriginalFiles = true;
|
||||
}
|
||||
if (cli.hasOption("p") || cli.hasOption("frame-path")) {
|
||||
buildOptions.frameworkFolderLocation = cli.getOptionValue("p");
|
||||
config.copyOriginalFiles = true;
|
||||
}
|
||||
if (cli.hasOption("nc") || cli.hasOption("no-crunch")) {
|
||||
buildOptions.noCrunch = true;
|
||||
config.noCrunch = true;
|
||||
}
|
||||
|
||||
// Temporary flag to enable the use of aapt2. This will transform in time to a use-aapt1 flag, which will be
|
||||
// legacy and eventually removed.
|
||||
if (cli.hasOption("use-aapt2")) {
|
||||
buildOptions.useAapt2 = true;
|
||||
}
|
||||
if (cli.hasOption("api") || cli.hasOption("api-level")) {
|
||||
buildOptions.forceApi = Integer.parseInt(cli.getOptionValue("api"));
|
||||
config.useAapt2 = true;
|
||||
}
|
||||
|
||||
File outFile;
|
||||
if (cli.hasOption("o") || cli.hasOption("output")) {
|
||||
outFile = new File(cli.getOptionValue("o"));
|
||||
} else {
|
||||
outFile = null;
|
||||
}
|
||||
|
||||
if (buildOptions.netSecConf && !buildOptions.useAapt2) {
|
||||
if (config.netSecConf && !config.useAapt2) {
|
||||
System.err.println("-n / --net-sec-conf is only supported with --use-aapt2.");
|
||||
System.exit(1);
|
||||
}
|
||||
@ -259,56 +257,39 @@ public class Main {
|
||||
// try and build apk
|
||||
try {
|
||||
if (cli.hasOption("a") || cli.hasOption("aapt")) {
|
||||
buildOptions.aaptVersion = AaptManager.getAaptVersion(cli.getOptionValue("a"));
|
||||
config.aaptVersion = AaptManager.getAaptVersion(cli.getOptionValue("a"));
|
||||
}
|
||||
new Androlib(buildOptions).build(new File(appDirName), outFile);
|
||||
new Androlib(config).build(new File(appDirName), outFile);
|
||||
} catch (BrutException ex) {
|
||||
System.err.println(ex.getMessage());
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
private static void cmdInstallFramework(CommandLine cli) throws AndrolibException {
|
||||
int paraCount = cli.getArgList().size();
|
||||
String apkName = cli.getArgList().get(paraCount - 1);
|
||||
|
||||
brut.androlib.options.BuildOptions buildOptions = new BuildOptions();
|
||||
if (cli.hasOption("p") || cli.hasOption("frame-path")) {
|
||||
buildOptions.frameworkFolderLocation = cli.getOptionValue("p");
|
||||
}
|
||||
if (cli.hasOption("t") || cli.hasOption("tag")) {
|
||||
buildOptions.frameworkTag = cli.getOptionValue("t");
|
||||
}
|
||||
new Androlib(buildOptions).installFramework(new File(apkName));
|
||||
private static void cmdInstallFramework(CommandLine cli, Config config) throws AndrolibException {
|
||||
String apkName = getLastArg(cli);
|
||||
new Androlib(config).installFramework(new File(apkName));
|
||||
}
|
||||
|
||||
private static void cmdListFrameworks(CommandLine cli) throws AndrolibException {
|
||||
brut.androlib.options.BuildOptions buildOptions = new BuildOptions();
|
||||
if (cli.hasOption("p") || cli.hasOption("frame-path")) {
|
||||
buildOptions.frameworkFolderLocation = cli.getOptionValue("p");
|
||||
}
|
||||
|
||||
new Androlib(buildOptions).listFrameworks();
|
||||
private static void cmdListFrameworks(CommandLine cli, Config config) throws AndrolibException {
|
||||
new Androlib(config).listFrameworks();
|
||||
}
|
||||
|
||||
private static void cmdPublicizeResources(CommandLine cli) throws AndrolibException {
|
||||
int paraCount = cli.getArgList().size();
|
||||
String apkName = cli.getArgList().get(paraCount - 1);
|
||||
|
||||
new Androlib().publicizeResources(new File(apkName));
|
||||
private static void cmdPublicizeResources(CommandLine cli, Config config) throws AndrolibException {
|
||||
String apkName = getLastArg(cli);
|
||||
new Androlib(config).publicizeResources(new File(apkName));
|
||||
}
|
||||
|
||||
private static void cmdEmptyFrameworkDirectory(CommandLine cli) throws AndrolibException {
|
||||
brut.androlib.options.BuildOptions buildOptions = new BuildOptions();
|
||||
|
||||
private static void cmdEmptyFrameworkDirectory(CommandLine cli, Config config) throws AndrolibException {
|
||||
if (cli.hasOption("f") || cli.hasOption("force")) {
|
||||
buildOptions.forceDeleteFramework = true;
|
||||
}
|
||||
if (cli.hasOption("p") || cli.hasOption("frame-path")) {
|
||||
buildOptions.frameworkFolderLocation = cli.getOptionValue("p");
|
||||
config.forceDeleteFramework = true;
|
||||
}
|
||||
new Androlib(config).emptyFrameworkDirectory();
|
||||
}
|
||||
|
||||
new Androlib(buildOptions).emptyFrameworkDirectory();
|
||||
private static String getLastArg(CommandLine cli) {
|
||||
int paraCount = cli.getArgList().size();
|
||||
return cli.getArgList().get(paraCount - 1);
|
||||
}
|
||||
|
||||
private static void _version() {
|
||||
|
@ -19,7 +19,6 @@ package brut.androlib;
|
||||
import brut.androlib.exceptions.AndrolibException;
|
||||
import brut.androlib.meta.MetaInfo;
|
||||
import brut.androlib.meta.UsesFramework;
|
||||
import brut.androlib.options.BuildOptions;
|
||||
import brut.androlib.res.AndrolibResources;
|
||||
import brut.androlib.res.data.ResConfigFlags;
|
||||
import brut.androlib.res.data.ResPackage;
|
||||
@ -52,18 +51,18 @@ import java.util.zip.ZipFile;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
public class Androlib {
|
||||
private final AndrolibResources mAndRes = new AndrolibResources();
|
||||
private final AndrolibResources mAndRes;
|
||||
protected final ResUnknownFiles mResUnknownFiles = new ResUnknownFiles();
|
||||
public final BuildOptions buildOptions;
|
||||
private final Config config;
|
||||
private int mMinSdkVersion = 0;
|
||||
|
||||
public Androlib() {
|
||||
this(new BuildOptions());
|
||||
this(Config.getDefaultConfig());
|
||||
}
|
||||
|
||||
public Androlib(BuildOptions buildOptions) {
|
||||
this.buildOptions = buildOptions;
|
||||
mAndRes.buildOptions = buildOptions;
|
||||
public Androlib(Config config) {
|
||||
this.config = config;
|
||||
mAndRes = new AndrolibResources(config);
|
||||
}
|
||||
|
||||
public ResTable getResTable(ExtFile apkFile)
|
||||
@ -90,7 +89,7 @@ public class Androlib {
|
||||
}
|
||||
}
|
||||
|
||||
public void decodeSourcesSmali(File apkFile, File outDir, String filename, boolean bakDeb, int apiLevel)
|
||||
public void decodeSourcesSmali(File apkFile, File outDir, String filename)
|
||||
throws AndrolibException {
|
||||
try {
|
||||
File smaliDir;
|
||||
@ -103,7 +102,8 @@ public class Androlib {
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
smaliDir.mkdirs();
|
||||
LOGGER.info("Baksmaling " + filename + "...");
|
||||
DexFile dexFile = SmaliDecoder.decode(apkFile, smaliDir, filename, bakDeb, apiLevel);
|
||||
DexFile dexFile = SmaliDecoder.decode(apkFile, smaliDir, filename,
|
||||
config.baksmaliDebugMode, config.apiLevel);
|
||||
int minSdkVersion = dexFile.getOpcodes().api;
|
||||
if (mMinSdkVersion == 0 || mMinSdkVersion > minSdkVersion) {
|
||||
mMinSdkVersion = minSdkVersion;
|
||||
@ -148,13 +148,13 @@ public class Androlib {
|
||||
mAndRes.decodeManifestWithResources(resTable, apkFile, outDir);
|
||||
}
|
||||
|
||||
public void decodeRawFiles(ExtFile apkFile, File outDir, short decodeAssetMode)
|
||||
public void decodeRawFiles(ExtFile apkFile, File outDir)
|
||||
throws AndrolibException {
|
||||
LOGGER.info("Copying assets and libs...");
|
||||
try {
|
||||
Directory in = apkFile.getDirectory();
|
||||
|
||||
if (decodeAssetMode == ApkDecoder.DECODE_ASSETS_FULL) {
|
||||
if (config.decodeAssets == Config.DECODE_ASSETS_FULL) {
|
||||
if (in.containsDir("assets")) {
|
||||
in.copyToDir(outDir, "assets");
|
||||
}
|
||||
@ -296,9 +296,9 @@ public class Androlib {
|
||||
LOGGER.info("Using Apktool " + Androlib.getVersion());
|
||||
|
||||
MetaInfo meta = readMetaFile(appDir);
|
||||
buildOptions.isFramework = meta.isFrameworkApk;
|
||||
buildOptions.resourcesAreCompressed = meta.compressionType;
|
||||
buildOptions.doNotCompress = meta.doNotCompress;
|
||||
config.isFramework = meta.isFrameworkApk;
|
||||
config.resourcesAreCompressed = meta.compressionType;
|
||||
config.doNotCompress = meta.doNotCompress;
|
||||
|
||||
mAndRes.setSdkInfo(meta.sdkInfo);
|
||||
mAndRes.setPackageId(meta.packageInfo);
|
||||
@ -415,7 +415,7 @@ public class Androlib {
|
||||
return false;
|
||||
}
|
||||
File stored = new File(appDir, APK_DIRNAME + "/" + filename);
|
||||
if (buildOptions.forceBuildAll || isModified(working, stored)) {
|
||||
if (config.forceBuildAll || isModified(working, stored)) {
|
||||
LOGGER.info("Copying " + appDir.toString() + " " + filename + " file...");
|
||||
try {
|
||||
BrutIO.copyAndClose(Files.newInputStream(working.toPath()), Files.newOutputStream(stored.toPath()));
|
||||
@ -434,14 +434,14 @@ public class Androlib {
|
||||
return false;
|
||||
}
|
||||
File dex = new File(appDir, APK_DIRNAME + "/" + filename);
|
||||
if (! buildOptions.forceBuildAll) {
|
||||
if (! config.forceBuildAll) {
|
||||
LOGGER.info("Checking whether sources has changed...");
|
||||
}
|
||||
if (buildOptions.forceBuildAll || isModified(smaliDir, dex)) {
|
||||
if (config.forceBuildAll || isModified(smaliDir, dex)) {
|
||||
LOGGER.info("Smaling " + folder + " folder into " + filename + "...");
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
dex.delete();
|
||||
SmaliBuilder.build(smaliDir, dex, buildOptions.forceApi > 0 ? buildOptions.forceApi : mMinSdkVersion);
|
||||
SmaliBuilder.build(smaliDir, dex, config.forceApi > 0 ? config.forceApi : mMinSdkVersion);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -461,10 +461,10 @@ public class Androlib {
|
||||
return false;
|
||||
}
|
||||
File apkDir = new File(appDir, APK_DIRNAME);
|
||||
if (! buildOptions.forceBuildAll) {
|
||||
if (! config.forceBuildAll) {
|
||||
LOGGER.info("Checking whether resources has changed...");
|
||||
}
|
||||
if (buildOptions.forceBuildAll || isModified(newFiles(APK_RESOURCES_FILENAMES, appDir),
|
||||
if (config.forceBuildAll || isModified(newFiles(APK_RESOURCES_FILENAMES, appDir),
|
||||
newFiles(APK_RESOURCES_FILENAMES, apkDir))) {
|
||||
LOGGER.info("Copying raw resources...");
|
||||
appDir.getDirectory().copyToDir(apkDir, APK_RESOURCES_FILENAMES);
|
||||
@ -481,18 +481,18 @@ public class Androlib {
|
||||
if (!new File(appDir, "res").exists()) {
|
||||
return false;
|
||||
}
|
||||
if (! buildOptions.forceBuildAll) {
|
||||
if (! config.forceBuildAll) {
|
||||
LOGGER.info("Checking whether resources has changed...");
|
||||
}
|
||||
File apkDir = new File(appDir, APK_DIRNAME);
|
||||
File resourceFile = new File(apkDir.getParent(), "resources.zip");
|
||||
|
||||
if (buildOptions.forceBuildAll || isModified(newFiles(APP_RESOURCES_FILENAMES, appDir),
|
||||
newFiles(APK_RESOURCES_FILENAMES, apkDir)) || (buildOptions.isAapt2() && !isFile(resourceFile))) {
|
||||
if (config.forceBuildAll || isModified(newFiles(APP_RESOURCES_FILENAMES, appDir),
|
||||
newFiles(APK_RESOURCES_FILENAMES, apkDir)) || (config.isAapt2() && !isFile(resourceFile))) {
|
||||
LOGGER.info("Building resources...");
|
||||
|
||||
if (buildOptions.debugMode) {
|
||||
if (buildOptions.isAapt2()) {
|
||||
if (config.debugMode) {
|
||||
if (config.isAapt2()) {
|
||||
LOGGER.info("Using aapt2 - setting 'debuggable' attribute to 'true' in AndroidManifest.xml");
|
||||
ResXmlPatcher.setApplicationDebugTagTrue(new File(appDir, "AndroidManifest.xml"));
|
||||
} else {
|
||||
@ -500,7 +500,7 @@ public class Androlib {
|
||||
}
|
||||
}
|
||||
|
||||
if (buildOptions.netSecConf) {
|
||||
if (config.netSecConf) {
|
||||
MetaInfo meta = readMetaFile(new ExtFile(appDir));
|
||||
if (meta.sdkInfo != null && meta.sdkInfo.get("targetSdkVersion") != null) {
|
||||
if (Integer.parseInt(meta.sdkInfo.get("targetSdkVersion")) < ResConfigFlags.SDK_NOUGAT) {
|
||||
@ -576,13 +576,13 @@ public class Androlib {
|
||||
if (!new File(appDir, "AndroidManifest.xml").exists()) {
|
||||
return false;
|
||||
}
|
||||
if (! buildOptions.forceBuildAll) {
|
||||
if (! config.forceBuildAll) {
|
||||
LOGGER.info("Checking whether resources has changed...");
|
||||
}
|
||||
|
||||
File apkDir = new File(appDir, APK_DIRNAME);
|
||||
|
||||
if (buildOptions.forceBuildAll || isModified(newFiles(APK_MANIFEST_FILENAMES, appDir),
|
||||
if (config.forceBuildAll || isModified(newFiles(APK_MANIFEST_FILENAMES, appDir),
|
||||
newFiles(APK_MANIFEST_FILENAMES, apkDir))) {
|
||||
LOGGER.info("Building AndroidManifest.xml...");
|
||||
|
||||
@ -629,7 +629,7 @@ public class Androlib {
|
||||
}
|
||||
|
||||
File stored = new File(appDir, APK_DIRNAME + "/" + folder);
|
||||
if (buildOptions.forceBuildAll || isModified(working, stored)) {
|
||||
if (config.forceBuildAll || isModified(working, stored)) {
|
||||
LOGGER.info("Copying libs... (/" + folder + ")");
|
||||
try {
|
||||
OS.rmdir(stored);
|
||||
@ -642,7 +642,7 @@ public class Androlib {
|
||||
|
||||
public void buildCopyOriginalFiles(File appDir)
|
||||
throws AndrolibException {
|
||||
if (buildOptions.copyOriginalFiles) {
|
||||
if (config.copyOriginalFiles) {
|
||||
File originalDir = new File(appDir, "original");
|
||||
if (originalDir.exists()) {
|
||||
try {
|
||||
|
@ -40,32 +40,31 @@ import java.util.*;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class ApkDecoder {
|
||||
public ApkDecoder() {
|
||||
this(new Androlib());
|
||||
|
||||
private final static Logger LOGGER = Logger.getLogger(ApkDecoder.class.getName());
|
||||
private final Config config;
|
||||
private final Androlib mAndrolib;
|
||||
private final ExtFile mApkFile;
|
||||
private File mOutDir;
|
||||
private ResTable mResTable;
|
||||
private Collection<String> mUncompressedFiles;
|
||||
|
||||
public ApkDecoder(ExtFile apkFile) {
|
||||
this(Config.getDefaultConfig(), apkFile);
|
||||
}
|
||||
|
||||
public ApkDecoder(Androlib androlib) {
|
||||
mAndrolib = androlib;
|
||||
public ApkDecoder(Config config, ExtFile apkFile) {
|
||||
this.config = config;
|
||||
mAndrolib = new Androlib(config);
|
||||
mApkFile = apkFile;
|
||||
}
|
||||
|
||||
public ApkDecoder(File apkFile) {
|
||||
this(apkFile, new Androlib());
|
||||
this(new ExtFile(apkFile));
|
||||
}
|
||||
|
||||
public ApkDecoder(File apkFile, Androlib androlib) {
|
||||
mAndrolib = androlib;
|
||||
setApkFile(apkFile);
|
||||
}
|
||||
|
||||
public void setApkFile(File apkFile) {
|
||||
if (mApkFile != null) {
|
||||
try {
|
||||
mApkFile.close();
|
||||
} catch (IOException ignored) {}
|
||||
}
|
||||
|
||||
mApkFile = new ExtFile(apkFile);
|
||||
mResTable = null;
|
||||
public ApkDecoder(Config config, File apkFile) {
|
||||
this(config, new ExtFile(apkFile));
|
||||
}
|
||||
|
||||
public void setOutDir(File outDir) {
|
||||
@ -75,9 +74,8 @@ public class ApkDecoder {
|
||||
public void decode() throws AndrolibException, IOException, DirectoryException {
|
||||
try {
|
||||
File outDir = getOutDir();
|
||||
AndrolibResources.sKeepBroken = mKeepBrokenResources;
|
||||
|
||||
if (!mForceDelete && outDir.exists()) {
|
||||
if (!config.forceDelete && outDir.exists()) {
|
||||
throw new OutDirExistsException();
|
||||
}
|
||||
|
||||
@ -95,17 +93,17 @@ public class ApkDecoder {
|
||||
LOGGER.info("Using Apktool " + Androlib.getVersion() + " on " + mApkFile.getName());
|
||||
|
||||
if (hasResources()) {
|
||||
switch (mDecodeResources) {
|
||||
case DECODE_RESOURCES_NONE:
|
||||
switch (config.decodeResources) {
|
||||
case Config.DECODE_RESOURCES_NONE:
|
||||
mAndrolib.decodeResourcesRaw(mApkFile, outDir);
|
||||
if (mForceDecodeManifest == FORCE_DECODE_MANIFEST_FULL) {
|
||||
if (config.forceDecodeManifest == Config.FORCE_DECODE_MANIFEST_FULL) {
|
||||
// done after raw decoding of resources because copyToDir overwrites dest files
|
||||
if (hasManifest()) {
|
||||
mAndrolib.decodeManifestWithResources(mApkFile, outDir, getResTable());
|
||||
}
|
||||
}
|
||||
break;
|
||||
case DECODE_RESOURCES_FULL:
|
||||
case Config.DECODE_RESOURCES_FULL:
|
||||
if (hasManifest()) {
|
||||
mAndrolib.decodeManifestWithResources(mApkFile, outDir, getResTable());
|
||||
}
|
||||
@ -116,8 +114,8 @@ public class ApkDecoder {
|
||||
// if there's no resources.arsc, decode the manifest without looking
|
||||
// up attribute references
|
||||
if (hasManifest()) {
|
||||
if (mDecodeResources == DECODE_RESOURCES_FULL
|
||||
|| mForceDecodeManifest == FORCE_DECODE_MANIFEST_FULL) {
|
||||
if (config.decodeResources == Config.DECODE_RESOURCES_FULL
|
||||
|| config.forceDecodeManifest == Config.FORCE_DECODE_MANIFEST_FULL) {
|
||||
mAndrolib.decodeManifestFull(mApkFile, outDir, getResTable());
|
||||
}
|
||||
else {
|
||||
@ -127,13 +125,13 @@ public class ApkDecoder {
|
||||
}
|
||||
|
||||
if (hasSources()) {
|
||||
switch (mDecodeSources) {
|
||||
case DECODE_SOURCES_NONE:
|
||||
switch (config.decodeSources) {
|
||||
case Config.DECODE_SOURCES_NONE:
|
||||
mAndrolib.decodeSourcesRaw(mApkFile, outDir, "classes.dex");
|
||||
break;
|
||||
case DECODE_SOURCES_SMALI:
|
||||
case DECODE_SOURCES_SMALI_ONLY_MAIN_CLASSES:
|
||||
mAndrolib.decodeSourcesSmali(mApkFile, outDir, "classes.dex", mBakDeb, mApiLevel);
|
||||
case Config.DECODE_SOURCES_SMALI:
|
||||
case Config.DECODE_SOURCES_SMALI_ONLY_MAIN_CLASSES:
|
||||
mAndrolib.decodeSourcesSmali(mApkFile, outDir, "classes.dex");
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -144,16 +142,16 @@ public class ApkDecoder {
|
||||
for (String file : files) {
|
||||
if (file.endsWith(".dex")) {
|
||||
if (! file.equalsIgnoreCase("classes.dex")) {
|
||||
switch(mDecodeSources) {
|
||||
case DECODE_SOURCES_NONE:
|
||||
switch(config.decodeSources) {
|
||||
case Config.DECODE_SOURCES_NONE:
|
||||
mAndrolib.decodeSourcesRaw(mApkFile, outDir, file);
|
||||
break;
|
||||
case DECODE_SOURCES_SMALI:
|
||||
mAndrolib.decodeSourcesSmali(mApkFile, outDir, file, mBakDeb, mApiLevel);
|
||||
case Config.DECODE_SOURCES_SMALI:
|
||||
mAndrolib.decodeSourcesSmali(mApkFile, outDir, file);
|
||||
break;
|
||||
case DECODE_SOURCES_SMALI_ONLY_MAIN_CLASSES:
|
||||
case Config.DECODE_SOURCES_SMALI_ONLY_MAIN_CLASSES:
|
||||
if (file.startsWith("classes") && file.endsWith(".dex")) {
|
||||
mAndrolib.decodeSourcesSmali(mApkFile, outDir, file, mBakDeb, mApiLevel);
|
||||
mAndrolib.decodeSourcesSmali(mApkFile, outDir, file);
|
||||
} else {
|
||||
mAndrolib.decodeSourcesRaw(mApkFile, outDir, file);
|
||||
}
|
||||
@ -164,7 +162,7 @@ public class ApkDecoder {
|
||||
}
|
||||
}
|
||||
|
||||
mAndrolib.decodeRawFiles(mApkFile, outDir, mDecodeAssets);
|
||||
mAndrolib.decodeRawFiles(mApkFile, outDir);
|
||||
mAndrolib.decodeUnknownFiles(mApkFile, outDir);
|
||||
mUncompressedFiles = new ArrayList<>();
|
||||
mAndrolib.recordUncompressedFiles(mApkFile, mUncompressedFiles);
|
||||
@ -177,70 +175,6 @@ public class ApkDecoder {
|
||||
}
|
||||
}
|
||||
|
||||
public void setDecodeSources(short mode) throws AndrolibException {
|
||||
if (mode != DECODE_SOURCES_NONE && mode != DECODE_SOURCES_SMALI && mode != DECODE_SOURCES_SMALI_ONLY_MAIN_CLASSES) {
|
||||
throw new AndrolibException("Invalid decode sources mode: " + mode);
|
||||
}
|
||||
if (mDecodeSources == DECODE_SOURCES_NONE && mode == DECODE_SOURCES_SMALI_ONLY_MAIN_CLASSES) {
|
||||
LOGGER.info("--only-main-classes cannot be paired with -s/--no-src. Ignoring.");
|
||||
return;
|
||||
}
|
||||
mDecodeSources = mode;
|
||||
}
|
||||
|
||||
public void setDecodeResources(short mode) throws AndrolibException {
|
||||
if (mode != DECODE_RESOURCES_NONE && mode != DECODE_RESOURCES_FULL) {
|
||||
throw new AndrolibException("Invalid decode resources mode");
|
||||
}
|
||||
mDecodeResources = mode;
|
||||
}
|
||||
|
||||
public void setForceDecodeManifest(short mode) throws AndrolibException {
|
||||
if (mode != FORCE_DECODE_MANIFEST_NONE && mode != FORCE_DECODE_MANIFEST_FULL) {
|
||||
throw new AndrolibException("Invalid force decode manifest mode");
|
||||
}
|
||||
mForceDecodeManifest = mode;
|
||||
}
|
||||
|
||||
public void setDecodeAssets(short mode) throws AndrolibException {
|
||||
if (mode != DECODE_ASSETS_NONE && mode != DECODE_ASSETS_FULL) {
|
||||
throw new AndrolibException("Invalid decode asset mode");
|
||||
}
|
||||
mDecodeAssets = mode;
|
||||
}
|
||||
|
||||
public void setAnalysisMode(boolean mode) {
|
||||
mAnalysisMode = mode;
|
||||
|
||||
if (mResTable != null) {
|
||||
mResTable.setAnalysisMode(mode);
|
||||
}
|
||||
}
|
||||
|
||||
public void setApiLevel(int apiLevel) {
|
||||
mApiLevel = apiLevel;
|
||||
}
|
||||
|
||||
public void setBaksmaliDebugMode(boolean bakDeb) {
|
||||
mBakDeb = bakDeb;
|
||||
}
|
||||
|
||||
public void setForceDelete(boolean forceDelete) {
|
||||
mForceDelete = forceDelete;
|
||||
}
|
||||
|
||||
public void setFrameworkTag(String tag) {
|
||||
mAndrolib.buildOptions.frameworkTag = tag;
|
||||
}
|
||||
|
||||
public void setKeepBrokenResources(boolean keepBrokenResources) {
|
||||
mKeepBrokenResources = keepBrokenResources;
|
||||
}
|
||||
|
||||
public void setFrameworkDir(String dir) {
|
||||
mAndrolib.buildOptions.frameworkFolderLocation = dir;
|
||||
}
|
||||
|
||||
public ResTable getResTable() throws AndrolibException {
|
||||
if (mResTable == null) {
|
||||
boolean hasResources = hasResources();
|
||||
@ -250,7 +184,7 @@ public class ApkDecoder {
|
||||
"Apk doesn't contain either AndroidManifest.xml file or resources.arsc file");
|
||||
}
|
||||
mResTable = mAndrolib.getResTable(mApkFile, hasResources);
|
||||
mResTable.setAnalysisMode(mAnalysisMode);
|
||||
mResTable.setAnalysisMode(config.analysisMode);
|
||||
}
|
||||
return mResTable;
|
||||
}
|
||||
@ -302,19 +236,6 @@ public class ApkDecoder {
|
||||
}
|
||||
}
|
||||
|
||||
public final static short DECODE_SOURCES_NONE = 0x0000;
|
||||
public final static short DECODE_SOURCES_SMALI = 0x0001;
|
||||
public final static short DECODE_SOURCES_SMALI_ONLY_MAIN_CLASSES = 0x0010;
|
||||
|
||||
public final static short DECODE_RESOURCES_NONE = 0x0100;
|
||||
public final static short DECODE_RESOURCES_FULL = 0x0101;
|
||||
|
||||
public final static short FORCE_DECODE_MANIFEST_NONE = 0x0000;
|
||||
public final static short FORCE_DECODE_MANIFEST_FULL = 0x0001;
|
||||
|
||||
public final static short DECODE_ASSETS_NONE = 0x0000;
|
||||
public final static short DECODE_ASSETS_FULL = 0x0001;
|
||||
|
||||
private File getOutDir() throws AndrolibException {
|
||||
if (mOutDir == null) {
|
||||
throw new AndrolibException("Out dir not set");
|
||||
@ -360,8 +281,8 @@ public class ApkDecoder {
|
||||
meta.usesFramework = new UsesFramework();
|
||||
meta.usesFramework.ids = Arrays.asList(ids);
|
||||
|
||||
if (mAndrolib.buildOptions.frameworkTag != null) {
|
||||
meta.usesFramework.tag = mAndrolib.buildOptions.frameworkTag;
|
||||
if (config.frameworkTag != null) {
|
||||
meta.usesFramework.tag = config.frameworkTag;
|
||||
}
|
||||
}
|
||||
|
||||
@ -448,22 +369,4 @@ public class ApkDecoder {
|
||||
meta.doNotCompress = mUncompressedFiles;
|
||||
}
|
||||
}
|
||||
|
||||
private final Androlib mAndrolib;
|
||||
|
||||
private final static Logger LOGGER = Logger.getLogger(Androlib.class.getName());
|
||||
|
||||
private ExtFile mApkFile;
|
||||
private File mOutDir;
|
||||
private ResTable mResTable;
|
||||
private short mDecodeSources = DECODE_SOURCES_SMALI;
|
||||
private short mDecodeResources = DECODE_RESOURCES_FULL;
|
||||
private short mForceDecodeManifest = FORCE_DECODE_MANIFEST_NONE;
|
||||
private short mDecodeAssets = DECODE_ASSETS_FULL;
|
||||
private boolean mForceDelete = false;
|
||||
private boolean mKeepBrokenResources = false;
|
||||
private boolean mBakDeb = true;
|
||||
private Collection<String> mUncompressedFiles;
|
||||
private boolean mAnalysisMode = false;
|
||||
private int mApiLevel = 0;
|
||||
}
|
||||
|
139
brut.apktool/apktool-lib/src/main/java/brut/androlib/Config.java
Normal file
139
brut.apktool/apktool-lib/src/main/java/brut/androlib/Config.java
Normal file
@ -0,0 +1,139 @@
|
||||
/*
|
||||
* Copyright (C) 2010 Ryszard Wiśniewski <brut.alll@gmail.com>
|
||||
* Copyright (C) 2010 Connor Tumbleson <connor.tumbleson@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package brut.androlib;
|
||||
|
||||
import brut.androlib.exceptions.AndrolibException;
|
||||
import brut.util.OSDetection;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class Config {
|
||||
|
||||
private final static Logger LOGGER = Logger.getLogger(Config.class.getName());
|
||||
|
||||
public final static short DECODE_SOURCES_NONE = 0x0000;
|
||||
public final static short DECODE_SOURCES_SMALI = 0x0001;
|
||||
public final static short DECODE_SOURCES_SMALI_ONLY_MAIN_CLASSES = 0x0010;
|
||||
|
||||
public final static short DECODE_RESOURCES_NONE = 0x0100;
|
||||
public final static short DECODE_RESOURCES_FULL = 0x0101;
|
||||
|
||||
public final static short FORCE_DECODE_MANIFEST_NONE = 0x0000;
|
||||
public final static short FORCE_DECODE_MANIFEST_FULL = 0x0001;
|
||||
|
||||
public final static short DECODE_ASSETS_NONE = 0x0000;
|
||||
public final static short DECODE_ASSETS_FULL = 0x0001;
|
||||
|
||||
// Build options
|
||||
public boolean forceBuildAll = false;
|
||||
public boolean forceDeleteFramework = false;
|
||||
public boolean debugMode = false;
|
||||
public boolean netSecConf = false;
|
||||
public boolean verbose = false;
|
||||
public boolean copyOriginalFiles = false;
|
||||
public boolean updateFiles = false;
|
||||
public boolean isFramework = false;
|
||||
public boolean resourcesAreCompressed = false;
|
||||
public boolean useAapt2 = false;
|
||||
public boolean noCrunch = false;
|
||||
public int forceApi = 0;
|
||||
public Collection<String> doNotCompress;
|
||||
|
||||
// Decode options
|
||||
public short decodeSources = DECODE_SOURCES_SMALI;
|
||||
public short decodeResources = DECODE_RESOURCES_FULL;
|
||||
public short forceDecodeManifest = FORCE_DECODE_MANIFEST_NONE;
|
||||
public short decodeAssets = DECODE_ASSETS_FULL;
|
||||
public int apiLevel = 0;
|
||||
public boolean analysisMode = false;
|
||||
public boolean forceDelete = false;
|
||||
public boolean keepBrokenResources = false;
|
||||
public boolean baksmaliDebugMode = true;
|
||||
|
||||
// Common options
|
||||
public String frameworkDirectory = null;
|
||||
public String frameworkTag = null;
|
||||
public String aaptPath = "";
|
||||
public int aaptVersion = 1; // default to v1
|
||||
|
||||
// Utility functions
|
||||
public boolean isAapt2() {
|
||||
return this.useAapt2 || this.aaptVersion == 2;
|
||||
}
|
||||
|
||||
private Config() {
|
||||
|
||||
}
|
||||
|
||||
private void setDefaultFrameworkDirectory() {
|
||||
File parentPath = new File(System.getProperty("user.home"));
|
||||
String path;
|
||||
if (OSDetection.isMacOSX()) {
|
||||
path = parentPath.getAbsolutePath() + String.format("%1$sLibrary%1$sapktool%1$sframework", File.separatorChar);
|
||||
} else if (OSDetection.isWindows()) {
|
||||
path = parentPath.getAbsolutePath() + String.format("%1$sAppData%1$sLocal%1$sapktool%1$sframework", File.separatorChar);
|
||||
} else {
|
||||
String xdgDataFolder = System.getenv("XDG_DATA_HOME");
|
||||
if (xdgDataFolder != null) {
|
||||
path = xdgDataFolder + String.format("%1$sapktool%1$sframework", File.separatorChar);
|
||||
} else {
|
||||
path = parentPath.getAbsolutePath() + String.format("%1$s.local%1$sshare%1$sapktool%1$sframework", File.separatorChar);
|
||||
}
|
||||
}
|
||||
frameworkDirectory = path;
|
||||
}
|
||||
|
||||
public void setDecodeSources(short mode) throws AndrolibException {
|
||||
if (mode != DECODE_SOURCES_NONE && mode != DECODE_SOURCES_SMALI && mode != DECODE_SOURCES_SMALI_ONLY_MAIN_CLASSES) {
|
||||
throw new AndrolibException("Invalid decode sources mode: " + mode);
|
||||
}
|
||||
if (decodeSources == DECODE_SOURCES_NONE && mode == DECODE_SOURCES_SMALI_ONLY_MAIN_CLASSES) {
|
||||
LOGGER.info("--only-main-classes cannot be paired with -s/--no-src. Ignoring.");
|
||||
return;
|
||||
}
|
||||
decodeSources = mode;
|
||||
}
|
||||
|
||||
public void setDecodeResources(short mode) throws AndrolibException {
|
||||
if (mode != DECODE_RESOURCES_NONE && mode != DECODE_RESOURCES_FULL) {
|
||||
throw new AndrolibException("Invalid decode resources mode");
|
||||
}
|
||||
decodeResources = mode;
|
||||
}
|
||||
|
||||
public void setForceDecodeManifest(short mode) throws AndrolibException {
|
||||
if (mode != FORCE_DECODE_MANIFEST_NONE && mode != FORCE_DECODE_MANIFEST_FULL) {
|
||||
throw new AndrolibException("Invalid force decode manifest mode");
|
||||
}
|
||||
forceDecodeManifest = mode;
|
||||
}
|
||||
|
||||
public void setDecodeAssets(short mode) throws AndrolibException {
|
||||
if (mode != DECODE_ASSETS_NONE && mode != DECODE_ASSETS_FULL) {
|
||||
throw new AndrolibException("Invalid decode asset mode");
|
||||
}
|
||||
decodeAssets = mode;
|
||||
}
|
||||
|
||||
public static Config getDefaultConfig() {
|
||||
Config config = new Config();
|
||||
config.setDefaultFrameworkDirectory();
|
||||
return config;
|
||||
}
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2010 Ryszard Wiśniewski <brut.alll@gmail.com>
|
||||
* Copyright (C) 2010 Connor Tumbleson <connor.tumbleson@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package brut.androlib.options;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class BuildOptions {
|
||||
public boolean forceBuildAll = false;
|
||||
public boolean forceDeleteFramework = false;
|
||||
public boolean debugMode = false;
|
||||
public boolean netSecConf = false;
|
||||
public boolean verbose = false;
|
||||
public boolean copyOriginalFiles = false;
|
||||
public final boolean updateFiles = false;
|
||||
public boolean isFramework = false;
|
||||
public boolean resourcesAreCompressed = false;
|
||||
public boolean useAapt2 = false;
|
||||
public boolean noCrunch = false;
|
||||
public int forceApi = 0;
|
||||
public Collection<String> doNotCompress;
|
||||
|
||||
public String frameworkFolderLocation = null;
|
||||
public String frameworkTag = null;
|
||||
public String aaptPath = "";
|
||||
|
||||
public int aaptVersion = 1; // default to v1
|
||||
|
||||
public boolean isAapt2() {
|
||||
return this.useAapt2 || this.aaptVersion == 2;
|
||||
}
|
||||
}
|
@ -17,8 +17,8 @@
|
||||
package brut.androlib.res;
|
||||
|
||||
import brut.androlib.exceptions.AndrolibException;
|
||||
import brut.androlib.options.BuildOptions;
|
||||
import brut.androlib.exceptions.CantFindFrameworkResException;
|
||||
import brut.androlib.Config;
|
||||
import brut.androlib.meta.MetaInfo;
|
||||
import brut.androlib.meta.PackageInfo;
|
||||
import brut.androlib.meta.VersionInfo;
|
||||
@ -46,6 +46,40 @@ import java.util.zip.ZipFile;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
final public class AndrolibResources {
|
||||
|
||||
private final Config config;
|
||||
|
||||
public Map<String, String> mResFileMapping = new HashMap<>();
|
||||
|
||||
private final static Logger LOGGER = Logger.getLogger(AndrolibResources.class.getName());
|
||||
|
||||
private File mFrameworkDirectory = null;
|
||||
|
||||
private ExtFile mFramework = null;
|
||||
|
||||
private String mMinSdkVersion = null;
|
||||
private String mMaxSdkVersion = null;
|
||||
private String mTargetSdkVersion = null;
|
||||
private String mVersionCode = null;
|
||||
private String mVersionName = null;
|
||||
private String mPackageRenamed = null;
|
||||
private String mPackageId = null;
|
||||
|
||||
private boolean mSharedLibrary = false;
|
||||
private boolean mSparseResources = false;
|
||||
|
||||
private final static String[] IGNORED_PACKAGES = new String[] {
|
||||
"android", "com.htc", "com.lge", "com.lge.internal", "yi", "flyme", "air.com.adobe.appentry",
|
||||
"FFFFFFFFFFFFFFFFFFFFFF" };
|
||||
|
||||
public AndrolibResources(Config config) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
public AndrolibResources() {
|
||||
this.config = Config.getDefaultConfig();
|
||||
}
|
||||
|
||||
public ResTable getResTable(ExtFile apkFile) throws AndrolibException {
|
||||
return getResTable(apkFile, true);
|
||||
}
|
||||
@ -62,7 +96,7 @@ final public class AndrolibResources {
|
||||
public ResPackage loadMainPkg(ResTable resTable, ExtFile apkFile)
|
||||
throws AndrolibException {
|
||||
LOGGER.info("Loading resource table...");
|
||||
ResPackage[] pkgs = getResPackagesFromApk(apkFile, resTable, sKeepBroken);
|
||||
ResPackage[] pkgs = getResPackagesFromApk(apkFile, resTable, config.keepBrokenResources);
|
||||
ResPackage pkg;
|
||||
|
||||
switch (pkgs.length) {
|
||||
@ -103,9 +137,9 @@ final public class AndrolibResources {
|
||||
return (id == 0) ? pkgs[0] : pkgs[index];
|
||||
}
|
||||
|
||||
public ResPackage loadFrameworkPkg(ResTable resTable, int id, String frameTag)
|
||||
public ResPackage loadFrameworkPkg(ResTable resTable, int id)
|
||||
throws AndrolibException {
|
||||
File apk = getFrameworkApk(id, frameTag);
|
||||
File apk = getFrameworkApk(id, config.frameworkTag);
|
||||
|
||||
LOGGER.info("Loading resource table from file: " + apk);
|
||||
mFramework = new ExtFile(apk);
|
||||
@ -195,7 +229,7 @@ final public class AndrolibResources {
|
||||
fileDecoder.decodeManifest(inApk, "AndroidManifest.xml", out, "AndroidManifest.xml");
|
||||
|
||||
// Remove versionName / versionCode (aapt API 16)
|
||||
if (!resTable.getAnalysisMode()) {
|
||||
if (!config.analysisMode) {
|
||||
|
||||
// check for a mismatch between resources.arsc package and the package listed in AndroidManifest
|
||||
// also remove the android::versionCode / versionName from manifest for rebuild
|
||||
@ -298,8 +332,8 @@ final public class AndrolibResources {
|
||||
return Integer.toString(target);
|
||||
}
|
||||
|
||||
private File createDoNotCompressExtensionsFile(BuildOptions buildOptions) throws AndrolibException {
|
||||
if (buildOptions.doNotCompress == null || buildOptions.doNotCompress.isEmpty()) {
|
||||
private File createDoNotCompressExtensionsFile(Config config) throws AndrolibException {
|
||||
if (config.doNotCompress == null || config.doNotCompress.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -309,7 +343,7 @@ final public class AndrolibResources {
|
||||
doNotCompressFile.deleteOnExit();
|
||||
|
||||
BufferedWriter fileWriter = new BufferedWriter(new FileWriter(doNotCompressFile));
|
||||
for (String extension : buildOptions.doNotCompress) {
|
||||
for (String extension : config.doNotCompress) {
|
||||
fileWriter.write(extension);
|
||||
fileWriter.newLine();
|
||||
}
|
||||
@ -350,11 +384,11 @@ final public class AndrolibResources {
|
||||
cmd.add("-o");
|
||||
cmd.add(resourcesZip.getAbsolutePath());
|
||||
|
||||
if (buildOptions.verbose) {
|
||||
if (config.verbose) {
|
||||
cmd.add("-v");
|
||||
}
|
||||
|
||||
if (buildOptions.noCrunch) {
|
||||
if (config.noCrunch) {
|
||||
cmd.add("--no-crunch");
|
||||
}
|
||||
|
||||
@ -427,25 +461,25 @@ final public class AndrolibResources {
|
||||
cmd.add("--enable-sparse-encoding");
|
||||
}
|
||||
|
||||
if (buildOptions.isFramework) {
|
||||
if (config.isFramework) {
|
||||
cmd.add("-x");
|
||||
}
|
||||
|
||||
if (buildOptions.doNotCompress != null && !customAapt) {
|
||||
if (config.doNotCompress != null && !customAapt) {
|
||||
// Use custom -e option to avoid limits on commandline length.
|
||||
// Can only be used when custom aapt binary is not used.
|
||||
String extensionsFilePath =
|
||||
Objects.requireNonNull(createDoNotCompressExtensionsFile(buildOptions)).getAbsolutePath();
|
||||
Objects.requireNonNull(createDoNotCompressExtensionsFile(config)).getAbsolutePath();
|
||||
cmd.add("-e");
|
||||
cmd.add(extensionsFilePath);
|
||||
} else if (buildOptions.doNotCompress != null) {
|
||||
for (String file : buildOptions.doNotCompress) {
|
||||
} else if (config.doNotCompress != null) {
|
||||
for (String file : config.doNotCompress) {
|
||||
cmd.add("-0");
|
||||
cmd.add(file);
|
||||
}
|
||||
}
|
||||
|
||||
if (!buildOptions.resourcesAreCompressed) {
|
||||
if (!config.resourcesAreCompressed) {
|
||||
cmd.add("-0");
|
||||
cmd.add("arsc");
|
||||
}
|
||||
@ -470,7 +504,7 @@ final public class AndrolibResources {
|
||||
cmd.add(rawDir.getAbsolutePath());
|
||||
}
|
||||
|
||||
if (buildOptions.verbose) {
|
||||
if (config.verbose) {
|
||||
cmd.add("-v");
|
||||
}
|
||||
|
||||
@ -493,16 +527,16 @@ final public class AndrolibResources {
|
||||
|
||||
cmd.add("p");
|
||||
|
||||
if (buildOptions.verbose) { // output aapt verbose
|
||||
if (config.verbose) { // output aapt verbose
|
||||
cmd.add("-v");
|
||||
}
|
||||
if (buildOptions.updateFiles) {
|
||||
if (config.updateFiles) {
|
||||
cmd.add("-u");
|
||||
}
|
||||
if (buildOptions.debugMode) { // inject debuggable="true" into manifest
|
||||
if (config.debugMode) { // inject debuggable="true" into manifest
|
||||
cmd.add("--debug-mode");
|
||||
}
|
||||
if (buildOptions.noCrunch) {
|
||||
if (config.noCrunch) {
|
||||
cmd.add("--no-crunch");
|
||||
}
|
||||
// force package id so that some frameworks build with correct id
|
||||
@ -550,25 +584,25 @@ final public class AndrolibResources {
|
||||
cmd.add("-F");
|
||||
cmd.add(apkFile.getAbsolutePath());
|
||||
|
||||
if (buildOptions.isFramework) {
|
||||
if (config.isFramework) {
|
||||
cmd.add("-x");
|
||||
}
|
||||
|
||||
if (buildOptions.doNotCompress != null && !customAapt) {
|
||||
if (config.doNotCompress != null && !customAapt) {
|
||||
// Use custom -e option to avoid limits on commandline length.
|
||||
// Can only be used when custom aapt binary is not used.
|
||||
String extensionsFilePath =
|
||||
Objects.requireNonNull(createDoNotCompressExtensionsFile(buildOptions)).getAbsolutePath();
|
||||
Objects.requireNonNull(createDoNotCompressExtensionsFile(config)).getAbsolutePath();
|
||||
cmd.add("-e");
|
||||
cmd.add(extensionsFilePath);
|
||||
} else if (buildOptions.doNotCompress != null) {
|
||||
for (String file : buildOptions.doNotCompress) {
|
||||
} else if (config.doNotCompress != null) {
|
||||
for (String file : config.doNotCompress) {
|
||||
cmd.add("-0");
|
||||
cmd.add(file);
|
||||
}
|
||||
}
|
||||
|
||||
if (!buildOptions.resourcesAreCompressed) {
|
||||
if (!config.resourcesAreCompressed) {
|
||||
cmd.add("-0");
|
||||
cmd.add("arsc");
|
||||
}
|
||||
@ -606,7 +640,7 @@ final public class AndrolibResources {
|
||||
public void aaptPackage(File apkFile, File manifest, File resDir, File rawDir, File assetDir, File[] include)
|
||||
throws AndrolibException {
|
||||
|
||||
String aaptPath = buildOptions.aaptPath;
|
||||
String aaptPath = config.aaptPath;
|
||||
boolean customAapt = !aaptPath.isEmpty();
|
||||
List<String> cmd = new ArrayList<>();
|
||||
|
||||
@ -618,7 +652,7 @@ final public class AndrolibResources {
|
||||
cmd.add(AaptManager.getAaptBinaryName(getAaptVersion()));
|
||||
}
|
||||
|
||||
if (buildOptions.isAapt2()) {
|
||||
if (config.isAapt2()) {
|
||||
aapt2Package(apkFile, manifest, resDir, rawDir, assetDir, include, cmd, customAapt);
|
||||
return;
|
||||
}
|
||||
@ -629,7 +663,7 @@ final public class AndrolibResources {
|
||||
throws AndrolibException {
|
||||
|
||||
try {
|
||||
ZipUtils.zipFolders(rawDir, apkFile, assetDir, buildOptions.doNotCompress);
|
||||
ZipUtils.zipFolders(rawDir, apkFile, assetDir, config.doNotCompress);
|
||||
} catch (IOException | BrutException ex) {
|
||||
throw new AndrolibException(ex);
|
||||
}
|
||||
@ -773,12 +807,12 @@ final public class AndrolibResources {
|
||||
}
|
||||
}
|
||||
|
||||
private ResPackage[] getResPackagesFromApk(ExtFile apkFile, ResTable resTable, boolean keepBroken)
|
||||
private ResPackage[] getResPackagesFromApk(ExtFile apkFile, ResTable resTable, boolean keepBrokenResources)
|
||||
throws AndrolibException {
|
||||
try {
|
||||
Directory dir = apkFile.getDirectory();
|
||||
try (BufferedInputStream bfi = new BufferedInputStream(dir.getFileInput("resources.arsc"))) {
|
||||
return ARSCDecoder.decode(bfi, false, keepBroken, resTable).getPackages();
|
||||
return ARSCDecoder.decode(bfi, false, keepBrokenResources, resTable).getPackages();
|
||||
}
|
||||
} catch (DirectoryException | IOException ex) {
|
||||
throw new AndrolibException("Could not load resources.arsc from file: " + apkFile, ex);
|
||||
@ -787,7 +821,7 @@ final public class AndrolibResources {
|
||||
|
||||
public File getFrameworkApk(int id, String frameTag)
|
||||
throws AndrolibException {
|
||||
File dir = getFrameworkDir();
|
||||
File dir = getFrameworkDirectory();
|
||||
File apk;
|
||||
|
||||
if (frameTag != null) {
|
||||
@ -816,7 +850,7 @@ final public class AndrolibResources {
|
||||
}
|
||||
|
||||
public void emptyFrameworkDirectory() throws AndrolibException {
|
||||
File dir = getFrameworkDir();
|
||||
File dir = getFrameworkDirectory();
|
||||
File apk;
|
||||
|
||||
apk = new File(dir, "1.apk");
|
||||
@ -825,7 +859,7 @@ final public class AndrolibResources {
|
||||
LOGGER.warning("Can't empty framework directory, no file found at: " + apk.getAbsolutePath());
|
||||
} else {
|
||||
try {
|
||||
if (apk.exists() && Objects.requireNonNull(dir.listFiles()).length > 1 && ! buildOptions.forceDeleteFramework) {
|
||||
if (apk.exists() && Objects.requireNonNull(dir.listFiles()).length > 1 && ! config.forceDeleteFramework) {
|
||||
LOGGER.warning("More than default framework detected. Please run command with `--force` parameter to wipe framework directory.");
|
||||
} else {
|
||||
for (File file : Objects.requireNonNull(dir.listFiles())) {
|
||||
@ -843,7 +877,7 @@ final public class AndrolibResources {
|
||||
}
|
||||
|
||||
public void listFrameworkDirectory() throws AndrolibException {
|
||||
File dir = getFrameworkDir();
|
||||
File dir = getFrameworkDirectory();
|
||||
if (dir == null) {
|
||||
LOGGER.severe("No framework directory found. Nothing to list.");
|
||||
return;
|
||||
@ -857,7 +891,7 @@ final public class AndrolibResources {
|
||||
}
|
||||
|
||||
public void installFramework(File frameFile) throws AndrolibException {
|
||||
installFramework(frameFile, buildOptions.frameworkTag);
|
||||
installFramework(frameFile, config.frameworkTag);
|
||||
}
|
||||
|
||||
public void installFramework(File frameFile, String tag)
|
||||
@ -878,7 +912,7 @@ final public class AndrolibResources {
|
||||
ARSCData arsc = ARSCDecoder.decode(new ByteArrayInputStream(data), true, true);
|
||||
publicizeResources(data, arsc.getFlagsOffsets());
|
||||
|
||||
File outFile = new File(getFrameworkDir(), arsc
|
||||
File outFile = new File(getFrameworkDirectory(), arsc
|
||||
.getOnePackage().getId()
|
||||
+ (tag == null ? "" : '-' + tag)
|
||||
+ ".apk");
|
||||
@ -949,32 +983,15 @@ final public class AndrolibResources {
|
||||
}
|
||||
}
|
||||
|
||||
public File getFrameworkDir() throws AndrolibException {
|
||||
public File getFrameworkDirectory() throws AndrolibException {
|
||||
if (mFrameworkDirectory != null) {
|
||||
return mFrameworkDirectory;
|
||||
}
|
||||
|
||||
String path;
|
||||
|
||||
// if a framework path was specified on the command line, use it
|
||||
if (buildOptions.frameworkFolderLocation != null) {
|
||||
path = buildOptions.frameworkFolderLocation;
|
||||
} else {
|
||||
File parentPath = new File(System.getProperty("user.home"));
|
||||
|
||||
if (OSDetection.isMacOSX()) {
|
||||
path = parentPath.getAbsolutePath() + String.format("%1$sLibrary%1$sapktool%1$sframework", File.separatorChar);
|
||||
} else if (OSDetection.isWindows()) {
|
||||
path = parentPath.getAbsolutePath() + String.format("%1$sAppData%1$sLocal%1$sapktool%1$sframework", File.separatorChar);
|
||||
} else {
|
||||
String xdgDataFolder = System.getenv("XDG_DATA_HOME");
|
||||
if (xdgDataFolder != null) {
|
||||
path = xdgDataFolder + String.format("%1$sapktool%1$sframework", File.separatorChar);
|
||||
} else {
|
||||
path = parentPath.getAbsolutePath() + String.format("%1$s.local%1$sshare%1$sapktool%1$sframework", File.separatorChar);
|
||||
}
|
||||
}
|
||||
}
|
||||
// use default framework path or specified on the command line
|
||||
path = config.frameworkDirectory;
|
||||
|
||||
File dir = new File(path);
|
||||
|
||||
@ -988,7 +1005,7 @@ final public class AndrolibResources {
|
||||
|
||||
if (! dir.exists()) {
|
||||
if (! dir.mkdirs()) {
|
||||
if (buildOptions.frameworkFolderLocation != null) {
|
||||
if (config.frameworkDirectory != null) {
|
||||
LOGGER.severe("Can't create Framework directory: " + dir);
|
||||
}
|
||||
throw new AndrolibException(String.format(
|
||||
@ -997,7 +1014,7 @@ final public class AndrolibResources {
|
||||
}
|
||||
}
|
||||
|
||||
if (buildOptions.frameworkFolderLocation == null) {
|
||||
if (config.frameworkDirectory == null) {
|
||||
if (! dir.canWrite()) {
|
||||
LOGGER.severe(String.format("WARNING: Could not write to (%1$s), using %2$s instead...",
|
||||
dir.getAbsolutePath(), System.getProperty("java.io.tmpdir")));
|
||||
@ -1024,7 +1041,7 @@ final public class AndrolibResources {
|
||||
}
|
||||
|
||||
private int getAaptVersion() {
|
||||
return buildOptions.isAapt2() ? 2 : 1;
|
||||
return config.isAapt2() ? 2 : 1;
|
||||
}
|
||||
|
||||
public InputStream getAndroidFrameworkResourcesAsStream() {
|
||||
@ -1036,32 +1053,4 @@ final public class AndrolibResources {
|
||||
mFramework.close();
|
||||
}
|
||||
}
|
||||
|
||||
public BuildOptions buildOptions;
|
||||
|
||||
public Map<String, String> mResFileMapping = new HashMap<>();
|
||||
|
||||
// TODO: dirty static hack. I have to refactor decoding mechanisms.
|
||||
public static boolean sKeepBroken = false;
|
||||
|
||||
private final static Logger LOGGER = Logger.getLogger(AndrolibResources.class.getName());
|
||||
|
||||
private File mFrameworkDirectory = null;
|
||||
|
||||
private ExtFile mFramework = null;
|
||||
|
||||
private String mMinSdkVersion = null;
|
||||
private String mMaxSdkVersion = null;
|
||||
private String mTargetSdkVersion = null;
|
||||
private String mVersionCode = null;
|
||||
private String mVersionName = null;
|
||||
private String mPackageRenamed = null;
|
||||
private String mPackageId = null;
|
||||
|
||||
private boolean mSharedLibrary = false;
|
||||
private boolean mSparseResources = false;
|
||||
|
||||
private final static String[] IGNORED_PACKAGES = new String[] {
|
||||
"android", "com.htc", "com.lge", "com.lge.internal", "yi", "flyme", "air.com.adobe.appentry",
|
||||
"FFFFFFFFFFFFFFFFFFFFFF" };
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ public class ResTable {
|
||||
return pkg;
|
||||
}
|
||||
if (mAndRes != null) {
|
||||
return mAndRes.loadFrameworkPkg(this, id, mAndRes.buildOptions.frameworkTag);
|
||||
return mAndRes.loadFrameworkPkg(this, id);
|
||||
}
|
||||
throw new UndefinedResObjectException(String.format("package: id=%d", id));
|
||||
}
|
||||
|
@ -17,7 +17,6 @@
|
||||
package brut.androlib;
|
||||
|
||||
import brut.androlib.exceptions.AndrolibException;
|
||||
import brut.androlib.options.BuildOptions;
|
||||
import brut.androlib.res.AndrolibResources;
|
||||
import brut.common.BrutException;
|
||||
import brut.directory.DirUtil;
|
||||
@ -119,7 +118,7 @@ public abstract class TestUtils {
|
||||
}
|
||||
|
||||
public static void cleanFrameworkFile() throws BrutException {
|
||||
File framework = new File(getFrameworkDir(), "1.apk");
|
||||
File framework = new File(getFrameworkDirectory(), "1.apk");
|
||||
|
||||
if (Files.exists(framework.toPath())) {
|
||||
OS.rmfile(framework.getAbsolutePath());
|
||||
@ -137,10 +136,10 @@ public abstract class TestUtils {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
static File getFrameworkDir() throws AndrolibException {
|
||||
AndrolibResources androlibResources = new AndrolibResources();
|
||||
androlibResources.buildOptions = new BuildOptions();
|
||||
return androlibResources.getFrameworkDir();
|
||||
static File getFrameworkDirectory() throws AndrolibException {
|
||||
Config config = Config.getDefaultConfig();
|
||||
AndrolibResources androlibResources = new AndrolibResources(config);
|
||||
return androlibResources.getFrameworkDirectory();
|
||||
}
|
||||
|
||||
public static class ResValueElementQualifier implements ElementQualifier {
|
||||
|
@ -17,7 +17,7 @@
|
||||
package brut.androlib.aapt1;
|
||||
|
||||
import brut.androlib.*;
|
||||
import brut.androlib.options.BuildOptions;
|
||||
import brut.androlib.Config;
|
||||
import brut.directory.ExtFile;
|
||||
import brut.common.BrutException;
|
||||
import brut.util.OS;
|
||||
@ -47,8 +47,8 @@ public class AndroidOreoNotSparseTest extends BaseTest {
|
||||
apkDecoder.decode();
|
||||
|
||||
LOGGER.info("Building not_sparse.apk...");
|
||||
BuildOptions buildOptions = new BuildOptions();
|
||||
new Androlib(buildOptions).build(sTestNewDir, testApk);
|
||||
Config config = Config.getDefaultConfig();
|
||||
new Androlib(config).build(sTestNewDir, testApk);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
|
@ -17,7 +17,7 @@
|
||||
package brut.androlib.aapt1;
|
||||
|
||||
import brut.androlib.*;
|
||||
import brut.androlib.options.BuildOptions;
|
||||
import brut.androlib.Config;
|
||||
import brut.directory.ExtFile;
|
||||
import brut.common.BrutException;
|
||||
import brut.util.OS;
|
||||
@ -47,8 +47,8 @@ public class AndroidOreoSparseTest extends BaseTest {
|
||||
apkDecoder.decode();
|
||||
|
||||
LOGGER.info("Building sparse.apk...");
|
||||
BuildOptions buildOptions = new BuildOptions();
|
||||
new Androlib(buildOptions).build(sTestNewDir, testApk);
|
||||
Config config = Config.getDefaultConfig();
|
||||
new Androlib(config).build(sTestNewDir, testApk);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
|
@ -17,7 +17,7 @@
|
||||
package brut.androlib.aapt1;
|
||||
|
||||
import brut.androlib.*;
|
||||
import brut.androlib.options.BuildOptions;
|
||||
import brut.androlib.Config;
|
||||
import brut.directory.ExtFile;
|
||||
import brut.common.BrutException;
|
||||
import brut.util.OS;
|
||||
@ -47,11 +47,11 @@ public class DebugTagRetainedTest extends BaseTest {
|
||||
TestUtils.copyResourceDir(DebugTagRetainedTest.class, "aapt1/issue1235/", sTestOrigDir);
|
||||
|
||||
LOGGER.info("Building issue1235.apk...");
|
||||
BuildOptions buildOptions = new BuildOptions();
|
||||
buildOptions.debugMode = true;
|
||||
Config config = Config.getDefaultConfig();
|
||||
config.debugMode = true;
|
||||
|
||||
File testApk = new File(sTmpDir, "issue1235.apk");
|
||||
new Androlib(buildOptions).build(sTestOrigDir, testApk);
|
||||
new Androlib(config).build(sTestOrigDir, testApk);
|
||||
|
||||
LOGGER.info("Decoding issue1235.apk...");
|
||||
ApkDecoder apkDecoder = new ApkDecoder(testApk);
|
||||
|
@ -18,7 +18,7 @@ package brut.androlib.aapt1;
|
||||
|
||||
import brut.androlib.Androlib;
|
||||
import brut.androlib.ApkDecoder;
|
||||
import brut.androlib.options.BuildOptions;
|
||||
import brut.androlib.Config;
|
||||
import brut.androlib.TestUtils;
|
||||
import brut.directory.ExtFile;
|
||||
import brut.common.BrutException;
|
||||
@ -50,8 +50,8 @@ public class EmptyResourcesArscTest {
|
||||
apkDecoder.decode();
|
||||
|
||||
LOGGER.info("Building issue1730.apk...");
|
||||
BuildOptions buildOptions = new BuildOptions();
|
||||
new Androlib(buildOptions).build(sTestNewDir, testApk);
|
||||
Config config = Config.getDefaultConfig();
|
||||
new Androlib(config).build(sTestNewDir, testApk);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
|
@ -52,7 +52,7 @@ public class ReferenceVersionCodeTest extends BaseTest {
|
||||
String apk = "issue1234.apk";
|
||||
|
||||
// decode issue1234.apk
|
||||
ApkDecoder apkDecoder = new ApkDecoder(new File(sTmpDir + File.separator + apk));
|
||||
ApkDecoder apkDecoder = new ApkDecoder(new ExtFile(sTmpDir + File.separator + apk));
|
||||
ExtFile decodedApk = new ExtFile(sTmpDir + File.separator + apk + ".out");
|
||||
apkDecoder.setOutDir(new File(sTmpDir + File.separator + apk + ".out"));
|
||||
apkDecoder.decode();
|
||||
|
@ -18,7 +18,6 @@ package brut.androlib.aapt1;
|
||||
|
||||
import brut.androlib.*;
|
||||
import brut.androlib.exceptions.AndrolibException;
|
||||
import brut.androlib.options.BuildOptions;
|
||||
import brut.directory.ExtFile;
|
||||
import brut.common.BrutException;
|
||||
import brut.util.OS;
|
||||
@ -51,11 +50,11 @@ public class SharedLibraryTest extends BaseTest {
|
||||
public void isFrameworkTaggingWorking() throws AndrolibException {
|
||||
String apkName = "library.apk";
|
||||
|
||||
BuildOptions buildOptions = new BuildOptions();
|
||||
buildOptions.frameworkFolderLocation = sTmpDir.getAbsolutePath();
|
||||
buildOptions.frameworkTag = "building";
|
||||
Config config = Config.getDefaultConfig();
|
||||
config.frameworkDirectory = sTmpDir.getAbsolutePath();
|
||||
config.frameworkTag = "building";
|
||||
|
||||
new Androlib(buildOptions).installFramework(new File(sTmpDir + File.separator + apkName));
|
||||
new Androlib(config).installFramework(new File(sTmpDir + File.separator + apkName));
|
||||
|
||||
assertTrue(fileExists("2-building.apk"));
|
||||
}
|
||||
@ -64,10 +63,10 @@ public class SharedLibraryTest extends BaseTest {
|
||||
public void isFrameworkInstallingWorking() throws AndrolibException {
|
||||
String apkName = "library.apk";
|
||||
|
||||
BuildOptions buildOptions = new BuildOptions();
|
||||
buildOptions.frameworkFolderLocation = sTmpDir.getAbsolutePath();
|
||||
Config config = Config.getDefaultConfig();
|
||||
config.frameworkDirectory = sTmpDir.getAbsolutePath();
|
||||
|
||||
new Androlib(buildOptions).installFramework(new File(sTmpDir + File.separator + apkName));
|
||||
new Androlib(config).installFramework(new File(sTmpDir + File.separator + apkName));
|
||||
|
||||
assertTrue(fileExists("2.apk"));
|
||||
}
|
||||
@ -78,36 +77,32 @@ public class SharedLibraryTest extends BaseTest {
|
||||
String client = "client.apk";
|
||||
|
||||
// setup apkOptions
|
||||
BuildOptions buildOptions = new BuildOptions();
|
||||
buildOptions.frameworkFolderLocation = sTmpDir.getAbsolutePath();
|
||||
buildOptions.frameworkTag = "shared";
|
||||
Config config = Config.getDefaultConfig();
|
||||
config.frameworkDirectory = sTmpDir.getAbsolutePath();
|
||||
config.frameworkTag = "shared";
|
||||
|
||||
// install library/framework
|
||||
new Androlib(buildOptions).installFramework(new File(sTmpDir + File.separator + library));
|
||||
new Androlib(config).installFramework(new File(sTmpDir + File.separator + library));
|
||||
assertTrue(fileExists("2-shared.apk"));
|
||||
|
||||
// decode client.apk
|
||||
ApkDecoder apkDecoder = new ApkDecoder(new File(sTmpDir + File.separator + client));
|
||||
ApkDecoder apkDecoder = new ApkDecoder(config, new ExtFile(sTmpDir + File.separator + client));
|
||||
apkDecoder.setOutDir(new File(sTmpDir + File.separator + client + ".out"));
|
||||
apkDecoder.setFrameworkDir(buildOptions.frameworkFolderLocation);
|
||||
apkDecoder.setFrameworkTag(buildOptions.frameworkTag);
|
||||
apkDecoder.decode();
|
||||
|
||||
// decode library.apk
|
||||
ApkDecoder libraryDecoder = new ApkDecoder(new File(sTmpDir + File.separator + library));
|
||||
ApkDecoder libraryDecoder = new ApkDecoder(config, new ExtFile(sTmpDir + File.separator + library));
|
||||
libraryDecoder.setOutDir(new File(sTmpDir + File.separator + library + ".out"));
|
||||
libraryDecoder.setFrameworkDir(buildOptions.frameworkFolderLocation);
|
||||
libraryDecoder.setFrameworkTag(buildOptions.frameworkTag);
|
||||
libraryDecoder.decode();
|
||||
|
||||
// build client.apk
|
||||
ExtFile clientApk = new ExtFile(sTmpDir, client + ".out");
|
||||
new Androlib(buildOptions).build(clientApk, null);
|
||||
new Androlib(config).build(clientApk, null);
|
||||
assertTrue(fileExists(client + ".out" + File.separator + "dist" + File.separator + client));
|
||||
|
||||
// build library.apk (shared library)
|
||||
ExtFile libraryApk = new ExtFile(sTmpDir, library + ".out");
|
||||
new Androlib(buildOptions).build(libraryApk, null);
|
||||
new Androlib(config).build(libraryApk, null);
|
||||
assertTrue(fileExists(library + ".out" + File.separator + "dist" + File.separator + library));
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,7 @@ package brut.androlib.aapt1;
|
||||
|
||||
import brut.androlib.ApkDecoder;
|
||||
import brut.androlib.BaseTest;
|
||||
import brut.androlib.Config;
|
||||
import brut.androlib.TestUtils;
|
||||
import brut.directory.ExtFile;
|
||||
import brut.common.BrutException;
|
||||
@ -46,13 +47,15 @@ public class SkipAssetTest extends BaseTest {
|
||||
public void checkIfEnablingSkipAssetWorks() throws BrutException, IOException {
|
||||
String apk = "issue1605.apk";
|
||||
|
||||
Config config = Config.getDefaultConfig();
|
||||
config.decodeAssets = Config.DECODE_ASSETS_NONE;
|
||||
config.forceDelete = true;
|
||||
|
||||
// decode issue1605.apk
|
||||
ApkDecoder apkDecoder = new ApkDecoder(new File(sTmpDir + File.separator + apk));
|
||||
ApkDecoder apkDecoder = new ApkDecoder(config, new ExtFile(sTmpDir + File.separator + apk));
|
||||
sTestOrigDir = new ExtFile(sTmpDir + File.separator + apk + ".out");
|
||||
|
||||
apkDecoder.setOutDir(sTestOrigDir);
|
||||
apkDecoder.setDecodeAssets(ApkDecoder.DECODE_ASSETS_NONE);
|
||||
apkDecoder.setForceDelete(true);
|
||||
apkDecoder.decode();
|
||||
|
||||
checkFileDoesNotExist("assets" + File.separator + "kotlin.kotlin_builtins");
|
||||
@ -63,13 +66,15 @@ public class SkipAssetTest extends BaseTest {
|
||||
public void checkControl() throws BrutException, IOException {
|
||||
String apk = "issue1605.apk";
|
||||
|
||||
Config config = Config.getDefaultConfig();
|
||||
config.decodeAssets = Config.DECODE_ASSETS_FULL;
|
||||
config.forceDelete = true;
|
||||
|
||||
// decode issue1605.apk
|
||||
ApkDecoder apkDecoder = new ApkDecoder(new File(sTmpDir + File.separator + apk));
|
||||
ApkDecoder apkDecoder = new ApkDecoder(config, new ExtFile(sTmpDir + File.separator + apk));
|
||||
sTestOrigDir = new ExtFile(sTmpDir + File.separator + apk + ".out");
|
||||
|
||||
apkDecoder.setOutDir(sTestOrigDir);
|
||||
apkDecoder.setDecodeAssets(ApkDecoder.DECODE_ASSETS_FULL);
|
||||
apkDecoder.setForceDelete(true);
|
||||
apkDecoder.decode();
|
||||
|
||||
checkFileDoesExist("assets" + File.separator + "kotlin.kotlin_builtins");
|
||||
|
@ -17,7 +17,7 @@
|
||||
package brut.androlib.aapt1;
|
||||
|
||||
import brut.androlib.*;
|
||||
import brut.androlib.options.BuildOptions;
|
||||
import brut.androlib.Config;
|
||||
import brut.directory.ExtFile;
|
||||
import brut.common.BrutException;
|
||||
import brut.util.OS;
|
||||
@ -40,19 +40,20 @@ public class UnknownCompressionTest extends BaseTest {
|
||||
TestUtils.copyResourceDir(UnknownCompressionTest.class, "aapt1/unknown_compression/", sTmpDir);
|
||||
|
||||
String apk = "deflated_unknowns.apk";
|
||||
BuildOptions buildOptions = new BuildOptions();
|
||||
buildOptions.frameworkFolderLocation = sTmpDir.getAbsolutePath();
|
||||
Config config = Config.getDefaultConfig();
|
||||
config.frameworkDirectory = sTmpDir.getAbsolutePath();
|
||||
|
||||
sTestOrigDir = new ExtFile(sTmpDir, apk);
|
||||
|
||||
// decode deflated_unknowns.apk
|
||||
ApkDecoder apkDecoder = new ApkDecoder(sTestOrigDir);
|
||||
// need new ExtFile because closed in decode()
|
||||
ApkDecoder apkDecoder = new ApkDecoder(new ExtFile(sTestOrigDir));
|
||||
apkDecoder.setOutDir(new File(sTestOrigDir.getAbsolutePath() + ".out"));
|
||||
apkDecoder.decode();
|
||||
|
||||
// build deflated_unknowns
|
||||
ExtFile clientApkFolder = new ExtFile(sTestOrigDir.getAbsolutePath() + ".out");
|
||||
new Androlib(buildOptions).build(clientApkFolder, null);
|
||||
new Androlib(config).build(clientApkFolder, null);
|
||||
sTestNewDir = new ExtFile(clientApkFolder, "dist" + File.separator + apk);
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@ package brut.androlib.aapt2;
|
||||
|
||||
import brut.androlib.*;
|
||||
import brut.androlib.meta.MetaInfo;
|
||||
import brut.androlib.options.BuildOptions;
|
||||
import brut.androlib.Config;
|
||||
import brut.common.BrutException;
|
||||
import brut.directory.ExtFile;
|
||||
import brut.util.OS;
|
||||
@ -43,13 +43,13 @@ public class BuildAndDecodeTest extends BaseTest {
|
||||
LOGGER.info("Unpacking testapp...");
|
||||
TestUtils.copyResourceDir(BuildAndDecodeTest.class, "aapt2/testapp/", sTestOrigDir);
|
||||
|
||||
BuildOptions buildOptions = new BuildOptions();
|
||||
buildOptions.useAapt2 = true;
|
||||
buildOptions.verbose = true;
|
||||
Config config = Config.getDefaultConfig();
|
||||
config.useAapt2 = true;
|
||||
config.verbose = true;
|
||||
|
||||
LOGGER.info("Building testapp.apk...");
|
||||
File testApk = new File(sTmpDir, "testapp.apk");
|
||||
new Androlib(buildOptions).build(sTestOrigDir, testApk);
|
||||
new Androlib(config).build(sTestOrigDir, testApk);
|
||||
|
||||
LOGGER.info("Decoding testapp.apk...");
|
||||
ApkDecoder apkDecoder = new ApkDecoder(testApk);
|
||||
|
@ -17,7 +17,7 @@
|
||||
package brut.androlib.aapt2;
|
||||
|
||||
import brut.androlib.*;
|
||||
import brut.androlib.options.BuildOptions;
|
||||
import brut.androlib.Config;
|
||||
import brut.common.BrutException;
|
||||
import brut.directory.ExtFile;
|
||||
import brut.util.OS;
|
||||
@ -47,13 +47,13 @@ public class DebuggableFalseChangeToTrueTest extends BaseTest {
|
||||
TestUtils.copyResourceDir(DebuggableFalseChangeToTrueTest.class, "aapt2/issue2328/debuggable-false", sTestOrigDir);
|
||||
|
||||
LOGGER.info("Building issue2328-debuggable-flase.apk...");
|
||||
BuildOptions buildOptions = new BuildOptions();
|
||||
buildOptions.debugMode = true;
|
||||
buildOptions.useAapt2 = true;
|
||||
buildOptions.verbose = true;
|
||||
Config config = Config.getDefaultConfig();
|
||||
config.debugMode = true;
|
||||
config.useAapt2 = true;
|
||||
config.verbose = true;
|
||||
|
||||
File testApk = new File(sTmpDir, "issue2328-debuggable-flase.apk");
|
||||
new Androlib(buildOptions).build(sTestOrigDir, testApk);
|
||||
new Androlib(config).build(sTestOrigDir, testApk);
|
||||
|
||||
LOGGER.info("Decoding issue2328-debuggable-flase.apk...");
|
||||
ApkDecoder apkDecoder = new ApkDecoder(testApk);
|
||||
|
@ -17,7 +17,7 @@
|
||||
package brut.androlib.aapt2;
|
||||
|
||||
import brut.androlib.*;
|
||||
import brut.androlib.options.BuildOptions;
|
||||
import brut.androlib.Config;
|
||||
import brut.common.BrutException;
|
||||
import brut.directory.ExtFile;
|
||||
import brut.util.OS;
|
||||
@ -47,13 +47,13 @@ public class DebuggableTrueAddedTest extends BaseTest {
|
||||
TestUtils.copyResourceDir(DebuggableTrueAddedTest.class, "aapt2/issue2328/debuggable-missing", sTestOrigDir);
|
||||
|
||||
LOGGER.info("Building issue2328-debuggable-missing.apk...");
|
||||
BuildOptions buildOptions = new BuildOptions();
|
||||
buildOptions.debugMode = true;
|
||||
buildOptions.useAapt2 = true;
|
||||
buildOptions.verbose = true;
|
||||
Config config = Config.getDefaultConfig();
|
||||
config.debugMode = true;
|
||||
config.useAapt2 = true;
|
||||
config.verbose = true;
|
||||
|
||||
File testApk = new File(sTmpDir, "issue2328-debuggable-missing.apk");
|
||||
new Androlib(buildOptions).build(sTestOrigDir, testApk);
|
||||
new Androlib(config).build(sTestOrigDir, testApk);
|
||||
|
||||
LOGGER.info("Decoding issue2328-debuggable-missing.apk...");
|
||||
ApkDecoder apkDecoder = new ApkDecoder(testApk);
|
||||
|
@ -17,7 +17,7 @@
|
||||
package brut.androlib.aapt2;
|
||||
|
||||
import brut.androlib.*;
|
||||
import brut.androlib.options.BuildOptions;
|
||||
import brut.androlib.Config;
|
||||
import brut.common.BrutException;
|
||||
import brut.directory.ExtFile;
|
||||
import brut.util.OS;
|
||||
@ -47,13 +47,13 @@ public class DebuggableTrueRetainedTest extends BaseTest {
|
||||
TestUtils.copyResourceDir(DebuggableTrueRetainedTest.class, "aapt2/issue2328/debuggable-true", sTestOrigDir);
|
||||
|
||||
LOGGER.info("Building issue2328-debuggable-true.apk...");
|
||||
BuildOptions buildOptions = new BuildOptions();
|
||||
buildOptions.debugMode = true;
|
||||
buildOptions.useAapt2 = true;
|
||||
buildOptions.verbose = true;
|
||||
Config config = Config.getDefaultConfig();
|
||||
config.debugMode = true;
|
||||
config.useAapt2 = true;
|
||||
config.verbose = true;
|
||||
|
||||
File testApk = new File(sTmpDir, "issue2328-debuggable-true.apk");
|
||||
new Androlib(buildOptions).build(sTestOrigDir, testApk);
|
||||
new Androlib(config).build(sTestOrigDir, testApk);
|
||||
|
||||
LOGGER.info("Decoding issue2328-debuggable-true.apk...");
|
||||
ApkDecoder apkDecoder = new ApkDecoder(testApk);
|
||||
|
@ -17,7 +17,7 @@
|
||||
package brut.androlib.aapt2;
|
||||
|
||||
import brut.androlib.*;
|
||||
import brut.androlib.options.BuildOptions;
|
||||
import brut.androlib.Config;
|
||||
import brut.common.BrutException;
|
||||
import brut.directory.ExtFile;
|
||||
import brut.util.OS;
|
||||
@ -53,11 +53,11 @@ public class NetworkConfigTest extends BaseTest {
|
||||
TestUtils.copyResourceDir(NetworkConfigTest.class, "aapt2/network_config/", sTestOrigDir);
|
||||
|
||||
LOGGER.info("Building testapp.apk...");
|
||||
BuildOptions buildOptions = new BuildOptions();
|
||||
buildOptions.netSecConf = true;
|
||||
buildOptions.useAapt2 = true;
|
||||
Config config = Config.getDefaultConfig();
|
||||
config.netSecConf = true;
|
||||
config.useAapt2 = true;
|
||||
File testApk = new File(sTmpDir, "testapp.apk");
|
||||
new Androlib(buildOptions).build(sTestOrigDir, testApk);
|
||||
new Androlib(config).build(sTestOrigDir, testApk);
|
||||
|
||||
LOGGER.info("Decoding testapp.apk...");
|
||||
ApkDecoder apkDecoder = new ApkDecoder(testApk);
|
||||
|
@ -17,7 +17,7 @@
|
||||
package brut.androlib.aapt2;
|
||||
|
||||
import brut.androlib.*;
|
||||
import brut.androlib.options.BuildOptions;
|
||||
import brut.androlib.Config;
|
||||
import brut.common.BrutException;
|
||||
import brut.directory.ExtFile;
|
||||
import brut.util.OS;
|
||||
@ -56,11 +56,11 @@ public class NoNetworkConfigTest extends BaseTest {
|
||||
TestUtils.copyResourceDir(NoNetworkConfigTest.class, "aapt2/testapp/", sTestOrigDir);
|
||||
|
||||
LOGGER.info("Building testapp.apk...");
|
||||
BuildOptions buildOptions = new BuildOptions();
|
||||
buildOptions.netSecConf = true;
|
||||
buildOptions.useAapt2 = true;
|
||||
Config config = Config.getDefaultConfig();
|
||||
config.netSecConf = true;
|
||||
config.useAapt2 = true;
|
||||
File testApk = new File(sTmpDir, "testapp.apk");
|
||||
new Androlib(buildOptions).build(sTestOrigDir, testApk);
|
||||
new Androlib(config).build(sTestOrigDir, testApk);
|
||||
|
||||
LOGGER.info("Decoding testapp.apk...");
|
||||
ApkDecoder apkDecoder = new ApkDecoder(testApk);
|
||||
|
@ -18,7 +18,6 @@ package brut.androlib.aapt2;
|
||||
|
||||
import brut.androlib.*;
|
||||
import brut.androlib.exceptions.AndrolibException;
|
||||
import brut.androlib.options.BuildOptions;
|
||||
import brut.androlib.res.data.ResTable;
|
||||
import brut.common.BrutException;
|
||||
import brut.directory.ExtFile;
|
||||
@ -45,13 +44,13 @@ public class NonStandardPkgIdTest extends BaseTest {
|
||||
LOGGER.info("Unpacking pkgid8...");
|
||||
TestUtils.copyResourceDir(BuildAndDecodeTest.class, "aapt2/pkgid8/", sTestOrigDir);
|
||||
|
||||
BuildOptions buildOptions = new BuildOptions();
|
||||
buildOptions.useAapt2 = true;
|
||||
buildOptions.verbose = true;
|
||||
Config config = Config.getDefaultConfig();
|
||||
config.useAapt2 = true;
|
||||
config.verbose = true;
|
||||
|
||||
LOGGER.info("Building pkgid8.apk...");
|
||||
File testApk = new File(sTmpDir, "pkgid8.apk");
|
||||
new Androlib(buildOptions).build(sTestOrigDir, testApk);
|
||||
new Androlib(config).build(sTestOrigDir, testApk);
|
||||
|
||||
LOGGER.info("Decoding pkgid8.apk...");
|
||||
ApkDecoder apkDecoder = new ApkDecoder(testApk);
|
||||
|
@ -17,6 +17,7 @@
|
||||
package brut.androlib.androlib;
|
||||
|
||||
import brut.androlib.BaseTest;
|
||||
import brut.androlib.Config;
|
||||
import brut.androlib.res.AndrolibResources;
|
||||
import org.junit.Test;
|
||||
import java.util.LinkedHashMap;
|
||||
|
@ -18,6 +18,7 @@ package brut.androlib.decode;
|
||||
|
||||
import brut.androlib.ApkDecoder;
|
||||
import brut.androlib.BaseTest;
|
||||
import brut.androlib.Config;
|
||||
import brut.androlib.TestUtils;
|
||||
import brut.directory.ExtFile;
|
||||
import brut.common.BrutException;
|
||||
@ -59,12 +60,14 @@ public class AndResGuardTest extends BaseTest {
|
||||
|
||||
@Test
|
||||
public void checkifAndResDecodeRemapsRFolderInRawMode() throws BrutException, IOException {
|
||||
String apk = "issue1170.apk";
|
||||
ApkDecoder apkDecoder = new ApkDecoder(new File(sTmpDir + File.separator + apk));
|
||||
sTestOrigDir = new ExtFile(sTmpDir + File.separator + apk + ".raw.out");
|
||||
|
||||
Config config = Config.getDefaultConfig();
|
||||
config.forceDelete = true;
|
||||
config.decodeResources = Config.DECODE_RESOURCES_NONE;
|
||||
String apk = "issue1170.apk";
|
||||
ApkDecoder apkDecoder = new ApkDecoder(config, new File(sTmpDir + File.separator + apk));
|
||||
sTestOrigDir = new ExtFile(sTmpDir + File.separator + apk + ".raw.out");
|
||||
apkDecoder.setOutDir(new File(sTmpDir + File.separator + apk + ".raw.out"));
|
||||
apkDecoder.setDecodeResources(ApkDecoder.DECODE_RESOURCES_NONE);
|
||||
apkDecoder.decode();
|
||||
|
||||
File aPng = new File(sTestOrigDir,"r/a/a.png");
|
||||
|
@ -52,45 +52,46 @@ public class DecodeKotlinCoroutinesTest extends BaseTest {
|
||||
@Test
|
||||
public void kotlinCoroutinesDecodeTest() throws IOException, AndrolibException, DirectoryException {
|
||||
|
||||
Config config = Config.getDefaultConfig();
|
||||
config.forceDelete = true;
|
||||
// decode kotlin coroutines
|
||||
ApkDecoder apkDecoder = new ApkDecoder(new File(sTmpDir + File.separator + apk));
|
||||
ApkDecoder apkDecoder = new ApkDecoder(config, new File(sTmpDir + File.separator + apk));
|
||||
apkDecoder.setOutDir(new File(sTmpDir + File.separator + apk + ".out"));
|
||||
apkDecoder.setForceDelete(true);
|
||||
apkDecoder.decode();
|
||||
File coroutinesExceptionHandler = new File(sTmpDir + File.separator + apk + ".out" + File.separator + "META-INF" + File.separator + "services", "kotlinx.coroutines.CoroutineExceptionHandler");
|
||||
File coroutinenMainDispatcherHandler = new File(sTmpDir + File.separator + apk + ".out" + File.separator + "META-INF" + File.separator + "services", "kotlinx.coroutines.internal.MainDispatcherFactory");
|
||||
File coroutinesMainDispatcherHandler = new File(sTmpDir + File.separator + apk + ".out" + File.separator + "META-INF" + File.separator + "services", "kotlinx.coroutines.internal.MainDispatcherFactory");
|
||||
|
||||
assert (coroutinesExceptionHandler.exists());
|
||||
assert (coroutinenMainDispatcherHandler.exists());
|
||||
assert (coroutinesMainDispatcherHandler.exists());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void kotlinCoroutinesEncodeAfterDecodeTest() throws IOException, BrutException {
|
||||
|
||||
Config config = Config.getDefaultConfig();
|
||||
config.forceDelete = true;
|
||||
// decode kotlin coroutines
|
||||
ApkDecoder apkDecoder = new ApkDecoder(new File(sTmpDir + File.separator + apk));
|
||||
ApkDecoder apkDecoder = new ApkDecoder(config, new File(sTmpDir + File.separator + apk));
|
||||
apkDecoder.setOutDir(new File(sTmpDir + File.separator + apk + ".out"));
|
||||
apkDecoder.setForceDelete(true);
|
||||
apkDecoder.decode();
|
||||
|
||||
// build kotlin coroutines
|
||||
ExtFile testApk = new ExtFile(sTmpDir, apk + ".out");
|
||||
new Androlib().build(testApk, null);
|
||||
new Androlib(config).build(testApk, null);
|
||||
String newApk = apk + ".out" + File.separator + "dist" + File.separator + apk;
|
||||
assertTrue(fileExists(newApk));
|
||||
|
||||
// decode kotlin coroutines again
|
||||
apkDecoder = new ApkDecoder(new File(sTmpDir + File.separator + newApk));
|
||||
apkDecoder = new ApkDecoder(config, new File(sTmpDir + File.separator + newApk));
|
||||
apkDecoder.setOutDir(new File(sTmpDir + File.separator + apk + ".out.two"));
|
||||
apkDecoder.setForceDelete(true);
|
||||
apkDecoder.decode();
|
||||
|
||||
Files.readAllBytes(Paths.get(sTmpDir + File.separator + apk + ".out.two" + File.separator + "AndroidManifest.xml"));
|
||||
File coroutinesExceptionHandler = new File(sTmpDir + File.separator + apk + ".out.two" + File.separator + "META-INF" + File.separator + "services", "kotlinx.coroutines.CoroutineExceptionHandler");
|
||||
File coroutinenMainDispatcherHandler = new File(sTmpDir + File.separator + apk + ".out.two" + File.separator + "META-INF" + File.separator + "services", "kotlinx.coroutines.internal.MainDispatcherFactory");
|
||||
File coroutinesMainDispatcherHandler = new File(sTmpDir + File.separator + apk + ".out.two" + File.separator + "META-INF" + File.separator + "services", "kotlinx.coroutines.internal.MainDispatcherFactory");
|
||||
|
||||
assert (coroutinesExceptionHandler.exists());
|
||||
assert (coroutinenMainDispatcherHandler.exists());
|
||||
assert (coroutinesMainDispatcherHandler.exists());
|
||||
}
|
||||
|
||||
private boolean fileExists(String filepath) {
|
||||
|
@ -18,7 +18,6 @@ package brut.androlib.decode;
|
||||
|
||||
import brut.androlib.*;
|
||||
import brut.androlib.exceptions.AndrolibException;
|
||||
import brut.androlib.options.BuildOptions;
|
||||
import brut.common.BrutException;
|
||||
import brut.directory.ExtFile;
|
||||
import brut.util.OS;
|
||||
@ -55,8 +54,8 @@ public class DuplicateDexTest extends BaseTest {
|
||||
apkDecoder.decode();
|
||||
|
||||
LOGGER.info("Building duplicatedex.apk...");
|
||||
BuildOptions buildOptions = new BuildOptions();
|
||||
new Androlib(buildOptions).build(sTestNewDir, testApk);
|
||||
Config config = Config.getDefaultConfig();
|
||||
new Androlib(config).build(sTestNewDir, testApk);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -64,14 +63,15 @@ public class DuplicateDexTest extends BaseTest {
|
||||
File testApk = new File(sTestOrigDir, "duplicatedex.apk");
|
||||
|
||||
LOGGER.info("Decoding duplicatedex.apk...");
|
||||
ApkDecoder apkDecoder = new ApkDecoder(testApk);
|
||||
apkDecoder.setDecodeSources(ApkDecoder.DECODE_SOURCES_SMALI_ONLY_MAIN_CLASSES);
|
||||
Config config = Config.getDefaultConfig();
|
||||
config.decodeSources = Config.DECODE_SOURCES_SMALI_ONLY_MAIN_CLASSES;
|
||||
|
||||
ApkDecoder apkDecoder = new ApkDecoder(config, testApk);
|
||||
apkDecoder.setOutDir(sTestNewDir);
|
||||
apkDecoder.decode();
|
||||
|
||||
LOGGER.info("Building duplicatedex.apk...");
|
||||
BuildOptions buildOptions = new BuildOptions();
|
||||
new Androlib(buildOptions).build(sTestNewDir, testApk);
|
||||
new Androlib(config).build(sTestNewDir, testApk);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ package brut.androlib.decode;
|
||||
|
||||
import brut.androlib.ApkDecoder;
|
||||
import brut.androlib.BaseTest;
|
||||
import brut.androlib.Config;
|
||||
import brut.androlib.TestUtils;
|
||||
import brut.common.BrutException;
|
||||
import brut.directory.ExtFile;
|
||||
@ -61,10 +62,10 @@ public class ForceManifestDecodeNoResourcesTest extends BaseTest {
|
||||
String output = sTmpDir + File.separator + apk + ".out";
|
||||
|
||||
// decode issue1680.apk
|
||||
decodeFile(sTmpDir + File.separator + apk, ApkDecoder.DECODE_RESOURCES_NONE,
|
||||
ApkDecoder.FORCE_DECODE_MANIFEST_FULL, output);
|
||||
decodeFile(sTmpDir + File.separator + apk, Config.DECODE_RESOURCES_NONE,
|
||||
Config.FORCE_DECODE_MANIFEST_FULL, output);
|
||||
|
||||
// lets probe filetype of manifest, we should detect XML
|
||||
// let's probe filetype of manifest, we should detect XML
|
||||
File manifestFile = new File(output + File.separator + "AndroidManifest.xml");
|
||||
byte[] magic = TestUtils.readHeaderOfFile(manifestFile, 6);
|
||||
assertArrayEquals(this.xmlHeader, magic);
|
||||
@ -80,10 +81,10 @@ public class ForceManifestDecodeNoResourcesTest extends BaseTest {
|
||||
String output = sTmpDir + File.separator + apk + ".out";
|
||||
|
||||
// decode issue1680.apk
|
||||
decodeFile(sTmpDir + File.separator + apk, ApkDecoder.DECODE_RESOURCES_FULL,
|
||||
ApkDecoder.FORCE_DECODE_MANIFEST_FULL, output);
|
||||
decodeFile(sTmpDir + File.separator + apk, Config.DECODE_RESOURCES_FULL,
|
||||
Config.FORCE_DECODE_MANIFEST_FULL, output);
|
||||
|
||||
// lets probe filetype of manifest, we should detect XML
|
||||
// let's probe filetype of manifest, we should detect XML
|
||||
File manifestFile = new File(output + File.separator + "AndroidManifest.xml");
|
||||
byte[] magic = TestUtils.readHeaderOfFile(manifestFile, 6);
|
||||
assertArrayEquals(this.xmlHeader, magic);
|
||||
@ -99,8 +100,8 @@ public class ForceManifestDecodeNoResourcesTest extends BaseTest {
|
||||
String output = sTmpDir + File.separator + apk + ".out";
|
||||
|
||||
// decode issue1680.apk
|
||||
decodeFile(sTmpDir + File.separator + apk, ApkDecoder.DECODE_RESOURCES_FULL,
|
||||
ApkDecoder.FORCE_DECODE_MANIFEST_NONE, output);
|
||||
decodeFile(sTmpDir + File.separator + apk, Config.DECODE_RESOURCES_FULL,
|
||||
Config.FORCE_DECODE_MANIFEST_NONE, output);
|
||||
|
||||
// lets probe filetype of manifest, we should detect XML
|
||||
File manifestFile = new File(output + File.separator + "AndroidManifest.xml");
|
||||
@ -118,8 +119,8 @@ public class ForceManifestDecodeNoResourcesTest extends BaseTest {
|
||||
String output = sTmpDir + File.separator + apk + ".out";
|
||||
|
||||
// decode issue1680.apk
|
||||
decodeFile(sTmpDir + File.separator + apk, ApkDecoder.DECODE_RESOURCES_NONE,
|
||||
ApkDecoder.FORCE_DECODE_MANIFEST_NONE, output);
|
||||
decodeFile(sTmpDir + File.separator + apk, Config.DECODE_RESOURCES_NONE,
|
||||
Config.FORCE_DECODE_MANIFEST_NONE, output);
|
||||
|
||||
// lets probe filetype of manifest, we should not detect XML
|
||||
File manifestFile = new File(output + File.separator + "AndroidManifest.xml");
|
||||
@ -133,11 +134,12 @@ public class ForceManifestDecodeNoResourcesTest extends BaseTest {
|
||||
|
||||
private void decodeFile(String apk, short decodeResources, short decodeManifest, String output)
|
||||
throws BrutException, IOException {
|
||||
ApkDecoder apkDecoder = new ApkDecoder(new File(apk));
|
||||
apkDecoder.setDecodeResources(decodeResources);
|
||||
apkDecoder.setForceDecodeManifest(decodeManifest);
|
||||
apkDecoder.setForceDelete(true); // delete directory due to multiple tests.
|
||||
|
||||
Config config = Config.getDefaultConfig();
|
||||
config.forceDelete = true;
|
||||
config.decodeResources = decodeResources;
|
||||
config.forceDecodeManifest = decodeManifest;
|
||||
ApkDecoder apkDecoder = new ApkDecoder(config, new File(apk));
|
||||
apkDecoder.setOutDir(new File(output));
|
||||
apkDecoder.decode();
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ package brut.androlib.decode;
|
||||
|
||||
import brut.androlib.ApkDecoder;
|
||||
import brut.androlib.BaseTest;
|
||||
import brut.androlib.Config;
|
||||
import brut.androlib.TestUtils;
|
||||
import brut.directory.ExtFile;
|
||||
import brut.common.BrutException;
|
||||
@ -44,9 +45,10 @@ public class MinifiedArscTest extends BaseTest {
|
||||
String apk = "issue1157.apk";
|
||||
sTestNewDir = new ExtFile(sTmpDir, "issue1157");
|
||||
|
||||
Config config = Config.getDefaultConfig();
|
||||
config.forceDelete = true;
|
||||
// decode issue1157.apk
|
||||
ApkDecoder apkDecoder = new ApkDecoder(new ExtFile(sTmpDir, apk));
|
||||
apkDecoder.setForceDelete(true);
|
||||
ApkDecoder apkDecoder = new ApkDecoder(config, new ExtFile(sTmpDir, apk));
|
||||
apkDecoder.setOutDir(sTestNewDir);
|
||||
|
||||
// this should not raise an exception:
|
||||
|
@ -18,6 +18,7 @@ package brut.androlib.decode;
|
||||
|
||||
import brut.androlib.ApkDecoder;
|
||||
import brut.androlib.BaseTest;
|
||||
import brut.androlib.Config;
|
||||
import brut.androlib.TestUtils;
|
||||
import brut.common.BrutException;
|
||||
import brut.directory.ExtFile;
|
||||
@ -47,10 +48,11 @@ public class ParentDirectoryTraversalTest extends BaseTest {
|
||||
public void checkIfDrawableFileDecodesProperly() throws BrutException, IOException {
|
||||
String apk = "issue1498.apk";
|
||||
|
||||
Config config = Config.getDefaultConfig();
|
||||
config.forceDelete = true;
|
||||
config.decodeResources = Config.DECODE_RESOURCES_NONE;
|
||||
// decode issue1498.apk
|
||||
ApkDecoder apkDecoder = new ApkDecoder(new File(sTmpDir + File.separator + apk));
|
||||
apkDecoder.setDecodeResources(ApkDecoder.DECODE_RESOURCES_NONE);
|
||||
|
||||
ApkDecoder apkDecoder = new ApkDecoder(config, new File(sTmpDir + File.separator + apk));
|
||||
apkDecoder.setOutDir(new File(sTmpDir + File.separator + apk + ".out"));
|
||||
|
||||
// this should not raise an exception:
|
||||
|
@ -18,7 +18,7 @@ package brut.androlib.res.src;
|
||||
|
||||
import brut.androlib.*;
|
||||
import brut.androlib.aapt2.BuildAndDecodeTest;
|
||||
import brut.androlib.options.BuildOptions;
|
||||
import brut.androlib.Config;
|
||||
import brut.common.BrutException;
|
||||
import brut.directory.ExtFile;
|
||||
import brut.util.OS;
|
||||
@ -45,16 +45,16 @@ public class DexStaticFieldValueTest extends BaseTest {
|
||||
LOGGER.info("Unpacking issue2543...");
|
||||
TestUtils.copyResourceDir(BuildAndDecodeTest.class, "decode/issue2543/", sTestOrigDir);
|
||||
|
||||
BuildOptions buildOptions = new BuildOptions();
|
||||
Config config = Config.getDefaultConfig();
|
||||
|
||||
LOGGER.info("Building issue2543.apk...");
|
||||
File testApk = new File(sTmpDir, "issue2543.apk");
|
||||
new Androlib(buildOptions).build(sTestOrigDir, testApk);
|
||||
new Androlib(config).build(sTestOrigDir, testApk);
|
||||
|
||||
LOGGER.info("Decoding issue2543.apk...");
|
||||
ApkDecoder apkDecoder = new ApkDecoder(testApk);
|
||||
config.baksmaliDebugMode = false;
|
||||
ApkDecoder apkDecoder = new ApkDecoder(config, new ExtFile(testApk));
|
||||
apkDecoder.setOutDir(sTestNewDir);
|
||||
apkDecoder.setBaksmaliDebugMode(false);
|
||||
apkDecoder.decode();
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@ package brut.androlib.yaml;
|
||||
import brut.androlib.Androlib;
|
||||
import brut.androlib.BaseTest;
|
||||
import brut.androlib.TestUtils;
|
||||
import brut.androlib.options.BuildOptions;
|
||||
import brut.androlib.Config;
|
||||
import brut.common.BrutException;
|
||||
import brut.directory.ExtFile;
|
||||
import brut.util.OS;
|
||||
@ -43,8 +43,8 @@ public class MaliciousYamlTest extends BaseTest {
|
||||
|
||||
@Test(expected = ConstructorException.class)
|
||||
public void testMaliciousYamlNotLoaded() throws BrutException {
|
||||
BuildOptions buildOptions = new BuildOptions();
|
||||
Config config = Config.getDefaultConfig();
|
||||
File testApk = new File(sTmpDir, "cve20220476.apk");
|
||||
new Androlib(buildOptions).build(sTestNewDir, testApk);
|
||||
new Androlib(config).build(sTestNewDir, testApk);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user