refactor: rename ApkOptions -> Options/BuildOptions

This commit is contained in:
Connor Tumbleson 2021-09-05 06:45:03 -04:00 committed by Connor Tumbleson
parent bc51024ea8
commit 3b179f8750
20 changed files with 162 additions and 147 deletions

View File

@ -20,6 +20,7 @@ import brut.androlib.*;
import brut.androlib.err.CantFindFrameworkResException;
import brut.androlib.err.InFileNotFoundException;
import brut.androlib.err.OutDirExistsException;
import brut.androlib.options.BuildOptions;
import brut.common.BrutException;
import brut.directory.DirectoryException;
import brut.util.AaptManager;
@ -207,39 +208,39 @@ public class Main {
String[] args = cli.getArgs();
String appDirName = args.length < 2 ? "." : args[1];
File outFile;
ApkOptions apkOptions = new ApkOptions();
brut.androlib.options.BuildOptions buildOptions = new BuildOptions();
// check for build options
if (cli.hasOption("f") || cli.hasOption("force-all")) {
apkOptions.forceBuildAll = true;
buildOptions.forceBuildAll = true;
}
if (cli.hasOption("d") || cli.hasOption("debug")) {
apkOptions.debugMode = true;
buildOptions.debugMode = true;
}
if (cli.hasOption("v") || cli.hasOption("verbose")) {
apkOptions.verbose = true;
buildOptions.verbose = true;
}
if (cli.hasOption("a") || cli.hasOption("aapt")) {
apkOptions.aaptPath = cli.getOptionValue("a");
buildOptions.aaptPath = cli.getOptionValue("a");
}
if (cli.hasOption("c") || cli.hasOption("copy-original")) {
System.err.println("-c/--copy-original has been deprecated. Removal planned for v3.0.0 (#2129)");
apkOptions.copyOriginalFiles = true;
buildOptions.copyOriginalFiles = true;
}
if (cli.hasOption("p") || cli.hasOption("frame-path")) {
apkOptions.frameworkFolderLocation = cli.getOptionValue("p");
buildOptions.frameworkFolderLocation = cli.getOptionValue("p");
}
if (cli.hasOption("nc") || cli.hasOption("no-crunch")) {
apkOptions.noCrunch = true;
buildOptions.noCrunch = true;
}
// Temporary flag to enable the use of aapt2. This will tranform in time to a use-aapt1 flag, which will be
// legacy and eventually removed.
if (cli.hasOption("use-aapt2")) {
apkOptions.useAapt2 = true;
buildOptions.useAapt2 = true;
}
if (cli.hasOption("api") || cli.hasOption("api-level")) {
apkOptions.forceApi = Integer.parseInt(cli.getOptionValue("api"));
buildOptions.forceApi = Integer.parseInt(cli.getOptionValue("api"));
}
if (cli.hasOption("o") || cli.hasOption("output")) {
outFile = new File(cli.getOptionValue("o"));
@ -250,9 +251,9 @@ public class Main {
// try and build apk
try {
if (cli.hasOption("a") || cli.hasOption("aapt")) {
apkOptions.aaptVersion = AaptManager.getAaptVersion(cli.getOptionValue("a"));
buildOptions.aaptVersion = AaptManager.getAaptVersion(cli.getOptionValue("a"));
}
new Androlib(apkOptions).build(new File(appDirName), outFile);
new Androlib(buildOptions).build(new File(appDirName), outFile);
} catch (BrutException ex) {
System.err.println(ex.getMessage());
System.exit(1);
@ -263,23 +264,23 @@ public class Main {
int paraCount = cli.getArgList().size();
String apkName = cli.getArgList().get(paraCount - 1);
ApkOptions apkOptions = new ApkOptions();
brut.androlib.options.BuildOptions buildOptions = new BuildOptions();
if (cli.hasOption("p") || cli.hasOption("frame-path")) {
apkOptions.frameworkFolderLocation = cli.getOptionValue("p");
buildOptions.frameworkFolderLocation = cli.getOptionValue("p");
}
if (cli.hasOption("t") || cli.hasOption("tag")) {
apkOptions.frameworkTag = cli.getOptionValue("t");
buildOptions.frameworkTag = cli.getOptionValue("t");
}
new Androlib(apkOptions).installFramework(new File(apkName));
new Androlib(buildOptions).installFramework(new File(apkName));
}
private static void cmdListFrameworks(CommandLine cli) throws AndrolibException {
ApkOptions apkOptions = new ApkOptions();
brut.androlib.options.BuildOptions buildOptions = new BuildOptions();
if (cli.hasOption("p") || cli.hasOption("frame-path")) {
apkOptions.frameworkFolderLocation = cli.getOptionValue("p");
buildOptions.frameworkFolderLocation = cli.getOptionValue("p");
}
new Androlib(apkOptions).listFrameworks();
new Androlib(buildOptions).listFrameworks();
}
private static void cmdPublicizeResources(CommandLine cli) throws AndrolibException {
@ -290,16 +291,16 @@ public class Main {
}
private static void cmdEmptyFrameworkDirectory(CommandLine cli) throws AndrolibException {
ApkOptions apkOptions = new ApkOptions();
brut.androlib.options.BuildOptions buildOptions = new BuildOptions();
if (cli.hasOption("f") || cli.hasOption("force")) {
apkOptions.forceDeleteFramework = true;
buildOptions.forceDeleteFramework = true;
}
if (cli.hasOption("p") || cli.hasOption("frame-path")) {
apkOptions.frameworkFolderLocation = cli.getOptionValue("p");
buildOptions.frameworkFolderLocation = cli.getOptionValue("p");
}
new Androlib(apkOptions).emptyFrameworkDirectory();
new Androlib(buildOptions).emptyFrameworkDirectory();
}
private static void _version() {

View File

@ -18,6 +18,7 @@ package brut.androlib;
import brut.androlib.meta.MetaInfo;
import brut.androlib.meta.UsesFramework;
import brut.androlib.options.BuildOptions;
import brut.androlib.res.AndrolibResources;
import brut.androlib.res.data.ResPackage;
import brut.androlib.res.data.ResTable;
@ -47,16 +48,16 @@ import java.util.zip.ZipOutputStream;
public class Androlib {
private final AndrolibResources mAndRes = new AndrolibResources();
protected final ResUnknownFiles mResUnknownFiles = new ResUnknownFiles();
public final ApkOptions apkOptions;
public final BuildOptions buildOptions;
private int mMinSdkVersion = 0;
public Androlib() {
this(new ApkOptions());
this(new BuildOptions());
}
public Androlib(ApkOptions apkOptions) {
this.apkOptions = apkOptions;
mAndRes.apkOptions = apkOptions;
public Androlib(BuildOptions buildOptions) {
this.buildOptions = buildOptions;
mAndRes.buildOptions = buildOptions;
}
public ResTable getResTable(ExtFile apkFile)
@ -281,9 +282,9 @@ public class Androlib {
LOGGER.info("Using Apktool " + Androlib.getVersion());
MetaInfo meta = readMetaFile(appDir);
apkOptions.isFramework = meta.isFrameworkApk;
apkOptions.resourcesAreCompressed = meta.compressionType;
apkOptions.doNotCompress = meta.doNotCompress;
buildOptions.isFramework = meta.isFrameworkApk;
buildOptions.resourcesAreCompressed = meta.compressionType;
buildOptions.doNotCompress = meta.doNotCompress;
mAndRes.setSdkInfo(meta.sdkInfo);
mAndRes.setPackageId(meta.packageInfo);
@ -398,7 +399,7 @@ public class Androlib {
return false;
}
File stored = new File(appDir, APK_DIRNAME + "/" + filename);
if (apkOptions.forceBuildAll || isModified(working, stored)) {
if (buildOptions.forceBuildAll || isModified(working, stored)) {
LOGGER.info("Copying " + appDir.toString() + " " + filename + " file...");
try {
BrutIO.copyAndClose(new FileInputStream(working), new FileOutputStream(stored));
@ -417,13 +418,13 @@ public class Androlib {
return false;
}
File dex = new File(appDir, APK_DIRNAME + "/" + filename);
if (! apkOptions.forceBuildAll) {
if (! buildOptions.forceBuildAll) {
LOGGER.info("Checking whether sources has changed...");
}
if (apkOptions.forceBuildAll || isModified(smaliDir, dex)) {
if (buildOptions.forceBuildAll || isModified(smaliDir, dex)) {
LOGGER.info("Smaling " + folder + " folder into " + filename + "...");
dex.delete();
SmaliBuilder.build(smaliDir, dex, apkOptions.forceApi > 0 ? apkOptions.forceApi : mMinSdkVersion);
SmaliBuilder.build(smaliDir, dex, buildOptions.forceApi > 0 ? buildOptions.forceApi : mMinSdkVersion);
}
return true;
}
@ -443,10 +444,10 @@ public class Androlib {
return false;
}
File apkDir = new File(appDir, APK_DIRNAME);
if (! apkOptions.forceBuildAll) {
if (! buildOptions.forceBuildAll) {
LOGGER.info("Checking whether resources has changed...");
}
if (apkOptions.forceBuildAll || isModified(newFiles(APK_RESOURCES_FILENAMES, appDir),
if (buildOptions.forceBuildAll || isModified(newFiles(APK_RESOURCES_FILENAMES, appDir),
newFiles(APK_RESOURCES_FILENAMES, apkDir))) {
LOGGER.info("Copying raw resources...");
appDir.getDirectory().copyToDir(apkDir, APK_RESOURCES_FILENAMES);
@ -463,18 +464,18 @@ public class Androlib {
if (!new File(appDir, "res").exists()) {
return false;
}
if (! apkOptions.forceBuildAll) {
if (! buildOptions.forceBuildAll) {
LOGGER.info("Checking whether resources has changed...");
}
File apkDir = new File(appDir, APK_DIRNAME);
File resourceFile = new File(apkDir.getParent(), "resources.zip");
if (apkOptions.forceBuildAll || isModified(newFiles(APP_RESOURCES_FILENAMES, appDir),
newFiles(APK_RESOURCES_FILENAMES, apkDir)) || (apkOptions.isAapt2() && !isFile(resourceFile))) {
if (buildOptions.forceBuildAll || isModified(newFiles(APP_RESOURCES_FILENAMES, appDir),
newFiles(APK_RESOURCES_FILENAMES, apkDir)) || (buildOptions.isAapt2() && !isFile(resourceFile))) {
LOGGER.info("Building resources...");
if (apkOptions.debugMode) {
if (apkOptions.isAapt2()) {
if (buildOptions.debugMode) {
if (buildOptions.isAapt2()) {
LOGGER.info("Using aapt2 - setting 'debuggable' attribute to 'true' in AndroidManifest.xml");
ResXmlPatcher.setApplicationDebugTagTrue(new File(appDir, "AndroidManifest.xml"));
} else {
@ -534,13 +535,13 @@ public class Androlib {
if (!new File(appDir, "AndroidManifest.xml").exists()) {
return false;
}
if (! apkOptions.forceBuildAll) {
if (! buildOptions.forceBuildAll) {
LOGGER.info("Checking whether resources has changed...");
}
File apkDir = new File(appDir, APK_DIRNAME);
if (apkOptions.forceBuildAll || isModified(newFiles(APK_MANIFEST_FILENAMES, appDir),
if (buildOptions.forceBuildAll || isModified(newFiles(APK_MANIFEST_FILENAMES, appDir),
newFiles(APK_MANIFEST_FILENAMES, apkDir))) {
LOGGER.info("Building AndroidManifest.xml...");
@ -583,7 +584,7 @@ public class Androlib {
}
File stored = new File(appDir, APK_DIRNAME + "/" + folder);
if (apkOptions.forceBuildAll || isModified(working, stored)) {
if (buildOptions.forceBuildAll || isModified(working, stored)) {
LOGGER.info("Copying libs... (/" + folder + ")");
try {
OS.rmdir(stored);
@ -596,7 +597,7 @@ public class Androlib {
public void buildCopyOriginalFiles(File appDir)
throws AndrolibException {
if (apkOptions.copyOriginalFiles) {
if (buildOptions.copyOriginalFiles) {
File originalDir = new File(appDir, "original");
if (originalDir.exists()) {
try {

View File

@ -225,7 +225,7 @@ public class ApkDecoder {
}
public void setFrameworkTag(String tag) {
mAndrolib.apkOptions.frameworkTag = tag;
mAndrolib.buildOptions.frameworkTag = tag;
}
public void setKeepBrokenResources(boolean keepBrokenResources) {
@ -233,7 +233,7 @@ public class ApkDecoder {
}
public void setFrameworkDir(String dir) {
mAndrolib.apkOptions.frameworkFolderLocation = dir;
mAndrolib.buildOptions.frameworkFolderLocation = dir;
}
public ResTable getResTable() throws AndrolibException {
@ -355,8 +355,8 @@ public class ApkDecoder {
meta.usesFramework = new UsesFramework();
meta.usesFramework.ids = Arrays.asList(ids);
if (mAndrolib.apkOptions.frameworkTag != null) {
meta.usesFramework.tag = mAndrolib.apkOptions.frameworkTag;
if (mAndrolib.buildOptions.frameworkTag != null) {
meta.usesFramework.tag = mAndrolib.buildOptions.frameworkTag;
}
}

View File

@ -14,11 +14,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package brut.androlib;
package brut.androlib.options;
import java.util.Collection;
public class ApkOptions {
public class BuildOptions {
public boolean forceBuildAll = false;
public boolean forceDeleteFramework = false;
public boolean debugMode = false;

View File

@ -17,7 +17,7 @@
package brut.androlib.res;
import brut.androlib.AndrolibException;
import brut.androlib.ApkOptions;
import brut.androlib.options.BuildOptions;
import brut.androlib.err.CantFindFrameworkResException;
import brut.androlib.meta.MetaInfo;
import brut.androlib.meta.PackageInfo;
@ -306,8 +306,8 @@ final public class AndrolibResources {
return Integer.toString(target);
}
private File createDoNotCompressExtensionsFile(ApkOptions apkOptions) throws AndrolibException {
if (apkOptions.doNotCompress == null || apkOptions.doNotCompress.isEmpty()) {
private File createDoNotCompressExtensionsFile(BuildOptions buildOptions) throws AndrolibException {
if (buildOptions.doNotCompress == null || buildOptions.doNotCompress.isEmpty()) {
return null;
}
@ -317,7 +317,7 @@ final public class AndrolibResources {
doNotCompressFile.deleteOnExit();
BufferedWriter fileWriter = new BufferedWriter(new FileWriter(doNotCompressFile));
for (String extension : apkOptions.doNotCompress) {
for (String extension : buildOptions.doNotCompress) {
fileWriter.write(extension);
fileWriter.newLine();
}
@ -358,11 +358,11 @@ final public class AndrolibResources {
cmd.add("-o");
cmd.add(resourcesZip.getAbsolutePath());
if (apkOptions.verbose) {
if (buildOptions.verbose) {
cmd.add("-v");
}
if (apkOptions.noCrunch) {
if (buildOptions.noCrunch) {
cmd.add("--no-crunch");
}
@ -433,24 +433,24 @@ final public class AndrolibResources {
cmd.add("--enable-sparse-encoding");
}
if (apkOptions.isFramework) {
if (buildOptions.isFramework) {
cmd.add("-x");
}
if (apkOptions.doNotCompress != null && !customAapt) {
if (buildOptions.doNotCompress != null && !customAapt) {
// Use custom -e option to avoid limits on commandline length.
// Can only be used when custom aapt binary is not used.
String extensionsFilePath = createDoNotCompressExtensionsFile(apkOptions).getAbsolutePath();
String extensionsFilePath = createDoNotCompressExtensionsFile(buildOptions).getAbsolutePath();
cmd.add("-e");
cmd.add(extensionsFilePath);
} else if (apkOptions.doNotCompress != null) {
for (String file : apkOptions.doNotCompress) {
} else if (buildOptions.doNotCompress != null) {
for (String file : buildOptions.doNotCompress) {
cmd.add("-0");
cmd.add(file);
}
}
if (!apkOptions.resourcesAreCompressed) {
if (!buildOptions.resourcesAreCompressed) {
cmd.add("-0");
cmd.add("arsc");
}
@ -475,7 +475,7 @@ final public class AndrolibResources {
cmd.add(rawDir.getAbsolutePath());
}
if (apkOptions.verbose) {
if (buildOptions.verbose) {
cmd.add("-v");
}
@ -498,16 +498,16 @@ final public class AndrolibResources {
cmd.add("p");
if (apkOptions.verbose) { // output aapt verbose
if (buildOptions.verbose) { // output aapt verbose
cmd.add("-v");
}
if (apkOptions.updateFiles) {
if (buildOptions.updateFiles) {
cmd.add("-u");
}
if (apkOptions.debugMode) { // inject debuggable="true" into manifest
if (buildOptions.debugMode) { // inject debuggable="true" into manifest
cmd.add("--debug-mode");
}
if (apkOptions.noCrunch) {
if (buildOptions.noCrunch) {
cmd.add("--no-crunch");
}
// force package id so that some frameworks build with correct id
@ -555,24 +555,24 @@ final public class AndrolibResources {
cmd.add("-F");
cmd.add(apkFile.getAbsolutePath());
if (apkOptions.isFramework) {
if (buildOptions.isFramework) {
cmd.add("-x");
}
if (apkOptions.doNotCompress != null && !customAapt) {
if (buildOptions.doNotCompress != null && !customAapt) {
// Use custom -e option to avoid limits on commandline length.
// Can only be used when custom aapt binary is not used.
String extensionsFilePath = createDoNotCompressExtensionsFile(apkOptions).getAbsolutePath();
String extensionsFilePath = createDoNotCompressExtensionsFile(buildOptions).getAbsolutePath();
cmd.add("-e");
cmd.add(extensionsFilePath);
} else if (apkOptions.doNotCompress != null) {
for (String file : apkOptions.doNotCompress) {
} else if (buildOptions.doNotCompress != null) {
for (String file : buildOptions.doNotCompress) {
cmd.add("-0");
cmd.add(file);
}
}
if (!apkOptions.resourcesAreCompressed) {
if (!buildOptions.resourcesAreCompressed) {
cmd.add("-0");
cmd.add("arsc");
}
@ -610,7 +610,7 @@ final public class AndrolibResources {
public void aaptPackage(File apkFile, File manifest, File resDir, File rawDir, File assetDir, File[] include)
throws AndrolibException {
String aaptPath = apkOptions.aaptPath;
String aaptPath = buildOptions.aaptPath;
boolean customAapt = !aaptPath.isEmpty();
List<String> cmd = new ArrayList<>();
@ -622,7 +622,7 @@ final public class AndrolibResources {
cmd.add(AaptManager.getAaptBinaryName(getAaptVersion()));
}
if (apkOptions.isAapt2()) {
if (buildOptions.isAapt2()) {
aapt2Package(apkFile, manifest, resDir, rawDir, assetDir, include, cmd, customAapt);
return;
}
@ -633,7 +633,7 @@ final public class AndrolibResources {
throws AndrolibException {
try {
ZipUtils.zipFolders(rawDir, apkFile, assetDir, apkOptions.doNotCompress);
ZipUtils.zipFolders(rawDir, apkFile, assetDir, buildOptions.doNotCompress);
} catch (IOException | BrutException ex) {
throw new AndrolibException(ex);
}
@ -827,7 +827,7 @@ final public class AndrolibResources {
LOGGER.warning("Can't empty framework directory, no file found at: " + apk.getAbsolutePath());
} else {
try {
if (apk.exists() && dir.listFiles().length > 1 && ! apkOptions.forceDeleteFramework) {
if (apk.exists() && dir.listFiles().length > 1 && ! buildOptions.forceDeleteFramework) {
LOGGER.warning("More than default framework detected. Please run command with `--force` parameter to wipe framework directory.");
} else {
for (File file : dir.listFiles()) {
@ -858,7 +858,7 @@ final public class AndrolibResources {
}
public void installFramework(File frameFile) throws AndrolibException {
installFramework(frameFile, apkOptions.frameworkTag);
installFramework(frameFile, buildOptions.frameworkTag);
}
public void installFramework(File frameFile, String tag)
@ -957,8 +957,8 @@ final public class AndrolibResources {
String path;
// if a framework path was specified on the command line, use it
if (apkOptions.frameworkFolderLocation != null) {
path = apkOptions.frameworkFolderLocation;
if (buildOptions.frameworkFolderLocation != null) {
path = buildOptions.frameworkFolderLocation;
} else {
File parentPath = new File(System.getProperty("user.home"));
@ -983,7 +983,7 @@ final public class AndrolibResources {
if (! dir.exists()) {
if (! dir.mkdirs()) {
if (apkOptions.frameworkFolderLocation != null) {
if (buildOptions.frameworkFolderLocation != null) {
LOGGER.severe("Can't create Framework directory: " + dir);
}
throw new AndrolibException(String.format(
@ -992,7 +992,7 @@ final public class AndrolibResources {
}
}
if (apkOptions.frameworkFolderLocation == null) {
if (buildOptions.frameworkFolderLocation == null) {
if (! dir.canWrite()) {
LOGGER.severe(String.format("WARNING: Could not write to (%1$s), using %2$s instead...",
dir.getAbsolutePath(), System.getProperty("java.io.tmpdir")));
@ -1019,7 +1019,7 @@ final public class AndrolibResources {
}
private int getAaptVersion() {
return apkOptions.isAapt2() ? 2 : 1;
return buildOptions.isAapt2() ? 2 : 1;
}
public InputStream getAndroidFrameworkResourcesAsStream() {
@ -1032,7 +1032,7 @@ final public class AndrolibResources {
}
}
public ApkOptions apkOptions;
public BuildOptions buildOptions;
// TODO: dirty static hack. I have to refactor decoding mechanisms.
public static boolean sKeepBroken = false;

View File

@ -78,7 +78,7 @@ public class ResTable {
return pkg;
}
if (mAndRes != null) {
return mAndRes.loadFrameworkPkg(this, id, mAndRes.apkOptions.frameworkTag);
return mAndRes.loadFrameworkPkg(this, id, mAndRes.buildOptions.frameworkTag);
}
throw new UndefinedResObjectException(String.format("package: id=%d", id));
}

View File

@ -16,6 +16,7 @@
*/
package brut.androlib;
import brut.androlib.options.BuildOptions;
import brut.androlib.res.AndrolibResources;
import brut.common.BrutException;
import brut.directory.DirUtil;
@ -137,7 +138,7 @@ public abstract class TestUtils {
static File getFrameworkDir() throws AndrolibException {
AndrolibResources androlibResources = new AndrolibResources();
androlibResources.apkOptions = new ApkOptions();
androlibResources.buildOptions = new BuildOptions();
return androlibResources.getFrameworkDir();
}

View File

@ -17,6 +17,7 @@
package brut.androlib.aapt1;
import brut.androlib.*;
import brut.androlib.options.BuildOptions;
import brut.directory.ExtFile;
import brut.common.BrutException;
import brut.util.OS;
@ -46,8 +47,8 @@ public class AndroidOreoNotSparseTest extends BaseTest {
apkDecoder.decode();
LOGGER.info("Building not_sparse.apk...");
ApkOptions apkOptions = new ApkOptions();
new Androlib(apkOptions).build(sTestNewDir, testApk);
BuildOptions buildOptions = new BuildOptions();
new Androlib(buildOptions).build(sTestNewDir, testApk);
}
@AfterClass

View File

@ -17,6 +17,7 @@
package brut.androlib.aapt1;
import brut.androlib.*;
import brut.androlib.options.BuildOptions;
import brut.directory.ExtFile;
import brut.common.BrutException;
import brut.util.OS;
@ -46,8 +47,8 @@ public class AndroidOreoSparseTest extends BaseTest {
apkDecoder.decode();
LOGGER.info("Building sparse.apk...");
ApkOptions apkOptions = new ApkOptions();
new Androlib(apkOptions).build(sTestNewDir, testApk);
BuildOptions buildOptions = new BuildOptions();
new Androlib(buildOptions).build(sTestNewDir, testApk);
}
@AfterClass

View File

@ -17,6 +17,7 @@
package brut.androlib.aapt1;
import brut.androlib.*;
import brut.androlib.options.BuildOptions;
import brut.directory.ExtFile;
import brut.common.BrutException;
import brut.util.OS;
@ -46,11 +47,11 @@ public class DebugTagRetainedTest extends BaseTest {
TestUtils.copyResourceDir(DebugTagRetainedTest.class, "aapt1/issue1235/", sTestOrigDir);
LOGGER.info("Building issue1235.apk...");
ApkOptions apkOptions = new ApkOptions();
apkOptions.debugMode = true;
BuildOptions buildOptions = new BuildOptions();
buildOptions.debugMode = true;
File testApk = new File(sTmpDir, "issue1235.apk");
new Androlib(apkOptions).build(sTestOrigDir, testApk);
new Androlib(buildOptions).build(sTestOrigDir, testApk);
LOGGER.info("Decoding issue1235.apk...");
ApkDecoder apkDecoder = new ApkDecoder(testApk);

View File

@ -18,7 +18,7 @@ package brut.androlib.aapt1;
import brut.androlib.Androlib;
import brut.androlib.ApkDecoder;
import brut.androlib.ApkOptions;
import brut.androlib.options.BuildOptions;
import brut.androlib.TestUtils;
import brut.directory.ExtFile;
import brut.common.BrutException;
@ -50,8 +50,8 @@ public class EmptyResourcesArscTest {
apkDecoder.decode();
LOGGER.info("Building issue1730.apk...");
ApkOptions apkOptions = new ApkOptions();
new Androlib(apkOptions).build(sTestNewDir, testApk);
BuildOptions buildOptions = new BuildOptions();
new Androlib(buildOptions).build(sTestNewDir, testApk);
}
@AfterClass

View File

@ -17,6 +17,7 @@
package brut.androlib.aapt1;
import brut.androlib.*;
import brut.androlib.options.BuildOptions;
import brut.directory.ExtFile;
import brut.common.BrutException;
import brut.util.OS;
@ -49,11 +50,11 @@ public class SharedLibraryTest extends BaseTest {
public void isFrameworkTaggingWorking() throws AndrolibException {
String apkName = "library.apk";
ApkOptions apkOptions = new ApkOptions();
apkOptions.frameworkFolderLocation = sTmpDir.getAbsolutePath();
apkOptions.frameworkTag = "building";
BuildOptions buildOptions = new BuildOptions();
buildOptions.frameworkFolderLocation = sTmpDir.getAbsolutePath();
buildOptions.frameworkTag = "building";
new Androlib(apkOptions).installFramework(new File(sTmpDir + File.separator + apkName));
new Androlib(buildOptions).installFramework(new File(sTmpDir + File.separator + apkName));
assertTrue(fileExists("2-building.apk"));
}
@ -62,10 +63,10 @@ public class SharedLibraryTest extends BaseTest {
public void isFrameworkInstallingWorking() throws AndrolibException {
String apkName = "library.apk";
ApkOptions apkOptions = new ApkOptions();
apkOptions.frameworkFolderLocation = sTmpDir.getAbsolutePath();
BuildOptions buildOptions = new BuildOptions();
buildOptions.frameworkFolderLocation = sTmpDir.getAbsolutePath();
new Androlib(apkOptions).installFramework(new File(sTmpDir + File.separator + apkName));
new Androlib(buildOptions).installFramework(new File(sTmpDir + File.separator + apkName));
assertTrue(fileExists("2.apk"));
}
@ -76,36 +77,36 @@ public class SharedLibraryTest extends BaseTest {
String client = "client.apk";
// setup apkOptions
ApkOptions apkOptions = new ApkOptions();
apkOptions.frameworkFolderLocation = sTmpDir.getAbsolutePath();
apkOptions.frameworkTag = "shared";
BuildOptions buildOptions = new BuildOptions();
buildOptions.frameworkFolderLocation = sTmpDir.getAbsolutePath();
buildOptions.frameworkTag = "shared";
// install library/framework
new Androlib(apkOptions).installFramework(new File(sTmpDir + File.separator + library));
new Androlib(buildOptions).installFramework(new File(sTmpDir + File.separator + library));
assertTrue(fileExists("2-shared.apk"));
// decode client.apk
ApkDecoder apkDecoder = new ApkDecoder(new File(sTmpDir + File.separator + client));
apkDecoder.setOutDir(new File(sTmpDir + File.separator + client + ".out"));
apkDecoder.setFrameworkDir(apkOptions.frameworkFolderLocation);
apkDecoder.setFrameworkTag(apkOptions.frameworkTag);
apkDecoder.setFrameworkDir(buildOptions.frameworkFolderLocation);
apkDecoder.setFrameworkTag(buildOptions.frameworkTag);
apkDecoder.decode();
// decode library.apk
ApkDecoder libraryDecoder = new ApkDecoder(new File(sTmpDir + File.separator + library));
libraryDecoder.setOutDir(new File(sTmpDir + File.separator + library + ".out"));
libraryDecoder.setFrameworkDir(apkOptions.frameworkFolderLocation);
libraryDecoder.setFrameworkTag(apkOptions.frameworkTag);
libraryDecoder.setFrameworkDir(buildOptions.frameworkFolderLocation);
libraryDecoder.setFrameworkTag(buildOptions.frameworkTag);
libraryDecoder.decode();
// build client.apk
ExtFile clientApk = new ExtFile(sTmpDir, client + ".out");
new Androlib(apkOptions).build(clientApk, null);
new Androlib(buildOptions).build(clientApk, null);
assertTrue(fileExists(client + ".out" + File.separator + "dist" + File.separator + client));
// build library.apk (shared library)
ExtFile libraryApk = new ExtFile(sTmpDir, library + ".out");
new Androlib(apkOptions).build(libraryApk, null);
new Androlib(buildOptions).build(libraryApk, null);
assertTrue(fileExists(library + ".out" + File.separator + "dist" + File.separator + library));
}

View File

@ -17,6 +17,7 @@
package brut.androlib.aapt1;
import brut.androlib.*;
import brut.androlib.options.BuildOptions;
import brut.directory.ExtFile;
import brut.common.BrutException;
import brut.util.OS;
@ -39,8 +40,8 @@ public class UnknownCompressionTest extends BaseTest {
TestUtils.copyResourceDir(UnknownCompressionTest.class, "aapt1/unknown_compression/", sTmpDir);
String apk = "deflated_unknowns.apk";
ApkOptions apkOptions = new ApkOptions();
apkOptions.frameworkFolderLocation = sTmpDir.getAbsolutePath();
BuildOptions buildOptions = new BuildOptions();
buildOptions.frameworkFolderLocation = sTmpDir.getAbsolutePath();
sTestOrigDir = new ExtFile(sTmpDir, apk);
@ -51,7 +52,7 @@ public class UnknownCompressionTest extends BaseTest {
// build deflated_unknowns
ExtFile clientApkFolder = new ExtFile(sTestOrigDir.getAbsolutePath() + ".out");
new Androlib(apkOptions).build(clientApkFolder, null);
new Androlib(buildOptions).build(clientApkFolder, null);
sTestNewDir = new ExtFile(clientApkFolder, "dist" + File.separator + apk);
}

View File

@ -18,6 +18,7 @@ package brut.androlib.aapt2;
import brut.androlib.*;
import brut.androlib.meta.MetaInfo;
import brut.androlib.options.BuildOptions;
import brut.common.BrutException;
import brut.directory.ExtFile;
import brut.util.OS;
@ -42,13 +43,13 @@ public class BuildAndDecodeTest extends BaseTest {
LOGGER.info("Unpacking testapp...");
TestUtils.copyResourceDir(BuildAndDecodeTest.class, "aapt2/testapp/", sTestOrigDir);
ApkOptions apkOptions = new ApkOptions();
apkOptions.useAapt2 = true;
apkOptions.verbose = true;
BuildOptions buildOptions = new BuildOptions();
buildOptions.useAapt2 = true;
buildOptions.verbose = true;
LOGGER.info("Building testapp.apk...");
File testApk = new File(sTmpDir, "testapp.apk");
new Androlib(apkOptions).build(sTestOrigDir, testApk);
new Androlib(buildOptions).build(sTestOrigDir, testApk);
LOGGER.info("Decoding testapp.apk...");
ApkDecoder apkDecoder = new ApkDecoder(testApk);

View File

@ -17,6 +17,7 @@
package brut.androlib.aapt2;
import brut.androlib.*;
import brut.androlib.options.BuildOptions;
import brut.common.BrutException;
import brut.directory.ExtFile;
import brut.util.OS;
@ -46,13 +47,13 @@ public class DebuggableFalseChangeToTrueTest extends BaseTest {
TestUtils.copyResourceDir(DebuggableFalseChangeToTrueTest.class, "aapt2/issue2328/debuggable-false", sTestOrigDir);
LOGGER.info("Building issue2328-debuggable-flase.apk...");
ApkOptions apkOptions = new ApkOptions();
apkOptions.debugMode = true;
apkOptions.useAapt2 = true;
apkOptions.verbose = true;
BuildOptions buildOptions = new BuildOptions();
buildOptions.debugMode = true;
buildOptions.useAapt2 = true;
buildOptions.verbose = true;
File testApk = new File(sTmpDir, "issue2328-debuggable-flase.apk");
new Androlib(apkOptions).build(sTestOrigDir, testApk);
new Androlib(buildOptions).build(sTestOrigDir, testApk);
LOGGER.info("Decoding issue2328-debuggable-flase.apk...");
ApkDecoder apkDecoder = new ApkDecoder(testApk);

View File

@ -17,6 +17,7 @@
package brut.androlib.aapt2;
import brut.androlib.*;
import brut.androlib.options.BuildOptions;
import brut.common.BrutException;
import brut.directory.ExtFile;
import brut.util.OS;
@ -46,13 +47,13 @@ public class DebuggableTrueAddedTest extends BaseTest {
TestUtils.copyResourceDir(DebuggableTrueAddedTest.class, "aapt2/issue2328/debuggable-missing", sTestOrigDir);
LOGGER.info("Building issue2328-debuggable-missing.apk...");
ApkOptions apkOptions = new ApkOptions();
apkOptions.debugMode = true;
apkOptions.useAapt2 = true;
apkOptions.verbose = true;
BuildOptions buildOptions = new BuildOptions();
buildOptions.debugMode = true;
buildOptions.useAapt2 = true;
buildOptions.verbose = true;
File testApk = new File(sTmpDir, "issue2328-debuggable-missing.apk");
new Androlib(apkOptions).build(sTestOrigDir, testApk);
new Androlib(buildOptions).build(sTestOrigDir, testApk);
LOGGER.info("Decoding issue2328-debuggable-missing.apk...");
ApkDecoder apkDecoder = new ApkDecoder(testApk);

View File

@ -17,6 +17,7 @@
package brut.androlib.aapt2;
import brut.androlib.*;
import brut.androlib.options.BuildOptions;
import brut.common.BrutException;
import brut.directory.ExtFile;
import brut.util.OS;
@ -46,13 +47,13 @@ public class DebuggableTrueRetainedTest extends BaseTest {
TestUtils.copyResourceDir(DebuggableTrueRetainedTest.class, "aapt2/issue2328/debuggable-true", sTestOrigDir);
LOGGER.info("Building issue2328-debuggable-true.apk...");
ApkOptions apkOptions = new ApkOptions();
apkOptions.debugMode = true;
apkOptions.useAapt2 = true;
apkOptions.verbose = true;
BuildOptions buildOptions = new BuildOptions();
buildOptions.debugMode = true;
buildOptions.useAapt2 = true;
buildOptions.verbose = true;
File testApk = new File(sTmpDir, "issue2328-debuggable-true.apk");
new Androlib(apkOptions).build(sTestOrigDir, testApk);
new Androlib(buildOptions).build(sTestOrigDir, testApk);
LOGGER.info("Decoding issue2328-debuggable-true.apk...");
ApkDecoder apkDecoder = new ApkDecoder(testApk);

View File

@ -17,6 +17,7 @@
package brut.androlib.aapt2;
import brut.androlib.*;
import brut.androlib.options.BuildOptions;
import brut.androlib.res.data.ResTable;
import brut.common.BrutException;
import brut.directory.ExtFile;
@ -43,13 +44,13 @@ public class NonStandardPkgIdTest extends BaseTest {
LOGGER.info("Unpacking pkgid8...");
TestUtils.copyResourceDir(BuildAndDecodeTest.class, "aapt2/pkgid8/", sTestOrigDir);
ApkOptions apkOptions = new ApkOptions();
apkOptions.useAapt2 = true;
apkOptions.verbose = true;
BuildOptions buildOptions = new BuildOptions();
buildOptions.useAapt2 = true;
buildOptions.verbose = true;
LOGGER.info("Building pkgid8.apk...");
File testApk = new File(sTmpDir, "pkgid8.apk");
new Androlib(apkOptions).build(sTestOrigDir, testApk);
new Androlib(buildOptions).build(sTestOrigDir, testApk);
LOGGER.info("Decoding pkgid8.apk...");
ApkDecoder apkDecoder = new ApkDecoder(testApk);

View File

@ -17,6 +17,7 @@
package brut.androlib.decode;
import brut.androlib.*;
import brut.androlib.options.BuildOptions;
import brut.common.BrutException;
import brut.directory.ExtFile;
import brut.util.OS;
@ -53,8 +54,8 @@ public class DuplicateDexTest extends BaseTest {
apkDecoder.decode();
LOGGER.info("Building duplicatedex.apk...");
ApkOptions apkOptions = new ApkOptions();
new Androlib(apkOptions).build(sTestNewDir, testApk);
BuildOptions buildOptions = new BuildOptions();
new Androlib(buildOptions).build(sTestNewDir, testApk);
}
@Test
@ -68,8 +69,8 @@ public class DuplicateDexTest extends BaseTest {
apkDecoder.decode();
LOGGER.info("Building duplicatedex.apk...");
ApkOptions apkOptions = new ApkOptions();
new Androlib(apkOptions).build(sTestNewDir, testApk);
BuildOptions buildOptions = new BuildOptions();
new Androlib(buildOptions).build(sTestNewDir, testApk);
}
}

View File

@ -18,6 +18,7 @@ package brut.androlib.res.src;
import brut.androlib.*;
import brut.androlib.aapt2.BuildAndDecodeTest;
import brut.androlib.options.BuildOptions;
import brut.common.BrutException;
import brut.directory.ExtFile;
import brut.util.OS;
@ -44,11 +45,11 @@ public class DexStaticFieldValueTest extends BaseTest {
LOGGER.info("Unpacking issue2543...");
TestUtils.copyResourceDir(BuildAndDecodeTest.class, "decode/issue2543/", sTestOrigDir);
ApkOptions apkOptions = new ApkOptions();
BuildOptions buildOptions = new BuildOptions();
LOGGER.info("Building issue2543.apk...");
File testApk = new File(sTmpDir, "issue2543.apk");
new Androlib(apkOptions).build(sTestOrigDir, testApk);
new Androlib(buildOptions).build(sTestOrigDir, testApk);
LOGGER.info("Decoding issue2543.apk...");
ApkDecoder apkDecoder = new ApkDecoder(testApk);