| 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.decode; |
| 18 |
|
| 19 |
import brut.androlib.*; |
| 20 |
import brut.androlib.options.BuildOptions; |
| 21 |
import brut.common.BrutException; |
| 22 |
import brut.directory.ExtFile; |
| 23 |
import brut.util.OS; |
| 24 |
import org.junit.*; |
| 25 |
|
| 26 |
import java.io.File; |
| 27 |
import java.io.IOException; |
| 28 |
|
| 29 |
|
| 30 |
public class DuplicateDexTest extends BaseTest { |
| 31 |
|
| 32 |
@Before |
| 33 |
public void beforeClass() throws Exception { |
| 34 |
TestUtils.cleanFrameworkFile(); |
| 35 |
sTmpDir = new ExtFile(OS.createTempDirectory()); |
| 36 |
sTestOrigDir = new ExtFile(sTmpDir, "duplicatedex-orig"); |
| 37 |
sTestNewDir = new ExtFile(sTmpDir, "duplicatedex-new"); |
| 38 |
LOGGER.info("Unpacking duplicatedex.apk..."); |
| 39 |
TestUtils.copyResourceDir(DuplicateDexTest.class, "decode/duplicatedex", sTestOrigDir); |
| 40 |
} |
| 41 |
|
| 42 |
@After |
| 43 |
public void afterClass() throws BrutException { |
| 44 |
OS.rmdir(sTmpDir); |
| 45 |
} |
| 46 |
|
| 47 |
@Test(expected = AndrolibException.class) |
| 48 |
public void decodeAllSourcesShouldThrowException() throws BrutException, IOException { |
| 49 |
File testApk = new File(sTestOrigDir, "duplicatedex.apk"); |
| 50 |
|
| 51 |
LOGGER.info("Decoding duplicatedex.apk..."); |
| 52 |
ApkDecoder apkDecoder = new ApkDecoder(testApk); |
| 53 |
apkDecoder.setOutDir(sTestNewDir); |
| 54 |
apkDecoder.decode(); |
| 55 |
|
| 56 |
LOGGER.info("Building duplicatedex.apk..."); |
| 57 |
BuildOptions buildOptions = new BuildOptions(); |
| 58 |
new Androlib(buildOptions).build(sTestNewDir, testApk); |
| 59 |
} |
| 60 |
|
| 61 |
@Test |
| 62 |
public void decodeUsingOnlyMainClassesMode() throws BrutException, IOException { |
| 63 |
File testApk = new File(sTestOrigDir, "duplicatedex.apk"); |
| 64 |
|
| 65 |
LOGGER.info("Decoding duplicatedex.apk..."); |
| 66 |
ApkDecoder apkDecoder = new ApkDecoder(testApk); |
| 67 |
apkDecoder.setDecodeSources(ApkDecoder.DECODE_SOURCES_SMALI_ONLY_MAIN_CLASSES); |
| 68 |
apkDecoder.setOutDir(sTestNewDir); |
| 69 |
apkDecoder.decode(); |
| 70 |
|
| 71 |
LOGGER.info("Building duplicatedex.apk..."); |
| 72 |
BuildOptions buildOptions = new BuildOptions(); |
| 73 |
new Androlib(buildOptions).build(sTestNewDir, testApk); |
| 74 |
} |
| 75 |
|
| 76 |
} |