diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/BinaryXmlResourceParser.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/BinaryXmlResourceParser.java index 4ce08f3c93..3b50115e62 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/BinaryXmlResourceParser.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/BinaryXmlResourceParser.java @@ -277,7 +277,7 @@ public String getAttributeNamespace(int index) { // namespace, but it's better than not resolving it at all. if (attr.ns < 0) { if (nameId.pkgId() == ResTable.APP_PACKAGE_ID) { - return getNonDefaultNamespaceUri(index); + return ResXmlUtils.ANDROID_RES_NS_AUTO; } if (nameId.pkgId() == ResTable.SYS_PACKAGE_ID) { return ResXmlUtils.ANDROID_RES_NS; @@ -292,7 +292,7 @@ public String getAttributeNamespace(int index) { return uri; } if (nameId.pkgId() == ResTable.APP_PACKAGE_ID) { - return getNonDefaultNamespaceUri(index); + return ResXmlUtils.ANDROID_RES_NS_AUTO; } return ResXmlUtils.ANDROID_RES_NS; } @@ -577,17 +577,6 @@ public int nextTag() throws XmlPullParserException, IOException { // Utility methods - private String getNonDefaultNamespaceUri(int pos) { - String prefix = getNamespacePrefix(pos); - if (prefix == null) { - // If we are here, there is some clever obfuscation going on. - // Our reference points to the namespace are gone. We have the namespaces that can't be touched in the - // opening tag, though no known way to correlate them at this time, so return the res-auto namespace. - return ResXmlUtils.ANDROID_RES_NS_AUTO; - } - return getNamespaceUri(pos); - } - private Attribute getAttribute(int index) { if (mEventType != START_TAG) { throw new IndexOutOfBoundsException("Parser must be on START_TAG to get attributes."); diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/res/decoder/StrippedNsTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/res/decoder/StrippedNsTest.java new file mode 100644 index 0000000000..30aeaede82 --- /dev/null +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/res/decoder/StrippedNsTest.java @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2010 Ryszard Wiśniewski + * Copyright (C) 2010 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 + * + * https://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.res.decoder; + +import brut.androlib.BaseTest; +import brut.androlib.ApkDecoder; +import brut.androlib.Config; + +import java.io.File; +import java.nio.file.Files; +import java.util.Arrays; + +import org.junit.*; +import static org.junit.Assert.*; + +public class StrippedNsTest extends BaseTest { + private static final String TEST_APK = "issue3533.apk"; + private static final String TEST_RES = "res/drawable/trap.xml"; + + private static final byte[] XML_HEADER = { + 0x3C, // < + 0x3F, // ? + 0x78, // x + 0x6D, // m + 0x6C, // l + 0x20, // (empty) + }; + + @BeforeClass + public static void beforeClass() throws Exception { + copyResourceDir(StrippedNsTest.class, "issue3533", sTmpDir); + } + + @Test + public void assertAssignsCorrectNamespace() throws Exception { + File testApk = new File(sTmpDir, TEST_APK); + File testDir = new File(testApk + ".out.none"); + new ApkDecoder(testApk, sConfig).decode(testDir); + + File decodedXml = new File(testDir, TEST_RES); + assertTrue(decodedXml.isFile()); + assertTrue(Arrays.equals(XML_HEADER, readHeaderOfFile(decodedXml, 6))); + + String content = new String(Files.readAllBytes(decodedXml.toPath()), "UTF-8"); + + // Ensure the wiped namespace was decoded as "test" and not "android" + assertTrue(content.contains("test:is_obfuscated")); + assertFalse(content.contains("android:is_obfuscated")); + } +} diff --git a/brut.apktool/apktool-lib/src/test/resources/issue3533/issue3533.apk b/brut.apktool/apktool-lib/src/test/resources/issue3533/issue3533.apk new file mode 100644 index 0000000000..732807bb43 Binary files /dev/null and b/brut.apktool/apktool-lib/src/test/resources/issue3533/issue3533.apk differ