Skip to content

Commit

Permalink
Merge pull request #3 from ThisIsLibra/1.2-stable
Browse files Browse the repository at this point in the history
Version 1.2-stable
  • Loading branch information
ThisIsLibra authored Mar 14, 2019
2 parents e321079 + 680edf3 commit 7ea023c
Show file tree
Hide file tree
Showing 42 changed files with 757 additions and 266 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>libra</groupId>
<artifactId>AndroidProjectCreator</artifactId>
<version>1.1-stable</version>
<version>1.2-stable</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
170 changes: 147 additions & 23 deletions src/main/java/apc/AndroidProjectCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import enumeration.Action;
import enumeration.DecompilerType;
import java.io.File;
import model.ArgumentPackage;

/**
* This class serves as a front for a possible GUI. The 'ArgumentManager' class
Expand All @@ -44,42 +46,164 @@ public static void main(String[] args) {
*/
boolean debugging = false;
if (debugging) {
decompileTest(DecompilerType.CFR);
//installTest();
//updateTest();
decompileTest(DecompilerType.JEB3);
System.exit(0);
}

ArgumentManager manager = new ArgumentManager();
//Instantiate the ArgumentParser for later use
ArgumentParser argumentParser = new ArgumentParser();
//Instantiate the ArgumentManager for later use
ArgumentManager argumentManager = new ArgumentManager();
//Show the version information
manager.showVersion();
argumentManager.showVersion();
//Set the action, if there is an error, the Action.ERROR value is provided. This is all handled within the setArguments function
Action action = manager.setArguments(args);
ArgumentPackage argumentPackage = argumentParser.setArguments(args);
//If incorrect or unknown parameters are provided, APC provides feedback to the user and then terminates.
if (action == Action.ERROR) {
if (argumentPackage.getAction() == Action.ERROR) {
handleAction(argumentManager, args);
}
//Executes the action based on the return value of the setArguments function
argumentManager.execute(argumentPackage);
}

/**
* A method which is used during debugging to avoid mistakes in the code
*/
private static void installTest() {
ArgumentManager manager = new ArgumentManager();
manager.showVersion();
String[] args = new String[1];
args[0] = "-install";
ArgumentParser argumentParser = new ArgumentParser();
ArgumentPackage argumentPackage = argumentParser.setArguments(args);
manager.execute(argumentPackage);
}

/**
* A method which is used during debugging to avoid mistakes in the code
*/
private static void updateTest() {
ArgumentManager manager = new ArgumentManager();
manager.showVersion();
String[] args = new String[1];
args[0] = "-update";
ArgumentParser argumentParser = new ArgumentParser();
ArgumentPackage argumentPackage = argumentParser.setArguments(args);
manager.execute(argumentPackage);
}

/**
* A method which is used during debugging to avoid mistakes in the code
*
* @param decompiler the decompiler that should be used
*/
private static void decompileTest(DecompilerType decompiler) {
ArgumentManager manager = new ArgumentManager();
manager.showVersion();
String[] args;
if (decompiler == DecompilerType.JEB3) {
args = new String[5];
} else {
args = new String[4];
}
args[0] = "-decompile";
args[1] = decompiler.toString().toLowerCase();
args[2] = "/home/libra/Documents/apc-test/apk/challenge1_release.apk";
args[3] = "./test-output-guid-" + java.util.UUID.randomUUID();
if (decompiler == DecompilerType.JEB3) {
args[4] = "/home/libra/Downloads/jeb-pro";
}
ArgumentParser argumentParser = new ArgumentParser();
ArgumentPackage argumentPackage = argumentParser.setArguments(args);
manager.execute(argumentPackage);
}

//TODO refactor this method into the argument parser
private static void handleAction(ArgumentManager manager, String[] args) {
//If no arguments are given, the general usage information should be given
if (args.length == 0 || args.length == 1) {
manager.showUsage();
System.exit(1);
} else if (args.length > 4) {
//Since there is no option to support more than four arguments, this should be fixed first
System.out.println("\tAndroidProjectCreator does not support more than four arguments!");
} else {
//Obtain the provided arguments in a String-object for later use
String arguments = "";
//Concatenate the arguments behind one another
for (int i = 0; i < args.length; i++) {
arguments += args[i] + " ";
}
System.out.println("[+]The provided input has not been recognised by AndroidProjectCreator. Below is the information you've provided. \n Afterwards, the correct usage information is given below for an easy comparison.");
System.out.println("\t" + arguments);
System.out.println("");
manager.showUsage();
//Notify the user of the error
System.out.println("[+]The provided input has not been recognised by AndroidProjectCreator, the provided arguments are given below.\n");
//Display the received arguments back to the user
System.out.println("\t" + arguments + "\n");
//Loop through all of the arguments to display additional information
for (int i = 0; i < args.length; i++) {
switch (i) {
case 0:
//The first argument, in any case, is the requested method
System.out.println("\tThe requested method is:\t\t" + args[0]);
System.out.println("");
/**
* If this point is reached, either the "-decompile"
* method is called (since it requires more arguments
* than 1) or a non-existing method is called
*
*/
if (args[0].equalsIgnoreCase("-decompile")) {
System.out.println("\tThe embedded decompilers that are included are:");
for (DecompilerType decompilerType : DecompilerType.values()) {
if (decompilerType.toString().equalsIgnoreCase("apktool") || decompilerType.toString().equalsIgnoreCase("dex2jar")) {
continue;
}
System.out.println("\t\t" + decompilerType);
}
} else {
System.out.println("\tThe available methods are:");
for (Action method : Action.values()) {
if (method.toString().equalsIgnoreCase("error")) {
System.out.println("\t\t-HELP");
continue;
}
System.out.println("\t\t-" + method);
}
}
break;
case 1:
//If the decompile method is requested, the second argument is the requested decompiler
if (args[0].equalsIgnoreCase("-decompile")) {
System.out.println("\tThe requested decompiler is:\t\t" + args[1]);
} else {
//Notify the user that too many arguments are passed
System.out.println("\tOnly the \"-DECOMPILE\" option supports more than one argument!");
}
break;
case 2:
//If decompilation was chosen, the location of the APK file should also be provided
if (args[0].equalsIgnoreCase("-decompile")) {
//The location itself is shown
System.out.println("\tThe provided APK location is:\t\t" + args[2]);
File apk = new File(args[2]);
//At first, a check is done to see if the APK file actually exists, if this isn't the case, the user is notified
if (!apk.exists()) {
System.out.println("\t\tThe APK file does not exist!");
} else if (apk.exists() && apk.isFile()) { //If the file exists and is a file, the user is provided this information
System.out.println("\t\tThe APK file exists and is a file!");
} else if (apk.exists() && apk.isDirectory()) { //If the file is actually an existing folder, the user should know
System.out.println("\t\tThe APK file is not a file, but a folder!");
}
}
break;
default:
//The last argument of the decompilation method is the output location, this cannot be checked as it is made at the end of the decompilation process
break;
}
}
//Close APC with the 'unsuccessful' message, hence the '1' as parameter, instead of 0
System.exit(1);
}
//Executes the action based on the return value of the setArguments function
manager.executeAction(action);
}

private static void decompileTest(DecompilerType decompiler) {
ArgumentManager manager = new ArgumentManager();
manager.showVersion();
String[] arg = new String[4];
arg[0] = "-decompile";
arg[1] = decompiler.toString().toLowerCase();
arg[2] = "/Users/_taste/Desktop/secchating.apk";
arg[3] = "./procyon-test";
Action action = manager.setArguments(arg);
manager.executeAction(action);
}
}
Loading

0 comments on commit 7ea023c

Please sign in to comment.