diff --git a/docs/analysisinput.md b/docs/analysisinput.md index 4bcd03312b6..2aea18d6af0 100644 --- a/docs/analysisinput.md +++ b/docs/analysisinput.md @@ -105,16 +105,49 @@ AnalysisInputLocation jimpleLocation = new JimpleAnalysisInputLocation(path); JavaView view = new JavaView(jimpleLocation); ``` - ### Android Bytecode File-Extensions: `.apk` +The `ApkAnalysisInputLocation` is the APK frontend written for Sootup + +```java +Path path = Paths.get("Banana.apk"); +AnalysisInputLocation inputLocation = new ApkAnalysisInputLocation(path, "", DexBodyInterceptors.Default.bodyInterceptors()); +JavaView view = new JavaView(inputLocation); +``` + + +### Android Bytecode with Dex2Jar +File-Extensions: `.apk` + The `ApkAnalysisInputLocation` currently uses dex2jar internally ```java Path path = Paths.get("Banana.apk"); -AnalysisInputLocation inputLocation = new ApkAnalysisInputLocation(path); +AnalysisInputLocation inputLocation = new Dex2JarAnalysisInputLocation(path); JavaView view = new JavaView(inputLocation); + +``` + +```java +public class Dex2JarAnalysisInputLocation extends ArchiveBasedAnalysisInputLocation { + + public Dex2JarAnalysisInputLocation(@Nonnull Path path, @Nullable SourceType srcType) { + super(path, srcType); + String jarPath = dex2jar(path); + this.path = Paths.get(jarPath); + } + + private String dex2jar(Path path) { + String apkPath = path.toAbsolutePath().toString(); + String outDir = "./tmp/"; + int start = apkPath.lastIndexOf(File.separator); + int end = apkPath.lastIndexOf(".apk"); + String outputFile = outDir + apkPath.substring(start + 1, end) + ".jar"; + Dex2jarCmd.main("-f", apkPath, "-o", outputFile); + return outputFile; + } +} ``` !!! info "A SootUp solution to directly generate Jimple is WIP!" diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/ApkAnalysisInputLocation.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/ApkAnalysisInputLocation.java deleted file mode 100644 index 091c97e538a..00000000000 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/ApkAnalysisInputLocation.java +++ /dev/null @@ -1,50 +0,0 @@ -package sootup.java.bytecode.inputlocation; - -/*- - * #%L - * Soot - * %% - * Copyright (C) 2018-2020 Manuel Benz, Christian Brüggemann, Markus Schmidt and others - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * #L% - */ - -import com.googlecode.dex2jar.tools.Dex2jarCmd; -import java.io.File; -import java.nio.file.Path; -import java.nio.file.Paths; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import sootup.core.model.SourceType; - -public class ApkAnalysisInputLocation extends ArchiveBasedAnalysisInputLocation { - - public ApkAnalysisInputLocation(@Nonnull Path path, @Nullable SourceType srcType) { - super(path, srcType); - String jarPath = dex2jar(path); - this.path = Paths.get(jarPath); - } - - private String dex2jar(Path path) { - String apkPath = path.toAbsolutePath().toString(); - String outDir = "./tmp/"; - int start = apkPath.lastIndexOf(File.separator); - int end = apkPath.lastIndexOf(".apk"); - String outputFile = outDir + apkPath.substring(start + 1, end) + ".jar"; - Dex2jarCmd.main("-f", apkPath, "-o", outputFile); - return outputFile; - } -} diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/ApkAnalysisInputLocationTest.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/ApkAnalysisInputLocationTest.java deleted file mode 100644 index 8b3275f49e3..00000000000 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/ApkAnalysisInputLocationTest.java +++ /dev/null @@ -1,42 +0,0 @@ -package sootup.java.bytecode.inputlocation; - -/*- - * #%L - * Soot - * %% - * Copyright (C) 06.06.2018 Manuel Benz - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * #L% - */ - -import categories.TestCategories; -import java.util.Collections; -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; -import sootup.core.inputlocation.AnalysisInputLocation; -import sootup.core.types.ClassType; - -@Tag(TestCategories.JAVA_8_CATEGORY) -public class ApkAnalysisInputLocationTest extends AnalysisInputLocationTest { - - @Test - public void testApk() { - AnalysisInputLocation pathBasedNamespace = new ApkAnalysisInputLocation(apk, null); - final ClassType mainClass = - getIdentifierFactory().getClassType("de.upb.futuresoot.fields.MainActivity"); - testClassReceival(pathBasedNamespace, Collections.singletonList(mainClass), 1392); - } -} diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocationTest.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocationTest.java index 49f59bc2e9e..cd9f2726ae5 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocationTest.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocationTest.java @@ -55,15 +55,6 @@ @Tag(TestCategories.JAVA_8_CATEGORY) public class PathBasedAnalysisInputLocationTest extends AnalysisInputLocationTest { - @Test - public void testApk() { - PathBasedAnalysisInputLocation pathBasedNamespace = - new ApkAnalysisInputLocation(apk, SourceType.Application); - final ClassType mainClass = - getIdentifierFactory().getClassType("de.upb.futuresoot.fields.MainActivity"); - testClassReceival(pathBasedNamespace, Collections.singletonList(mainClass), 1392); - } - @Test public void testSingleClass() { PathBasedAnalysisInputLocation pathBasedNamespace =