check Class names

getClassName/Type


git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@572 379699f6-c40d-0410-875b-85095c16579e
stable
jochen 26 years ago
parent 4ff13e22dd
commit 05fbbd1b57
  1. 111
      jode/jode/bytecode/ConstantPool.java

@ -45,50 +45,74 @@ public class ConstantPool {
Object[] constants; Object[] constants;
void checkClassName(String clName) throws ClassFormatException {
boolean start = true;
for (int i=0; i< clName.length(); i++) {
char c = clName.charAt(i);
if (c == '/')
start = true;
else if (start && Character.isJavaIdentifierStart(c))
start = false;
else if ((start && false /*XXX*/)
|| !Character.isJavaIdentifierPart(c))
throw new ClassFormatException("Illegal java class name: "
+ clName);
}
}
void checkTypeSig(String typesig, boolean isMethod) void checkTypeSig(String typesig, boolean isMethod)
throws ClassFormatException { throws ClassFormatException {
if (typesig.indexOf('.') != -1) try {
throw new ClassFormatException int i = 0;
("Type sig error: "+typesig); if (isMethod) {
int i = 0; if (typesig.charAt(i++) != '(')
if (isMethod) {
if (typesig.charAt(i++) != '(')
throw new ClassFormatException throw new ClassFormatException
("Type sig doesn't match tag: "+typesig); ("Type sig doesn't match tag: "+typesig);
for (; i< typesig.length(); i++) { while (typesig.charAt(i) != ')') {
if (typesig.charAt(i) == ')') while (typesig.charAt(i) == '[') {
break; i++;
while (typesig.charAt(i) == '[') if (i >= typesig.length())
i++; throw new ClassFormatException
if (typesig.charAt(i) == 'L') { ("Type sig error: "+typesig);
i = typesig.indexOf(';', i); }
if (i == -1) if (typesig.charAt(i) == 'L') {
int end = typesig.indexOf(';', i);
if (end == -1)
throw new ClassFormatException
("Type sig error: "+typesig);
checkClassName(typesig.substring(i+1, end));
i = end;
} else {
if ("ZBSCIJFD".indexOf(typesig.charAt(i)) == -1)
throw new ClassFormatException throw new ClassFormatException
("Type sig error: "+typesig); ("Type sig error: "+typesig);
} else { }
if ("ZBSCIJFD".indexOf(typesig.charAt(i)) == -1) i++;
}
i++;
}
while (typesig.charAt(i) == '[')
i++;
if (typesig.charAt(i) == 'L') {
int end = typesig.indexOf(';', i);
if (i == -1)
throw new ClassFormatException
("Type sig error: "+typesig);
checkClassName(typesig.substring(i+1, end));
i = end;
} else {
if ("ZBSCIJFD".indexOf(typesig.charAt(i)) == -1)
if (!isMethod || typesig.charAt(i) != 'V')
throw new ClassFormatException throw new ClassFormatException
("Type sig error: "+typesig); ("Type sig error: "+typesig);
}
} }
i++; if (i+1 != typesig.length())
}
while (typesig.charAt(i) == '[')
i++;
if (typesig.charAt(i) == 'L') {
i = typesig.indexOf(';', i);
if (i == -1)
throw new ClassFormatException throw new ClassFormatException
("Type sig error: "+typesig); ("Type sig error: "+typesig);
} else { } catch (StringIndexOutOfBoundsException ex) {
if ("ZBSCIJFD".indexOf(typesig.charAt(i)) == -1)
if (!isMethod || typesig.charAt(i) != 'V')
throw new ClassFormatException
("Type sig error: "+typesig);
}
if (i+1 != typesig.length())
throw new ClassFormatException throw new ClassFormatException
("Type sig error: "+typesig); ("Incomplete type sig: "+typesig);
}
} }
public ConstantPool () { public ConstantPool () {
@ -172,9 +196,9 @@ public class ConstantPool {
throw new ClassFormatException("Tag mismatch"); throw new ClassFormatException("Tag mismatch");
String type = getUTF8(indices2[nameTypeIndex]); String type = getUTF8(indices2[nameTypeIndex]);
checkTypeSig(type, tags[i] != FIELDREF); checkTypeSig(type, tags[i] != FIELDREF);
String clName = getClassType(classIndex);
constants[i] = new Reference constants[i] = new Reference
(getClassName(classIndex), (clName, getUTF8(indices1[nameTypeIndex]), type);
getUTF8(indices1[nameTypeIndex]), type);
} }
return (Reference) constants[i]; return (Reference) constants[i];
} }
@ -194,12 +218,29 @@ public class ConstantPool {
throw new ClassFormatException("Tag mismatch: "+tags[i]); throw new ClassFormatException("Tag mismatch: "+tags[i]);
} }
public String getClassType(int i) throws ClassFormatException {
if (i == 0)
return null;
if (tags[i] != CLASS)
throw new ClassFormatException("Tag mismatch");
String clName = getUTF8(indices1[i]);
if (clName.charAt(0) == '[')
checkTypeSig(clName, false);
else {
checkClassName(clName);
clName = "L"+clName+';';
}
return clName;
}
public String getClassName(int i) throws ClassFormatException { public String getClassName(int i) throws ClassFormatException {
if (i == 0) if (i == 0)
return null; return null;
if (tags[i] != CLASS) if (tags[i] != CLASS)
throw new ClassFormatException("Tag mismatch"); throw new ClassFormatException("Tag mismatch");
return getUTF8(indices1[i]).replace('/', '.'); String clName = getUTF8(indices1[i]);
checkClassName(clName);
return clName.replace('/','.');
} }
public String toString(int i) { public String toString(int i) {

Loading…
Cancel
Save