org.apache.bcel.Constants Java Examples

The following examples show how to use org.apache.bcel.Constants. 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: ConstantValue.java    From ApkToolPlus with Apache License 2.0 6 votes vote down vote up
/**
 * @return String representation of constant value.
 */ 
public final String toString() {
  Constant c = constant_pool.getConstant(constantvalue_index);
	
  String   buf;
  int    i;

  // Print constant to string depending on its type
  switch(c.getTag()) {
  case Constants.CONSTANT_Long:    buf = "" + ((ConstantLong)c).getBytes();    break;
  case Constants.CONSTANT_Float:   buf = "" + ((ConstantFloat)c).getBytes();   break;
  case Constants.CONSTANT_Double:  buf = "" + ((ConstantDouble)c).getBytes();  break;
  case Constants.CONSTANT_Integer: buf = "" + ((ConstantInteger)c).getBytes(); break;
  case Constants.CONSTANT_String:  
    i   = ((ConstantString)c).getStringIndex();
    c   = constant_pool.getConstant(i, Constants.CONSTANT_Utf8);
    buf = "\"" + Utility.convertString(((ConstantUtf8)c).getBytes()) + "\"";
    break;

  default:
    throw new IllegalStateException("Type of ConstValue invalid: " + c);
  }

  return buf;
}
 
Example #2
Source File: ExceptionTable.java    From ApkToolPlus with Apache License 2.0 6 votes vote down vote up
/**
  * @return String representation, i.e., a list of thrown exceptions.
  */ 
 public final String toString() {
   StringBuffer buf = new StringBuffer("");
   String       str;

   for(int i=0; i < number_of_exceptions; i++) {
     str = constant_pool.getConstantString(exception_index_table[i],
				    Constants.CONSTANT_Class);
     buf.append(Utility.compactClassName(str, false));

     if(i < number_of_exceptions - 1)
buf.append(", ");
   }

   return buf.toString();    
 }
 
Example #3
Source File: InvokeInstruction.java    From ApkToolPlus with Apache License 2.0 6 votes vote down vote up
/**
  * Also works for instructions whose stack effect depends on the
  * constant pool entry they reference.
  * @return Number of words consumed from stack by this instruction
  */
 public int consumeStack(ConstantPoolGen cpg) {
     String signature = getSignature(cpg);
     Type[] args      = Type.getArgumentTypes(signature);
     int    sum;

     if(opcode == Constants.INVOKESTATIC)
sum = 0;
     else
sum = 1;  // this reference

     int n = args.length;
     for (int i = 0; i < n; i++)
sum += args[i].getSize();

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

    if (seen == Constants.INVOKEVIRTUAL && getClassConstantOperand().equals("javax/servlet/http/Cookie")
            && getNameConstantOperand().equals("setMaxAge")) {

        Object maxAge = stack.getStackItem(0).getConstant();
        Integer n = (maxAge instanceof Integer) ? (Integer)maxAge : 0;

        //Max age equal or greater than one year
        if (n >= 31536000) {
            bugReporter.reportBug(new BugInstance(this, "COOKIE_PERSISTENT", Priorities.NORMAL_PRIORITY) //
                    .addClass(this).addMethod(this).addSourceLine(this));
        }
    }
}
 
Example #5
Source File: BasicType.java    From ApkToolPlus with Apache License 2.0 6 votes vote down vote up
public static final BasicType getType(byte type) {
  switch(type) {
  case Constants.T_VOID:    return VOID;
  case Constants.T_BOOLEAN: return BOOLEAN;
  case Constants.T_BYTE:    return BYTE;
  case Constants.T_SHORT:   return SHORT;
  case Constants.T_CHAR:    return CHAR;
  case Constants.T_INT:     return INT;
  case Constants.T_LONG:    return LONG;
  case Constants.T_DOUBLE:  return DOUBLE;
  case Constants.T_FLOAT:   return FLOAT;

  default:
    throw new ClassGenException("Invalid type: " + type);
  }
}
 
Example #6
Source File: TaintFrameModelingVisitor.java    From Android_Code_Arbiter with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void handleStoreInstruction(StoreInstruction obj) {
    try {
        int numConsumed = obj.consumeStack(cpg);
        if (numConsumed == Constants.UNPREDICTABLE) {
            throw new InvalidBytecodeException("Unpredictable stack consumption");
        }
        int index = obj.getIndex();
        while (numConsumed-- > 0) {
            Taint value = new Taint(getFrame().popValue());
            value.setVariableIndex(index);
            getFrame().setValue(index++, value);
        }
    } catch (DataflowAnalysisException ex) {
        throw new InvalidBytecodeException(ex.toString(), ex);
    }
}
 
Example #7
Source File: TransitiveHull.java    From commons-bcel with Apache License 2.0 6 votes vote down vote up
private void visitRef(final ConstantCP ccp, final boolean method) {
    final String class_name = ccp.getClass(cp);
    add(class_name);

    final ConstantNameAndType cnat = (ConstantNameAndType) cp.getConstant(ccp.getNameAndTypeIndex(),
            Constants.CONSTANT_NameAndType);

    final String signature = cnat.getSignature(cp);

    if (method) {
        final Type type = Type.getReturnType(signature);

        checkType(type);

        for (final Type type1 : Type.getArgumentTypes(signature)) {
            checkType(type1);
        }
    } else {
        checkType(Type.getType(signature));
    }
}
 
Example #8
Source File: LocalVariableInstruction.java    From ApkToolPlus with Apache License 2.0 6 votes vote down vote up
/**
  * Read needed data (e.g. index) from file.
  * PRE: (ILOAD <= tag <= ALOAD_3) || (ISTORE <= tag <= ASTORE_3)
  */
 protected void initFromFile(ByteSequence bytes, boolean wide)
   throws IOException
 {
   if(wide) {
     n         = bytes.readUnsignedShort();
     length    = 4;
   } else if(((opcode >= Constants.ILOAD) &&
       (opcode <= Constants.ALOAD)) ||
      ((opcode >= Constants.ISTORE) &&
       (opcode <= Constants.ASTORE))) {
     n      = bytes.readUnsignedByte();
     length = 2;
   } else if(opcode <= Constants.ALOAD_3) { // compact load instruction such as ILOAD_2
     n      = (opcode - Constants.ILOAD_0) % 4;
     length = 1;
   } else { // Assert ISTORE_0 <= tag <= ASTORE_3
     n      = (opcode - Constants.ISTORE_0) % 4;
     length = 1;
   }
}
 
Example #9
Source File: RsaNoPaddingDetector.java    From Android_Code_Arbiter with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void sawOpcode(int seen) {
    if (seen == Constants.INVOKESTATIC
            && getClassConstantOperand().equals("javax/crypto/Cipher")
            && getNameConstantOperand().equals("getInstance")) {
        OpcodeStack.Item item = stack.getStackItem(getSigConstantOperand().contains(";L") ? 1 : 0);
        if (StackUtils.isConstantString(item)) {
            String cipherValue = (String) item.getConstant();
            // default padding for "RSA" only is PKCS1 so it is not reported
            if (cipherValue.startsWith("RSA/") && cipherValue.endsWith("/NoPadding")) {
                bugReporter.reportBug(new BugInstance(this, RSA_NO_PADDING_TYPE, Priorities.NORMAL_PRIORITY) //
                        .addClass(this).addMethod(this).addSourceLine(this));
            }
        }
    }
}
 
Example #10
Source File: StickyBroadcastDetector.java    From Android_Code_Arbiter with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
    public void sawOpcode(int seen) {
        //printOpCode(seen);

        // getClassConstantOperand().equals("java/net/Socket")

        if (seen == Constants.INVOKEVIRTUAL && ( //List of method mark as external file access
                getNameConstantOperand().equals("sendStickyBroadcast") ||
                        getNameConstantOperand().equals("sendStickyOrderedBroadcast") ||
                        getNameConstantOperand().equals("sendStickyBroadcastAsUser") ||
                        getNameConstantOperand().equals("sendStickyOrderedBroadcastAsUser")
        )) {
//            System.out.println(getSigConstantOperand());
            bugReporter.reportBug(new BugInstance(this, ANDROID_STICKY_BROADCAST_TYPE, Priorities.NORMAL_PRIORITY) //
                    .addClass(this).addMethod(this).addSourceLine(this));
        }
    }
 
Example #11
Source File: ClassParser.java    From ApkToolPlus with Apache License 2.0 6 votes vote down vote up
/**
 * Read information about the class and its super class.
 * @throws  IOException
 * @throws  ClassFormatException
 */
private final void readClassInfo() throws IOException, ClassFormatException
{
  access_flags = file.readUnsignedShort();

  /* Interfaces are implicitely abstract, the flag should be set
   * according to the JVM specification.
   */
  if((access_flags & Constants.ACC_INTERFACE) != 0)
    access_flags |= Constants.ACC_ABSTRACT;

  if(((access_flags & Constants.ACC_ABSTRACT) != 0) && 
     ((access_flags & Constants.ACC_FINAL)    != 0 ))
    throw new ClassFormatException("Class can't be both final and abstract");

  class_name_index      = file.readUnsignedShort();
  superclass_name_index = file.readUnsignedShort();
}
 
Example #12
Source File: ExternalFileAccessDetector.java    From Android_Code_Arbiter with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
    public void sawOpcode(int seen) {
//        printOpCode(seen);

        // getClassConstantOperand().equals("java/net/Socket")

        if (seen == Constants.INVOKEVIRTUAL && ( //List of method mark as external file access
                getNameConstantOperand().equals("getExternalCacheDir") ||
                getNameConstantOperand().equals("getExternalCacheDirs") ||
                getNameConstantOperand().equals("getExternalFilesDir") ||
                getNameConstantOperand().equals("getExternalFilesDirs") ||
                getNameConstantOperand().equals("getExternalMediaDirs")
            )) {
//            System.out.println(getSigConstantOperand());
            bugReporter.reportBug(new BugInstance(this, ANDROID_EXTERNAL_FILE_ACCESS_TYPE, Priorities.NORMAL_PRIORITY) //
                    .addClass(this).addMethod(this).addSourceLine(this));
        }
        else if(seen == Constants.INVOKESTATIC && getClassConstantOperand().equals("android/os/Environment") && (
                getNameConstantOperand().equals("getExternalStorageDirectory") ||
                getNameConstantOperand().equals("getExternalStoragePublicDirectory")
            )) {
            bugReporter.reportBug(new BugInstance(this, ANDROID_EXTERNAL_FILE_ACCESS_TYPE, Priorities.NORMAL_PRIORITY) //
                    .addClass(this).addMethod(this).addSourceLine(this));
        }
    }
 
Example #13
Source File: InstructionFactory.java    From ApkToolPlus with Apache License 2.0 6 votes vote down vote up
/** Create a field instruction.
 *
 * @param class_name name of the accessed class
 * @param name name of the referenced field
 * @param type  type of field
 * @param kind how to access, i.e., GETFIELD, PUTFIELD, GETSTATIC, PUTSTATIC
 * @see Constants
 */
public FieldInstruction createFieldAccess(String class_name, String name, Type type, short kind) {
  int    index;
  String signature  = type.getSignature();

  index = cp.addFieldref(class_name, name, signature);

  switch(kind) {
  case Constants.GETFIELD:  return new GETFIELD(index);
  case Constants.PUTFIELD:  return new PUTFIELD(index);
  case Constants.GETSTATIC: return new GETSTATIC(index);
  case Constants.PUTSTATIC: return new PUTSTATIC(index);

  default:
    throw new RuntimeException("Oops: Unknown getfield kind:" + kind);
  }
}
 
Example #14
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 #15
Source File: JavaBuilder.java    From luaj with MIT License 6 votes vote down vote up
private String createLuaStringField(LuaString value) {
	String name = PREFIX_CONSTANT+constants.size();
	FieldGen fg = new FieldGen(Constants.ACC_STATIC | Constants.ACC_FINAL, 
			TYPE_LUAVALUE, name, cp);
	cg.addField(fg.getField());
	LuaString ls = value.checkstring();
	if ( ls.isValidUtf8() ) {
		init.append(new PUSH(cp, value.tojstring()));
		init.append(factory.createInvoke(STR_LUASTRING, "valueOf",
				TYPE_LUASTRING, ARG_TYPES_STRING, Constants.INVOKESTATIC));
	} else {
		char[] c = new char[ls.m_length];
		for ( int j=0; j<ls.m_length; j++ ) 
			c[j] = (char) (0xff & (int) (ls.m_bytes[ls.m_offset+j]));
		init.append(new PUSH(cp, new String(c)));
		init.append(factory.createInvoke(STR_STRING, "toCharArray",
				TYPE_CHARARRAY, Type.NO_ARGS,
				Constants.INVOKEVIRTUAL));
		init.append(factory.createInvoke(STR_LUASTRING, "valueOf",
				TYPE_LUASTRING, ARG_TYPES_CHARARRAY,
				Constants.INVOKESTATIC));
	}
	init.append(factory.createPutStatic(classname, name, TYPE_LUAVALUE));			
	return name;
}
 
Example #16
Source File: AwkCompilerImpl.java    From vscrawler with Apache License 2.0 6 votes vote down vote up
private void createResetMethod(String method_name, String field_name) {
	InstructionList tmpIl = new InstructionList();
	// no-arg method
	MethodGen method = new MethodGen(ACC_PUBLIC | ACC_FINAL, Type.VOID, buildArgs(new Class[] {}), new String[] {}, method_name, classname, tmpIl, cp);

	// implement: setXX(ZERO)

	tmpIl.append(InstructionConstants.ALOAD_0);
	tmpIl.append(factory.createFieldAccess(classname, "ZERO", getObjectType(Integer.class), Constants.GETSTATIC));
	tmpIl.append(factory.createFieldAccess(classname, field_name, getObjectType(Object.class), Constants.PUTFIELD));

	tmpIl.append(InstructionFactory.createReturn(Type.VOID));

	method.setMaxStack();
	method.setMaxLocals();
	cg.addMethod(method.getMethod());
	tmpIl.dispose();
}
 
Example #17
Source File: InstructionFactory.java    From ApkToolPlus with Apache License 2.0 6 votes vote down vote up
/**
 * @param type type of elements of array, i.e., array.getElementType()
 */
public static ArrayInstruction createArrayStore(Type type) {
  switch(type.getType()) {
  case Constants.T_BOOLEAN:
  case Constants.T_BYTE:   return BASTORE;
  case Constants.T_CHAR:   return CASTORE;
  case Constants.T_SHORT:  return SASTORE;
  case Constants.T_INT:    return IASTORE;
  case Constants.T_FLOAT:  return FASTORE;
  case Constants.T_DOUBLE: return DASTORE;
  case Constants.T_LONG:   return LASTORE;
  case Constants.T_ARRAY:
  case Constants.T_OBJECT: return AASTORE;
  default:       throw new RuntimeException("Invalid type " + type);
  }
}
 
Example #18
Source File: InstructionFactory.java    From ApkToolPlus with Apache License 2.0 6 votes vote down vote up
/**
 * @param type type of elements of array, i.e., array.getElementType()
 */
public static ArrayInstruction createArrayLoad(Type type) {
  switch(type.getType()) {
  case Constants.T_BOOLEAN:
  case Constants.T_BYTE:   return BALOAD;
  case Constants.T_CHAR:   return CALOAD;
  case Constants.T_SHORT:  return SALOAD;
  case Constants.T_INT:    return IALOAD;
  case Constants.T_FLOAT:  return FALOAD;
  case Constants.T_DOUBLE: return DALOAD;
  case Constants.T_LONG:   return LALOAD;
  case Constants.T_ARRAY:
  case Constants.T_OBJECT: return AALOAD;
  default:       throw new RuntimeException("Invalid type " + type);
  }
}
 
Example #19
Source File: LineNumberTable.java    From ApkToolPlus with Apache License 2.0 5 votes vote down vote up
public LineNumberTable(int name_index, int length,
	 LineNumber[] line_number_table,
	 ConstantPool constant_pool)
{
  super(Constants.ATTR_LINE_NUMBER_TABLE, name_index, length, constant_pool);
  setLineNumberTable(line_number_table);
}
 
Example #20
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 #21
Source File: MethodGen.java    From ApkToolPlus with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a local variable to this method.
 * 
 * @param name
 *            variable name
 * @param type
 *            variable type
 * @param slot
 *            the index of the local variable, if type is long or double,
 *            the next available index is slot+2
 * @param start
 *            from where the variable is valid
 * @param end
 *            until where the variable is valid
 * @return new local variable object
 * @see LocalVariable
 */
public LocalVariableGen addLocalVariable(String name, Type type, int slot,
		InstructionHandle start, InstructionHandle end) {
	byte t = type.getType();

	if (t != Constants.T_ADDRESS) {
		int add = type.getSize();

		if (slot + add > max_locals)
			max_locals = slot + add;

		LocalVariableGen l = new LocalVariableGen(slot, name, type, start,
				end);
		int i;

		if ((i = variable_vec.indexOf(l)) >= 0) // Overwrite if necessary
			variable_vec.set(i, l);
		else
			variable_vec.add(l);

		return l;
	} else {
		throw new IllegalArgumentException("Can not use " + type
				+ " as type for local variable");

	}
}
 
Example #22
Source File: ClassPathLoaderJUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
  ClassGen cg = new ClassGen(name, "java.lang.Object", "<generated>", Constants.ACC_PUBLIC | Constants.ACC_SUPER, null);
  cg.addEmptyConstructor(Constants.ACC_PUBLIC);
  JavaClass jClazz = cg.getJavaClass();
  byte[] bytes = jClazz.getBytes();
  return defineClass(jClazz.getClassName(), bytes, 0, bytes.length);
}
 
Example #23
Source File: LocalVariableInstruction.java    From ApkToolPlus with Apache License 2.0 5 votes vote down vote up
/**
  * Long output format:
  *
  * &lt;name of opcode&gt; "["&lt;opcode number&gt;"]" 
  * "("&lt;length of instruction&gt;")" "&lt;"&lt; local variable index&gt;"&gt;"
  *
  * @param verbose long/short format switch
  * @return mnemonic for instruction
  */
 public String toString(boolean verbose) {
   if(((opcode >= Constants.ILOAD_0) &&
(opcode <= Constants.ALOAD_3)) ||
      ((opcode >= Constants.ISTORE_0) &&
(opcode <= Constants.ASTORE_3)))
     return super.toString(verbose);
   else
     return super.toString(verbose) + " " + n;
 }
 
Example #24
Source File: ArrayType.java    From ApkToolPlus with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor for array of given type
 *
 * @param type type of array (may be an array itself)
 */ 
public ArrayType(Type type, int dimensions) {
  super(Constants.T_ARRAY, "<dummy>");

  if((dimensions < 1) || (dimensions > Constants.MAX_BYTE))
    throw new ClassGenException("Invalid number of dimensions: " + dimensions);

  switch(type.getType()) {
  case Constants.T_ARRAY:
    ArrayType array = (ArrayType)type;
    this.dimensions = dimensions + array.dimensions;
    basic_type      = array.basic_type;
    break;
    
  case Constants.T_VOID:
    throw new ClassGenException("Invalid type: void[]");

  default: // Basic type or reference
    this.dimensions = dimensions;
    basic_type = type;
    break;
  }

  StringBuffer buf = new StringBuffer();
  for(int i=0; i < this.dimensions; i++)
    buf.append('[');

  buf.append(basic_type.getSignature());

  signature = buf.toString();
}
 
Example #25
Source File: ConstantNameAndType.java    From ApkToolPlus with Apache License 2.0 5 votes vote down vote up
/**
 * @param name_index Name of field/method
 * @param signature_index and its signature
 */
public ConstantNameAndType(int name_index,
	     int signature_index)
{
  super(Constants.CONSTANT_NameAndType);
  this.name_index      = name_index;
  this.signature_index = signature_index;
}
 
Example #26
Source File: FieldOrMethod.java    From ApkToolPlus with Apache License 2.0 5 votes vote down vote up
/**
 * @return String representation of object's type signature (java style)
 */   
public final String getSignature() {
  ConstantUtf8  c;
  c = (ConstantUtf8)constant_pool.getConstant(signature_index,
				Constants.CONSTANT_Utf8);
  return c.getBytes();
}
 
Example #27
Source File: JavaBuilder.java    From luaj with MIT License 5 votes vote down vote up
private String createLuaDoubleField(double value) {
	String name = PREFIX_CONSTANT+constants.size();
	FieldGen fg = new FieldGen(Constants.ACC_STATIC | Constants.ACC_FINAL, 
			TYPE_LUAVALUE, name, cp);
	cg.addField(fg.getField());
	init.append(new PUSH(cp, value));
	init.append(factory.createInvoke(STR_LUAVALUE, "valueOf",
			TYPE_LUANUMBER, ARG_TYPES_DOUBLE, Constants.INVOKESTATIC));
	init.append(factory.createPutStatic(classname, name, TYPE_LUAVALUE));			
	return name;
}
 
Example #28
Source File: LocalVariableGen.java    From ApkToolPlus with Apache License 2.0 5 votes vote down vote up
/**
 * Generate a local variable that with index `index'. Note that double and long
 * variables need two indexs. Index indices have to be provided by the user.
 *
 * @param index index of local variable
 * @param name its name
 * @param type its type
 * @param start from where the instruction is valid (null means from the start)
 * @param end until where the instruction is valid (null means to the end)
 */
public LocalVariableGen(int index, String name, Type type,
	  InstructionHandle start, InstructionHandle end) {
  if((index < 0) || (index > Constants.MAX_SHORT))
    throw new ClassGenException("Invalid index index: " + index);
  
  this.name  = name;
  this.type  = type;
  this.index  = index;
  setStart(start);
  setEnd(end);
}
 
Example #29
Source File: BCELFactory.java    From ApkToolPlus with Apache License 2.0 5 votes vote down vote up
public void visitInvokeInstruction(InvokeInstruction i) {
  short  opcode      = i.getOpcode();
  String class_name  = i.getClassName(_cp);
  String method_name = i.getMethodName(_cp);
  Type   type        = i.getReturnType(_cp);
  Type[] arg_types   = i.getArgumentTypes(_cp);

  _out.println("il.append(_factory.createInvoke(\"" +
 class_name + "\", \"" + method_name + "\", " +
 BCELifier.printType(type) + ", " +
 BCELifier.printArgumentTypes(arg_types) + ", " +
 "Constants." + Constants.OPCODE_NAMES[opcode].toUpperCase() +
 "));");
}
 
Example #30
Source File: Pass2Verifier.java    From ApkToolPlus with Apache License 2.0 5 votes vote down vote up
public void visitConstantMethodref(ConstantMethodref obj){
	if (obj.getTag() != Constants.CONSTANT_Methodref){
		throw new ClassConstraintException("Wrong constant tag in '"+tostring(obj)+"'.");
	}
	checkIndex(obj, obj.getClassIndex(), CONST_Class);
	checkIndex(obj, obj.getNameAndTypeIndex(), CONST_NameAndType);
}