package uk.ac.cam.gpe21.droidssl.analysis;

import soot.*;
import soot.options.Options;

import java.util.Arrays;
import java.util.Map;

public final class StaticAnalyser {
	public static void main(String[] args) {
		/*
		 * Set path to input APK.
		 */
		Options.v().set_src_prec(Options.src_prec_apk);
		Options.v().set_process_dir(Arrays.asList("test-hv/build/apk/test-hv-release-unsigned.apk"));

		/*
		 * Prevent Soot from outputting *.jimple files.
		 */
		Options.v().set_output_format(Options.output_format_none);

		/*
		 * Set the path to the Android SDK.
		 */
		Options.v().set_android_jars("/opt/android/platforms");

		/*
		 * Enable the SPARK points-to analysis.
		 */
		Options.v().set_whole_program(true);
		PhaseOptions.v().processPhaseOptions("cg.spark", "enabled:true");

		/*
		 * Add transforms to the Whole Jimple Pre-processing Pack.
		 */
		Pack wjpp = PackManager.v().getPack("wjpp");
		wjpp.add(new Transform("wjpp.activity_entry_transformer", new ActivityEntryTransformer()));
		wjpp.add(new Transform("wjpp.known_vulnerable_class_tagger", new KnownVulnerableClassTagger()));

		/*
		 * Add transforms to the Jimple Transformation Pack.
		 */
		Pack jtp = PackManager.v().getPack("jtp");
		jtp.add(new Transform("jtp.jsse_hostname_verifier", new JsseHostnameVerifierTransformer()));
		jtp.add(new Transform("jtp.httpclient_hostname_verifier", new HttpClientHostnameVerifierTransformer()));
		jtp.add(new Transform("jtp.default_jsse_hostname_verifier", new DefaultJsseHostnameVerifierTransformer()));

		/*
		 * Add transforms for the Whole Jimple Transformation Pack.
		 */
		Pack wjtp = PackManager.v().getPack("wjtp");
		wjtp.add(new Transform("wjtp.print_call_graph", new SceneTransformer() {
			@Override
			protected void internalTransform(String phase, Map<String, String> options) {
				System.err.print(Scene.v().getCallGraph());
			}
		}));

		/*
		 * Perform the analysis.
		 */
		Scene.v().loadNecessaryClasses();
		PackManager.v().runPacks();
	}
}

@@ -110,30 +110,8 @@
 ays;
-%0Aimport java.util.Map;
 %0A%0Apu
@@ -1505,358 +1505,8 @@
 );%0A%0A
-%09%09/*%0A%09%09 * Add transforms for the Whole Jimple Transformation Pack.%0A%09%09 */%0A%09%09Pack wjtp = PackManager.v().getPack(%22wjtp%22);%0A%09%09wjtp.add(new Transform(%22wjtp.print_call_graph%22, new SceneTransformer() %7B%0A%09%09%09@Override%0A%09%09%09protected void internalTransform(String phase, Map%3CString, String%3E options) %7B%0A%09%09%09%09System.err.print(Scene.v().getCallGraph());%0A%09%09%09%7D%0A%09%09%7D));%0A%0A
 %09%09/*

Remove code to print the call graph.