mirror of
https://github.com/revanced/Apktool.git
synced 2024-11-07 05:06:59 +01:00
Revert "build: introduce "buildUnknownAndUncompressedAssets""
This reverts commit e35f66b0e0
.
This commit is contained in:
parent
72196f3544
commit
0700c684b6
@ -19,6 +19,7 @@ package brut.androlib;
|
|||||||
import brut.androlib.meta.MetaInfo;
|
import brut.androlib.meta.MetaInfo;
|
||||||
import brut.androlib.meta.UsesFramework;
|
import brut.androlib.meta.UsesFramework;
|
||||||
import brut.androlib.res.AndrolibResources;
|
import brut.androlib.res.AndrolibResources;
|
||||||
|
import brut.androlib.res.data.ResConfigFlags;
|
||||||
import brut.androlib.res.data.ResPackage;
|
import brut.androlib.res.data.ResPackage;
|
||||||
import brut.androlib.res.data.ResTable;
|
import brut.androlib.res.data.ResTable;
|
||||||
import brut.androlib.res.data.ResUnknownFiles;
|
import brut.androlib.res.data.ResUnknownFiles;
|
||||||
@ -261,7 +262,6 @@ public class Androlib {
|
|||||||
apkOptions.isFramework = meta.isFrameworkApk;
|
apkOptions.isFramework = meta.isFrameworkApk;
|
||||||
apkOptions.resourcesAreCompressed = meta.compressionType;
|
apkOptions.resourcesAreCompressed = meta.compressionType;
|
||||||
apkOptions.doNotCompress = meta.doNotCompress;
|
apkOptions.doNotCompress = meta.doNotCompress;
|
||||||
apkOptions.noCompressAssets = meta.noCompressAssets;
|
|
||||||
|
|
||||||
mAndRes.setSdkInfo(meta.sdkInfo);
|
mAndRes.setSdkInfo(meta.sdkInfo);
|
||||||
mAndRes.setPackageId(meta.packageInfo);
|
mAndRes.setPackageId(meta.packageInfo);
|
||||||
@ -293,8 +293,8 @@ public class Androlib {
|
|||||||
buildApk(appDir, outFile);
|
buildApk(appDir, outFile);
|
||||||
|
|
||||||
// we must go after the Apk is built, and copy the files in via Zip
|
// we must go after the Apk is built, and copy the files in via Zip
|
||||||
// this is because Aapt won't add files it doesn't know (ex unknown files & uncompressed assets)
|
// this is because Aapt won't add files it doesn't know (ex unknown files)
|
||||||
buildUnknownAndUncompressedAssets(appDir, outFile, meta);
|
buildUnknownFiles(appDir, outFile, meta);
|
||||||
|
|
||||||
// we copied the AndroidManifest.xml to AndroidManifest.xml.orig so we can edit it
|
// we copied the AndroidManifest.xml to AndroidManifest.xml.orig so we can edit it
|
||||||
// lets restore the unedited one, to not change the original
|
// lets restore the unedited one, to not change the original
|
||||||
@ -589,16 +589,12 @@ public class Androlib {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void buildUnknownAndUncompressedAssets(File appDir, File outFile, MetaInfo meta)
|
public void buildUnknownFiles(File appDir, File outFile, MetaInfo meta)
|
||||||
throws AndrolibException {
|
throws AndrolibException {
|
||||||
if (meta.unknownFiles == null && meta.noCompressAssets == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (meta.unknownFiles != null) {
|
if (meta.unknownFiles != null) {
|
||||||
LOGGER.info("Copying unknown files/dir...");
|
LOGGER.info("Copying unknown files/dir...");
|
||||||
}
|
|
||||||
|
|
||||||
|
Map<String, String> files = meta.unknownFiles;
|
||||||
File tempFile = new File(outFile.getParent(), outFile.getName() + ".apktool_temp");
|
File tempFile = new File(outFile.getParent(), outFile.getName() + ".apktool_temp");
|
||||||
boolean renamed = outFile.renameTo(tempFile);
|
boolean renamed = outFile.renameTo(tempFile);
|
||||||
if (!renamed) {
|
if (!renamed) {
|
||||||
@ -609,9 +605,8 @@ public class Androlib {
|
|||||||
ZipFile inputFile = new ZipFile(tempFile);
|
ZipFile inputFile = new ZipFile(tempFile);
|
||||||
ZipOutputStream actualOutput = new ZipOutputStream(new FileOutputStream(outFile))
|
ZipOutputStream actualOutput = new ZipOutputStream(new FileOutputStream(outFile))
|
||||||
) {
|
) {
|
||||||
copyExistingFiles(inputFile, actualOutput, meta.noCompressAssets);
|
copyExistingFiles(inputFile, actualOutput);
|
||||||
copyUncompressedAssetFiles(appDir, actualOutput, meta.noCompressAssets);
|
copyUnknownFiles(appDir, actualOutput, files);
|
||||||
copyUnknownFiles(appDir, actualOutput, meta.unknownFiles);
|
|
||||||
} catch (IOException | BrutException ex) {
|
} catch (IOException | BrutException ex) {
|
||||||
throw new AndrolibException(ex);
|
throw new AndrolibException(ex);
|
||||||
}
|
}
|
||||||
@ -619,16 +614,13 @@ public class Androlib {
|
|||||||
// Remove our temporary file.
|
// Remove our temporary file.
|
||||||
tempFile.delete();
|
tempFile.delete();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void copyExistingFiles(ZipFile inputFile, ZipOutputStream outputFile, Collection<String> assets)
|
private void copyExistingFiles(ZipFile inputFile, ZipOutputStream outputFile) throws IOException {
|
||||||
throws IOException {
|
|
||||||
// First, copy the contents from the existing outFile:
|
// First, copy the contents from the existing outFile:
|
||||||
Enumeration<? extends ZipEntry> entries = inputFile.entries();
|
Enumeration<? extends ZipEntry> entries = inputFile.entries();
|
||||||
while (entries.hasMoreElements()) {
|
while (entries.hasMoreElements()) {
|
||||||
ZipEntry entry = new ZipEntry(entries.nextElement());
|
ZipEntry entry = new ZipEntry(entries.nextElement());
|
||||||
if (assets != null && assets.contains(entry.getName())) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// We can't reuse the compressed size because it depends on compression sizes.
|
// We can't reuse the compressed size because it depends on compression sizes.
|
||||||
entry.setCompressedSize(-1);
|
entry.setCompressedSize(-1);
|
||||||
@ -645,25 +637,25 @@ public class Androlib {
|
|||||||
|
|
||||||
private void copyUnknownFiles(File appDir, ZipOutputStream outputFile, Map<String, String> files)
|
private void copyUnknownFiles(File appDir, ZipOutputStream outputFile, Map<String, String> files)
|
||||||
throws BrutException, IOException {
|
throws BrutException, IOException {
|
||||||
|
|
||||||
File unknownFileDir = new File(appDir, UNK_DIRNAME);
|
File unknownFileDir = new File(appDir, UNK_DIRNAME);
|
||||||
if (files == null || files.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// loop through unknown files
|
// loop through unknown files
|
||||||
for (Map.Entry<String,String> unknownFileInfo : files.entrySet()) {
|
for (Map.Entry<String,String> unknownFileInfo : files.entrySet()) {
|
||||||
String cleanedPath = BrutIO.sanitizeUnknownFile(unknownFileDir, unknownFileInfo.getKey());
|
File inputFile = new File(unknownFileDir, BrutIO.sanitizeUnknownFile(unknownFileDir, unknownFileInfo.getKey()));
|
||||||
File inputFile = new File(unknownFileDir, cleanedPath);
|
|
||||||
if (inputFile.isDirectory()) {
|
if (inputFile.isDirectory()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ZipEntry newEntry = new ZipEntry(cleanedPath);
|
ZipEntry newEntry = new ZipEntry(unknownFileInfo.getKey());
|
||||||
int method = Integer.parseInt(unknownFileInfo.getValue());
|
int method = Integer.parseInt(unknownFileInfo.getValue());
|
||||||
LOGGER.fine(String.format("Copying unknown file %s with method %d", unknownFileInfo.getKey(), method));
|
LOGGER.fine(String.format("Copying unknown file %s with method %d", unknownFileInfo.getKey(), method));
|
||||||
if (method == ZipEntry.STORED) {
|
if (method == ZipEntry.STORED) {
|
||||||
newEntry = getStoredZipEntry(cleanedPath, inputFile);
|
newEntry.setMethod(ZipEntry.STORED);
|
||||||
|
newEntry.setSize(inputFile.length());
|
||||||
|
newEntry.setCompressedSize(-1);
|
||||||
|
BufferedInputStream unknownFile = new BufferedInputStream(new FileInputStream(inputFile));
|
||||||
|
CRC32 crc = BrutIO.calculateCrc(unknownFile);
|
||||||
|
newEntry.setCrc(crc.getValue());
|
||||||
} else {
|
} else {
|
||||||
newEntry.setMethod(ZipEntry.DEFLATED);
|
newEntry.setMethod(ZipEntry.DEFLATED);
|
||||||
}
|
}
|
||||||
@ -674,45 +666,6 @@ public class Androlib {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void copyUncompressedAssetFiles(File appDir, ZipOutputStream outputFile, Collection<String> files)
|
|
||||||
throws BrutException, IOException {
|
|
||||||
|
|
||||||
if (files == null || files.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
File assetFileDir = new File(appDir, ASSET_DIRNAME);
|
|
||||||
|
|
||||||
for (String asset : files) {
|
|
||||||
String cleanedPath = BrutIO.sanitizeUnknownFile(assetFileDir, asset);
|
|
||||||
|
|
||||||
File inputFile = new File(appDir, cleanedPath);
|
|
||||||
if (inputFile.isDirectory()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
LOGGER.fine(String.format("Copying uncompressed asset: %s", asset));
|
|
||||||
ZipEntry newEntry = getStoredZipEntry(cleanedPath, inputFile);
|
|
||||||
outputFile.putNextEntry(newEntry);
|
|
||||||
BrutIO.copy(inputFile, outputFile);
|
|
||||||
outputFile.closeEntry();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private ZipEntry getStoredZipEntry(String cleanedPath, File inputFile)
|
|
||||||
throws IOException {
|
|
||||||
|
|
||||||
ZipEntry newEntry = new ZipEntry(cleanedPath);
|
|
||||||
newEntry.setMethod(ZipEntry.STORED);
|
|
||||||
newEntry.setSize(inputFile.length());
|
|
||||||
newEntry.setCompressedSize(-1);
|
|
||||||
BufferedInputStream unknownFile = new BufferedInputStream(new FileInputStream(inputFile));
|
|
||||||
CRC32 crc = BrutIO.calculateCrc(unknownFile);
|
|
||||||
newEntry.setCrc(crc.getValue());
|
|
||||||
|
|
||||||
return newEntry;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void buildApk(File appDir, File outApk) throws AndrolibException {
|
public void buildApk(File appDir, File outApk) throws AndrolibException {
|
||||||
LOGGER.info("Building apk file...");
|
LOGGER.info("Building apk file...");
|
||||||
if (outApk.exists()) {
|
if (outApk.exists()) {
|
||||||
@ -810,7 +763,6 @@ public class Androlib {
|
|||||||
private final static String SMALI_DIRNAME = "smali";
|
private final static String SMALI_DIRNAME = "smali";
|
||||||
private final static String APK_DIRNAME = "build/apk";
|
private final static String APK_DIRNAME = "build/apk";
|
||||||
private final static String UNK_DIRNAME = "unknown";
|
private final static String UNK_DIRNAME = "unknown";
|
||||||
private final static String ASSET_DIRNAME = "assets";
|
|
||||||
private final static String[] APK_RESOURCES_FILENAMES = new String[] {
|
private final static String[] APK_RESOURCES_FILENAMES = new String[] {
|
||||||
"resources.arsc", "AndroidManifest.xml", "res" };
|
"resources.arsc", "AndroidManifest.xml", "res" };
|
||||||
private final static String[] APK_RESOURCES_WITHOUT_RES_FILENAMES = new String[] {
|
private final static String[] APK_RESOURCES_WITHOUT_RES_FILENAMES = new String[] {
|
||||||
@ -825,6 +777,6 @@ public class Androlib {
|
|||||||
// Taken from AOSP's frameworks/base/tools/aapt/Package.cpp
|
// Taken from AOSP's frameworks/base/tools/aapt/Package.cpp
|
||||||
private final static Pattern NO_COMPRESS_PATTERN = Pattern.compile("\\.(" +
|
private final static Pattern NO_COMPRESS_PATTERN = Pattern.compile("\\.(" +
|
||||||
"jpg|jpeg|png|gif|wav|mp2|mp3|ogg|aac|mpg|mpeg|mid|midi|smf|jet|rtttl|imy|xmf|mp4|" +
|
"jpg|jpeg|png|gif|wav|mp2|mp3|ogg|aac|mpg|mpeg|mid|midi|smf|jet|rtttl|imy|xmf|mp4|" +
|
||||||
"m4a|m4v|3gp|3gpp|3g2|3gpp2|amr|awb|wma|wmv|webm|mkv|arsc)$");
|
"m4a|m4v|3gp|3gpp|3g2|3gpp2|amr|awb|wma|wmv|webm|mkv)$");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user