List of usage examples for org.objectweb.asm Opcodes GETFIELD
int GETFIELD
To view the source code for org.objectweb.asm Opcodes GETFIELD.
Click Source Link
From source file:com.khubla.jvmbasic.jvmbasicc.function.impl.rule.rightfuncRule.java
License:Open Source License
@Override public boolean execute(GenerationContext generationContext) throws Exception { try {/*from w ww.j a v a 2s .co m*/ /* * get the operands */ Dispatcher.dispatchChildren(generationContext); /* * there should be 6 values. grammar is "RIGHT LPAREN expression COMMA expression RPAREN" */ if (generationContext.getParseTree().getChildCount() == 6) { generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "pop", "()Lcom/khubla/jvmbasic/jvmbasicrt/Value;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "resolveValue", "(Lcom/khubla/jvmbasic/jvmbasicrt/Value;)Lcom/khubla/jvmbasic/jvmbasicrt/Value;"); generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "pop", "()Lcom/khubla/jvmbasic/jvmbasicrt/Value;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "resolveValue", "(Lcom/khubla/jvmbasic/jvmbasicrt/Value;)Lcom/khubla/jvmbasic/jvmbasicrt/Value;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKESTATIC, "com/khubla/jvmbasic/jvmbasicrt/StringFunctions", "RIGHT", "(Lcom/khubla/jvmbasic/jvmbasicrt/Value;Lcom/khubla/jvmbasic/jvmbasicrt/Value;)Ljava/lang/String;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "push", "(Ljava/lang/String;)V"); return true; } else { throw new Exception("Invalid number of values passed to rightfuncRule"); } } catch (final Exception e) { throw new Exception("Exception in execute", e); } }
From source file:com.khubla.jvmbasic.jvmbasicc.function.impl.rule.rndfuncRule.java
License:Open Source License
@Override public boolean execute(GenerationContext generationContext) throws Exception { try {/*from www . java 2s .c o m*/ /* * get the operands */ Dispatcher.dispatchChildren(generationContext); /* * declare the local var Random */ generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitTypeInsn(Opcodes.NEW, "java/util/Random"); generationContext.getMethodVisitor().visitInsn(Opcodes.DUP); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKESPECIAL, "java/util/Random", "<init>", "()V"); generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "pop", "()Lcom/khubla/jvmbasic/jvmbasicrt/Value;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, "com/khubla/jvmbasic/jvmbasicrt/Value", "getInteger", "()Ljava/lang/Integer;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Integer", "intValue", "()I"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/Random", "nextInt", "(I)I"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "push", "(Ljava/lang/Integer;)V"); return true; } catch (final Exception e) { throw new Exception("Exception in execute", e); } }
From source file:com.khubla.jvmbasic.jvmbasicc.function.impl.rule.sinfuncRule.java
License:Open Source License
@Override public boolean execute(GenerationContext generationContext) throws Exception { try {//from ww w. ja v a 2s.c om /* * get the argument */ Dispatcher.dispatchChildren(generationContext); /* * pop the argument and apply abs */ generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "pop", "()Lcom/khubla/jvmbasic/jvmbasicrt/Value;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKESTATIC, RTLHelper.JASIC_RUNTIME_MATH, "SIN", "(Lcom/khubla/jvmbasic/jvmbasicrt/Value;)Ljava/lang/Double;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "push", "(Ljava/lang/Double;)V"); return true; } catch (final Exception e) { throw new Exception("Exception in execute", e); } }
From source file:com.khubla.jvmbasic.jvmbasicc.function.impl.rule.sqrfuncRule.java
License:Open Source License
@Override public boolean execute(GenerationContext generationContext) throws Exception { try {//w w w . j ava 2 s.co m /* * get the operands */ Dispatcher.dispatchChildren(generationContext); /* * pop the argument and apply sqr */ generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "pop", "()Lcom/khubla/jvmbasic/jvmbasicrt/Value;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "resolveValue", "(Lcom/khubla/jvmbasic/jvmbasicrt/Value;)Lcom/khubla/jvmbasic/jvmbasicrt/Value;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKESTATIC, RTLHelper.JASIC_RUNTIME_MATH, "SQR", "(Lcom/khubla/jvmbasic/jvmbasicrt/Value;)Ljava/lang/Double;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "push", "(Ljava/lang/Double;)V"); return true; } catch (final Exception e) { throw new Exception("Exception in execute", e); } }
From source file:com.khubla.jvmbasic.jvmbasicc.function.impl.rule.strfuncRule.java
License:Open Source License
@Override public boolean execute(GenerationContext generationContext) throws Exception { try {/*w w w .j a v a2 s .c om*/ /* * get the operands */ Dispatcher.dispatchChildren(generationContext); /* * there should be 4 */ if (generationContext.getParseTree().getChildCount() == 4) { generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "pop", "()Lcom/khubla/jvmbasic/jvmbasicrt/Value;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "resolveValue", "(Lcom/khubla/jvmbasic/jvmbasicrt/Value;)Lcom/khubla/jvmbasic/jvmbasicrt/Value;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKESTATIC, "com/khubla/jvmbasic/jvmbasicrt/StringFunctions", "STR", "(Lcom/khubla/jvmbasic/jvmbasicrt/Value;)Ljava/lang/String;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "push", "(Ljava/lang/String;)V"); return true; } else { throw new Exception("strfuncRule requires a value"); } } catch (final Exception e) { throw new Exception("Exception in execute", e); } }
From source file:com.khubla.jvmbasic.jvmbasicc.function.impl.rule.tanfuncRule.java
License:Open Source License
@Override public boolean execute(GenerationContext generationContext) throws Exception { try {// w w w . jav a 2s.com /* * get the argument */ Dispatcher.dispatchChildren(generationContext); /* * pop the argument and apply abs */ generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "pop", "()Lcom/khubla/jvmbasic/jvmbasicrt/Value;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKESTATIC, RTLHelper.JASIC_RUNTIME_MATH, "TAN", "(Lcom/khubla/jvmbasic/jvmbasicrt/Value;)Ljava/lang/Double;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "push", "(Ljava/lang/Double;)V"); return true; } catch (final Exception e) { throw new Exception("Exception in execute", e); } }
From source file:com.khubla.jvmbasic.jvmbasicc.function.impl.rule.valfuncRule.java
License:Open Source License
@Override public boolean execute(GenerationContext generationContext) throws Exception { try {//from w ww . j a v a 2 s .c o m /* * get the operands */ Dispatcher.dispatchChildren(generationContext); /* * there should be 4 values */ if (generationContext.getParseTree().getChildCount() == 4) { generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "pop", "()Lcom/khubla/jvmbasic/jvmbasicrt/Value;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "resolveValue", "(Lcom/khubla/jvmbasic/jvmbasicrt/Value;)Lcom/khubla/jvmbasic/jvmbasicrt/Value;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKESTATIC, "com/khubla/jvmbasic/jvmbasicrt/StringFunctions", "VAL", "(Lcom/khubla/jvmbasic/jvmbasicrt/Value;)Ljava/lang/String;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "push", "(Ljava/lang/String;)V"); return true; } else { throw new Exception("VAL requires a value"); } } catch (final Exception e) { throw new Exception("Exception in execute", e); } }
From source file:com.khubla.jvmbasic.jvmbasicc.function.impl.rule.variableassignmentRule.java
License:Open Source License
@Override public boolean execute(GenerationContext generationContext) throws Exception { try {//from ww w .j av a 2 s .c o m /* * the tree should have 3 sub nodes like this "variableassignment : vardecl EQ exprlist" */ String variableName = null; if (generationContext.getParseTree().getChildCount() == 3) { /* * get the variable name */ variableName = VariableNameUtil .getVariableName((VardeclContext) generationContext.getParseTree().getChild(0)); /* * get the tree for the value. this should push the value onto the ExecutionContextStack */ final ExprlistContext exprlistContext = (ExprlistContext) generationContext.getParseTree() .getChild(2); final GenerationContext subGenerationContext = new GenerationContext(generationContext, exprlistContext); Dispatcher.dispatch(subGenerationContext); } else { throw new Exception( "Invalid number of arguments '" + generationContext.getParseTree().getChildCount() + "'"); } /* * store the top of the stack into slot 1 */ generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "pop", "()Lcom/khubla/jvmbasic/jvmbasicrt/Value;"); generationContext.getMethodVisitor().visitVarInsn(Opcodes.ASTORE, 1); /* * put the value in slot 1 into the variable in the execution context */ generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitLdcInsn(variableName); generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 1); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "setVariable", "(Ljava/lang/String;Lcom/khubla/jvmbasic/jvmbasicrt/Value;)V"); return true; } catch (final Exception e) { throw new Exception("Exception in execute", e); } }
From source file:com.liferay.portal.nio.intraband.proxy.IntrabandProxyUtilTest.java
License:Open Source License
private void _doTestCreateProxyMethodNode(Method method, int index, String skeletonId, String stubInternalName) { MethodNode proxyMethodNode = IntrabandProxyUtil.createProxyMethodNode(method, index, skeletonId, Type.getType(stubInternalName)); _assertMethodNodeSignature(proxyMethodNode, method.getModifiers() & ~Modifier.ABSTRACT, method.getName(), Type.getMethodDescriptor(method), method.getExceptionTypes()); InsnList insnList = proxyMethodNode.instructions; Iterator<AbstractInsnNode> iterator = insnList.iterator(); // NEW com/liferay/portal/kernel/io/Serializer _assertTypeInsnNode(iterator.next(), Opcodes.NEW, Serializer.class); // DUP//from w w w . jav a 2 s .c o m _assertInsnNode(iterator.next(), Opcodes.DUP); // INVOKESPECIAL com/liferay/portal/kernel/io/Serializer <init> ()V _assertMethodInsnNode(iterator.next(), Opcodes.INVOKESPECIAL, Type.getInternalName(Serializer.class), "<init>", Type.VOID_TYPE); // ASTORE argumentsSize Type methodType = Type.getType(method); int argumentsAndReturnSizes = methodType.getArgumentsAndReturnSizes(); int argumentsSize = argumentsAndReturnSizes >> 2; _assertVarInsnNode(iterator.next(), Opcodes.ASTORE, argumentsSize); // ALOAD argumentsSize _assertVarInsnNode(iterator.next(), Opcodes.ALOAD, argumentsSize); // LDC skeletonId _assertLdcInsnNode(iterator.next(), Opcodes.LDC, skeletonId); // INVOKEVIRTUAL com/liferay/portal/kernel/io/Serializer writeString // (Ljava/lang/String;)V _assertMethodInsnNode(iterator.next(), Opcodes.INVOKEVIRTUAL, Type.getInternalName(Serializer.class), "writeString", Type.VOID_TYPE, Type.getType(String.class)); // ALOAD argumentsSize _assertVarInsnNode(iterator.next(), Opcodes.ALOAD, argumentsSize); // ALOAD 0 _assertVarInsnNode(iterator.next(), Opcodes.ALOAD, 0); // GETFIELD stubInternalName _id Ljava/lang/String; _assertFieldInsnNode(iterator.next(), Opcodes.GETFIELD, stubInternalName, "_id", String.class); // INVOKEVIRTUAL com/liferay/portal/kernel/io/Serializer writeString // (Ljava/lang/String;)V _assertMethodInsnNode(iterator.next(), Opcodes.INVOKEVIRTUAL, Type.getInternalName(Serializer.class), "writeString", Type.VOID_TYPE, Type.getType(String.class)); // ALOAD argumentsSize _assertVarInsnNode(iterator.next(), Opcodes.ALOAD, argumentsSize); if (index <= 5) { // ICONST_index _assertInsnNode(iterator.next(), Opcodes.ICONST_0 + index); } else { // BIPUSH index _assertIntInsnNode(iterator.next(), Opcodes.BIPUSH, index); } // INVOKEVIRTUAL com/liferay/portal/kernel/io/Serializer writeInt (I)V _assertMethodInsnNode(iterator.next(), Opcodes.INVOKEVIRTUAL, Type.getInternalName(Serializer.class), "writeInt", Type.VOID_TYPE, Type.INT_TYPE); Class<?>[] parameterTypes = method.getParameterTypes(); int offset = 1; for (int i = 0; i < parameterTypes.length; i++) { Class<?> parameterClass = parameterTypes[i]; // ALOAD argumentsSize _assertVarInsnNode(iterator.next(), Opcodes.ALOAD, argumentsSize); // xLOAD i Type parameterType = Type.getType(parameterClass); _assertVarInsnNode(iterator.next(), parameterType.getOpcode(Opcodes.ILOAD), offset); offset += parameterType.getSize(); if (parameterClass.isPrimitive() || (parameterClass == String.class)) { String name = TextFormatter.format(parameterClass.getSimpleName(), TextFormatter.G); _assertMethodInsnNode(iterator.next(), Opcodes.INVOKEVIRTUAL, Type.getInternalName(Serializer.class), "write".concat(name), Type.VOID_TYPE, parameterType); } else { _assertMethodInsnNode(iterator.next(), Opcodes.INVOKEVIRTUAL, Type.getInternalName(Serializer.class), "writeObject", Type.VOID_TYPE, Type.getType(Serializable.class)); } } // ALOAD 0 _assertVarInsnNode(iterator.next(), Opcodes.ALOAD, 0); // ALOAD argumentsSize _assertVarInsnNode(iterator.next(), Opcodes.ALOAD, argumentsSize); Class<?> returnClass = method.getReturnType(); Type returnType = Type.getType(returnClass); if (returnClass == void.class) { // INVOKESPECIAL stubInternalName _send // (Lcom/liferay/portal/kernel/io/Serializer;)V _assertMethodInsnNode(iterator.next(), Opcodes.INVOKESPECIAL, stubInternalName, "_send", Type.VOID_TYPE, Type.getType(Serializer.class)); _assertInsnNode(iterator.next(), Opcodes.RETURN); } else { // INVOKESPECIAL stubInternalName _syncSend // (Lcom/liferay/portal/kernel/io/Serializer;)Ljava/io/Serializable; _assertMethodInsnNode(iterator.next(), Opcodes.INVOKESPECIAL, stubInternalName, "_syncSend", Type.getType(Serializable.class), Type.getType(Serializer.class)); if (returnClass.isPrimitive()) { // ASTORE argumentsSize + 1 _assertVarInsnNode(iterator.next(), Opcodes.ASTORE, argumentsSize + 1); // ALOAD argumentsSize + 1 _assertVarInsnNode(iterator.next(), Opcodes.ALOAD, argumentsSize + 1); // IFNULL nullCheckLabel LabelNode nullCheckLabelNode = _assertJumpInsnNode(iterator.next(), Opcodes.IFNULL); // ALOAD argumentsSize + 1 _assertVarInsnNode(iterator.next(), Opcodes.ALOAD, argumentsSize + 1); // CHECKCAST returnType _assertTypeInsnNode(iterator.next(), Opcodes.CHECKCAST, _autoboxingMap.get(returnClass)); if (returnClass == boolean.class) { // INVOKEVIRTUAL java/lang/Boolean booleanValue ()Z _assertMethodInsnNode(iterator.next(), Opcodes.INVOKEVIRTUAL, Type.getInternalName(Boolean.class), "booleanValue", Type.BOOLEAN_TYPE); } else if (returnClass == byte.class) { // INVOKEVIRTUAL java/lang/Number intValue ()I _assertMethodInsnNode(iterator.next(), Opcodes.INVOKEVIRTUAL, Type.getInternalName(Number.class), "intValue", Type.INT_TYPE); } else if (returnClass == char.class) { // INVOKEVIRTUAL java/lang/Character charValue ()C _assertMethodInsnNode(iterator.next(), Opcodes.INVOKEVIRTUAL, Type.getInternalName(Character.class), "charValue", Type.CHAR_TYPE); } else if (returnClass == double.class) { // INVOKEVIRTUAL java/lang/Number doubleValue ()D _assertMethodInsnNode(iterator.next(), Opcodes.INVOKEVIRTUAL, Type.getInternalName(Number.class), "doubleValue", Type.DOUBLE_TYPE); } else if (returnClass == float.class) { // INVOKEVIRTUAL java/lang/Number floatValue ()F _assertMethodInsnNode(iterator.next(), Opcodes.INVOKEVIRTUAL, Type.getInternalName(Number.class), "floatValue", Type.FLOAT_TYPE); } else if (returnClass == int.class) { // INVOKEVIRTUAL java/lang/Number intValue ()I _assertMethodInsnNode(iterator.next(), Opcodes.INVOKEVIRTUAL, Type.getInternalName(Number.class), "intValue", Type.INT_TYPE); } else if (returnClass == long.class) { // INVOKEVIRTUAL java/lang/Number longValue ()J _assertMethodInsnNode(iterator.next(), Opcodes.INVOKEVIRTUAL, Type.getInternalName(Number.class), "longValue", Type.LONG_TYPE); } else if (returnClass == short.class) { // INVOKEVIRTUAL java/lang/Number intValue ()I _assertMethodInsnNode(iterator.next(), Opcodes.INVOKEVIRTUAL, Type.getInternalName(Number.class), "intValue", Type.INT_TYPE); } // xRETURN _assertInsnNode(iterator.next(), returnType.getOpcode(Opcodes.IRETURN)); // nullCheckLabel Assert.assertSame(nullCheckLabelNode, iterator.next()); // xRETURN null/0 if (!returnClass.isPrimitive()) { _assertInsnNode(iterator.next(), Opcodes.ACONST_NULL); _assertInsnNode(iterator.next(), Opcodes.ARETURN); } else if (returnClass == void.class) { _assertInsnNode(iterator.next(), Opcodes.RETURN); } else if (returnClass == float.class) { _assertInsnNode(iterator.next(), Opcodes.FCONST_0); _assertInsnNode(iterator.next(), Opcodes.FRETURN); } else if (returnClass == double.class) { _assertInsnNode(iterator.next(), Opcodes.DCONST_0); _assertInsnNode(iterator.next(), Opcodes.DRETURN); } else if (returnClass == long.class) { _assertInsnNode(iterator.next(), Opcodes.LCONST_0); _assertInsnNode(iterator.next(), Opcodes.LRETURN); } else { _assertInsnNode(iterator.next(), Opcodes.ICONST_0); _assertInsnNode(iterator.next(), Opcodes.IRETURN); } } else { if (returnClass != Object.class) { // CHECKCAST _assertTypeInsnNode(iterator.next(), Opcodes.CHECKCAST, returnClass); } // ARETURN _assertInsnNode(iterator.next(), Opcodes.ARETURN); } } Assert.assertFalse(iterator.hasNext()); }
From source file:com.lion328.thaifixes.coremod.patcher.GuiNewChatBytecodePatcher.java
License:Open Source License
@Override public byte[] patchClass(byte[] source) { if (ThaiFixesConfiguration.getFontStyle() != ThaiFixesFontStyle.MCPX) return source; ClassReader classReader = new ClassReader(source); ClassNode classNode = new ClassNode(); classReader.accept(classNode, 0);// www . jav a 2 s . co m for (MethodNode method : classNode.methods) { if (method.name.equals(CLASSMAP.getMethod("drawChat")) && method.desc.equals("(I)V")) { AbstractInsnNode currentNode = null; for (int i = 0; i < method.instructions.size(); i++) { currentNode = method.instructions.get(i); if (currentNode.getOpcode() == Opcodes.BIPUSH) { if (method.instructions.get(i + 1).getOpcode() == Opcodes.IMUL) method.instructions.set(currentNode, new VarInsnNode(Opcodes.BIPUSH, ThaiFixesFontRenderer.MCPX_CHATBLOCK_HEIGHT)); else if (method.instructions.get(i + 1).getOpcode() == Opcodes.ISUB && method.instructions.get(i - 1).getOpcode() == Opcodes.ILOAD) { IntInsnNode node = (IntInsnNode) currentNode; if (node.operand == 9) method.instructions.set(currentNode, new VarInsnNode(Opcodes.BIPUSH, ThaiFixesFontRenderer.MCPX_CHATBLOCK_HEIGHT)); else if (node.operand == 8) method.instructions.set(currentNode, new VarInsnNode(Opcodes.BIPUSH, ThaiFixesFontRenderer.MCPX_CHATBLOCK_TEXT_YPOS)); } } } } else if (method.name.equals(CLASSMAP.getMethod("func_146236_a")) && method.desc.equals("(II)L" + ClassMap.getClassMap("net.minecraft.util.IChatComponent") .getClassInfo().getProductionClassName().replace('.', '/') + ";")) { for (int i = 0; i < method.instructions.size(); i++) { if (method.instructions.get(i).getOpcode() == Opcodes.GETFIELD) { FieldInsnNode node = (FieldInsnNode) method.instructions.get(i); if (node.owner.equals(ClassMap.getClassMap("net.minecraft.client.gui.FontRenderer") .getClassInfo().getProductionClassName().replace('.', '/')) && node.name.equals(ClassMap.getClassMap("net.minecraft.client.gui.FontRenderer") .getField("FONT_HEIGHT"))) { method.instructions.set(node, new VarInsnNode(Opcodes.BIPUSH, ThaiFixesFontRenderer.MCPX_CHATBLOCK_HEIGHT)); method.instructions.remove(method.instructions.get(i - 1)); // GETFIELD Minecraft.mc method.instructions.remove(method.instructions.get(i - 2)); // GETFIELD GuiNewChat.mc method.instructions.remove(method.instructions.get(i - 3)); // ALOAD 0 } } } } } ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS); classNode.accept(writer); return writer.toByteArray(); }