You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
141 lines
4.0 KiB
141 lines
4.0 KiB
/* StrongRenamer Copyright (C) 1999 Jochen Hoenicke.
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
* any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; see the file COPYING. If not, write to
|
|
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
*
|
|
* $Id$
|
|
*/
|
|
|
|
package jode.obfuscator;
|
|
import @COLLECTIONS@.Collection;
|
|
import @COLLECTIONS@.Iterator;
|
|
import @COLLECTIONEXTRA@.UnsupportedOperationException;
|
|
|
|
public class StrongRenamer implements Renamer, OptionHandler {
|
|
static String[] idents = {
|
|
"Package", "Class", "Field", "Method", "Local"
|
|
};
|
|
static String[] parts = {
|
|
"Start", "Part"
|
|
};
|
|
String charsets[][];
|
|
|
|
public StrongRenamer() {
|
|
charsets = new String[idents.length][parts.length];
|
|
for (int i=0; i< idents.length; i++)
|
|
for (int j=0; j< parts.length; j++)
|
|
charsets[i][j] = "abcdefghijklmnopqrstuvwxyz";
|
|
}
|
|
|
|
public void setOption(String option, Collection values) {
|
|
if (option.startsWith("charset")) {
|
|
Object value = values.iterator().next();
|
|
if (values.size() != 1 || !(value instanceof String))
|
|
throw new IllegalArgumentException
|
|
("Only string parameter are supported.");
|
|
String set = (String) value;
|
|
String remOpt = option.substring("charset".length());
|
|
int part = -1, ident = -1;
|
|
if (remOpt.length() > 0) {
|
|
for (int i=0; i < idents.length; i++) {
|
|
if (remOpt.startsWith(idents[i])) {
|
|
remOpt = option.substring(idents[i].length());
|
|
ident = i;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if (remOpt.length() > 0) {
|
|
for (int j=0; j < parts.length; j++) {
|
|
if (remOpt.startsWith(parts[j])) {
|
|
remOpt = option.substring(parts[j].length());
|
|
part = j;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if (remOpt.length() > 0)
|
|
throw new IllegalArgumentException("Invalid charset `"
|
|
+option+"'");
|
|
for (int i = 0; i < idents.length; i++) {
|
|
if (ident >= 0 && ident != i)
|
|
continue;
|
|
for (int j = 0; j < parts.length; j++) {
|
|
if (part >= 0 && part != j)
|
|
continue;
|
|
charsets[i][j] = set;
|
|
}
|
|
}
|
|
} else
|
|
throw new IllegalArgumentException("Invalid option `"
|
|
+option+"'");
|
|
}
|
|
|
|
public Iterator generateNames(Identifier ident) {
|
|
final String[] currCharset;
|
|
if (ident instanceof PackageIdentifier)
|
|
currCharset = charsets[0];
|
|
else if (ident instanceof PackageIdentifier)
|
|
currCharset = charsets[1];
|
|
else if (ident instanceof ClassIdentifier)
|
|
currCharset = charsets[2];
|
|
else if (ident instanceof FieldIdentifier)
|
|
currCharset = charsets[3];
|
|
else if (ident instanceof MethodIdentifier)
|
|
currCharset = charsets[4];
|
|
else if (ident instanceof LocalIdentifier)
|
|
currCharset = charsets[5];
|
|
else
|
|
throw new IllegalArgumentException(ident.getClass().getName());
|
|
|
|
return new Iterator() {
|
|
char[] name = null;
|
|
|
|
public boolean hasNext() {
|
|
return true;
|
|
}
|
|
public Object next() {
|
|
if (name == null) {
|
|
name = new char[] { currCharset[0].charAt(0) };
|
|
return new String(name);
|
|
}
|
|
|
|
int pos = name.length - 1;
|
|
String charset = currCharset[1];
|
|
while (pos >= 0) {
|
|
if (pos == 0)
|
|
charset = currCharset[0];
|
|
|
|
int index = charset.indexOf(name[pos]) + 1;
|
|
if (index < charset.length()) {
|
|
name[pos] = charset.charAt(index);
|
|
return new String(name);
|
|
}
|
|
name[pos--] = charset.charAt(0);
|
|
}
|
|
|
|
name = new char[name.length+1];
|
|
name[0] = currCharset[0].charAt(0);
|
|
char firstCont = currCharset[1].charAt(0);
|
|
for (int i=1; i <name.length; i++)
|
|
name[i] = firstCont;
|
|
return new String(name);
|
|
}
|
|
|
|
public void remove() {
|
|
throw new UnsupportedOperationException();
|
|
}
|
|
};
|
|
}
|
|
}
|
|
|