Java Code Examples for org.objectweb.asm.Type#toString()

The following examples show how to use org.objectweb.asm.Type#toString() . 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: Utils.java    From obfuscator with MIT License 6 votes vote down vote up
public static String getInternalName(Type type) {
    switch (type.toString()) {
        case "V":
            return "void";
        case "Z":
            return "boolean";
        case "C":
            return "char";
        case "B":
            return "byte";
        case "S":
            return "short";
        case "I":
            return "int";
        case "F":
            return "float";
        case "J":
            return "long";
        case "D":
            return "double";
        default:
            throw new IllegalArgumentException("Type not known.");
    }
}
 
Example 2
Source File: FloatingPointComparisionMangler.java    From obfuscator with MIT License 6 votes vote down vote up
/**
 * Generates a method that looks like this:
 * <p>
 * private static int compare(double, double);
 * Flags: PRIVATE, STATIC
 * Code:
 * 0: dload_0
 * 1: dload_2
 * 2: dcmpl (<--- The opcode)
 * 3: ireturn
 *
 * @param cn     The ClassNode the method is supposed to be
 * @param opcode the comparision opcode. Allowed opcodes: LCMP, FCMPL, FCMPG, DCMPL, DCMPG
 * @return The method node
 */
private static MethodNode generateComparisionMethod(ClassNode cn, int opcode) {
    if (!(opcode >= Opcodes.LCMP && opcode <= Opcodes.DCMPG))
        throw new IllegalArgumentException("The opcode must be LCMP, FCMPL, FCMPG, DCMPL or DCMPG");

    // The type of numbers which are compared
    Type type = opcode == Opcodes.LCMP ? Type.LONG_TYPE : (opcode == Opcodes.FCMPG || opcode == Opcodes.FCMPL) ? Type.FLOAT_TYPE : Type.DOUBLE_TYPE;
    String desc = "(" + type.toString() + type.toString() + ")I";

    MethodNode methodNode = new MethodNode(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC, NameUtils.generateMethodName(cn, desc), desc, null, new String[0]);

    methodNode.instructions = new InsnList();

    methodNode.instructions.add(new VarInsnNode(type.getOpcode(Opcodes.ILOAD), 0));
    methodNode.instructions.add(new VarInsnNode(type.getOpcode(Opcodes.ILOAD), type.getSize()));
    methodNode.instructions.add(new InsnNode(opcode));
    methodNode.instructions.add(new InsnNode(Opcodes.IRETURN));

    return methodNode;
}
 
Example 3
Source File: TypeUtils.java    From maple-ir with GNU General Public License v3.0 5 votes vote down vote up
public static int getBitAndOpcode(Type type) {
	if (type == Type.INT_TYPE) {
		return IAND;
	} else if (type == Type.LONG_TYPE) {
		return LAND;
	} else {
		throw new IllegalArgumentException(type.toString());
	}
}
 
Example 4
Source File: TypeUtils.java    From maple-ir with GNU General Public License v3.0 5 votes vote down vote up
public static int getPopOpcode(Type type) {
	if (type.getSize() == 1) {
		return Opcodes.POP;
	} else if (type.getSize() == 2) {
		return Opcodes.POP2;
	} else {
		throw new IllegalArgumentException(type.toString());
	}
}
 
Example 5
Source File: TypeUtils.java    From maple-ir with GNU General Public License v3.0 5 votes vote down vote up
public static int getDupOpcode(Type type) {
	if (type.getSize() == 1) {
		return Opcodes.DUP;
	} else if (type.getSize() == 2) {
		return Opcodes.DUP2;
	} else {
		throw new IllegalArgumentException(type.toString());
	}
}
 
Example 6
Source File: TypeUtils.java    From maple-ir with GNU General Public License v3.0 5 votes vote down vote up
public static int getNegateOpcode(Type type) {
	if (type == Type.INT_TYPE || type == Type.SHORT_TYPE || type == Type.BYTE_TYPE) {
		return Opcodes.INEG;
	} else if (type == Type.LONG_TYPE) {
		return Opcodes.LNEG;
	} else if (type == Type.FLOAT_TYPE) {
		return Opcodes.FNEG;
	} else if (type == Type.DOUBLE_TYPE) {
		return Opcodes.DNEG;
	} else {
		throw new IllegalArgumentException(type.toString());
	}
}
 
Example 7
Source File: TypeUtils.java    From maple-ir with GNU General Public License v3.0 5 votes vote down vote up
public static int getBitShiftRightUnsignedOpcode(Type type) {
	if (type == Type.INT_TYPE) {
		return IUSHR;
	} else if (type == Type.LONG_TYPE) {
		return LUSHR;
	} else {
		throw new IllegalArgumentException(type.toString());
	}
}
 
Example 8
Source File: TypeUtils.java    From maple-ir with GNU General Public License v3.0 5 votes vote down vote up
public static int bitShiftRightOpcode(Type type) {
	if (type == Type.INT_TYPE) {
		return ISHR;
	} else if (type == Type.LONG_TYPE) {
		return LSHR;
	} else {
		throw new IllegalArgumentException(type.toString());
	}
}
 
Example 9
Source File: TypeUtils.java    From maple-ir with GNU General Public License v3.0 5 votes vote down vote up
public static int getBitShiftLeftOpcode(Type type) {
	if (type == Type.INT_TYPE) {
		return ISHL;
	} else if (type == Type.LONG_TYPE) {
		return LSHL;
	} else {
		throw new IllegalArgumentException(type.toString());
	}
}
 
Example 10
Source File: TypeUtils.java    From maple-ir with GNU General Public License v3.0 5 votes vote down vote up
public static int getBitXorOpcode(Type type) {
	if (type == Type.INT_TYPE) {
		return IXOR;
	} else if (type == Type.LONG_TYPE) {
		return LXOR;
	} else {
		throw new IllegalArgumentException(type.toString());
	}
}
 
Example 11
Source File: TypeUtils.java    From maple-ir with GNU General Public License v3.0 5 votes vote down vote up
public static int getBitOrOpcode(Type type) {
	if (type == Type.INT_TYPE) {
		return IOR;
	} else if (type == Type.LONG_TYPE) {
		return LOR;
	} else {
		throw new IllegalArgumentException(type.toString());
	}
}
 
Example 12
Source File: TypeUtils.java    From maple-ir with GNU General Public License v3.0 5 votes vote down vote up
public static int getRemainderOpcode(Type type) {
	if (type == Type.INT_TYPE) {
		return IREM;
	} else if (type == Type.LONG_TYPE) {
		return LREM;
	} else if (type == Type.FLOAT_TYPE) {
		return FREM;
	} else if (type == Type.DOUBLE_TYPE) {
		return DREM;
	} else {
		throw new IllegalArgumentException(type.toString());
	}
}
 
Example 13
Source File: TypeUtils.java    From maple-ir with GNU General Public License v3.0 5 votes vote down vote up
public static int getDivideOpcode(Type type) {
	if (type == Type.INT_TYPE) {
		return IDIV;
	} else if (type == Type.LONG_TYPE) {
		return LDIV;
	} else if (type == Type.FLOAT_TYPE) {
		return FDIV;
	} else if (type == Type.DOUBLE_TYPE) {
		return DDIV;
	} else {
		throw new IllegalArgumentException(type.toString());
	}
}
 
Example 14
Source File: TypeUtils.java    From maple-ir with GNU General Public License v3.0 5 votes vote down vote up
public static int getMultiplyOpcode(Type type) {
	if (type == Type.INT_TYPE) {
		return IMUL;
	} else if (type == Type.LONG_TYPE) {
		return LMUL;
	} else if (type == Type.FLOAT_TYPE) {
		return FMUL;
	} else if (type == Type.DOUBLE_TYPE) {
		return DMUL;
	} else {
		throw new IllegalArgumentException(type.toString());
	}
}
 
Example 15
Source File: TypeUtils.java    From maple-ir with GNU General Public License v3.0 5 votes vote down vote up
public static int getSubtractOpcode(Type type) {
	if (type == Type.INT_TYPE) {
		return ISUB;
	} else if (type == Type.LONG_TYPE) {
		return LSUB;
	} else if (type == Type.FLOAT_TYPE) {
		return FSUB;
	} else if (type == Type.DOUBLE_TYPE) {
		return DSUB;
	} else {
		throw new IllegalArgumentException(type.toString());
	}
}
 
Example 16
Source File: NegationExpr.java    From maple-ir with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Type getType() {
	Type t = expression.getType();
	if (t.getSort() >= Type.BOOLEAN && t.getSort() <= Type.INT) {
		return Type.INT_TYPE;
	} else if (t == Type.LONG_TYPE || t == Type.FLOAT_TYPE || t == Type.DOUBLE_TYPE) {
		return t;
	} else {
		throw new IllegalArgumentException(t.toString());
	}
}
 
Example 17
Source File: GenerationVerifier.java    From maple-ir with GNU General Public License v3.0 5 votes vote down vote up
static int size(Type t) {
	String s = t.toString();
	switch(s) {
		case "D":
		case "J":
			return 2;
		default:
			return 1;
	}
}
 
Example 18
Source File: MixinTargetContext.java    From Mixin with MIT License 5 votes vote down vote up
private String transformSingleDescriptor(Type type) {
    if (type.getSort() < Type.ARRAY) {
        return type.toString();
    }

    return this.transformSingleDescriptor(type.toString(), false);
}
 
Example 19
Source File: NodeUtils.java    From obfuscator with MIT License 5 votes vote down vote up
public static AbstractInsnNode getWrapperMethod(Type type) {
    if (type.getSort() != Type.VOID && TYPE_TO_WRAPPER.containsKey(type)) {
        return new MethodInsnNode(Opcodes.INVOKESTATIC, TYPE_TO_WRAPPER.get(type), "valueOf", "(" + type.toString() + ")L" + TYPE_TO_WRAPPER.get(type) + ";", false);
    }

    return new InsnNode(Opcodes.NOP);
}
 
Example 20
Source File: ReflectiveFunctorFactory.java    From maple-ir with GNU General Public License v3.0 4 votes vote down vote up
@Override
public EvaluationFunctor<Boolean> branch(Type lt, Type rt, ConditionalJumpStmt.ComparisonType type) {
	Type opType = TypeUtils.resolveBinOpType(lt, rt);
	String name = lt.getClassName() + type.name() + rt.getClassName() + "OPTYPE" + opType.getClassName() + "RETbool";

	String desc = "(" + lt.getDescriptor() + rt.getDescriptor() + ")Z";

	if(cache.containsKey(name)) {
		return _get(name);
	}

	MethodNode m = makeBase(name, desc);
	{
		InsnList insns = new InsnList();
		
		insns.add(new VarInsnNode(TypeUtils.getVariableLoadOpcode(lt), 0));
		cast(insns, lt, opType);
		insns.add(new VarInsnNode(TypeUtils.getVariableLoadOpcode(rt), lt.getSize()));
		cast(insns, rt, opType);
		

		LabelNode trueSuccessor = new LabelNode();
		
		if (opType == Type.INT_TYPE) {
			insns.add(new JumpInsnNode(Opcodes.IF_ICMPEQ + type.ordinal(), trueSuccessor));
		} else if (opType == Type.LONG_TYPE) {
			insns.add(new InsnNode(Opcodes.LCMP));
			insns.add(new JumpInsnNode(Opcodes.IFEQ + type.ordinal(), trueSuccessor));
		} else if (opType == Type.FLOAT_TYPE) {
			insns.add(new InsnNode((type == ConditionalJumpStmt.ComparisonType.LT || type == ConditionalJumpStmt.ComparisonType.LE) ? Opcodes.FCMPL : Opcodes.FCMPG));
			insns.add(new JumpInsnNode(Opcodes.IFEQ + type.ordinal(), trueSuccessor));
		} else if (opType == Type.DOUBLE_TYPE) {
			insns.add(new InsnNode((type == ConditionalJumpStmt.ComparisonType.LT || type == ConditionalJumpStmt.ComparisonType.LE) ? Opcodes.DCMPL : Opcodes.DCMPG));
			insns.add(new JumpInsnNode(Opcodes.IFEQ + type.ordinal(), trueSuccessor));
		} else {
			throw new IllegalArgumentException(opType.toString());
		}
		
		branchReturn(insns, trueSuccessor);
		
		m.node.instructions = insns;
	}
	
	return buildBridge(m);
}