| 1 |
/* |
| 2 |
* Copyright (C) 2010 Ryszard Wiśniewski <[email protected]> |
| 3 |
* Copyright (C) 2010 Connor Tumbleson <[email protected]> |
| 4 |
* |
| 5 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 |
* you may not use this file except in compliance with the License. |
| 7 |
* You may obtain a copy of the License at |
| 8 |
* |
| 9 |
* https://www.apache.org/licenses/LICENSE-2.0 |
| 10 |
* |
| 11 |
* Unless required by applicable law or agreed to in writing, software |
| 12 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 13 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 |
* See the License for the specific language governing permissions and |
| 15 |
* limitations under the License. |
| 16 |
*/ |
| 17 |
package brut.androlib.aapt1; |
| 18 |
|
| 19 |
import brut.androlib.Androlib; |
| 20 |
import brut.androlib.ApkDecoder; |
| 21 |
import brut.androlib.BaseTest; |
| 22 |
import brut.androlib.TestUtils; |
| 23 |
import brut.common.BrutException; |
| 24 |
import brut.directory.ExtFile; |
| 25 |
import brut.util.OS; |
| 26 |
import org.junit.AfterClass; |
| 27 |
import org.junit.BeforeClass; |
| 28 |
import org.junit.Test; |
| 29 |
|
| 30 |
import java.io.File; |
| 31 |
import java.io.IOException; |
| 32 |
import java.nio.file.Files; |
| 33 |
import java.nio.file.Paths; |
| 34 |
|
| 35 |
import static org.junit.Assert.assertEquals; |
| 36 |
|
| 37 |
public class DefaultBaksmaliVariableTest extends BaseTest { |
| 38 |
|
| 39 |
@BeforeClass |
| 40 |
public static void beforeClass() throws Exception { |
| 41 |
sTmpDir = new ExtFile(OS.createTempDirectory()); |
| 42 |
sTestOrigDir = new ExtFile(sTmpDir, "testjar-orig"); |
| 43 |
sTestNewDir = new ExtFile(sTmpDir, "testjar-new"); |
| 44 |
LOGGER.info("Unpacking testjar..."); |
| 45 |
TestUtils.copyResourceDir(DefaultBaksmaliVariableTest.class, "aapt1/issue1481/", sTestOrigDir); |
| 46 |
|
| 47 |
LOGGER.info("Building issue1481.jar..."); |
| 48 |
File testJar = new File(sTmpDir, "issue1481.jar"); |
| 49 |
new Androlib().build(sTestOrigDir, testJar); |
| 50 |
|
| 51 |
LOGGER.info("Decoding issue1481.jar..."); |
| 52 |
ApkDecoder apkDecoder = new ApkDecoder(testJar); |
| 53 |
apkDecoder.setOutDir(sTestNewDir); |
| 54 |
apkDecoder.decode(); |
| 55 |
} |
| 56 |
|
| 57 |
@AfterClass |
| 58 |
public static void afterClass() throws BrutException { |
| 59 |
OS.rmdir(sTmpDir); |
| 60 |
} |
| 61 |
|
| 62 |
@Test |
| 63 |
public void confirmBaksmaliParamsAreTheSame() throws BrutException, IOException { |
| 64 |
String expected = TestUtils.replaceNewlines(".class public final Lcom/ibotpeaches/issue1481/BuildConfig;\n" + |
| 65 |
".super Ljava/lang/Object;\n" + |
| 66 |
".source \"BuildConfig.java\"\n" + |
| 67 |
"\n" + |
| 68 |
"\n" + |
| 69 |
"# static fields\n" + |
| 70 |
".field public static final APPLICATION_ID:Ljava/lang/String; = \"com.ibotpeaches.issue1481\"\n" + |
| 71 |
"\n" + |
| 72 |
".field public static final BUILD_TYPE:Ljava/lang/String; = \"debug\"\n" + |
| 73 |
"\n" + |
| 74 |
".field public static final DEBUG:Z\n" + |
| 75 |
"\n" + |
| 76 |
".field public static final FLAVOR:Ljava/lang/String; = \"\"\n" + |
| 77 |
"\n" + |
| 78 |
".field public static final VERSION_CODE:I = 0x1\n" + |
| 79 |
"\n" + |
| 80 |
".field public static final VERSION_NAME:Ljava/lang/String; = \"1.0\"\n" + |
| 81 |
"\n" + |
| 82 |
"\n" + |
| 83 |
"# direct methods\n" + |
| 84 |
".method static constructor <clinit>()V\n" + |
| 85 |
" .locals 1\n" + |
| 86 |
"\n" + |
| 87 |
" .prologue\n" + |
| 88 |
" .line 7\n" + |
| 89 |
" const-string v0, \"true\"\n" + |
| 90 |
"\n" + |
| 91 |
" invoke-static {v0}, Ljava/lang/Boolean;->parseBoolean(Ljava/lang/String;)Z\n" + |
| 92 |
"\n" + |
| 93 |
" move-result v0\n" + |
| 94 |
"\n" + |
| 95 |
" sput-boolean v0, Lcom/ibotpeaches/issue1481/BuildConfig;->DEBUG:Z\n" + |
| 96 |
"\n" + |
| 97 |
" return-void\n" + |
| 98 |
".end method\n" + |
| 99 |
"\n" + |
| 100 |
".method public constructor <init>()V\n" + |
| 101 |
" .locals 0\n" + |
| 102 |
"\n" + |
| 103 |
" .prologue\n" + |
| 104 |
" .line 6\n" + |
| 105 |
" invoke-direct {p0}, Ljava/lang/Object;-><init>()V\n" + |
| 106 |
"\n" + |
| 107 |
" return-void\n" + |
| 108 |
".end method"); |
| 109 |
|
| 110 |
byte[] encoded = Files.readAllBytes(Paths.get(sTestNewDir + File.separator + "smali" + File.separator |
| 111 |
+ "com" + File.separator + "ibotpeaches" + File.separator + "issue1481" + File.separator + "BuildConfig.smali")); |
| 112 |
|
| 113 |
String obtained = TestUtils.replaceNewlines(new String(encoded)); |
| 114 |
assertEquals(expected, obtained); |
| 115 |
} |
| 116 |
} |