Initial commit from SVN.
This commit is contained in:
120
Obfuscation/src/com/de22/obfuscation/Main.java
Normal file
120
Obfuscation/src/com/de22/obfuscation/Main.java
Normal file
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* Copyright (c) 2008,2009 Declarative Engineering LLC.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Declarative Engineering LLC
|
||||
* verson 1 which accompanies this distribution, and is available at
|
||||
* http://declarativeengineering.com/legal/DE_Developer_License_v1.txt
|
||||
*/
|
||||
package com.de22.obfuscation;
|
||||
|
||||
import com.common.debug.Debug;
|
||||
import com.common.io.StreamSupport;
|
||||
import com.common.util.*;
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.Arrays;
|
||||
|
||||
/*
|
||||
* A runnable class that will read in class files, mangle them, and output them to another location.
|
||||
*/
|
||||
public class Main {
|
||||
/**
|
||||
* Main constructor.
|
||||
*/
|
||||
private Main() {
|
||||
}//Main()//
|
||||
/**
|
||||
* Mangles a class file.
|
||||
* @param args Four arguments are expected: <br>
|
||||
* args[0]: Whether to mangle the source file name.
|
||||
* args[1]: The input directory.
|
||||
* args[2]: The output directory for the classes in the previous input directory.
|
||||
* args[3]: The semi-colon separated package names to exclude. Package names must use '/' and not '.' as a separator. A value of ';' can be used if nothing is being passed.
|
||||
* args[4]: The semi-colon separated package names to include (exclusions are applied first). Package names must use '/' and not '.' as a separator.
|
||||
* args[5]: The external jar directory (containing jars used during the obfuscation but not obfuscated).
|
||||
* args[6]: The optional metadata file name (assumes the metadata file is located directly in the input directory).
|
||||
* args[7]: The optional metadata file output name (assumes the metadata file is located directly in the input directory).
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
/*
|
||||
ClassLoader loader = new ClassLoader() {
|
||||
private File root = new File("c:/data/workspace-deploy/archives/temp/contents_temp/");
|
||||
|
||||
protected Class findClass(String name) throws ClassNotFoundException {
|
||||
File file = new File(root, name.replace('.', '/') + ".class");
|
||||
Class result = null;
|
||||
|
||||
if(file.exists() && file.canRead()) {
|
||||
byte[] bytes = null;
|
||||
|
||||
try {
|
||||
bytes = StreamSupport.readBytes(file);
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
Debug.log(e);
|
||||
}//catch//
|
||||
|
||||
if(bytes != null) {
|
||||
result = defineClass(name, bytes, 0, bytes.length);
|
||||
}//if//
|
||||
}//if//
|
||||
|
||||
return result != null ? result : super.findClass(name);
|
||||
}//findClass()//
|
||||
public Class loadClass(String name) throws ClassNotFoundException {
|
||||
return super.loadClass(name);
|
||||
}//loadClass()//
|
||||
};
|
||||
|
||||
try {
|
||||
loader.loadClass("java.lang.String");
|
||||
Debug.log("Loaded String");
|
||||
}catch(Throwable e) {Debug.log(e);}
|
||||
|
||||
try {
|
||||
//loader.loadClass("java.lang.String[]");
|
||||
Class.forName("[Ljava.lang.String;");
|
||||
Debug.log("Loaded String[]");
|
||||
}catch(Throwable e) {Debug.log(e);}
|
||||
|
||||
try {
|
||||
loader.loadClass("com.de22.release.interfaces.IReleaseServerConnection");
|
||||
Class.forName("[Lcom.de22.release.interfaces.IReleaseServerConnection;");
|
||||
Debug.log("Loaded IProxyInterfaceLoader[]");
|
||||
}catch(Throwable e) {Debug.log(e);}
|
||||
*/
|
||||
boolean printInstructions = false;
|
||||
|
||||
try {
|
||||
if(args.length < 5) {
|
||||
printInstructions = true;
|
||||
}//if//
|
||||
else {
|
||||
boolean mangleSourceFileNames = Boolean.parseBoolean(args[0]);
|
||||
File inputDirectory = new File(args[1]);
|
||||
File outputDirectory = new File(args[2]);
|
||||
String exclusionsText = args[3].trim();
|
||||
IList exclusions = exclusionsText.length() == 0 || (exclusionsText.length() == 1 && exclusionsText.charAt(0) == ';') ? LiteList.EMPTY_LIST : new LiteList(exclusionsText.split(";"));
|
||||
IList inclusions = new LiteList(args[4].trim().split(";"));
|
||||
File mapping = new File(outputDirectory, "mapping.txt");
|
||||
DevelopmentMangler mangler = new DevelopmentMangler(exclusions, inclusions, inputDirectory, outputDirectory, args.length > 5 ? new File(args[5]) : null, args.length > 6 ? args[6] : null, args.length > 7 ? args[7] : null, mangleSourceFileNames);
|
||||
|
||||
mangler.mangleClasses();
|
||||
StreamSupport.writeText(mangler.getPairings(), mapping, "UTF8");
|
||||
}//else//
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
Debug.log(e);
|
||||
}//catch//
|
||||
|
||||
if(printInstructions) {
|
||||
Debug.log("Process was passed these arguments:");
|
||||
|
||||
for(int index = 0; index < args.length; index++) {
|
||||
Debug.log("arg[" + index + "]: '" + args[index] + "'");
|
||||
}//for//
|
||||
|
||||
Debug.log("Usage:\r\n arg[0]: Whether source file references should be obfuscated.\r\n arg[1]: The input directory (or file).\r\n arg[2]: The output directory.\r\n arg[3]: The semi-colon separated package names to exclude. Package names must use '/' and not '.' as a separator. A single semi-colon can be used for an empty set.\r\n arg[4]: The semi-colon separated package names to include (exclusions are applied first). Package names must use '/' and not '.' as a separator.\r\n arg[5]: The optional directory containing jars that won't be mangled, but will be used to load classes during mangling.\r\n arg[6]: The optional input metadata file name and extension (no path - assumes that it is directly in the input directory).\r\n arg[7]: The optional ouput metadata file name and extension (no path - assumes that it is directly in the input directory).");
|
||||
}//if//
|
||||
}//main()//
|
||||
}//Main//
|
||||
Reference in New Issue
Block a user