package it.unisannio.srss.ame;

import it.unisannio.srss.ame.payloads.common.Utils;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;

import org.xml.sax.SAXException;

// "/home/danilo/git/androidmalwareengine/AndroidMalwareEngine/tools/HelloWorld/AndroidManifest.xml"
public class AndroidMalwareEngine {

	public final static String APKTOOL = "tools/apktool";
	
	
	public static void main(String[] args) throws ParserConfigurationException,
			SAXException, IOException, TransformerException {

		String apk = args[1];
		File apkFile = null;
		if (apk == null || !(apkFile = new File(apk)).canRead()) {
			System.err.println("APK not found!");
			System.exit(1);
			return;
		}
		
		File tmpDir = Files.createTempDirectory("srss",null).toFile();
		tmpDir.deleteOnExit();
		
		
		
		List<String> perms = new ArrayList<String>();
		perms.add("android.permission.READ_SMS");
		perms.add("android.permission.WRITE_EXTERNAL_STORAGE");
		perms.add("android.permission.READ_PHONE_STATE");
		Utils.updateManifest(new File(manifest), perms);
	}
}

@@ -474,16 +474,118 @@
 st.xml%22%0A
+// %22/home/ermanno/git/androidmalwareengine/AndroidMalwareEngine/tools/HelloWord//AndroidManifest.xml%22%0A
 public c
@@ -672,12 +672,9 @@
 l%22;%0A
-%09%0A%09
 %0A
+
 %09pub
@@ -820,17 +820,17 @@
  = args%5B
-1
+0
 %5D;%0A%09%09Fil
@@ -983,18 +983,16 @@
 rn;%0A%09%09%7D%0A
-%09%09
 %0A%09%09File 
@@ -1036,13 +1036,8 @@
 rss%22
-,null
 ).to
@@ -1046,16 +1046,19 @@
 le();%0A%09%09
+// 
 tmpDir.d
@@ -1074,22 +1074,173 @@
 it();%0A%09%09
-%0A%09%09%0A%09%09
+System.out.println(tmpDir.getAbsolutePath());%0A%09%09Runtime.getRuntime().exec(%0A%09%09%09%09APKTOOL + %22 ./apktool d -o %22 + tmpDir.getAbsolutePath()%0A%09%09%09%09%09%09+ %22 -f %22 + apk);
 %0A%09%09List%3C
@@ -1378,24 +1378,24 @@
 _STORAGE%22);%0A
-
 %09%09perms.add(
@@ -1434,16 +1434,113 @@
 TATE%22);%0A
+%09%09//Non trova il file!%0A%09%09String manifest = tmpDir.getAbsolutePath() + %22//AndroidManifest.xml%22;%0A%09%0A
 %09%09Utils.

Add apktool functionality but not read manifest from tmp folder