Merge branch 'master' into issue-1498

This commit is contained in:
Marvin Killing
2017-06-09 22:56:04 +02:00
committed by GitHub
39 changed files with 376 additions and 59 deletions

View File

@ -21,7 +21,6 @@ import brut.common.BrutException;
import brut.util.OS;
import java.io.File;
import java.io.IOException;
import java.util.logging.Logger;
import org.junit.*;
import static org.junit.Assert.*;
@ -29,10 +28,10 @@ import static org.junit.Assert.*;
public class AndResGuardTest {
@BeforeClass
public static void beforeClass() throws Exception, BrutException {
public static void beforeClass() throws Exception {
TestUtils.cleanFrameworkFile();
sTmpDir = new ExtFile(OS.createTempDirectory());
TestUtils.copyResourceDir(LargeIntsInManifestTest.class, "brut/apktool/issue1170/", sTmpDir);
TestUtils.copyResourceDir(AndResGuardTest.class, "brut/apktool/issue1170/", sTmpDir);
}
@AfterClass
@ -62,6 +61,4 @@ public class AndResGuardTest {
private static ExtFile sTmpDir;
private static ExtFile sTestOrigDir;
private final static Logger LOGGER = Logger.getLogger(BuildAndDecodeTest.class.getName());
}
}

View File

@ -33,7 +33,7 @@ import static org.junit.Assert.assertTrue;
public class BuildAndDecodeJarTest {
@BeforeClass
public static void beforeClass() throws Exception, BrutException {
public static void beforeClass() throws Exception {
TestUtils.cleanFrameworkFile();
sTmpDir = new ExtFile(OS.createTempDirectory());
sTestOrigDir = new ExtFile(sTmpDir, "testjar-orig");
@ -66,4 +66,4 @@ public class BuildAndDecodeJarTest {
private static ExtFile sTestNewDir;
private final static Logger LOGGER = Logger.getLogger(BuildAndDecodeJarTest.class.getName());
}
}

View File

@ -44,7 +44,7 @@ import javax.imageio.ImageIO;
public class BuildAndDecodeTest {
@BeforeClass
public static void beforeClass() throws Exception, BrutException {
public static void beforeClass() throws Exception {
TestUtils.cleanFrameworkFile();
sTmpDir = new ExtFile(OS.createTempDirectory());
@ -253,6 +253,11 @@ public class BuildAndDecodeTest {
compareValuesFiles("values-ast/strings.xml");
}
@Test
public void androidOStringTest() throws BrutException, IOException {
compareValuesFiles("values-ast/strings.xml");
}
@Test
public void twoLetterNotHandledAsBcpTest() throws BrutException, IOException {
checkFolderExists("res/values-fr");
@ -345,6 +350,89 @@ public class BuildAndDecodeTest {
assertEquals(controlImage.getRGB(30, 30), testImage.getRGB(30, 30));
}
@Test
public void issue1508Test() throws BrutException, IOException {
char slash = File.separatorChar;
String location = slash + "res" + slash + "drawable-xhdpi" + slash;
File control = new File((sTestOrigDir + location), "btn_zoom_up_normal.9.png");
File test = new File((sTestNewDir + location), "btn_zoom_up_normal.9.png");
BufferedImage controlImage = ImageIO.read(control);
BufferedImage testImage = ImageIO.read(test);
// 0, 0 = clear
assertEquals(controlImage.getRGB(0, 0), testImage.getRGB(0, 0));
// 30, 0 = black line
assertEquals(controlImage.getRGB(0, 30), testImage.getRGB(0, 30));
// 30, 30 = greyish button
assertEquals(controlImage.getRGB(30, 30), testImage.getRGB(30, 30));
}
@Test
public void issue1511Test() throws BrutException, IOException {
char slash = File.separatorChar;
String location = slash + "res" + slash + "drawable-xxhdpi" + slash;
File control = new File((sTestOrigDir + location), "textfield_activated_holo_dark.9.png");
File test = new File((sTestNewDir + location), "textfield_activated_holo_dark.9.png");
BufferedImage controlImage = ImageIO.read(control);
BufferedImage testImage = ImageIO.read(test);
// Check entire image as we cannot mess this up
final int w = controlImage.getWidth(),
h = controlImage.getHeight();
final int[] controlImageGrid = controlImage.getRGB(0, 0, w, h, null, 0, w);
final int[] testImageGrid = testImage.getRGB(0, 0, w, h, null, 0, w);
for (int i = 0; i < controlImageGrid.length; i++) {
assertEquals("Image lost Optical Bounds at i = " + i, controlImageGrid[i], testImageGrid[i]);
}
}
@Test
public void robust9patchTest() throws BrutException, IOException {
String[] ninePatches = {"ic_notification_overlay.9.png", "status_background.9.png",
"search_bg_transparent.9.png", "screenshot_panel.9.png", "recents_lower_gradient.9.png"};
char slash = File.separatorChar;
String location = slash + "res" + slash + "drawable-xxhdpi" + slash;
for (String ninePatch : ninePatches) {
File control = new File((sTestOrigDir + location), ninePatch);
File test = new File((sTestNewDir + location), ninePatch);
BufferedImage controlImage = ImageIO.read(control);
BufferedImage testImage = ImageIO.read(test);
int w = controlImage.getWidth(), h = controlImage.getHeight();
// Check the entire horizontal line
for (int i = 1; i < w; i++) {
if (isTransparent(controlImage.getRGB(i, 0))) {
assertTrue(isTransparent(testImage.getRGB(i, 0)));
} else {
assertEquals("Image lost npTc chunk on image " + ninePatch + " at (x, y) (" + i + "," + 0 + ")",
controlImage.getRGB(i, 0), testImage.getRGB(i, 0));
}
}
// Check the entire vertical line
for (int i = 1; i < h; i++) {
if (isTransparent(controlImage.getRGB(0, i))) {
assertTrue(isTransparent(testImage.getRGB(0, i)));
} else {
assertEquals("Image lost npTc chunk on image " + ninePatch + " at (x, y) (" + 0 + "," + i + ")",
controlImage.getRGB(0, i), testImage.getRGB(0, i));
}
}
}
}
@Test
public void drawableXxhdpiTest() throws BrutException, IOException {
compareResFolder("drawable-xxhdpi");
@ -465,6 +553,10 @@ public class BuildAndDecodeTest {
assertTrue(f.isDirectory());
}
private boolean isTransparent(int pixel) {
return pixel >> 24 == 0x00;
}
private void compareXmlFiles(String path, ElementQualifier qualifier) throws BrutException {
DetailedDiff diff;
try {

View File

@ -37,7 +37,7 @@ import static org.junit.Assert.assertTrue;
public class DebugTagRetainedTest {
@BeforeClass
public static void beforeClass() throws Exception, BrutException {
public static void beforeClass() throws Exception {
TestUtils.cleanFrameworkFile();
sTmpDir = new ExtFile(OS.createTempDirectory());
sTestOrigDir = new ExtFile(sTmpDir, "issue1235-orig");

View File

@ -18,12 +18,12 @@ import static org.junit.Assert.assertEquals;
public class DefaultBaksmaliVariableTest {
@BeforeClass
public static void beforeClass() throws Exception, BrutException {
public static void beforeClass() throws Exception {
sTmpDir = new ExtFile(OS.createTempDirectory());
sTestOrigDir = new ExtFile(sTmpDir, "testjar-orig");
sTestNewDir = new ExtFile(sTmpDir, "testjar-new");
LOGGER.info("Unpacking testjar...");
TestUtils.copyResourceDir(BuildAndDecodeJarTest.class, "brut/apktool/issue1481/", sTestOrigDir);
TestUtils.copyResourceDir(DefaultBaksmaliVariableTest.class, "brut/apktool/issue1481/", sTestOrigDir);
LOGGER.info("Building issue1481.jar...");
File testJar = new File(sTmpDir, "issue1481.jar");
@ -99,5 +99,5 @@ public class DefaultBaksmaliVariableTest {
private static ExtFile sTestOrigDir;
private static ExtFile sTestNewDir;
private final static Logger LOGGER = Logger.getLogger(BuildAndDecodeJarTest.class.getName());
private final static Logger LOGGER = Logger.getLogger(DefaultBaksmaliVariableTest.class.getName());
}

View File

@ -27,7 +27,6 @@ import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.util.logging.Logger;
import static org.junit.Assert.assertTrue;
@ -37,10 +36,10 @@ import static org.junit.Assert.assertTrue;
public class DoubleExtensionUnknownFileTest {
@BeforeClass
public static void beforeClass() throws Exception, BrutException {
public static void beforeClass() throws Exception {
TestUtils.cleanFrameworkFile();
sTmpDir = new ExtFile(OS.createTempDirectory());
TestUtils.copyResourceDir(LargeIntsInManifestTest.class, "brut/apktool/issue1244/", sTmpDir);
TestUtils.copyResourceDir(DoubleExtensionUnknownFileTest.class, "brut/apktool/issue1244/", sTmpDir);
}
@AfterClass
@ -67,6 +66,4 @@ public class DoubleExtensionUnknownFileTest {
}
private static ExtFile sTmpDir;
private final static Logger LOGGER = Logger.getLogger(BuildAndDecodeJarTest.class.getName());
}

View File

@ -0,0 +1,76 @@
/**
* Copyright 2014 Ryszard Wiśniewski <brut.alll@gmail.com>
* Copyright 2016 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
*
* 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;
import brut.directory.ExtFile;
import brut.common.BrutException;
import brut.util.OS;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.logging.Logger;
import static org.junit.Assert.assertEquals;
/**
* @author Connor Tumbleson <connor.tumbleson@gmail.com>
*/
public class ExternalEntityTest {
@BeforeClass
public static void beforeClass() throws Exception {
sOrigDir = new ExtFile(OS.createTempDirectory());
TestUtils.copyResourceDir(ExternalEntityTest.class, "brut/apktool/doctype/", sOrigDir);
LOGGER.info("Building doctype.apk...");
File testApk = new File(sOrigDir, "doctype.apk");
new Androlib().build(sOrigDir, testApk);
LOGGER.info("Decoding doctype.apk...");
ApkDecoder apkDecoder = new ApkDecoder(testApk);
apkDecoder.setOutDir(new File(sOrigDir + File.separator + "output"));
apkDecoder.decode();
}
@AfterClass
public static void afterClass() throws BrutException {
OS.rmdir(sOrigDir);
}
@Test
public void doctypeTest() throws BrutException, IOException {
String expected = TestUtils.replaceNewlines("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
"<manifest android:versionCode=\"1\" android:versionName=\"1.0\" hardwareAccelerated=\"true\" package=\"com.ibotpeaches.doctype\" platformBuildVersionCode=\"23\" platformBuildVersionName=\"6.0-2438415\"\n" +
" xmlns:android=\"http://schemas.android.com/apk/res/android\">\n" +
" <supports-screens android:anyDensity=\"true\" android:smallScreens=\"true\" android:normalScreens=\"true\" android:largeScreens=\"true\" android:resizeable=\"true\" android:xlargeScreens=\"true\" />\n" +
"</manifest>");
byte[] encoded = Files.readAllBytes(Paths.get(sOrigDir + File.separator + "output" + File.separator + "AndroidManifest.xml"));
String obtained = TestUtils.replaceNewlines(new String(encoded));
assertEquals(expected, obtained);
}
private static ExtFile sOrigDir;
private final static Logger LOGGER = Logger.getLogger(ExternalEntityTest.class.getName());
}

View File

@ -22,7 +22,6 @@ import brut.util.OS;
import java.io.*;
import java.io.File;
import java.io.IOException;
import java.util.logging.Logger;
import org.custommonkey.xmlunit.*;
import org.junit.*;
@ -32,7 +31,7 @@ import org.xml.sax.SAXException;
public class LargeIntsInManifestTest {
@BeforeClass
public static void beforeClass() throws Exception, BrutException {
public static void beforeClass() throws Exception {
TestUtils.cleanFrameworkFile();
sTmpDir = new ExtFile(OS.createTempDirectory());
TestUtils.copyResourceDir(LargeIntsInManifestTest.class, "brut/apktool/issue767/", sTmpDir);
@ -94,6 +93,4 @@ public class LargeIntsInManifestTest {
private static ExtFile sTmpDir;
private static ExtFile sTestOrigDir;
private static ExtFile sTestNewDir;
private final static Logger LOGGER = Logger.getLogger(BuildAndDecodeTest.class.getName());
}

View File

@ -35,10 +35,10 @@ import static org.junit.Assert.assertEquals;
public class MissingVersionManifestTest {
@BeforeClass
public static void beforeClass() throws Exception, BrutException {
public static void beforeClass() throws Exception {
TestUtils.cleanFrameworkFile();
sTmpDir = new ExtFile(OS.createTempDirectory());
TestUtils.copyResourceDir(LargeIntsInManifestTest.class, "brut/apktool/issue1264/", sTmpDir);
TestUtils.copyResourceDir(MissingVersionManifestTest.class, "brut/apktool/issue1264/", sTmpDir);
}
@AfterClass
@ -61,6 +61,4 @@ public class MissingVersionManifestTest {
}
private static ExtFile sTmpDir;
private final static Logger LOGGER = Logger.getLogger(BuildAndDecodeJarTest.class.getName());
}

View File

@ -17,7 +17,6 @@ package brut.androlib;
import brut.androlib.res.xml.ResXmlEncoders;
import org.junit.Test;
import java.util.logging.Logger;
import static org.junit.Assert.assertEquals;
@ -54,6 +53,4 @@ public class PositionalEnumerationTest {
private String enumerateArguments(String value) {
return ResXmlEncoders.enumerateNonPositionalSubstitutionsIfRequired(value);
}
private final static Logger LOGGER = Logger.getLogger(BuildAndDecodeJarTest.class.getName());
}

View File

@ -84,4 +84,4 @@ public class ProviderAttributeTest {
}
private static ExtFile sTmpDir;
}
}

View File

@ -25,7 +25,6 @@ import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.util.logging.Logger;
import static org.junit.Assert.assertEquals;
@ -35,10 +34,10 @@ import static org.junit.Assert.assertEquals;
public class ReferenceVersionCodeTest {
@BeforeClass
public static void beforeClass() throws Exception, BrutException {
public static void beforeClass() throws Exception {
TestUtils.cleanFrameworkFile();
sTmpDir = new ExtFile(OS.createTempDirectory());
TestUtils.copyResourceDir(LargeIntsInManifestTest.class, "brut/apktool/issue1234/", sTmpDir);
TestUtils.copyResourceDir(ReferenceVersionCodeTest.class, "brut/apktool/issue1234/", sTmpDir);
}
@AfterClass
@ -61,6 +60,4 @@ public class ReferenceVersionCodeTest {
}
private static ExtFile sTmpDir;
private final static Logger LOGGER = Logger.getLogger(BuildAndDecodeJarTest.class.getName());
}

View File

@ -25,7 +25,6 @@ import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.util.logging.Logger;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
@ -36,10 +35,10 @@ import static org.junit.Assert.assertNotSame;
public class UnknownCompressionTest {
@BeforeClass
public static void beforeClass() throws Exception, BrutException {
public static void beforeClass() throws Exception {
TestUtils.cleanFrameworkFile();
sTmpDir = new ExtFile(OS.createTempDirectory());
TestUtils.copyResourceDir(LargeIntsInManifestTest.class, "brut/apktool/unknown_compression/", sTmpDir);
TestUtils.copyResourceDir(UnknownCompressionTest.class, "brut/apktool/unknown_compression/", sTmpDir);
String apk = "deflated_unknowns.apk";
ApkOptions apkOptions = new ApkOptions();
@ -90,6 +89,4 @@ public class UnknownCompressionTest {
private static ExtFile sOriginalFile;
private static ExtFile sBuiltFile;
private final static Logger LOGGER = Logger.getLogger(BuildAndDecodeJarTest.class.getName());
}

View File

@ -25,7 +25,6 @@ import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.util.logging.Logger;
import static org.junit.Assert.assertTrue;
@ -66,6 +65,4 @@ public class VectorDrawableTest {
private static ExtFile sTmpDir;
private static ExtFile sTestOrigDir;
private final static Logger LOGGER = Logger.getLogger(VectorDrawableTest.class.getName());
}

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE manifest [<!ENTITY e1 SYSTEM 'http://ibotpeaches.com?z=APKTOOLXXE;'>]>
<manifest hardwareAccelerated="true" package="com.ibotpeaches.doctype" platformBuildVersionCode="24" platformBuildVersionName="6.0-2456767" xmlns:android="http://schemas.android.com/apk/res/android">
&e1;
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true"/>
</manifest>

View File

@ -0,0 +1,12 @@
version: 2.0.0
apkFileName: doctype.apk
isFrameworkApk: false
usesFramework:
ids:
- 1
packageInfo:
forced-package-id: '127'
versionInfo:
versionCode: '1'
versionName: '1.0'
compressionType: false

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 179 B

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="test1">"Forgot your username or password?\nVisit google.com/accounts/recovery."</string>
<string name="test2">Forgot your username or password?\n.Visit google.com/accounts/recovery</string>
<string name="test3"> (string8) "Forgot your username or password?\nVisit google.com/accounts/recovery."</string>
<string name="test4">Forgot your username or password?\nVisit google.com/accounts/recovery.</string>
<string name="test5">Forgot your username or password?
Visit google.com/accounts/recovery.</string>
</resources>

View File

@ -31,4 +31,14 @@ bar"</string>
<string name="test_string29" formatted="false">category=temp%temp%foo</string>
<string name="test_string30">res/foo/</string>
<string name="test_string31">res/foo</string>
<string name="test_string32">[<font size="17">TEST STRING</font>]</string>
<string name="test_string33"><font size="17">[TEST STRING]</font></string>
<string name="test_string34">[<font size="17">TEST STRING]</font></string>
<string name="test_string35"><font size="17">[TEST STRING</font>]</string>
<string name="test_string36"><font size="17">TEST STRING</font></string>
<string name="test_string37">[<font size="17">Ţåþ ţö ţýþé þåššŵöŕð one two three]</font></string>
<string name="test_string38">[<font size="17">Ţåþ ţö ţýþé þåššŵöŕð one two three</font>]</string>
<string name="test_string39"><font size="17">[Ţåþ ţö ţýþé þåššŵöŕð one two three</font>]</string>
<string name="test_string40">[<font size="17">]Ţåþ ţö ţýþé þåššŵöŕð one two three</font></string>
<string name="test_string41"><font size="17">[Ţåþ ţö ţýþé þåššŵöŕð one two three]</font></string>
</resources>