From 468ead8f100263673e94c2085f420b8e19185a54 Mon Sep 17 00:00:00 2001 From: Connor Tumbleson Date: Sun, 28 Mar 2021 07:44:16 -0400 Subject: [PATCH] test: add testcase for static field values --- .../res/src/DexStaticFieldValueTest.java | 91 ++++++++++++++++++ .../decode/issue2543/AndroidManifest.xml | 3 + .../resources/decode/issue2543/apktool.yml | 12 +++ .../resources/decode/issue2543/classes.dex | Bin 0 -> 540 bytes 4 files changed, 106 insertions(+) create mode 100644 brut.apktool/apktool-lib/src/test/java/brut/androlib/res/src/DexStaticFieldValueTest.java create mode 100644 brut.apktool/apktool-lib/src/test/resources/decode/issue2543/AndroidManifest.xml create mode 100644 brut.apktool/apktool-lib/src/test/resources/decode/issue2543/apktool.yml create mode 100644 brut.apktool/apktool-lib/src/test/resources/decode/issue2543/classes.dex diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/res/src/DexStaticFieldValueTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/res/src/DexStaticFieldValueTest.java new file mode 100644 index 00000000..a5b1de38 --- /dev/null +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/res/src/DexStaticFieldValueTest.java @@ -0,0 +1,91 @@ +/* + * 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 + * + * 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.res.src; + +import brut.androlib.*; +import brut.androlib.aapt2.BuildAndDecodeTest; +import brut.common.BrutException; +import brut.directory.ExtFile; +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 static org.junit.Assert.assertEquals; + +public class DexStaticFieldValueTest extends BaseTest { + + @BeforeClass + public static void beforeClass() throws Exception { + TestUtils.cleanFrameworkFile(); + + sTmpDir = new ExtFile(OS.createTempDirectory()); + sTestOrigDir = new ExtFile(sTmpDir, "issue2543-orig"); + sTestNewDir = new ExtFile(sTmpDir, "issue2543-new"); + LOGGER.info("Unpacking issue2543..."); + TestUtils.copyResourceDir(BuildAndDecodeTest.class, "decode/issue2543/", sTestOrigDir); + + ApkOptions apkOptions = new ApkOptions(); + + LOGGER.info("Building issue2543.apk..."); + File testApk = new File(sTmpDir, "issue2543.apk"); + new Androlib(apkOptions).build(sTestOrigDir, testApk); + + LOGGER.info("Decoding issue2543.apk..."); + ApkDecoder apkDecoder = new ApkDecoder(testApk); + apkDecoder.setOutDir(sTestNewDir); + apkDecoder.setBaksmaliDebugMode(false); + apkDecoder.decode(); + } + + @AfterClass + public static void afterClass() throws BrutException { + OS.rmdir(sTmpDir); + } + + @Test + public void disassembleDexFileToKeepDefaultParameters() throws IOException { + String expected = TestUtils.replaceNewlines( + ".class public LHelloWorld;\n" + + ".super Ljava/lang/Object;\n" + + "\n" + + "\n" + + "# static fields\n" + + ".field private static b:Z = false\n" + + "\n" + + ".field private static c:Z = true\n" + + "\n" + + "\n" + + "# direct methods\n" + + ".method public static main([Ljava/lang/String;)V\n" + + " .locals 1\n" + + "\n" + + " return-void\n" + + ".end method"); + + byte[] encoded = Files.readAllBytes(Paths.get(sTestNewDir + File.separator + "smali" + File.separator + + "HelloWorld.smali")); + + String obtained = TestUtils.replaceNewlines(new String(encoded)); + assertEquals(expected, obtained); + } +} diff --git a/brut.apktool/apktool-lib/src/test/resources/decode/issue2543/AndroidManifest.xml b/brut.apktool/apktool-lib/src/test/resources/decode/issue2543/AndroidManifest.xml new file mode 100644 index 00000000..37260b58 --- /dev/null +++ b/brut.apktool/apktool-lib/src/test/resources/decode/issue2543/AndroidManifest.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/brut.apktool/apktool-lib/src/test/resources/decode/issue2543/apktool.yml b/brut.apktool/apktool-lib/src/test/resources/decode/issue2543/apktool.yml new file mode 100644 index 00000000..7e576b37 --- /dev/null +++ b/brut.apktool/apktool-lib/src/test/resources/decode/issue2543/apktool.yml @@ -0,0 +1,12 @@ +version: 2.0.0 +apkFileName: issue2543.apk +isFrameworkApk: false +usesFramework: + ids: + - 1 +packageInfo: + forcedPackageId: '127' +versionInfo: + versionCode: '1' + versionName: '1.0' +compressionType: false \ No newline at end of file diff --git a/brut.apktool/apktool-lib/src/test/resources/decode/issue2543/classes.dex b/brut.apktool/apktool-lib/src/test/resources/decode/issue2543/classes.dex new file mode 100644 index 0000000000000000000000000000000000000000..69666d69bdd7f97774207650cd4334439960a2b5 GIT binary patch literal 540 zcmYjOF-yZ>5WO!+tqmHqB2*CUEJzErE)@g^=@3vTMARusLuiRfOMNf-A|5>M?!C)>+)F>2+09m4-u8~>%Nti8PvP0~&FA)ayH~p_KN|6- zAu<+`nYUX-%3`cUDyYbpfLj2R+yfYw2i?Eu{EFPfz!x&{132hcfpwq;>;Rl;0SqSY zvH-qe>V7}dO<6!swwz^=MV%?@6*5PV4nQ0NOKvwxlF{jClJq-Lb%*}7-$?v4ZX5^0 zD4cdgd1833sB>An_$T+KlR+9o4n&1wUHXHRd-;wf#?}EF9me15x$fW!%-PD8$~z8n z^c=rsFc)6(-oj7bOO2k=gThzpCGdcKGLs+F9lS0(VA;r%9f?&+dd^_)MU MsB8Kp`dj|vU$jO#`~Uy| literal 0 HcmV?d00001