1 19 20 package jode.obfuscator.modules; 21 import jode.obfuscator.*; 22 23 import java.util.Collection ; 24 import java.util.Set ; 25 import java.util.HashSet ; 26 import java.util.Iterator ; 27 import java.util.Random ; 28 import java.lang.UnsupportedOperationException ; 29 30 31 public class NameSwapper implements Renamer { 32 private Random rand; 33 private Set packs, clazzes, methods, fields, locals; 34 35 public NameSwapper(boolean swapAll, long seed) { 36 if (swapAll) { 37 packs = clazzes = methods = fields = locals = new HashSet (); 38 } else { 39 packs = new HashSet (); 40 clazzes = new HashSet (); 41 methods = new HashSet (); 42 fields = new HashSet (); 43 locals = new HashSet (); 44 } 45 } 46 47 public NameSwapper(boolean swapAll) { 48 this(swapAll, System.currentTimeMillis()); 49 } 50 51 private class NameGenerator implements Iterator { 52 Collection pool; 53 54 NameGenerator(Collection c) { 55 pool = c; 56 } 57 58 public boolean hasNext() { 59 return true; 60 } 61 62 public Object next() { 63 int pos = rand.nextInt(pool.size()); 64 Iterator i = pool.iterator(); 65 while (pos > 0) 66 i.next(); 67 return (String ) i.next(); 68 } 69 70 public void remove() { 71 throw new UnsupportedOperationException (); 72 } 73 } 74 75 public final Collection getCollection(Identifier ident) { 76 if (ident instanceof PackageIdentifier) 77 return packs; 78 else if (ident instanceof ClassIdentifier) 79 return clazzes; 80 else if (ident instanceof MethodIdentifier) 81 return methods; 82 else if (ident instanceof FieldIdentifier) 83 return fields; 84 else if (ident instanceof LocalIdentifier) 85 return locals; 86 else 87 throw new IllegalArgumentException (ident.getClass().getName()); 88 } 89 90 public final void addIdentifierName(Identifier ident) { 91 getCollection(ident).add(ident.getName()); 92 } 93 94 public Iterator generateNames(Identifier ident) { 95 return new NameGenerator(getCollection(ident)); 96 } 97 } 98 99 100 | Popular Tags |