mirror of
https://github.com/revanced/Apktool.git
synced 2025-05-01 06:34:25 +02:00
fixes issue #67 - only compresses resources.arsc if original apk had compressoin
This commit is contained in:
parent
7fc70058dc
commit
f82b2e1855
@ -155,7 +155,12 @@ public class Main {
|
|||||||
String.valueOf(ex.getPkgId()) + ". You must install proper " +
|
String.valueOf(ex.getPkgId()) + ". You must install proper " +
|
||||||
"framework files, see project website for more info.");
|
"framework files, see project website for more info.");
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
|
} catch (IOException ex) {
|
||||||
|
System.out.println(
|
||||||
|
"Could not modify file. Please ensure you have permission.");
|
||||||
|
System.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void cmdBuild(String[] args) throws BrutException {
|
private static void cmdBuild(String[] args) throws BrutException {
|
||||||
|
@ -183,6 +183,7 @@ public class Androlib {
|
|||||||
Map<String, Object> meta = readMetaFile(appDir);
|
Map<String, Object> meta = readMetaFile(appDir);
|
||||||
Object t1 = meta.get("isFrameworkApk");
|
Object t1 = meta.get("isFrameworkApk");
|
||||||
flags.put("framework", t1 == null ? false : (Boolean) t1);
|
flags.put("framework", t1 == null ? false : (Boolean) t1);
|
||||||
|
flags.put("compression", meta.get("compressionType") == null ? false : (Boolean) meta.get("compressionType"));
|
||||||
mAndRes.setSdkInfo((Map<String, String>) meta.get("sdkInfo"));
|
mAndRes.setSdkInfo((Map<String, String>) meta.get("sdkInfo"));
|
||||||
|
|
||||||
// check the orig apk
|
// check the orig apk
|
||||||
|
@ -26,7 +26,11 @@ import brut.common.BrutException;
|
|||||||
import brut.directory.DirectoryException;
|
import brut.directory.DirectoryException;
|
||||||
import brut.util.OS;
|
import brut.util.OS;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.jar.JarEntry;
|
||||||
|
import java.util.jar.JarFile;
|
||||||
|
import java.util.zip.ZipEntry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Ryszard Wiśniewski <brut.alll@gmail.com>
|
* @author Ryszard Wiśniewski <brut.alll@gmail.com>
|
||||||
@ -58,7 +62,7 @@ public class ApkDecoder {
|
|||||||
mOutDir = outDir;
|
mOutDir = outDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void decode() throws AndrolibException {
|
public void decode() throws AndrolibException, IOException {
|
||||||
File outDir = getOutDir();
|
File outDir = getOutDir();
|
||||||
|
|
||||||
if (!mForceDelete && outDir.exists()) {
|
if (!mForceDelete && outDir.exists()) {
|
||||||
@ -91,6 +95,20 @@ public class ApkDecoder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (hasResources()) {
|
if (hasResources()) {
|
||||||
|
|
||||||
|
// read the resources.arsc checking for STORED vs DEFLATE compression
|
||||||
|
// this will determine whether we compress on rebuild or not.
|
||||||
|
JarFile jf = new JarFile(mApkFile.getAbsoluteFile());
|
||||||
|
Enumeration<?> e = jf.entries();
|
||||||
|
while(e.hasMoreElements()) {
|
||||||
|
JarEntry je = (JarEntry) e.nextElement();
|
||||||
|
if (je.getName().equalsIgnoreCase("resources.arsc")) {
|
||||||
|
setCompressionType(je.getMethod());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
jf.close();
|
||||||
|
|
||||||
switch (mDecodeResources) {
|
switch (mDecodeResources) {
|
||||||
case DECODE_RESOURCES_NONE:
|
case DECODE_RESOURCES_NONE:
|
||||||
mAndrolib.decodeResourcesRaw(mApkFile, outDir);
|
mAndrolib.decodeResourcesRaw(mApkFile, outDir);
|
||||||
@ -227,6 +245,7 @@ public class ApkDecoder {
|
|||||||
putUsesFramework(meta);
|
putUsesFramework(meta);
|
||||||
putSdkInfo(meta);
|
putSdkInfo(meta);
|
||||||
putPackageInfo(meta);
|
putPackageInfo(meta);
|
||||||
|
putCompressionInfo(meta);
|
||||||
}
|
}
|
||||||
|
|
||||||
mAndrolib.writeMetaFile(mOutDir, meta);
|
mAndrolib.writeMetaFile(mOutDir, meta);
|
||||||
@ -271,6 +290,27 @@ public class ApkDecoder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void putCompressionInfo(Map<String, Object> meta)
|
||||||
|
throws AndrolibException {
|
||||||
|
meta.put("compressionType", getCompressionType());
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean getCompressionType() {
|
||||||
|
return mCompressResources;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setCompressionType(int compression) {
|
||||||
|
|
||||||
|
// check for deflate vs stored
|
||||||
|
if (compression == ZipEntry.STORED) {
|
||||||
|
mCompressResources = false;
|
||||||
|
} else if (compression == ZipEntry.DEFLATED) {
|
||||||
|
mCompressResources = true;
|
||||||
|
} else {
|
||||||
|
mCompressResources = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private final Androlib mAndrolib;
|
private final Androlib mAndrolib;
|
||||||
|
|
||||||
private ExtFile mApkFile;
|
private ExtFile mApkFile;
|
||||||
@ -284,4 +324,5 @@ public class ApkDecoder {
|
|||||||
private boolean mKeepBrokenResources = false;
|
private boolean mKeepBrokenResources = false;
|
||||||
private String mFrameworkDir = null;
|
private String mFrameworkDir = null;
|
||||||
private boolean mBakDeb = true;
|
private boolean mBakDeb = true;
|
||||||
|
private boolean mCompressResources = false;
|
||||||
}
|
}
|
||||||
|
@ -320,8 +320,11 @@ final public class AndrolibResources {
|
|||||||
|
|
||||||
if (flags.get("framework")) {
|
if (flags.get("framework")) {
|
||||||
cmd.add("-x");
|
cmd.add("-x");
|
||||||
// cmd.add("-0");
|
}
|
||||||
// cmd.add("arsc");
|
|
||||||
|
if (!(flags.get("compression"))) {
|
||||||
|
cmd.add("-0");
|
||||||
|
cmd.add("arsc");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (include != null) {
|
if (include != null) {
|
||||||
|
@ -33,7 +33,7 @@ import org.xml.sax.SAXException;
|
|||||||
public class BuildAndDecodeTest {
|
public class BuildAndDecodeTest {
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void beforeClass() throws BrutException {
|
public static void beforeClass() throws BrutException, IOException {
|
||||||
sTmpDir = new ExtFile(OS.createTempDirectory());
|
sTmpDir = new ExtFile(OS.createTempDirectory());
|
||||||
sTestOrigDir = new ExtFile(sTmpDir, "testapp-orig");
|
sTestOrigDir = new ExtFile(sTmpDir, "testapp-orig");
|
||||||
sTestNewDir = new ExtFile(sTmpDir, "testapp-new");
|
sTestNewDir = new ExtFile(sTmpDir, "testapp-new");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user