Removes general access bit hack

- fixed in aosp: android_libcore/commit/25681be69e19a834b00cfbf54cd99ac13f12b9ff
 - reverts 42f69fd745
 - reverts 47a5eac0b0
 - fixes googlecode issue 744
This commit is contained in:
Connor Tumbleson 2015-01-21 07:12:26 -06:00
parent e281f81546
commit 81e6af093b
8 changed files with 25 additions and 95 deletions

View File

@ -56,6 +56,7 @@ v2.0.0 (TBA)
-Fixed (issue #590) - Fixed issue with segfaulting aapt with certain apks.
-Fixed (issue #545) - Fixed issue with undefined attrs w/ updated internal frameworks
-Fixed (issue #702) - Fixed improper handling of MNC_ZERO which caused dupe`d resources
-Fixed (issue #744) - Fixed warnings of "Cleaning up unclosed ZipFile..."
-Fixed issue with APKs with multiple dex files.
-Fixed issue with using Apktool without smali/baksmali for ApktoolProperties (Thanks teprrr)
-Fixed issue with non-URI standard characters in apk name (Thanks rover12421)

View File

@ -35,6 +35,8 @@ import java.util.*;
import java.util.logging.Logger;
import java.util.zip.ZipEntry;
import java.nio.file.Files;
import java.util.zip.ZipFile;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;
@ -174,7 +176,7 @@ public class Androlib {
// with regular looping of apkFile for easy copy
try {
Directory unk = apkFile.getDirectory();
ZipExtFile apkZipFile = new ZipExtFile(apkFile.getAbsolutePath());
ZipFile apkZipFile = new ZipFile(apkFile.getAbsolutePath());
// loop all items in container recursively, ignoring any that are pre-defined by aapt
Set<String> files = unk.getFiles(true);
@ -184,8 +186,6 @@ public class Androlib {
// copy file out of archive into special "unknown" folder
unk.copyToDir(unknownOut, file);
try {
// ignore encryption
apkZipFile.getEntry(file).getGeneralPurposeBit().useEncryption(false);
invZipFile = apkZipFile.getEntry(file);
// lets record the name of the file, and its compression type

View File

@ -24,16 +24,15 @@ import brut.androlib.res.data.ResTable;
import brut.androlib.res.util.ExtFile;
import brut.common.BrutException;
import brut.directory.DirectoryException;
import brut.directory.ZipExtFile;
import brut.util.OS;
import com.google.common.base.Strings;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.logging.Logger;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
/**
* @author Ryszard Wiśniewski <brut.alll@gmail.com>
@ -196,13 +195,13 @@ public class ApkDecoder {
public void setCompressionMode() throws AndrolibException, IOException {
// read the resources.arsc checking for STORED vs DEFLATE
// this will determine whether we compress on rebuild or not.
ZipExtFile zef = new ZipExtFile(mApkFile.getAbsolutePath());
ZipArchiveEntry ze = zef.getEntry("resources.arsc");
ZipFile zf = new ZipFile(mApkFile.getAbsolutePath());
ZipEntry ze = zf.getEntry("resources.arsc");
if (ze != null) {
int compression = ze.getMethod();
mCompressResources = (compression == ZipEntry.DEFLATED);
}
zef.close();
zf.close();
}
public void setTargetSdkVersion() throws AndrolibException, IOException {

View File

@ -42,8 +42,6 @@ import javax.xml.transform.*;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
@ -665,10 +663,10 @@ final public class AndrolibResources {
public void installFramework(File frameFile, String tag)
throws AndrolibException {
InputStream in = null;
ZipArchiveOutputStream out = null;
ZipOutputStream out = null;
try {
ZipExtFile zip = new ZipExtFile(frameFile);
ZipArchiveEntry entry = zip.getEntry("resources.arsc");
ZipFile zip = new ZipFile(frameFile);
ZipEntry entry = zip.getEntry("resources.arsc");
if (entry == null) {
throw new AndrolibException("Can't find resources.arsc file");
@ -685,21 +683,17 @@ final public class AndrolibResources {
+ (tag == null ? "" : '-' + tag)
+ ".apk");
out = new ZipArchiveOutputStream(new FileOutputStream(outFile));
out = new ZipOutputStream(new FileOutputStream(outFile));
out.setMethod(ZipOutputStream.STORED);
CRC32 crc = new CRC32();
crc.update(data);
entry = new ZipArchiveEntry("resources.arsc");
entry = new ZipEntry("resources.arsc");
entry.setSize(data.length);
entry.setCrc(crc.getValue());
out.putArchiveEntry(entry);
out.putNextEntry(entry);
out.write(data);
out.closeArchiveEntry();
zip.close();
LOGGER.info("Framework installed to: " + outFile);
} catch (ZipException ex) {
throw new AndrolibException(ex);
} catch (IOException ex) {
throw new AndrolibException(ex);
} finally {

View File

@ -1,59 +0,0 @@
/**
* Copyright 2014 Ryszard Wiśniewski <brut.alll@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
*
* http://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.directory;
import org.apache.commons.compress.archivers.zip.*;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.zip.ZipException;
public class ZipExtFile extends ZipFile {
public ZipExtFile(File f) throws IOException {
super(f);
}
public ZipExtFile(String name) throws IOException {
super(name);
}
public ZipExtFile(String name, String encoding) throws IOException {
super(name, encoding);
}
public ZipExtFile(File f, String encoding) throws IOException {
super(f, encoding);
}
public ZipExtFile(File f, String encoding, boolean useUnicodeExtraFields) throws IOException {
super(f, encoding, useUnicodeExtraFields);
}
@Override
public InputStream getInputStream(ZipArchiveEntry ze)
throws IOException {
ze.getGeneralPurposeBit().useEncryption(false); // credit: Panxiaobo
return super.getInputStream(ze);
}
@Override
public ZipArchiveEntry getEntry(String name) {
return super.getEntry(name);
}
}

View File

@ -16,7 +16,6 @@
package brut.directory;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
@ -24,9 +23,11 @@ import java.io.OutputStream;
import java.util.Enumeration;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
public class ZipRODirectory extends AbstractDirectory {
private ZipExtFile mZipFile;
private ZipFile mZipFile;
private String mPath;
public ZipRODirectory(String zipFileName) throws DirectoryException {
@ -37,7 +38,7 @@ public class ZipRODirectory extends AbstractDirectory {
this(zipFile, "");
}
public ZipRODirectory(ZipExtFile zipFile) {
public ZipRODirectory(ZipFile zipFile) {
this(zipFile, "");
}
@ -49,14 +50,14 @@ public class ZipRODirectory extends AbstractDirectory {
public ZipRODirectory(File zipFile, String path) throws DirectoryException {
super();
try {
mZipFile = new ZipExtFile(zipFile);
mZipFile = new ZipFile(zipFile);
} catch (IOException e) {
throw new DirectoryException(e);
}
mPath = path;
}
public ZipRODirectory(ZipExtFile zipFile, String path) {
public ZipRODirectory(ZipFile zipFile, String path) {
super();
mZipFile = zipFile;
mPath = path;
@ -72,8 +73,7 @@ public class ZipRODirectory extends AbstractDirectory {
protected InputStream getFileInputLocal(String name)
throws DirectoryException {
try {
mZipFile.getEntry(getPath() + name).getGeneralPurposeBit().useEncryption(false);
return getZipFile().getInputStream(mZipFile.getEntry(getPath() + name));
return getZipFile().getInputStream(new ZipEntry(getPath() + name));
} catch (IOException e) {
throw new PathNotExist(name, e);
}
@ -105,12 +105,9 @@ public class ZipRODirectory extends AbstractDirectory {
mDirs = new LinkedHashMap<String, AbstractDirectory>();
int prefixLen = getPath().length();
Enumeration<? extends ZipArchiveEntry> entries = getZipFile().getEntries();
Enumeration<? extends ZipEntry> entries = getZipFile().entries();
while (entries.hasMoreElements()) {
ZipArchiveEntry entry = entries.nextElement();
// ignore general purpose bit, since AOSP does
entry.getGeneralPurposeBit().useEncryption(false);
ZipEntry entry = entries.nextElement();
String name = entry.getName();
if (name.equals(getPath()) || ! name.startsWith(getPath())) {
@ -140,7 +137,7 @@ public class ZipRODirectory extends AbstractDirectory {
return mPath;
}
private ZipExtFile getZipFile() {
private ZipFile getZipFile() {
return mZipFile;
}

View File

@ -16,7 +16,6 @@
dependencies {
compile project(':brut.j.common'),
depends.commons_io,
depends.commons_compress
depends.commons_io
testCompile depends.junit
}

View File

@ -87,7 +87,6 @@ subprojects {
antlr: 'org.antlr:antlr:3.5',
antlr_runtime: 'org.antlr:antlr-runtime:3.5',
commons_cli: 'commons-cli:commons-cli:1.2',
commons_compress: 'org.apache.commons:commons-compress:1.4.1',
commons_io: 'commons-io:commons-io:2.4',
commons_lang: 'org.apache.commons:commons-lang3:3.1',
findbugs: 'com.google.code.findbugs:jsr305:1.3.9',