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

The following examples show how to use org.apache.bcel.Constants#INVOKEINTERFACE . 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: InstructionFactory.java    From ApkToolPlus with Apache License 2.0 6 votes vote down vote up
/** Create an invoke instruction.
 *
 * @param class_name name of the called class
 * @param name name of the called method
 * @param ret_type return type of method
 * @param arg_types argument types of method
 * @param kind how to invoke, i.e., INVOKEINTERFACE, INVOKESTATIC, INVOKEVIRTUAL,
 * or INVOKESPECIAL
 * @see Constants
 */
public InvokeInstruction createInvoke(String class_name, String name, Type ret_type,
			Type[] arg_types, short kind) {
  int    index;
  int    nargs      = 0;
  String signature  = Type.getMethodSignature(ret_type, arg_types);

  for(int i=0; i < arg_types.length; i++) // Count size of arguments
    nargs += arg_types[i].getSize();

  if(kind == Constants.INVOKEINTERFACE)
    index = cp.addInterfaceMethodref(class_name, name, signature);
  else
    index = cp.addMethodref(class_name, name, signature);

  switch(kind) {
  case Constants.INVOKESPECIAL:   return new INVOKESPECIAL(index);
  case Constants.INVOKEVIRTUAL:   return new INVOKEVIRTUAL(index);
  case Constants.INVOKESTATIC:    return new INVOKESTATIC(index);
  case Constants.INVOKEINTERFACE: return new INVOKEINTERFACE(index, nargs + 1);
  default:
    throw new RuntimeException("Oops: Unknown invoke kind:" + kind);
  }
}
 
Example 2
Source File: UrlRewritingDetector.java    From Android_Code_Arbiter with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void sawOpcode(int seen) {

    if (seen == Constants.INVOKEINTERFACE && getClassConstantOperand().equals("javax/servlet/http/HttpServletResponse")
            && (getNameConstantOperand().equals("encodeURL") || getNameConstantOperand().equals("encodeUrl") ||
            getNameConstantOperand().equals("encodeRedirectURL") || getNameConstantOperand().equals("encodeRedirectUrl"))) {

        bugReporter.reportBug(new BugInstance(this, URL_REWRITING, Priorities.HIGH_PRIORITY) //
                .addClass(this).addMethod(this).addSourceLine(this));
    }
}
 
Example 3
Source File: EsapiEncryptorDetector.java    From Android_Code_Arbiter with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void sawOpcode(int seen) {
    //printOpCode(seen);
    if (seen == Constants.INVOKEINTERFACE && getClassConstantOperand().equals("org/owasp/esapi/Encryptor") &&
            (getNameConstantOperand().equals("encrypt") || getNameConstantOperand().equals("decrypt"))) {

        bugReporter.reportBug(new BugInstance(this, ESAPI_ENCRYPTOR_TYPE, Priorities.NORMAL_PRIORITY) //
                .addClass(this).addMethod(this).addSourceLine(this));
    }
}
 
Example 4
Source File: FileUploadFilenameDetector.java    From Android_Code_Arbiter with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void sawOpcode(int seen) {

    if (seen == Constants.INVOKEINTERFACE &&
            (getClassConstantOperand().equals("org/apache/wicket/util/upload/FileItem") ||
                    getClassConstantOperand().equals("org/apache/commons/fileupload/FileItem")) &&
            getNameConstantOperand().equals("getName")) {
        bugReporter.reportBug(new BugInstance(this, FILE_UPLOAD_FILENAME_TYPE, Priorities.NORMAL_PRIORITY) //
                .addClass(this).addMethod(this).addSourceLine(this));
    }

}
 
Example 5
Source File: INVOKEINTERFACE.java    From ApkToolPlus with Apache License 2.0 5 votes vote down vote up
public INVOKEINTERFACE(int index, int nargs) {
  super(Constants.INVOKEINTERFACE, index);
  length = 5;

  if(nargs < 1)
    throw new ClassGenException("Number of arguments must be > 0 " + nargs);

  this.nargs = nargs;
}
 
Example 6
Source File: ServletEndpointDetector.java    From Android_Code_Arbiter with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void sawOpcode(int seen) {

    //All call to ServletRequest
    if (seen == Constants.INVOKEINTERFACE && (getClassConstantOperand().equals("javax/servlet/ServletRequest") ||
            getClassConstantOperand().equals("javax/servlet/http/HttpServletRequest"))) {

        //ServletRequest

        if (getNameConstantOperand().equals("getParameter") ||
                getNameConstantOperand().equals("getParameterValues") ||
                getNameConstantOperand().equals("getParameterMap") ||
                getNameConstantOperand().equals("getParameterNames")) {

            bugReporter.reportBug(new BugInstance(this, GET_PARAMETER_TYPE, Priorities.LOW_PRIORITY) //
                    .addClass(this).addMethod(this).addSourceLine(this)
                    .addString(getNameConstantOperand())); //Passing the method name
        } else if (getNameConstantOperand().equals("getContentType")) {

            bugReporter.reportBug(new BugInstance(this, CONTENT_TYPE, Priorities.LOW_PRIORITY) //
                    .addClass(this).addMethod(this).addSourceLine(this));
        } else if (getNameConstantOperand().equals("getServerName")) {

            bugReporter.reportBug(new BugInstance(this, SERVER_NAME_TYPE, Priorities.LOW_PRIORITY) //
                    .addClass(this).addMethod(this).addSourceLine(this));
        }

        //HttpServletRequest

        else if (getNameConstantOperand().equals("getRequestedSessionId")) {
            bugReporter.reportBug(new BugInstance(this, SESSION_ID_TYPE, Priorities.LOW_PRIORITY) //
                    .addClass(this).addMethod(this).addSourceLine(this));
        } else if (getNameConstantOperand().equals("getQueryString")) {

            bugReporter.reportBug(new BugInstance(this, QUERY_STRING_TYPE, Priorities.LOW_PRIORITY) //
                    .addClass(this).addMethod(this).addSourceLine(this));
        } else if (getNameConstantOperand().equals("getHeader")) {
            //Extract the value being push..
            OpcodeStack.Item top = stack.getStackItem(0);
            String value = (String) top.getConstant();//Safe see if condition
            if ("Host".equals(value)) {

                bugReporter.reportBug(new BugInstance(this, SERVER_NAME_TYPE, Priorities.LOW_PRIORITY) //
                        .addClass(this).addMethod(this).addSourceLine(this));
            } else if ("Referer".equalsIgnoreCase(value)) {

                bugReporter.reportBug(new BugInstance(this, HEADER_REFERER_TYPE, Priorities.LOW_PRIORITY) //
                        .addClass(this).addMethod(this).addSourceLine(this));
            } else if ("User-Agent".equalsIgnoreCase(value)) {

                bugReporter.reportBug(new BugInstance(this, HEADER_USER_AGENT_TYPE, Priorities.LOW_PRIORITY) //
                        .addClass(this).addMethod(this).addSourceLine(this));
            } else {

                bugReporter.reportBug(new BugInstance(this, HEADER_TYPE, Priorities.LOW_PRIORITY) //
                        .addClass(this).addMethod(this).addSourceLine(this));
            }
        }
    }
}