Code with Finding: |
class ClassLoader {
/**
* Override this method to create you own classes on the fly. The
* name contains the special token $$BCEL$$. Everything before that
* token is considered to be a package name. You can encode your own
* arguments into the subsequent string. You must ensure however not
* to use any "illegal" characters, i.e., characters that may not
* appear in a Java class name too<br>
*
* The default implementation interprets the string as a encoded compressed
* Java class, unpacks and decodes it with the Utility.decode() method, and
* parses the resulting byte array and returns the resulting JavaClass object.
*
* @param class_name compressed byte code with "$$BCEL$$" in it
*/
protected JavaClass createClass( String class_name ) {
int index = class_name.indexOf(BCEL_TOKEN);
String real_name = class_name.substring(index + BCEL_TOKEN.length());
JavaClass clazz = null;
try {
byte[] bytes = Utility.decode(real_name, true);
ClassParser parser = new ClassParser(new ByteArrayInputStream(bytes), "foo");
clazz = parser.parse();
} catch (IOException e) {
e.printStackTrace();
return null;
}
// Adapt the class name to the passed value
ConstantPool cp = clazz.getConstantPool();
ConstantClass cl = (ConstantClass) cp.getConstant(clazz.getClassNameIndex(),
Constants.CONSTANT_Class);
ConstantUtf8 name = (ConstantUtf8) cp.getConstant(cl.getNameIndex(),
Constants.CONSTANT_Utf8);
name.setBytes(class_name.replace('.', '/'));
return clazz;
}
}
|