Java Code Examples for org.apache.bcel.Constants#CONSTANT_InterfaceMethodref

The following examples show how to use org.apache.bcel.Constants#CONSTANT_InterfaceMethodref . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Constant.java    From ApkToolPlus with Apache License 2.0 6 votes vote down vote up
/**
 * Read one constant from the given file, the type depends on a tag byte.
 *
 * @param file Input stream
 * @return Constant object
 */
static final Constant readConstant(DataInputStream file)
  throws IOException, ClassFormatException
{
  byte b = file.readByte(); // Read tag byte

  switch(b) {
  case Constants.CONSTANT_Class:              return new ConstantClass(file);
  case Constants.CONSTANT_Fieldref:           return new ConstantFieldref(file);
  case Constants.CONSTANT_Methodref:          return new ConstantMethodref(file);
  case Constants.CONSTANT_InterfaceMethodref: return new 
			ConstantInterfaceMethodref(file);
  case Constants.CONSTANT_String:             return new ConstantString(file);
  case Constants.CONSTANT_Integer:            return new ConstantInteger(file);
  case Constants.CONSTANT_Float:              return new ConstantFloat(file);
  case Constants.CONSTANT_Long:               return new ConstantLong(file);
  case Constants.CONSTANT_Double:             return new ConstantDouble(file);
  case Constants.CONSTANT_NameAndType:        return new ConstantNameAndType(file);
  case Constants.CONSTANT_Utf8:               return new ConstantUtf8(file);
  default:                          
    throw new ClassFormatException("Invalid byte tag in constant pool: " + b);
  }
}
 
Example 2
Source File: Pass2Verifier.java    From ApkToolPlus with Apache License 2.0 5 votes vote down vote up
public void visitConstantInterfaceMethodref(ConstantInterfaceMethodref obj){
	if (obj.getTag() != Constants.CONSTANT_InterfaceMethodref){
		throw new ClassConstraintException("Wrong constant tag in '"+tostring(obj)+"'.");
	}
	checkIndex(obj, obj.getClassIndex(), CONST_Class);
	checkIndex(obj, obj.getNameAndTypeIndex(), CONST_NameAndType);
}
 
Example 3
Source File: Pass2Verifier.java    From ApkToolPlus with Apache License 2.0 5 votes vote down vote up
public void visitConstantInterfaceMethodref(ConstantInterfaceMethodref obj){
	if (obj.getTag() != Constants.CONSTANT_InterfaceMethodref){
		throw new ClassConstraintException("ConstantInterfaceMethodref '"+tostring(obj)+"' has wrong tag!");
	}
	int name_and_type_index = obj.getNameAndTypeIndex();
	ConstantNameAndType cnat = (ConstantNameAndType) (cp.getConstant(name_and_type_index));
	String name = ((ConstantUtf8) (cp.getConstant(cnat.getNameIndex()))).getBytes(); // Field or Method name
	if (!validInterfaceMethodName(name)){
		throw new ClassConstraintException("Invalid (interface) method name '"+name+"' referenced by '"+tostring(obj)+"'.");
	}

	int class_index = obj.getClassIndex();
	ConstantClass cc = (ConstantClass) (cp.getConstant(class_index));
	String className = ((ConstantUtf8) (cp.getConstant(cc.getNameIndex()))).getBytes(); // Class Name in internal form
	if (! validClassName(className)){
		throw new ClassConstraintException("Illegal class name '"+className+"' used by '"+tostring(obj)+"'.");
	}

	String sig  = ((ConstantUtf8) (cp.getConstant(cnat.getSignatureIndex()))).getBytes(); // Field or Method signature(=descriptor)
				
	try{
		Type   t  = Type.getReturnType(sig);
		if ( name.equals(STATIC_INITIALIZER_NAME) && (t != Type.VOID) ){
			addMessage("Class or interface initialization method '"+STATIC_INITIALIZER_NAME+"' usually has VOID return type instead of '"+t+"'. Note this is really not a requirement of The Java Virtual Machine Specification, Second Edition.");
		}
	}
	catch (ClassFormatError cfe){
		// Well, BCEL sometimes is a little harsh describing exceptional situations.
		throw new ClassConstraintException("Illegal descriptor (==signature) '"+sig+"' used by '"+tostring(obj)+"'.");
	}

}
 
Example 4
Source File: ConstantInterfaceMethodref.java    From ApkToolPlus with Apache License 2.0 4 votes vote down vote up
/**
 * Initialize from another object.
 */
public ConstantInterfaceMethodref(ConstantInterfaceMethodref c) {
  super(Constants.CONSTANT_InterfaceMethodref, c.getClassIndex(), c.getNameAndTypeIndex());
}
 
Example 5
Source File: ConstantInterfaceMethodref.java    From ApkToolPlus with Apache License 2.0 4 votes vote down vote up
/**
 * @param class_index Reference to the class containing the method
 * @param name_and_type_index and the method signature
 */
public ConstantInterfaceMethodref(int class_index, 
		    int name_and_type_index) {
  super(Constants.CONSTANT_InterfaceMethodref, class_index, name_and_type_index);
}
 
Example 6
Source File: ConstantPool.java    From ApkToolPlus with Apache License 2.0 4 votes vote down vote up
/**
 * Resolve constant to a string representation.
 *
 * @param  constant Constant to be printed
 * @return String representation
 */
public String constantToString(Constant c)
     throws ClassFormatException  
{
  String   str;
  int      i;
  byte     tag = c.getTag();

  switch(tag) {
  case Constants.CONSTANT_Class: 
    i   = ((ConstantClass)c).getNameIndex();
    c   = getConstant(i, Constants.CONSTANT_Utf8);
    str = Utility.compactClassName(((ConstantUtf8)c).getBytes(), false);
    break;

  case Constants.CONSTANT_String:
    i   = ((ConstantString)c).getStringIndex();
    c   = getConstant(i, Constants.CONSTANT_Utf8);
    str = "\"" + escape(((ConstantUtf8)c).getBytes()) + "\"";
    break;

  case Constants.CONSTANT_Utf8:    str = ((ConstantUtf8)c).getBytes();         break;
  case Constants.CONSTANT_Double:  str = "" + ((ConstantDouble)c).getBytes();  break;
  case Constants.CONSTANT_Float:   str = "" + ((ConstantFloat)c).getBytes();   break;
  case Constants.CONSTANT_Long:    str = "" + ((ConstantLong)c).getBytes();    break;
  case Constants.CONSTANT_Integer: str = "" + ((ConstantInteger)c).getBytes(); break;

  case Constants.CONSTANT_NameAndType:
    str = (constantToString(((ConstantNameAndType)c).getNameIndex(),
	      Constants.CONSTANT_Utf8) + " " +
    constantToString(((ConstantNameAndType)c).getSignatureIndex(),
	      Constants.CONSTANT_Utf8));
    break;

  case Constants.CONSTANT_InterfaceMethodref: case Constants.CONSTANT_Methodref:
  case Constants.CONSTANT_Fieldref:
    str = (constantToString(((ConstantCP)c).getClassIndex(),
	      Constants.CONSTANT_Class) + "." + 
    constantToString(((ConstantCP)c).getNameAndTypeIndex(),
	      Constants.CONSTANT_NameAndType));	     
    break;

  default: // Never reached
    throw new RuntimeException("Unknown constant type " + tag);
  }
	
  return str;
}
 
Example 7
Source File: ConstantInterfaceMethodref.java    From ApkToolPlus with Apache License 2.0 2 votes vote down vote up
/**
 * Initialize instance from file data.
 *
 * @param file input stream
 * @throws IOException
 */
ConstantInterfaceMethodref(DataInputStream file) throws IOException
{
  super(Constants.CONSTANT_InterfaceMethodref, file);
}