Skip to content

Commit

Permalink
letzte Anderungen fuer die Facharbeit
Browse files Browse the repository at this point in the history
Alle hiernach gemachten Aenderungen duerfen nicht
mehr in den Code fuer die
Facharbeit mit eingehen!
  • Loading branch information
liketechnik committed Feb 8, 2018
1 parent b762d32 commit 9f37fea
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 42 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ apply plugin: 'idea'
apply plugin: 'application'

group 'florian.simpleJavaObfuscator'
version '1.0'
version 'facharbeit'

mainClassName = 'florian.simpleJavaObfuscator.run.Run'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package florian.simpleJavaObfuscator.names;


import florian.simpleJavaObfuscator.util.obfuscation.INameGenerator;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.FieldVisitor;
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/florian/simpleJavaObfuscator/run/Run.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
* @date 14. Januar 2018
*/
public class Run {

public static void main(String[] args) throws IOException {
public static void main(String[] args) {

Parameter[] params = new Parameter[]{new ObfuscationTypeParam()};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
* @date 02 of Februar 2018
*/
public class Content {

public static byte[] getFileContent(File file) throws IOException {
byte[] input = new byte[(int) file.length()];
InputStream in = new FileInputStream(file);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ public class DefaultMappings implements INameGenerator {
private PrintWriter printWriter;

private Hashtable<String, String> obfuscatedClassNames = new Hashtable<>();
private Hashtable<String, Hashtable<String, Hashtable<String, String>>> obfuscatedMethodNames = new Hashtable<>(); // class, desc, name
private Hashtable<String, Hashtable<String, Hashtable<String, String>>> obfuscatedMethodNames = new Hashtable<>(); // class, params, name
private Hashtable<String, Hashtable<String, String>> obfuscatedFieldNames = new Hashtable<>(); // class, name

private Hashtable<String, HashSet<String>> methodDescs = new Hashtable<>(); // class

private char[] classLetters;
private Hashtable<String, Hashtable<String, char[]>> methodLetters; // class, desc
private Hashtable<String, Hashtable<String, char[]>> methodLetters; // class, params
private Hashtable<String, char[]> fieldLetters; // class

private int maxNumberOfAutoOverloading = 3;
Expand Down Expand Up @@ -59,11 +59,6 @@ public void setLog(PrintWriter printWriter) {
}
}

/**
*
* @param orig The fully qualified class name.
* @return
*/
@Override
public void createClassName(String orig) {
String result;
Expand All @@ -73,9 +68,9 @@ public void createClassName(String orig) {
origArr[i] = new StringBuilder(origArr[i]).reverse().toString();
}

result = origArr[1] + "/" + this.toString(this.classLetters);
result = origArr[1] + "/" + new String(this.classLetters);
} else {
result = this.toString(this.classLetters);
result = new String(this.classLetters);
}

obfuscatedClassNames.put(orig, result);
Expand All @@ -92,7 +87,7 @@ public String getClassName(String orig) {

@Override
public void createMethodName(String orig, String className, String descriptor) {
descriptor = descriptor.split("\\)")[0]; // only when parameters are different
String params = descriptor.split("\\)")[0]; // only when parameters are different

// if this is the first field from the class, initialize
if (!methodDescs.containsKey(className)) {
Expand All @@ -102,35 +97,35 @@ public void createMethodName(String orig, String className, String descriptor) {
}
// replace global ones with local ones that dont contain all classes
HashSet<String> methodDescs = this.methodDescs.get(className);
Hashtable<String, Hashtable<String, String>> obfuscatedMethodNames = this.obfuscatedMethodNames.get(className); // desc, name
Hashtable<String, Hashtable<String, String>> obfuscatedMethodNames = this.obfuscatedMethodNames.get(className); // params, name
Hashtable<String, char[]> methodLetters = this.methodLetters.get(className); // desc

// grouping methods by descriptor, only methods with new descriptor from need new name
if (!methodDescs.contains(descriptor)) {
// grouping methods by descriptor, only methods with known params need new name
if (!methodDescs.contains(params)) {
// initializing letter array and new hashables
obfuscatedMethodNames.put(descriptor, new Hashtable<>());
obfuscatedMethodNames.put(params, new Hashtable<>());

int additionalOffset = methodDescs.size() / maxNumberOfAutoOverloading; // start new names for methods with a new descriptor with another letter after certain number of overloads
char[] methodLettersChar = new char[]{'a'};
for (int i = 0; i < additionalOffset; i++) {
methodLettersChar = generateNextName(methodLettersChar);
}
methodLetters.put(descriptor, methodLettersChar);
methodLetters.put(params, methodLettersChar);

methodDescs.add(descriptor);
methodDescs.add(params);
}

String result = this.toString(methodLetters.get(descriptor));
obfuscatedMethodNames.get(descriptor).put(orig, result);
methodLetters.put(descriptor, this.generateNextName(methodLetters.get(descriptor)));
String result = new String(methodLetters.get(params));
obfuscatedMethodNames.get(params).put(orig, result);
methodLetters.put(params, this.generateNextName(methodLetters.get(params)));
}

public String getMethodName(String orig, String className, String descriptor) {
descriptor = descriptor.split("\\)")[0];
String params = descriptor.split("\\)")[0];
if (obfuscatedMethodNames.containsKey(className) && // check if methods from class are obfuscated
obfuscatedMethodNames.get(className).containsKey(descriptor) && // check if desc is obfuscated
obfuscatedMethodNames.get(className).get(descriptor).containsKey(orig)) { // check if method is obfuscated
return obfuscatedMethodNames.get(className).get(descriptor).get(orig);
obfuscatedMethodNames.get(className).containsKey(params) && // check if desc is obfuscated
obfuscatedMethodNames.get(className).get(params).containsKey(orig)) { // check if method is obfuscated
return obfuscatedMethodNames.get(className).get(params).get(orig);
}
return orig;
}
Expand All @@ -147,7 +142,7 @@ public void createFieldName(String orig, String className) {
Hashtable<String, String> obfuscatedFieldNames = this.obfuscatedFieldNames.get(className);

// store obfuscated name and generate next one
String result = this.toString(fieldLetters);
String result = new String(fieldLetters);
obfuscatedFieldNames.put(orig, result);
this.fieldLetters.put(className, generateNextName(fieldLetters));
}
Expand Down Expand Up @@ -183,12 +178,4 @@ private char[] generateNextName(char[] letters) {

return letters;
}

private String toString(char[] letters) {
StringBuilder name = new StringBuilder();
for (char letter : letters) {
name.append(letter);
}
return name.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ public static String getObfuscatedFieldTypeDescriptor(String orig, INameGenerato
}
parts[classIndex] = "L" + mappings.getClassName(parts[classIndex].substring(0, parts[classIndex].length() - 1)) + ";"; // remove semicolon (last char) [.substring()]
if (classIndex == 0) { // either class name at index 0
System.out.println("Replaced '" + orig + "' with '" + parts[classIndex] + "'.");
mappings.getLog().println("Replaced '" + orig + "' with '" + parts[classIndex] + "'.");
return parts[classIndex];
} else { // or class name at index 1, array declaration at index 0
System.out.println("Replaced '" + orig + "' with '" + parts[0] + parts[classIndex] + "'.");
mappings.getLog().println("Replaced '" + orig + "' with '" + parts[0] + parts[classIndex] + "'.");
return parts[0] + parts[classIndex];
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
* @date 12. Januar 2018
*/
public interface INameGenerator {

void createClassName(String orig);
String getClassName(String orig);

Expand All @@ -22,5 +21,4 @@ public interface INameGenerator {

PrintWriter getLog();
void setLog(PrintWriter printWriter);

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
* @date 24. Januar 2018
*/
public class ObfuscationTypeParam extends Parameter {

@Override
public String getId() {
return "obfuscationType";
Expand Down

0 comments on commit 9f37fea

Please sign in to comment.