Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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.");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright (C) 2010 Ryszard Wiśniewski <brut.alll@gmail.com>
* Copyright (C) 2010 Connor Tumbleson <connor.tumbleson@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
*
* 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"));
}
}
Binary file not shown.
Loading