org.objectweb.asm.tree.TypeInsnNode Java Examples
The following examples show how to use
org.objectweb.asm.tree.TypeInsnNode.
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: Instrumentator.java From instrumentation with Apache License 2.0 | 6 votes |
private void addGetMethodInvocation(InsnList il) { il.add(TreeInstructions.getPushInstruction(this.methodArguments.length)); il.add(new TypeInsnNode(Opcodes.ANEWARRAY, "java/lang/Class")); int parameterClassesIndex = getFistAvailablePosition(); il.add(new VarInsnNode(Opcodes.ASTORE, parameterClassesIndex)); this.mn.maxLocals++; for (int i = 0; i < this.methodArguments.length; i++) { il.add(new VarInsnNode(Opcodes.ALOAD, parameterClassesIndex)); il.add(TreeInstructions.getPushInstruction(i)); il.add(TreeInstructions.getClassReferenceInstruction(methodArguments[i], cn.version & 0xFFFF)); il.add(new InsnNode(Opcodes.AASTORE)); } il.add(TreeInstructions.getClassConstantReference(this.classType, cn.version & 0xFFFF)); il.add(new LdcInsnNode(this.mn.name)); il.add(new VarInsnNode(Opcodes.ALOAD, parameterClassesIndex)); il.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "org/brutusin/instrumentation/utils/Helper", "getSource", "(Ljava/lang/Class;Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/Object;", false)); }
Example #2
Source File: TypeHandler.java From native-obfuscator with GNU General Public License v3.0 | 6 votes |
@Override protected void process(MethodContext context, TypeInsnNode node) { props.put("desc", node.desc); int classId = context.getCachedClasses().getId(node.desc); context.output.append(String.format("if (!cclasses[%d] || env->IsSameObject(cclasses[%d], NULL)) { cclasses_mtx[%d].lock(); if (!cclasses[%d] || env->IsSameObject(cclasses[%d], NULL)) { if (jclass clazz = %s) { cclasses[%d] = (jclass) env->NewWeakGlobalRef(clazz); env->DeleteLocalRef(clazz); } } cclasses_mtx[%d].unlock(); %s } ", classId, classId, classId, classId, classId, MethodProcessor.getClassGetter(context, node.desc), classId, classId, trimmedTryCatchBlock)); props.put("desc_ptr", context.getCachedClasses().getPointer(node.desc)); }
Example #3
Source File: NioBufferRefConverterTest.java From bazel with Apache License 2.0 | 6 votes |
@Test public void methodOfNioBufferWithCovariantTypes_afterDesugar( @AsmNode(className = "NioBufferInvocations", memberName = "getByteBufferPosition", round = 1) MethodNode after) { ImmutableList<AbstractInsnNode> methodInvocations = Arrays.stream(after.instructions.toArray()) .filter(insnNode -> insnNode.getType() == METHOD_INSN) .collect(toImmutableList()); assertThat(methodInvocations).hasSize(1); MethodInsnNode methodInsnNode = (MethodInsnNode) Iterables.getOnlyElement(methodInvocations); assertThat(methodInsnNode.owner).isEqualTo("java/nio/ByteBuffer"); assertThat(methodInsnNode.name).isEqualTo("position"); assertThat(methodInsnNode.desc).isEqualTo("(I)Ljava/nio/Buffer;"); TypeInsnNode typeInsnNode = (TypeInsnNode) methodInsnNode.getNext(); assertThat(typeInsnNode.getOpcode()).isEqualTo(Opcodes.CHECKCAST); assertThat(typeInsnNode.desc).isEqualTo("java/nio/ByteBuffer"); assertThat(typeInsnNode.getNext().getOpcode()).isEqualTo(Opcodes.ARETURN); }
Example #4
Source File: ImplicitActionsConverter.java From grappa with Apache License 2.0 | 6 votes |
private boolean isStoredIntoObjectArray(final InstructionGraphNode node) { // is the single dependent an AASTORE instruction ? final AbstractInsnNode insn = node.getInstruction(); if (insn.getOpcode() != AASTORE) return false; // Does this instruction store into an array of Object ? final List<InstructionGraphNode> dependents = getDependents(node); // an AASTORE instruction should have exactly one dependent Preconditions.checkState(dependents.size() == 1); final AbstractInsnNode newArrayInsn = dependents.get(0).getInstruction(); // which should be a n ANEWARRAY instruction Preconditions.checkState(newArrayInsn.getOpcode() == ANEWARRAY); final String desc = ((TypeInsnNode) newArrayInsn).desc; return CodegenUtils.p(Object.class).equals(desc); }
Example #5
Source File: StackHelper.java From zelixkiller with GNU General Public License v3.0 | 6 votes |
public InsnValue casting(TypeInsnNode tin, InsnValue value) { switch (tin.getOpcode()) { case Opcodes.CHECKCAST: return value; case Opcodes.INSTANCEOF: if (value.getValue() == null) { return InsnValue.intValue(0); } Class<?> clazz = value.getValue().getClass(); try { Class<?> compared = Class.forName(Type.getType(tin.desc).getClassName()); return InsnValue.intValue(clazz.isAssignableFrom(compared)); } catch (ClassNotFoundException e) { } return InsnValue.intValue(0); } return null; }
Example #6
Source File: LambdaClassFixer.java From bazel with Apache License 2.0 | 6 votes |
private void removeLastAllocation() { AbstractInsnNode insn = instructions.getLast(); while (insn != null && insn.getPrevious() != null) { AbstractInsnNode prev = insn.getPrevious(); if (prev.getOpcode() == Opcodes.NEW && insn.getOpcode() == Opcodes.DUP && ((TypeInsnNode) prev).desc.equals(lambdaInfo.methodReference().getOwner())) { instructions.remove(prev); instructions.remove(insn); return; } insn = prev; } throw new IllegalStateException( "Couldn't find allocation to rewrite ::new reference " + lambdaInfo.methodReference()); }
Example #7
Source File: ConstructorGenerator.java From grappa with Apache License 2.0 | 6 votes |
private static void createNewInstanceMethod(final ParserClassNode classNode) { // TODO: replace with Code{Block,GenUtils} final String desc = "()L" + Type.getType(BaseParser.class) .getInternalName() + ';'; final MethodNode method = new MethodNode(ACC_PUBLIC, "newInstance", desc, null, null); final InsnList instructions = method.instructions; instructions.add(new TypeInsnNode(NEW, classNode.name)); instructions.add(new InsnNode(DUP)); instructions.add(new MethodInsnNode(INVOKESPECIAL, classNode.name, "<init>", "()V", false)); instructions.add(new InsnNode(ARETURN)); classNode.methods.add(method); }
Example #8
Source File: ASMMethodVariables.java From pinpoint with Apache License 2.0 | 6 votes |
AbstractInsnNode findInitConstructorInstruction() { int nested = 0; for (AbstractInsnNode insnNode = this.methodNode.instructions.getFirst(); insnNode != null; insnNode = insnNode.getNext()) { if (insnNode instanceof TypeInsnNode) { if (insnNode.getOpcode() == Opcodes.NEW) { // new object(). nested++; } } else if (insnNode instanceof MethodInsnNode) { final MethodInsnNode methodInsnNode = (MethodInsnNode) insnNode; if (methodInsnNode.getOpcode() == Opcodes.INVOKESPECIAL && methodInsnNode.name.equals("<init>")) { if (--nested < 0) { // find this() or super(). return insnNode.getNext(); } } } } return null; }
Example #9
Source File: AccessorGeneratorObjectFactory.java From Mixin with MIT License | 6 votes |
@Override public MethodNode generate() { int returnSize = this.returnType.getSize(); // size includes return size x2 since we immediately DUP the value to invoke the ctor on it int size = Bytecode.getArgsSize(this.argTypes) + (returnSize * 2); MethodNode method = this.createMethod(size, size); String className = this.info.getClassNode().name; method.instructions.add(new TypeInsnNode(Opcodes.NEW, className)); method.instructions.add(new InsnNode(returnSize == 1 ? Opcodes.DUP : Opcodes.DUP2)); Bytecode.loadArgs(this.argTypes, method.instructions, 0); method.instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, className, Constants.CTOR, this.targetMethod.desc, false)); method.instructions.add(new InsnNode(Opcodes.ARETURN)); return method; }
Example #10
Source File: TransformerInjectTracker.java From Diorite with MIT License | 6 votes |
private AbstractInsnNode skipCheckCastBackwards(AbstractInsnNode node) { // skip possible (?) ALOAD 0 if not static if (! this.isStatic && (node instanceof VarInsnNode) && (node.getOpcode() == ALOAD) && (((VarInsnNode) node).var == 0)) { node = node.getPrevious(); } // skip possible check cast if ((node instanceof TypeInsnNode) && (node.getOpcode() == CHECKCAST)) { node = node.getPrevious(); } // skip possible (?) ALOAD 0 if not static if (! this.isStatic && (node instanceof VarInsnNode) && (node.getOpcode() == ALOAD) && (((VarInsnNode) node).var == 0)) { node = node.getPrevious(); } return node; }
Example #11
Source File: InstructionComparator.java From NOVA-Core with GNU Lesser General Public License v3.0 | 6 votes |
public static boolean insnEqual(AbstractInsnNode node1, AbstractInsnNode node2) { if (node1.getOpcode() != node2.getOpcode()) { return false; } switch (node2.getType()) { case VAR_INSN: return varInsnEqual((VarInsnNode) node1, (VarInsnNode) node2); case TYPE_INSN: return typeInsnEqual((TypeInsnNode) node1, (TypeInsnNode) node2); case FIELD_INSN: return fieldInsnEqual((FieldInsnNode) node1, (FieldInsnNode) node2); case METHOD_INSN: return methodInsnEqual((MethodInsnNode) node1, (MethodInsnNode) node2); case LDC_INSN: return ldcInsnEqual((LdcInsnNode) node1, (LdcInsnNode) node2); case IINC_INSN: return iincInsnEqual((IincInsnNode) node1, (IincInsnNode) node2); case INT_INSN: return intInsnEqual((IntInsnNode) node1, (IntInsnNode) node2); default: return true; } }
Example #12
Source File: InstructionComparator.java From NOVA-Core with GNU Lesser General Public License v3.0 | 6 votes |
public static boolean insnEqual(AbstractInsnNode node1, AbstractInsnNode node2) { if (node1.getOpcode() != node2.getOpcode()) { return false; } switch (node2.getType()) { case VAR_INSN: return varInsnEqual((VarInsnNode) node1, (VarInsnNode) node2); case TYPE_INSN: return typeInsnEqual((TypeInsnNode) node1, (TypeInsnNode) node2); case FIELD_INSN: return fieldInsnEqual((FieldInsnNode) node1, (FieldInsnNode) node2); case METHOD_INSN: return methodInsnEqual((MethodInsnNode) node1, (MethodInsnNode) node2); case LDC_INSN: return ldcInsnEqual((LdcInsnNode) node1, (LdcInsnNode) node2); case IINC_INSN: return iincInsnEqual((IincInsnNode) node1, (IincInsnNode) node2); case INT_INSN: return intInsnEqual((IntInsnNode) node1, (IntInsnNode) node2); default: return true; } }
Example #13
Source File: InstructionComparator.java From NOVA-Core with GNU Lesser General Public License v3.0 | 6 votes |
public static boolean insnEqual(AbstractInsnNode node1, AbstractInsnNode node2) { if (node1.getOpcode() != node2.getOpcode()) { return false; } switch (node2.getType()) { case VAR_INSN: return varInsnEqual((VarInsnNode) node1, (VarInsnNode) node2); case TYPE_INSN: return typeInsnEqual((TypeInsnNode) node1, (TypeInsnNode) node2); case FIELD_INSN: return fieldInsnEqual((FieldInsnNode) node1, (FieldInsnNode) node2); case METHOD_INSN: return methodInsnEqual((MethodInsnNode) node1, (MethodInsnNode) node2); case LDC_INSN: return ldcInsnEqual((LdcInsnNode) node1, (LdcInsnNode) node2); case IINC_INSN: return iincInsnEqual((IincInsnNode) node1, (IincInsnNode) node2); case INT_INSN: return intInsnEqual((IntInsnNode) node1, (IntInsnNode) node2); default: return true; } }
Example #14
Source File: GenericGenerators.java From coroutines with GNU Lesser General Public License v3.0 | 6 votes |
/** * Calls a constructor with a set of arguments. After execution the stack should have an extra item pushed on it: the object that was * created by this constructor. * @param constructor constructor to call * @param args constructor argument instruction lists -- each instruction list must leave one item on the stack of the type expected * by the constructor * @return instructions to invoke a constructor * @throws NullPointerException if any argument is {@code null} or array contains {@code null} * @throws IllegalArgumentException if the length of {@code args} doesn't match the number of parameters in {@code constructor} */ public static InsnList construct(Constructor<?> constructor, InsnList ... args) { Validate.notNull(constructor); Validate.notNull(args); Validate.noNullElements(args); Validate.isTrue(constructor.getParameterCount() == args.length); InsnList ret = new InsnList(); Type clsType = Type.getType(constructor.getDeclaringClass()); Type methodType = Type.getType(constructor); ret.add(new TypeInsnNode(Opcodes.NEW, clsType.getInternalName())); ret.add(new InsnNode(Opcodes.DUP)); for (InsnList arg : args) { ret.add(arg); } ret.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, clsType.getInternalName(), "<init>", methodType.getDescriptor(), false)); return ret; }
Example #15
Source File: TypeInstructionFilter.java From maple-ir with GNU General Public License v3.0 | 5 votes |
@Override public boolean accept(AbstractInsnNode t) { if (!(t instanceof TypeInsnNode)) return false; TypeInsnNode tin = (TypeInsnNode) t; return opcodeFilter.accept(tin) && descFilter.accept(tin.desc); }
Example #16
Source File: ModifyConstantInjector.java From Mixin with MIT License | 5 votes |
@Override protected void inject(Target target, InjectionNode node) { if (!this.preInject(node)) { return; } if (node.isReplaced()) { throw new UnsupportedOperationException("Target failure for " + this.info); } AbstractInsnNode targetNode = node.getCurrentTarget(); if (targetNode instanceof TypeInsnNode) { this.checkTargetModifiers(target, false); this.injectTypeConstantModifier(target, (TypeInsnNode)targetNode); return; } if (targetNode instanceof JumpInsnNode) { this.checkTargetModifiers(target, false); this.injectExpandedConstantModifier(target, (JumpInsnNode)targetNode); return; } if (Bytecode.isConstant(targetNode)) { this.checkTargetModifiers(target, false); this.injectConstantModifier(target, targetNode); return; } throw new InvalidInjectionException(this.info, String.format("%s annotation is targetting an invalid insn in %s in %s", this.annotationType, target, this)); }
Example #17
Source File: OpcodeFormatting.java From Cafebabe with GNU General Public License v3.0 | 5 votes |
public static String toString(AbstractInsnNode ain) { String s = getOpcodeText(ain.getOpcode()); switch (ain.getType()) { case AbstractInsnNode.FIELD_INSN: FieldInsnNode fin = (FieldInsnNode) ain; return s + " " + fin.owner + "#" + fin.name + " " + fin.desc; case AbstractInsnNode.METHOD_INSN: MethodInsnNode min = (MethodInsnNode) ain; return s + " " + min.owner + "#" + min.name + min.desc; case AbstractInsnNode.VAR_INSN: VarInsnNode vin = (VarInsnNode) ain; return s + " " + vin.var; case AbstractInsnNode.TYPE_INSN: TypeInsnNode tin = (TypeInsnNode) ain; return s + " " + tin.desc; case AbstractInsnNode.MULTIANEWARRAY_INSN: MultiANewArrayInsnNode mnin = (MultiANewArrayInsnNode) ain; return s + " " + mnin.dims + " " + mnin.desc; case AbstractInsnNode.JUMP_INSN: JumpInsnNode jin = (JumpInsnNode) ain; return s + " " + getIndex(jin.label); case AbstractInsnNode.LDC_INSN: LdcInsnNode ldc = (LdcInsnNode) ain; return s + " " + ldc.cst.toString(); case AbstractInsnNode.INT_INSN: return s + " " + getIntValue(ain); case AbstractInsnNode.IINC_INSN: IincInsnNode iinc = (IincInsnNode) ain; return s + " " + iinc.var + " +" + iinc.incr; case AbstractInsnNode.FRAME: FrameNode fn = (FrameNode) ain; return s + " " + getOpcodeText(fn.type) + " " + fn.local.size() + " " + fn.stack.size(); case AbstractInsnNode.LABEL: LabelNode ln = (LabelNode) ain; return s + " " + getIndex(ln); } return s; }
Example #18
Source File: BeforeNew.java From Mixin with MIT License | 5 votes |
@SuppressWarnings("unchecked") @Override public boolean find(String desc, InsnList insns, Collection<AbstractInsnNode> nodes) { boolean found = false; int ordinal = 0; Collection<TypeInsnNode> newNodes = new ArrayList<TypeInsnNode>(); Collection<AbstractInsnNode> candidates = (Collection<AbstractInsnNode>) (this.desc != null ? newNodes : nodes); ListIterator<AbstractInsnNode> iter = insns.iterator(); while (iter.hasNext()) { AbstractInsnNode insn = iter.next(); if (insn instanceof TypeInsnNode && insn.getOpcode() == Opcodes.NEW && this.matchesOwner((TypeInsnNode) insn)) { if (this.ordinal == -1 || this.ordinal == ordinal) { candidates.add(insn); found = this.desc == null; } ordinal++; } } if (this.desc != null) { for (TypeInsnNode newNode : newNodes) { if (this.findCtor(insns, newNode)) { nodes.add(newNode); found = true; } } } return found; }
Example #19
Source File: ObfMapping.java From NOVA-Core with GNU Lesser General Public License v3.0 | 5 votes |
@SuppressWarnings("deprecation") public AbstractInsnNode toInsn(int opcode) { if (isClass()) { return new TypeInsnNode(opcode, s_owner); } else if (isMethod()) { return new MethodInsnNode(opcode, s_owner, s_name, s_desc); } else { return new FieldInsnNode(opcode, s_owner, s_name, s_desc); } }
Example #20
Source File: GenericGenerators.java From coroutines with GNU Lesser General Public License v3.0 | 5 votes |
/** * Generates instructions to throw an exception of type {@link RuntimeException} with a constant message. * @param message message of exception * @return instructions to throw an exception * @throws NullPointerException if any argument is {@code null} */ public static InsnList throwRuntimeException(String message) { Validate.notNull(message); InsnList ret = new InsnList(); ret.add(new TypeInsnNode(Opcodes.NEW, "java/lang/RuntimeException")); ret.add(new InsnNode(Opcodes.DUP)); ret.add(new LdcInsnNode(message)); ret.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, "java/lang/RuntimeException", "<init>", "(Ljava/lang/String;)V", false)); ret.add(new InsnNode(Opcodes.ATHROW)); return ret; }
Example #21
Source File: ObfMapping.java From NOVA-Core with GNU Lesser General Public License v3.0 | 5 votes |
@SuppressWarnings("deprecation") public AbstractInsnNode toInsn(int opcode) { if (isClass()) { return new TypeInsnNode(opcode, s_owner); } else if (isMethod()) { return new MethodInsnNode(opcode, s_owner, s_name, s_desc); } else { return new FieldInsnNode(opcode, s_owner, s_name, s_desc); } }
Example #22
Source File: ReplacingInterpreter.java From Bats with Apache License 2.0 | 5 votes |
@Override public BasicValue newOperation(final AbstractInsnNode insn) throws AnalyzerException { if (insn.getOpcode() == Opcodes.NEW) { final TypeInsnNode t = (TypeInsnNode) insn; // if this is for a holder class, we'll replace it final ValueHolderIden iden = HOLDERS.get(t.desc); if (iden != null) { return ReplacingBasicValue.create(Type.getObjectType(t.desc), iden, index++, valueList); } } return super.newOperation(insn); }
Example #23
Source File: BeforeNew.java From Mixin with MIT License | 5 votes |
protected boolean findCtor(InsnList insns, TypeInsnNode newNode) { int indexOf = insns.indexOf(newNode); for (Iterator<AbstractInsnNode> iter = insns.iterator(indexOf); iter.hasNext();) { AbstractInsnNode insn = iter.next(); if (insn instanceof MethodInsnNode && insn.getOpcode() == Opcodes.INVOKESPECIAL) { MethodInsnNode methodNode = (MethodInsnNode)insn; if (Constants.CTOR.equals(methodNode.name) && methodNode.owner.equals(newNode.desc) && methodNode.desc.equals(this.desc)) { return true; } } } return false; }
Example #24
Source File: ModifyConstantInjector.java From Mixin with MIT License | 5 votes |
private void injectTypeConstantModifier(Target target, TypeInsnNode typeNode) { int opcode = typeNode.getOpcode(); if (opcode != Opcodes.INSTANCEOF) { throw new InvalidInjectionException(this.info, String.format("%s annotation does not support %s insn in %s in %s", this.annotationType, Bytecode.getOpcodeName(opcode), target, this)); } this.injectAtInstanceOf(target, typeNode); }
Example #25
Source File: JClassPatcher.java From rscplus with GNU General Public License v3.0 | 5 votes |
private void patchRandom(ClassNode node) { Logger.Info("Patching random (" + node.name + ".class)"); Iterator<MethodNode> methodNodeList = node.methods.iterator(); while (methodNodeList.hasNext()) { MethodNode methodNode = methodNodeList.next(); if (methodNode.name.equals("a")) { // System.out.println(methodNode.desc); if (methodNode.desc.equals("(ILtb;)V")) { Iterator<AbstractInsnNode> insnNodeList = methodNode.instructions.iterator(); while (insnNodeList.hasNext()) { AbstractInsnNode insnNode = insnNodeList.next(); AbstractInsnNode nextNode = insnNode.getNext(); if (nextNode == null) break; if (insnNode.getOpcode() == Opcodes.ALOAD && nextNode.getOpcode() == Opcodes.ICONST_0) { VarInsnNode call = (VarInsnNode) insnNode; Logger.Info("Patching validation..."); methodNode.instructions.insert( insnNode, new MethodInsnNode( Opcodes.INVOKEVIRTUAL, "java/util/Random", "nextBytes", "([B)V")); methodNode.instructions.insert(insnNode, new VarInsnNode(Opcodes.ALOAD, 2)); methodNode.instructions.insert( insnNode, new MethodInsnNode(Opcodes.INVOKESPECIAL, "java/util/Random", "<init>", "()V")); methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.DUP)); methodNode.instructions.insert( insnNode, new TypeInsnNode(Opcodes.NEW, "java/util/Random")); } } } } } }
Example #26
Source File: ANewArrayStep.java From deobfuscator with Apache License 2.0 | 5 votes |
@Override public AbstractInsnNode tryMatch(InstructionMatcher matcher, AbstractInsnNode now) { if (now.getOpcode() != Opcodes.ANEWARRAY) { return null; } TypeInsnNode typeInsnNode = (TypeInsnNode) now; if (!(basic ? TransformerHelper.basicType(typeInsnNode.desc) : typeInsnNode.desc).equals(type)) { return null; } return now.getNext(); }
Example #27
Source File: Target.java From Mixin with MIT License | 5 votes |
/** * Find the first <tt><init></tt> invocation after the specified * <tt>NEW</tt> insn * * @param newNode NEW insn * @return INVOKESPECIAL opcode of ctor, or null if not found */ public MethodInsnNode findInitNodeFor(TypeInsnNode newNode) { int start = this.indexOf(newNode); for (Iterator<AbstractInsnNode> iter = this.insns.iterator(start); iter.hasNext();) { AbstractInsnNode insn = iter.next(); if (insn instanceof MethodInsnNode && insn.getOpcode() == Opcodes.INVOKESPECIAL) { MethodInsnNode methodNode = (MethodInsnNode)insn; if (Constants.CTOR.equals(methodNode.name) && methodNode.owner.equals(newNode.desc)) { return methodNode; } } } return null; }
Example #28
Source File: BoxedPrimitivesMethods.java From rembulan with Apache License 2.0 | 5 votes |
public static InsnList loadBoxedConstant(Object k, Class<?> castTo) { InsnList il = new InsnList(); if (k == null) { il.add(loadNull()); } else if (k instanceof Boolean) { il.add(BoxedPrimitivesMethods.loadBoxedBoolean((Boolean) k)); } else if (k instanceof Double || k instanceof Float) { il.add(ASMUtils.loadDouble(((Number) k).doubleValue())); il.add(BoxedPrimitivesMethods.box(Type.DOUBLE_TYPE, Type.getType(Double.class))); } else if (k instanceof Number) { il.add(ASMUtils.loadLong(((Number) k).longValue())); il.add(BoxedPrimitivesMethods.box(Type.LONG_TYPE, Type.getType(Long.class))); } else if (k instanceof String) { il.add(new LdcInsnNode(k)); } else { throw new UnsupportedOperationException("Illegal constant type: " + k.getClass()); } if (castTo != null) { Objects.requireNonNull(k); if (!castTo.isAssignableFrom(k.getClass())) { il.add(new TypeInsnNode(CHECKCAST, Type.getInternalName(castTo))); } } return il; }
Example #29
Source File: OpUtils.java From JByteMod-Beta with GNU General Public License v2.0 | 5 votes |
public static String toString(AbstractInsnNode ain) { String s = getOpcodeText(ain.getOpcode()); switch (ain.getType()) { case AbstractInsnNode.FIELD_INSN: FieldInsnNode fin = (FieldInsnNode) ain; return s + " " + fin.owner + "#" + fin.name + " " + fin.desc; case AbstractInsnNode.METHOD_INSN: MethodInsnNode min = (MethodInsnNode) ain; return s + " " + min.owner + "#" + min.name + min.desc; case AbstractInsnNode.VAR_INSN: VarInsnNode vin = (VarInsnNode) ain; return s + " " + vin.var; case AbstractInsnNode.TYPE_INSN: TypeInsnNode tin = (TypeInsnNode) ain; return s + " " + tin.desc; case AbstractInsnNode.MULTIANEWARRAY_INSN: MultiANewArrayInsnNode mnin = (MultiANewArrayInsnNode) ain; return s + " " + mnin.dims + " " + mnin.desc; case AbstractInsnNode.JUMP_INSN: JumpInsnNode jin = (JumpInsnNode) ain; return s + " " + getIndex(jin.label); case AbstractInsnNode.LDC_INSN: LdcInsnNode ldc = (LdcInsnNode) ain; return s + " " + ldc.cst.toString(); case AbstractInsnNode.INT_INSN: return s + " " + getIntValue(ain); case AbstractInsnNode.IINC_INSN: IincInsnNode iinc = (IincInsnNode) ain; return s + " " + iinc.var + " +" + iinc.incr; case AbstractInsnNode.FRAME: FrameNode fn = (FrameNode) ain; return s + " " + getOpcodeText(fn.type) + " " + fn.local.size() + " " + fn.stack.size(); case AbstractInsnNode.LABEL: LabelNode ln = (LabelNode) ain; return s + " " + getIndex(ln); } return s; }
Example #30
Source File: ObfMapping.java From NOVA-Core with GNU Lesser General Public License v3.0 | 5 votes |
public AbstractInsnNode toInsn(int opcode) { if (isClass()) { return new TypeInsnNode(opcode, s_owner); } else if (isMethod()) { return new MethodInsnNode(opcode, s_owner, s_name, s_desc); } else { return new FieldInsnNode(opcode, s_owner, s_name, s_desc); } }