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 @@ -21,7 +21,6 @@
import brut.util.OSDetection;
import brut.xml.XmlUtils;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;

import javax.imageio.ImageIO;
Expand Down Expand Up @@ -90,20 +89,22 @@ public void confirmManifestStructureTest() throws Exception {
@Test
public void confirmPlatformManifestValuesTest() throws Exception {
Document doc = XmlUtils.loadDocument(new File(sTestNewDir, "AndroidManifest.xml"));
Node application = doc.getElementsByTagName("manifest").item(0);
NamedNodeMap attrs = application.getAttributes();

Node platformBuildVersionNameAttr = attrs.getNamedItem("platformBuildVersionName");
assertEquals("6.0-2438415", platformBuildVersionNameAttr.getNodeValue());
String platformBuildVersionNameExpr = "/manifest/@platformBuildVersionName";
String platformBuildVersionNameValue = XmlUtils.evaluateXPath(doc, platformBuildVersionNameExpr, String.class);
assertEquals("6.0-2438415", platformBuildVersionNameValue);

Node platformBuildVersionCodeAttr = attrs.getNamedItem("platformBuildVersionCode");
assertEquals("23", platformBuildVersionCodeAttr.getNodeValue());
String platformBuildVersionCodeExpr = "/manifest/@platformBuildVersionCode";
String platformBuildVersionCodeValue = XmlUtils.evaluateXPath(doc, platformBuildVersionCodeExpr, String.class);
assertEquals("23", platformBuildVersionCodeValue);

Node compileSdkVersionAttr = attrs.getNamedItem("compileSdkVersion");
assertNull("compileSdkVersion should have been stripped", compileSdkVersionAttr);
String compileSdkVersionExpr = "/manifest/@compileSdkVersion";
Node compileSdkVersionNode = XmlUtils.evaluateXPath(doc, compileSdkVersionExpr, Node.class);
assertNull("compileSdkVersion should have been stripped", compileSdkVersionNode);

Node compileSdkVersionCodenameAttr = attrs.getNamedItem("compileSdkVersionCodename");
assertNull("compileSdkVersionCodename should have been stripped", compileSdkVersionCodenameAttr);
String compileSdkVersionCodenameExpr = "/manifest/@compileSdkVersionCodename";
Node compileSdkVersionCodenameNode = XmlUtils.evaluateXPath(doc, compileSdkVersionCodenameExpr, Node.class);
assertNull("compileSdkVersionCodename should have been stripped", compileSdkVersionCodenameNode);
}

@Test
Expand Down Expand Up @@ -199,8 +200,8 @@ public void valuesMaxLengthTest() throws Exception {
// valuesExtraLongTest covers this scenario, but we want a specific test
// for such an edge case.
String expression = "/resources/string[@name='long_string_32767']/text()";
String str = XmlUtils.evaluateXPath(doc, expression, String.class);
assertEquals(0x7FFF, str.length());
String value = XmlUtils.evaluateXPath(doc, expression, String.class);
assertEquals(0x7FFF, value.length());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,5 @@ public void checkIfDecodeSucceeds() throws Exception {
String expression = "/resources/string[@name]";
NodeList nodes = XmlUtils.evaluateXPath(doc, expression, NodeList.class);
assertEquals(1002, nodes.getLength());

new ApkBuilder(testDir, sConfig).build(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,5 @@ public void checkIfDecodeSucceeds() throws Exception {
String expression = "/resources/string[contains(@name, 'APKTOOL')]";
NodeList nodes = XmlUtils.evaluateXPath(doc, expression, NodeList.class);
assertEquals(0, nodes.getLength());

new ApkBuilder(testDir, sConfig).build(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@

import brut.xml.XmlUtils;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import java.io.File;

Expand Down Expand Up @@ -56,31 +54,26 @@ public void buildAndDecodeTest() {
public void netSecConfGeneric() throws Exception {
log("Verifying network security configuration file contains user and system certificates...");

// Load the XML document
Document doc = XmlUtils.loadDocument(new File(sTestNewDir, "res/xml/network_security_config.xml"));

// Check if 'system' certificate exists
String systemCertExpr = "/network-security-config/base-config/trust-anchors/certificates[@src='system']";
NodeList systemCertNodes = XmlUtils.evaluateXPath(doc, systemCertExpr, NodeList.class);
assertTrue(systemCertNodes.getLength() > 0);
Node systemCertNode = XmlUtils.evaluateXPath(doc, systemCertExpr, Node.class);
assertNotNull(systemCertNode);

// Check if 'user' certificate exists
String userCertExpr = "/network-security-config/base-config/trust-anchors/certificates[@src='user']";
NodeList userCertNodes = XmlUtils.evaluateXPath(doc, userCertExpr, NodeList.class);
assertTrue(userCertNodes.getLength() > 0);
Node userCertNode = XmlUtils.evaluateXPath(doc, userCertExpr, Node.class);
assertNotNull(userCertNode);
}

@Test
public void netSecConfInManifest() throws Exception {
log("Validating network security config in Manifest...");

// Load the XML document
Document doc = XmlUtils.loadDocument(new File(sTestNewDir, "AndroidManifest.xml"));

// Check if network security config attribute is set correctly
Node application = doc.getElementsByTagName("application").item(0);
NamedNodeMap attrs = application.getAttributes();
Node netSecConfAttr = attrs.getNamedItem("android:networkSecurityConfig");
assertEquals("@xml/network_security_config", netSecConfAttr.getNodeValue());
Document doc = XmlUtils.loadDocument(new File(sTestNewDir, "AndroidManifest.xml"), true);
String expression = "/manifest/application/@android:networkSecurityConfig";
String value = XmlUtils.evaluateXPath(doc, expression, String.class);
assertEquals("@xml/network_security_config", value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

import brut.xml.XmlUtils;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;

import java.io.File;

Expand Down Expand Up @@ -76,13 +74,9 @@ public void netSecConfGeneric() throws Exception {
public void netSecConfInManifest() throws Exception {
log("Validating network security config in Manifest...");

// Load the XML document
Document doc = XmlUtils.loadDocument(new File(sTestNewDir, "AndroidManifest.xml"));

// Check if network security config attribute is set correctly
Node application = doc.getElementsByTagName("application").item(0);
NamedNodeMap attrs = application.getAttributes();
Node netSecConfAttr = attrs.getNamedItem("android:networkSecurityConfig");
assertEquals("@xml/network_security_config", netSecConfAttr.getNodeValue());
Document doc = XmlUtils.loadDocument(new File(sTestNewDir, "AndroidManifest.xml"), true);
String expression = "/manifest/application/@android:networkSecurityConfig";
String value = XmlUtils.evaluateXPath(doc, expression, String.class);
assertEquals("@xml/network_security_config", value);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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;

import brut.xml.XmlUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Node;

import java.io.File;

import org.junit.*;
import static org.junit.Assert.*;

public class StrippedNamespaceTest extends BaseTest {
private static final String TEST_APK = "issue3533.apk";

@BeforeClass
public static void beforeClass() throws Exception {
copyResourceDir(StrippedNamespaceTest.class, "issue3533", sTmpDir);
}

@Test
public void checkAssignedNamespaceTest() throws Exception {
File testApk = new File(sTmpDir, TEST_APK);
File testDir = new File(testApk + ".out");
new ApkDecoder(testApk, sConfig).decode(testDir);

Document doc = XmlUtils.loadDocument(new File(testDir, "res/drawable/trap.xml"), true);
String expression = "/selector/item/@test:is_obfuscated";
Node node = XmlUtils.evaluateXPath(doc, expression, Node.class);
assertNotNull(node);
}
}

This file was deleted.

Loading