total rework

git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@244 379699f6-c40d-0410-875b-85095c16579e
stable
jochen 26 years ago
parent 0ed411e832
commit 3e7e8ade3e
  1. 84
      jode/jode/obfuscator/ClassBundle.java

@ -19,82 +19,78 @@
package jode.obfuscator; package jode.obfuscator;
import jode.Obfuscator; import jode.Obfuscator;
import jode.bytecode.ClassInfo; import jode.bytecode.ClassInfo;
import java.io.*;
import java.util.*; import java.util.*;
public class ClassBundle { public class ClassBundle {
Hashtable loadedClasses = new Hashtable(); int preserveRule;
PackageIdentifier basePackage;
public ClassReachability getLoadedClass(String name) { public ClassBundle() {
return (ClassReachability) loadedClasses.get(name); basePackage = new PackageIdentifier(this, null, "", false);
basePackage.setReachable();
basePackage.setPreserved();
} }
public void loadClass(ClassInfo clazz) { public String getTypeAlias(String typeSig) {
if (loadedClasses.get(clazz.getName()) != null) { StringBuffer newSig = new StringBuffer();
Decompiler.err.println("warning: ignoring double class: " int index = 0, nextindex;
+ clazz.getName()); while ((nextindex = typeSig.indexOf('L', index)) != -1) {
return; newSig.append(typeSig.substring(index, nextindex+1));
index = typeSig.indexOf(';', nextindex);
String alias = basePackage.findAlias
(typeSig.substring(nextindex+1, index).replace('/','.'));
newSig.append(alias.replace('.', '/'));
} }
loadedClasses.put(clazz.getName(), return newSig.append(typeSig.substring(index)).toString();
new ClassReachability(this, clazz));
} }
public void loadClasses(String packageOrClass) { public Identifier getIdentifier(String name) {
if (ClassInfo.isPackage(packageOrClass)) { return basePackage.getIdentifier(name);
Enumeration enum = ClassInfo.getClasses(packageOrClass);
while (enum.hasMoreElements())
loadClass((ClassInfo)enum.nextElement());
} else
loadClass(ClassInfo.forName(packageOrClass));
}
public void markReachableField(String className, Type type, String name) {
ClassReachability cr = getLoadedClass(className);
if (cr != null)
cr.markReachableField(type, name);
} }
public void markReachable(String className) { public void loadClasses(String packageOrClass) {
ClassReachability cr = getLoadedClass(className); basePackage.loadClasses(packageOrClass);
if (cr != null)
cr.markReachableField(type, name);
} }
public void markPreservedField(String className, Type type, String name) { public void reachableIdentifier(String fqn, boolean isVirtual) {
ClassReachability cr = getLoadedClass(className); basePackage.reachableIdentifier(fqn, isVirtual);
if (cr != null)
cr.markPreservedField(type, name);
} }
public void markPreserved(int preserveRule, public void setPreserved(int preserveRule, Vector fullqualifiednames) {
Vector classnames, Vector methodnames) { this.preserveRule = preserveRule;
Enumeration enum = loadedClasses.elements();
Enumeration enum = fullqualifiednames.elements();
while (enum.hasMoreElements()) { while (enum.hasMoreElements()) {
((ClassReachability) enum.nextElement()) basePackage.preserveIdentifier((String) enum.nextElement());
.postInitialize();
} }
if (preserveRule != Obfuscator.PRESERVE_NONE) {
enum = loadedClasses.elements();
while (enum.hasMoreElements()) {
((ClassReachability) enum.nextElement())
.doPreserveRule(preserveRule);
}
}
/*XXX*/
} }
public void strip() { public void strip() {
basePackage.strip();
} }
public void buildTable(int renameRule) { public void buildTable(int renameRule) {
basePackage.buildTable(renameRule);
} }
public void readTable(String filename) { public void readTable(String filename) {
} }
public void writeTable(String filename) { public void writeTable(String filename) {
try {
PrintWriter out = new PrintWriter(new FileOutputStream(filename));
basePackage.writeTable(out);
out.close();
} catch (java.io.IOException ex) {
Obfuscator.err.println("Can't write rename table "+filename);
ex.printStackTrace();
}
} }
public void storeClasses(String destination) { public void storeClasses(String destination) {
basePackage.storeClasses(new File(destination));
} }
} }

Loading…
Cancel
Save