// Path: src/com/cc/dextamper/Configure.java
// public class Configure {
// 
// 	public int API_LEVEL = 16;
// 	public String inPath;
// 	public String outPath;
// 	public boolean hasModifed = false;	
// 	
// 	public Configure(String in, String out){
// 		this.inPath = in;
// 		this.outPath = out;
// 	}
// 	
// 	public Configure(String in, String out, int api){
// 		this(in, out);
// 		this.API_LEVEL = api;
// 	}
// 	
// }
// 
// Path: src/com/cc/dextamper/tamper/MergeDex.java
// public class MergeDex {
// 
// 	private String add_path;
// 	private Configure config;
// 	DexBackedDexFile dexfile;
// 	private Map<String, Integer> internedItem = new HashMap<>();
// 	private boolean ADD_ALL = false;
// 
// 	public MergeDex(Configure configure, String addpath) throws IOException{
// 		this.config = configure;
// 		this.add_path = addpath;
// 		if (configure.hasModifed) {
// 			dexfile = DexFileFactory.loadDexFile(configure.outPath, configure.API_LEVEL);
// 		}else{
// 			dexfile = DexFileFactory.loadDexFile(configure.inPath, configure.API_LEVEL);
// 		}
// 	}
// 	
// 	/*
// 	 * If you add a class name here, the class will be added to the new dex file
// 	 */
// 	public void addclassName(String className){
// 		className = className.replaceAll("\\.", "/");
// 		className = "L" + className + ";";
// 		if (!internedItem.containsKey(className)) {
// 			System.out.println(className);
// 			internedItem.put(className, 0);
// 		}
// 	}
// 	
// 	/*
// 	 * If you want to add all class except the class which has name starting with "Landroid"
// 	 * or "Ljava" or "Ldalvik", I will simply drop these kind of class and add the others.
// 	 * Just call this function
// 	 */
// 	public void addAllclass(){
// 		this.ADD_ALL = true;
// 	}
// 	
// 	public void merge(){
// 		try {
// 			DexBackedDexFile addfile = DexFileFactory.loadDexFile(add_path, config.API_LEVEL);
// 			dexfile.setaddDexFile(addfile, new FilterClassDef() {
// 				
// 				@Override
// 				public DexBackedClassDef rewrite(DexBackedClassDef classDef) {
// 					// TODO Auto-generated method stub
// 					String className = classDef.getType();
// 					if (ADD_ALL) {
// 						if (!className.startsWith("Landroid") && 
// 								!className.startsWith("Ljava") &&
// 								!className.startsWith("Ldalvik")) {
// 								return classDef;
// 						}else{
// 							return null;
// 						}
// 					}
// 					
// 					if (internedItem.containsKey(className)) {
// 						System.out.println("contain " + className);
// 						return classDef;
// 					}
// 					return null;
// 				}
// 			});
// 
// 			DexRewriter rewriter = new DexRewriter(new RewriterModule());
// 			DexFile rewrittenDexFile = rewriter.rewriteDexFile(dexfile);
// 			DexPool.writeTo(config.outPath, rewrittenDexFile);
// 			config.hasModifed = true;
// 		} catch (IOException e) {
// 			// TODO Auto-generated catch block
// 			e.printStackTrace();
// 		}
// 	}
// 	
// }


import java.io.IOException;
import com.cc.dextamper.Configure;
import com.cc.dextamper.tamper.MergeDex;
package com.cc.dextamper.sample;



public class AddClass {

	private static String path = "/Users/CwT/Documents/workspace/DexTamper/test/test.apk";
	private static String add_path = "/Users/CwT/Documents/workspace/DexTamper/test/add.apk";

	public static void main(String argv[]){
// Path: src/com/cc/dextamper/Configure.java
// public class Configure {
// 
// 	public int API_LEVEL = 16;
// 	public String inPath;
// 	public String outPath;
// 	public boolean hasModifed = false;	
// 	
// 	public Configure(String in, String out){
// 		this.inPath = in;
// 		this.outPath = out;
// 	}
// 	
// 	public Configure(String in, String out, int api){
// 		this(in, out);
// 		this.API_LEVEL = api;
// 	}
// 	
// }
// 
// Path: src/com/cc/dextamper/tamper/MergeDex.java
// public class MergeDex {
// 
// 	private String add_path;
// 	private Configure config;
// 	DexBackedDexFile dexfile;
// 	private Map<String, Integer> internedItem = new HashMap<>();
// 	private boolean ADD_ALL = false;
// 
// 	public MergeDex(Configure configure, String addpath) throws IOException{
// 		this.config = configure;
// 		this.add_path = addpath;
// 		if (configure.hasModifed) {
// 			dexfile = DexFileFactory.loadDexFile(configure.outPath, configure.API_LEVEL);
// 		}else{
// 			dexfile = DexFileFactory.loadDexFile(configure.inPath, configure.API_LEVEL);
// 		}
// 	}
// 	
// 	/*
// 	 * If you add a class name here, the class will be added to the new dex file
// 	 */
// 	public void addclassName(String className){
// 		className = className.replaceAll("\\.", "/");
// 		className = "L" + className + ";";
// 		if (!internedItem.containsKey(className)) {
// 			System.out.println(className);
// 			internedItem.put(className, 0);
// 		}
// 	}
// 	
// 	/*
// 	 * If you want to add all class except the class which has name starting with "Landroid"
// 	 * or "Ljava" or "Ldalvik", I will simply drop these kind of class and add the others.
// 	 * Just call this function
// 	 */
// 	public void addAllclass(){
// 		this.ADD_ALL = true;
// 	}
// 	
// 	public void merge(){
// 		try {
// 			DexBackedDexFile addfile = DexFileFactory.loadDexFile(add_path, config.API_LEVEL);
// 			dexfile.setaddDexFile(addfile, new FilterClassDef() {
// 				
// 				@Override
// 				public DexBackedClassDef rewrite(DexBackedClassDef classDef) {
// 					// TODO Auto-generated method stub
// 					String className = classDef.getType();
// 					if (ADD_ALL) {
// 						if (!className.startsWith("Landroid") && 
// 								!className.startsWith("Ljava") &&
// 								!className.startsWith("Ldalvik")) {
// 								return classDef;
// 						}else{
// 							return null;
// 						}
// 					}
// 					
// 					if (internedItem.containsKey(className)) {
// 						System.out.println("contain " + className);
// 						return classDef;
// 					}
// 					return null;
// 				}
// 			});
// 
// 			DexRewriter rewriter = new DexRewriter(new RewriterModule());
// 			DexFile rewrittenDexFile = rewriter.rewriteDexFile(dexfile);
// 			DexPool.writeTo(config.outPath, rewrittenDexFile);
// 			config.hasModifed = true;
// 		} catch (IOException e) {
// 			// TODO Auto-generated catch block
// 			e.printStackTrace();
// 		}
// 	}
// 	
// }


// Path: src/com/cc/dextamper/sample/AddClass.java
import java.io.IOException;
import com.cc.dextamper.Configure;
import com.cc.dextamper.tamper.MergeDex;

package com.cc.dextamper.sample;



public class AddClass {

	private static String path = "/Users/CwT/Documents/workspace/DexTamper/test/test.apk";
	private static String add_path = "/Users/CwT/Documents/workspace/DexTamper/test/add.apk";

	public static void main(String argv[]){
		Configure configure = new Configure(path, "out.dex");