diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/err/AXmlDecodingException.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/err/AXmlDecodingException.java new file mode 100644 index 00000000..cc28d000 --- /dev/null +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/err/AXmlDecodingException.java @@ -0,0 +1,37 @@ +/** + * Copyright (C) 2018 Ryszard Wiśniewski + * Copyright (C) 2018 Connor Tumbleson + * + * 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.androlib.err; + +import brut.androlib.AndrolibException; + +public class AXmlDecodingException extends AndrolibException { + + public AXmlDecodingException(Throwable cause) { + super(cause); + } + + public AXmlDecodingException(String message, Throwable cause) { + super(message, cause); + } + + public AXmlDecodingException(String message) { + super(message); + } + + public AXmlDecodingException() { + } +} \ No newline at end of file diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/err/RawXmlEncounteredException.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/err/RawXmlEncounteredException.java new file mode 100644 index 00000000..762f1074 --- /dev/null +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/err/RawXmlEncounteredException.java @@ -0,0 +1,37 @@ +/** + * Copyright (C) 2018 Ryszard Wiśniewski + * Copyright (C) 2018 Connor Tumbleson + * + * 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.androlib.err; + +import brut.androlib.AndrolibException; + +public class RawXmlEncounteredException extends AndrolibException { + + public RawXmlEncounteredException(Throwable cause) { + super(cause); + } + + public RawXmlEncounteredException(String message, Throwable cause) { + super(message, cause); + } + + public RawXmlEncounteredException(String message) { + super(message); + } + + public RawXmlEncounteredException() { + } +} diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/ResFileDecoder.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/ResFileDecoder.java index 33a5fbc0..cc98c0b5 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/ResFileDecoder.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/ResFileDecoder.java @@ -18,6 +18,7 @@ package brut.androlib.res.decoder; import brut.androlib.AndrolibException; import brut.androlib.err.CantFind9PatchChunk; +import brut.androlib.err.RawXmlEncounteredException; import brut.androlib.res.data.ResResource; import brut.androlib.res.data.value.ResBoolValue; import brut.androlib.res.data.value.ResFileValue; @@ -118,6 +119,11 @@ public class ResFileDecoder { } decode(inDir, inFileName, outDir, outFileName, "xml"); + } catch (RawXmlEncounteredException ex) { + // If we got an error to decode XML, lets assume the file is in raw format. + // This is a large assumption, that might increase runtime, but will save us for situations where + // XSD files are AXML`d on aapt1, but left in plaintext in aapt2. + decode(inDir, inFileName, outDir, outFileName, "raw"); } catch (AndrolibException ex) { LOGGER.log(Level.SEVERE, String.format( "Could not decode file, replacing by FALSE value: %s", diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/XmlPullStreamDecoder.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/XmlPullStreamDecoder.java index 888e47c4..25ef81e6 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/XmlPullStreamDecoder.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/XmlPullStreamDecoder.java @@ -19,8 +19,9 @@ package brut.androlib.res.decoder; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.util.logging.Logger; +import brut.androlib.err.AXmlDecodingException; +import brut.androlib.err.RawXmlEncounteredException; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.wrapper.XmlPullParserWrapper; @@ -142,9 +143,9 @@ public class XmlPullStreamDecoder implements ResStreamDecoder { } ser.flush(); } catch (XmlPullParserException ex) { - throw new AndrolibException("Could not decode XML", ex); + throw new AXmlDecodingException("Could not decode XML", ex); } catch (IOException ex) { - throw new AndrolibException("Could not decode XML", ex); + throw new RawXmlEncounteredException("Could not decode XML", ex); } } @@ -155,6 +156,4 @@ public class XmlPullStreamDecoder implements ResStreamDecoder { private final XmlPullParser mParser; private final ExtXmlSerializer mSerial; - - private final static Logger LOGGER = Logger.getLogger(XmlPullStreamDecoder.class.getName()); } diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/BuildAndDecodeTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/BuildAndDecodeTest.java index e2992018..ee9db151 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/BuildAndDecodeTest.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/BuildAndDecodeTest.java @@ -198,6 +198,11 @@ public class BuildAndDecodeTest extends BaseTest { compareXmlFiles("res/xml/references.xml"); } + @Test + public void xmlXsdFileTest() throws BrutException { + compareXmlFiles("res/xml/ww_box_styles_schema.xsd"); + } + @Test public void xmlIdsEmptyTest() throws BrutException { compareXmlFiles("res/values/ids.xml"); diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt2/BuildAndDecodeTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt2/BuildAndDecodeTest.java index bd4785de..f031f4da 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt2/BuildAndDecodeTest.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt2/BuildAndDecodeTest.java @@ -98,4 +98,9 @@ public class BuildAndDecodeTest extends BaseTest { public void confirmManifestStructureTest() throws BrutException { compareXmlFiles("AndroidManifest.xml"); } + + @Test + public void xmlXsdFileTest() throws BrutException { + compareXmlFiles("res/xml/ww_box_styles_schema.xsd"); + } } diff --git a/brut.apktool/apktool-lib/src/test/resources/aapt1/testapp/res/values/public.xml b/brut.apktool/apktool-lib/src/test/resources/aapt1/testapp/res/values/public.xml index 4a0a3a39..86c77ede 100644 --- a/brut.apktool/apktool-lib/src/test/resources/aapt1/testapp/res/values/public.xml +++ b/brut.apktool/apktool-lib/src/test/resources/aapt1/testapp/res/values/public.xml @@ -1,4 +1,5 @@ + \ No newline at end of file diff --git a/brut.apktool/apktool-lib/src/test/resources/aapt1/testapp/res/xml/ww_box_styles_schema.xsd b/brut.apktool/apktool-lib/src/test/resources/aapt1/testapp/res/xml/ww_box_styles_schema.xsd new file mode 100644 index 00000000..70bfc6c3 --- /dev/null +++ b/brut.apktool/apktool-lib/src/test/resources/aapt1/testapp/res/xml/ww_box_styles_schema.xsd @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/brut.apktool/apktool-lib/src/test/resources/aapt2/testapp/res/xml/ww_box_styles_schema.xsd b/brut.apktool/apktool-lib/src/test/resources/aapt2/testapp/res/xml/ww_box_styles_schema.xsd new file mode 100644 index 00000000..70bfc6c3 --- /dev/null +++ b/brut.apktool/apktool-lib/src/test/resources/aapt2/testapp/res/xml/ww_box_styles_schema.xsd @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file