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