Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prebuilt aapt not found if apktool jar is built into a spring boot app #1543

Closed
bingqiao opened this issue Jun 29, 2017 · 4 comments · Fixed by #1544
Closed

Prebuilt aapt not found if apktool jar is built into a spring boot app #1543

bingqiao opened this issue Jun 29, 2017 · 4 comments · Fixed by #1544

Comments

@bingqiao
Copy link
Contributor

I'm trying to use apktool jar in a Spring boot project and found that prebuilt aapt binaries are not accessible in the Spring boot executable jar while android-framework.jar is.
The cause of this is that Jar#extractToTmp calls getResourceAsStream on Class.class instead of AndrolibResources.class. And in the context of Spring boot, this call fails because the prebuilt aapt binaries are not packaged in the root directory.

Any chance to change this method and those calling it to something like this?

public static File extractToTmp(String resourcePath, String tmpPrefix, Class clazz)
		throws BrutException {
	try {
		InputStream in = clazz.getResourceAsStream(resourcePath);
		if (in == null) {
			throw new FileNotFoundException(resourcePath);
		}
		File fileOut = File.createTempFile(tmpPrefix, null);
		fileOut.deleteOnExit();
		OutputStream out = new FileOutputStream(fileOut);
		IOUtils.copy(in, out);
		in.close();
		out.close();
		return fileOut;
	} catch (IOException ex) {
		throw new BrutException(
			"Could not extract resource: " + resourcePath, ex);
	}
}

public static File extractToTmp(String resourcePath, String tmpPrefix) throws BrutException {
	return extractToTmp(resourcePath, tmpPrefix, Class.class);
}
@iBotPeaches
Copy link
Owner

prebuilt aapt binaries are not accessible in the Spring boot executable jar while android-framework.jar is.

Why is that? android-framework.jar is at /brut/androlib/, while aapt is at /prebuilt/aapt. While different directories they are both 2 directories deep. Granted, android-framework is in the folder path of the Brut Androlib package.

You can also do a Pull Request to propose changes to this functionality in that is easier to describe an enhancement or tweak.

@bingqiao
Copy link
Contributor Author

Class.class.getResourceAsStream tries to load resource from root directory. This fails when apktool is built into a fat jar like Spring boot executable becasue the classloader of Class tries to load the resource from the root directory of the Spring boot jar instead of that of the bundled appktool jar. The loading of android-framework.jar works because it's the classloader of AndrolibResources loading the jar.

I created a pull request to show the fix that works for my app.

@bingqiao
Copy link
Contributor Author

This is the classloader for AndrolibResources: org.springframework.boot.loader.LaunchedURLClassLoader.
And "Class" is loaded by BootStrap ClassLoader. The latter doesn't work when apktool jar is packaged inside a Spring boot jar without having prebuilt in the root directory of the Spring boot jar. I'm not sure if apktool is not supposed to be used this way but so far it seems to work perfectly except for this. I could package another copy of prebuilt in the root directory of Spring boot jar or build apktool with the aforementioned fix (I'd have to build it myself anyway to use it in a maven project).

@iBotPeaches
Copy link
Owner

Thanks for the report and quick pull request. This has been merged into master.

alebcay added a commit to alebcay/opengapps that referenced this issue Jul 31, 2017
- Android O Final Dev Preview support (iBotPeaches/Apktool#1520)
- SnakeYAML 1.1.8 Android Support (iBotPeaches/Apktool#591)
- Fix issue with APKs taking longer than usual to parse resources (iBotPeaches/Apktool#1489)
- Fix issue with internal binaries not accessible in a Spring boot environment. (iBotPeaches/Apktool#1543)
- Fix issues with rebuilding applications originally built with aapt2. (iBotPeaches/Apktool#1520)
- Patch aapt to support the $ character in resource filenames. (iBotPeaches/Apktool#1532)
- Fix issue where apktool was holding locks onto files during execution. (iBotPeaches/Apktool#1561)
- Fix issue with APKs that last resource in pool is INVALID_TYPE_CONFIG. (iBotPeaches/Apktool#1534)
- Fix issue with APKs that are including malformed characters to break parser. (iBotPeaches/Apktool#1564)
- Only exit with 0 error code during version commands.
- Enforce license header on all source files.
- [Security] Prevent malicous directory traversal with unknown files.
- [Security] Prevent XXE vulnerability when given a malicious AndroidManifest.xml
- Upgrade to gradle 4.0.
alebcay added a commit to alebcay/opengapps that referenced this issue Jul 31, 2017
- Android O Final Dev Preview support (iBotPeaches/Apktool#1520)
- SnakeYAML 1.1.8 Android Support (iBotPeaches/Apktool#591)
- Fix issue with APKs taking longer than usual to parse resources (iBotPeaches/Apktool#1489)
- Fix issue with internal binaries not accessible in a Spring boot environment. (iBotPeaches/Apktool#1543)
- Fix issues with rebuilding applications originally built with aapt2. (iBotPeaches/Apktool#1520)
- Patch aapt to support the $ character in resource filenames. (iBotPeaches/Apktool#1532)
- Fix issue where apktool was holding locks onto files during execution. (iBotPeaches/Apktool#1561)
- Fix issue with APKs that last resource in pool is INVALID_TYPE_CONFIG. (iBotPeaches/Apktool#1534)
- Fix issue with APKs that are including malformed characters to break parser. (iBotPeaches/Apktool#1564)
- Only exit with 0 error code during version commands.
- Enforce license header on all source files.
- [Security] Prevent malicous directory traversal with unknown files.
- [Security] Prevent XXE vulnerability when given a malicious AndroidManifest.xml
- Upgrade to gradle 4.0.
mfonville pushed a commit to opengapps/opengapps that referenced this issue Jul 31, 2017
- Android O Final Dev Preview support (iBotPeaches/Apktool#1520)
- SnakeYAML 1.1.8 Android Support (iBotPeaches/Apktool#591)
- Fix issue with APKs taking longer than usual to parse resources (iBotPeaches/Apktool#1489)
- Fix issue with internal binaries not accessible in a Spring boot environment. (iBotPeaches/Apktool#1543)
- Fix issues with rebuilding applications originally built with aapt2. (iBotPeaches/Apktool#1520)
- Patch aapt to support the $ character in resource filenames. (iBotPeaches/Apktool#1532)
- Fix issue where apktool was holding locks onto files during execution. (iBotPeaches/Apktool#1561)
- Fix issue with APKs that last resource in pool is INVALID_TYPE_CONFIG. (iBotPeaches/Apktool#1534)
- Fix issue with APKs that are including malformed characters to break parser. (iBotPeaches/Apktool#1564)
- Only exit with 0 error code during version commands.
- Enforce license header on all source files.
- [Security] Prevent malicous directory traversal with unknown files.
- [Security] Prevent XXE vulnerability when given a malicious AndroidManifest.xml
- Upgrade to gradle 4.0.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants