diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/Androlib.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/Androlib.java index 2bbc8e49..8a1aaf55 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/Androlib.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/Androlib.java @@ -22,7 +22,7 @@ import brut.androlib.res.AndrolibResources; import brut.androlib.res.data.ResPackage; import brut.androlib.res.data.ResTable; import brut.androlib.res.data.ResUnknownFiles; -import brut.androlib.res.util.ExtFile; +import brut.directory.ExtFile; import brut.androlib.res.xml.ResXmlPatcher; import brut.androlib.src.SmaliBuilder; import brut.androlib.src.SmaliDecoder; @@ -31,7 +31,6 @@ import brut.directory.*; import brut.util.BrutIO; import brut.util.OS; import java.io.*; -import java.nio.file.Files; import java.util.*; import java.util.logging.Logger; import java.util.regex.Pattern; diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/ApkDecoder.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/ApkDecoder.java index 2aa8be2a..aa2ca555 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/ApkDecoder.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/ApkDecoder.java @@ -26,7 +26,7 @@ import brut.androlib.meta.VersionInfo; import brut.androlib.res.AndrolibResources; import brut.androlib.res.data.ResPackage; import brut.androlib.res.data.ResTable; -import brut.androlib.res.util.ExtFile; +import brut.directory.ExtFile; import brut.androlib.res.xml.ResXmlPatcher; import brut.common.BrutException; import brut.directory.DirectoryException; diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/AndrolibResources.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/AndrolibResources.java index 9b500ddd..ae884321 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/AndrolibResources.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/AndrolibResources.java @@ -25,7 +25,7 @@ import brut.androlib.res.data.*; import brut.androlib.res.decoder.*; import brut.androlib.res.decoder.ARSCDecoder.ARSCData; import brut.androlib.res.decoder.ARSCDecoder.FlagsOffset; -import brut.androlib.res.util.ExtFile; +import brut.directory.ExtFile; import brut.androlib.res.util.ExtMXSerializer; import brut.androlib.res.util.ExtXmlSerializer; import brut.androlib.res.xml.ResValuesXmlSerializable; diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/util/ExtFile.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/util/ExtFile.java index 81d1b033..12fa9d40 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/util/ExtFile.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/util/ExtFile.java @@ -13,50 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package brut.androlib.res.util; -import brut.directory.Directory; -import brut.directory.DirectoryException; -import brut.directory.FileDirectory; -import brut.directory.ZipRODirectory; import java.io.File; -import java.net.URI; -/** - * @author Ryszard Wiśniewski - */ -public class ExtFile extends File { + +public class ExtFile extends brut.directory.ExtFile { public ExtFile(File file) { super(file.getPath()); } - - public ExtFile(URI uri) { - super(uri); - } - - public ExtFile(File parent, String child) { - super(parent, child); - } - - public ExtFile(String parent, String child) { - super(parent, child); - } - - public ExtFile(String pathname) { - super(pathname); - } - - public Directory getDirectory() throws DirectoryException { - if (mDirectory == null) { - if (isDirectory()) { - mDirectory = new FileDirectory(this); - } else { - mDirectory = new ZipRODirectory(this); - } - } - return mDirectory; - } - - private Directory mDirectory; } diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/src/SmaliBuilder.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/src/SmaliBuilder.java index 75fb2e35..57a375f2 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/src/SmaliBuilder.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/src/SmaliBuilder.java @@ -18,14 +18,12 @@ package brut.androlib.src; import brut.androlib.AndrolibException; import brut.androlib.mod.SmaliMod; -import brut.androlib.res.util.ExtFile; +import brut.directory.ExtFile; import brut.directory.DirectoryException; import java.io.*; -import java.util.List; import java.util.logging.Logger; import org.antlr.runtime.RecognitionException; -import org.apache.commons.io.IOUtils; import org.jf.dexlib2.Opcodes; import org.jf.dexlib2.writer.builder.DexBuilder; import org.jf.dexlib2.writer.io.FileDataStore; diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/AndResGuardTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/AndResGuardTest.java index e8d2e0d3..129db300 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/AndResGuardTest.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/AndResGuardTest.java @@ -16,7 +16,7 @@ */ package brut.androlib; -import brut.androlib.res.util.ExtFile; +import brut.directory.ExtFile; import brut.common.BrutException; import brut.util.OS; import java.io.File; diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/BuildAndDecodeJarTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/BuildAndDecodeJarTest.java index 4ca0146e..5ed1fa72 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/BuildAndDecodeJarTest.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/BuildAndDecodeJarTest.java @@ -15,7 +15,7 @@ */ package brut.androlib; -import brut.androlib.res.util.ExtFile; +import brut.directory.ExtFile; import brut.common.BrutException; import brut.util.OS; import org.junit.AfterClass; diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/BuildAndDecodeTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/BuildAndDecodeTest.java index 0305c7fc..cdce9e36 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/BuildAndDecodeTest.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/BuildAndDecodeTest.java @@ -16,7 +16,7 @@ package brut.androlib; import brut.androlib.meta.MetaInfo; -import brut.androlib.res.util.ExtFile; +import brut.directory.ExtFile; import brut.common.BrutException; import brut.directory.FileDirectory; import brut.util.OS; @@ -31,7 +31,6 @@ import org.custommonkey.xmlunit.*; import org.junit.*; import static org.junit.Assert.*; -import org.junit.rules.ExpectedException; import org.xml.sax.SAXException; import javax.imageio.ImageIO; @@ -420,7 +419,7 @@ public class BuildAndDecodeTest { String location = tmp + path; - FileDirectory fileDirectory = new FileDirectory(sTestOrigDir + location); + FileDirectory fileDirectory = new FileDirectory(sTestOrigDir, location); Set files = fileDirectory.getFiles(true); for (String filename : files) { diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/DebugTagRetainedTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/DebugTagRetainedTest.java index 7cde0856..fb77867a 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/DebugTagRetainedTest.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/DebugTagRetainedTest.java @@ -15,7 +15,7 @@ */ package brut.androlib; -import brut.androlib.res.util.ExtFile; +import brut.directory.ExtFile; import brut.common.BrutException; import brut.util.OS; import org.junit.AfterClass; diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/DoubleExtensionUnknownFileTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/DoubleExtensionUnknownFileTest.java index 11c2d13b..55b745ce 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/DoubleExtensionUnknownFileTest.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/DoubleExtensionUnknownFileTest.java @@ -17,7 +17,7 @@ package brut.androlib; import brut.androlib.meta.MetaInfo; -import brut.androlib.res.util.ExtFile; +import brut.directory.ExtFile; import brut.common.BrutException; import brut.util.OS; import org.apache.commons.lang3.StringUtils; diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/LargeIntsInManifestTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/LargeIntsInManifestTest.java index f8635315..74e03c99 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/LargeIntsInManifestTest.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/LargeIntsInManifestTest.java @@ -16,15 +16,12 @@ */ package brut.androlib; -import brut.androlib.res.util.ExtFile; +import brut.directory.ExtFile; import brut.common.BrutException; -import brut.directory.FileDirectory; import brut.util.OS; import java.io.*; import java.io.File; import java.io.IOException; -import java.util.Map; -import java.util.Set; import java.util.logging.Logger; import org.custommonkey.xmlunit.*; diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/MissingVersionManifestTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/MissingVersionManifestTest.java index 16d121f8..e93e1dc9 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/MissingVersionManifestTest.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/MissingVersionManifestTest.java @@ -16,7 +16,7 @@ package brut.androlib; import brut.androlib.meta.MetaInfo; -import brut.androlib.res.util.ExtFile; +import brut.directory.ExtFile; import brut.common.BrutException; import brut.util.OS; import org.junit.AfterClass; diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/ProviderAttributeTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/ProviderAttributeTest.java index 0d19efef..242b4af1 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/ProviderAttributeTest.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/ProviderAttributeTest.java @@ -16,9 +16,8 @@ */ package brut.androlib; -import brut.androlib.res.util.ExtFile; +import brut.directory.ExtFile; import brut.common.BrutException; -import brut.directory.DirectoryException; import brut.util.OS; import org.junit.AfterClass; import org.junit.BeforeClass; diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/ReferenceVersionCodeTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/ReferenceVersionCodeTest.java index 4fa4193f..533a739d 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/ReferenceVersionCodeTest.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/ReferenceVersionCodeTest.java @@ -16,7 +16,7 @@ package brut.androlib; import brut.androlib.meta.MetaInfo; -import brut.androlib.res.util.ExtFile; +import brut.directory.ExtFile; import brut.common.BrutException; import brut.util.OS; import org.junit.AfterClass; diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/SharedLibraryTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/SharedLibraryTest.java index ae35d255..e61e0f44 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/SharedLibraryTest.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/SharedLibraryTest.java @@ -16,9 +16,8 @@ */ package brut.androlib; -import brut.androlib.res.util.ExtFile; +import brut.directory.ExtFile; import brut.common.BrutException; -import brut.directory.DirectoryException; import brut.util.OS; import org.junit.AfterClass; import org.junit.BeforeClass; diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/TestUtils.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/TestUtils.java index d62d1d8b..33a0b155 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/TestUtils.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/TestUtils.java @@ -98,7 +98,11 @@ public abstract class TestUtils { URL dirURL = class_.getClassLoader().getResource(dirPath); if (dirURL != null && dirURL.getProtocol().equals("file")) { - DirUtil.copyToDir(new FileDirectory(dirURL.getFile()), out); + try { + DirUtil.copyToDir(new FileDirectory(dirURL.getFile()), out); + } catch (UnsupportedEncodingException ex) { + throw new BrutException(ex); + } return; } @@ -111,10 +115,10 @@ public abstract class TestUtils { String jarPath; try { jarPath = URLDecoder.decode(dirURL.getPath().substring(5, dirURL.getPath().indexOf("!")), "UTF-8"); + DirUtil.copyToDir(new FileDirectory(jarPath), out); } catch (UnsupportedEncodingException ex) { throw new BrutException(ex); } - DirUtil.copyToDir(new FileDirectory(jarPath), out); } } diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/UnknownCompressionTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/UnknownCompressionTest.java index f7d1875e..39e5e2bc 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/UnknownCompressionTest.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/UnknownCompressionTest.java @@ -16,7 +16,7 @@ */ package brut.androlib; -import brut.androlib.res.util.ExtFile; +import brut.directory.ExtFile; import brut.common.BrutException; import brut.util.OS; import org.junit.AfterClass; diff --git a/brut.j.dir/src/main/java/brut/directory/ExtFile.java b/brut.j.dir/src/main/java/brut/directory/ExtFile.java new file mode 100644 index 00000000..583c3fa1 --- /dev/null +++ b/brut.j.dir/src/main/java/brut/directory/ExtFile.java @@ -0,0 +1,58 @@ +/** + * Copyright 2014 Ryszard Wiśniewski + * + * 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 java.io.File; +import java.net.URI; + +/** + * @author Ryszard Wiśniewski + */ +public class ExtFile extends File { + public ExtFile(File file) { + super(file.getPath()); + } + + public ExtFile(URI uri) { + super(uri); + } + + public ExtFile(File parent, String child) { + super(parent, child); + } + + public ExtFile(String parent, String child) { + super(parent, child); + } + + public ExtFile(String pathname) { + super(pathname); + } + + public Directory getDirectory() throws DirectoryException { + if (mDirectory == null) { + if (isDirectory()) { + mDirectory = new FileDirectory(this); + } else { + mDirectory = new ZipRODirectory(this); + } + } + return mDirectory; + } + + private Directory mDirectory; +} diff --git a/brut.j.dir/src/main/java/brut/directory/FileDirectory.java b/brut.j.dir/src/main/java/brut/directory/FileDirectory.java index 8124b47a..ae911408 100644 --- a/brut.j.dir/src/main/java/brut/directory/FileDirectory.java +++ b/brut.j.dir/src/main/java/brut/directory/FileDirectory.java @@ -16,20 +16,20 @@ package brut.directory; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.InputStream; -import java.io.OutputStream; +import java.io.*; +import java.net.URLDecoder; import java.util.LinkedHashMap; import java.util.LinkedHashSet; public class FileDirectory extends AbstractDirectory { private File mDir; - public FileDirectory(String dir) throws DirectoryException { - this(new File(dir)); + public FileDirectory(ExtFile dir, String folder) throws DirectoryException, UnsupportedEncodingException { + this(new File(dir.toString().replaceAll("%20", " "), folder)); + } + + public FileDirectory(String dir) throws DirectoryException, UnsupportedEncodingException { + this(new File(URLDecoder.decode(dir, "UTF-8"))); } public FileDirectory(File dir) throws DirectoryException { @@ -79,7 +79,7 @@ public class FileDirectory extends AbstractDirectory { protected void removeFileLocal(String name) { new File(generatePath(name)).delete(); } - + private String generatePath(String name) { return getDir().getPath() + separator + name; } @@ -87,7 +87,7 @@ public class FileDirectory extends AbstractDirectory { private void loadAll() { mFiles = new LinkedHashSet(); mDirs = new LinkedHashMap(); - + File[] files = getDir().listFiles(); for (int i = 0; i < files.length; i++) { File file = files[i];