类org.objectweb.asm.tree.FieldInsnNode源码实例Demo

下面列出了怎么用org.objectweb.asm.tree.FieldInsnNode的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: Cafebabe   文件: SourceInterpreter.java
@Override
public SourceValue newOperation(final AbstractInsnNode insn) {
	int size;
	switch (insn.getOpcode()) {
	case LCONST_0:
	case LCONST_1:
	case DCONST_0:
	case DCONST_1:
		size = 2;
		break;
	case LDC:
		Object value = ((LdcInsnNode) insn).cst;
		size = value instanceof Long || value instanceof Double ? 2 : 1;
		break;
	case GETSTATIC:
		size = Type.getType(((FieldInsnNode) insn).desc).getSize();
		break;
	default:
		size = 1;
		break;
	}
	return new SourceValue(size, insn);
}
 
源代码2 项目: Concurnas   文件: SourceInterpreter.java
@Override
public SourceValue newOperation(final AbstractInsnNode insn) {
  int size;
  switch (insn.getOpcode()) {
    case LCONST_0:
    case LCONST_1:
    case DCONST_0:
    case DCONST_1:
      size = 2;
      break;
    case LDC:
      Object value = ((LdcInsnNode) insn).cst;
      size = value instanceof Long || value instanceof Double ? 2 : 1;
      break;
    case GETSTATIC:
      size = Type.getType(((FieldInsnNode) insn).desc).getSize();
      break;
    default:
      size = 1;
      break;
  }
  return new SourceValue(size, insn);
}
 
源代码3 项目: rscplus   文件: JClassPatcher.java
/**
 * TODO: Complete JavaDoc
 *
 * @param methodNode
 * @param owner The class of the variable to be hooked
 * @param var The variable to be hooked
 * @param desc
 * @param newClass The class the hooked variable will be stored in
 * @param newVar The variable name the hooked variable will be stored in
 * @param newDesc
 */
private void hookStaticVariable(
    MethodNode methodNode,
    String owner,
    String var,
    String desc,
    String newClass,
    String newVar,
    String newDesc) {
  Iterator<AbstractInsnNode> insnNodeList = methodNode.instructions.iterator();
  while (insnNodeList.hasNext()) {
    AbstractInsnNode insnNode = insnNodeList.next();

    int opcode = insnNode.getOpcode();
    if (opcode == Opcodes.GETSTATIC || opcode == Opcodes.PUTSTATIC) {
      FieldInsnNode field = (FieldInsnNode) insnNode;
      if (field.owner.equals(owner) && field.name.equals(var) && field.desc.equals(desc)) {
        field.owner = newClass;
        field.name = newVar;
        field.desc = newDesc;
      }
    }
  }
}
 
源代码4 项目: NOVA-Core   文件: InstructionComparator.java
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;
	}
}
 
源代码5 项目: NOVA-Core   文件: InstructionComparator.java
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;
	}
}
 
源代码6 项目: JReFrameworker   文件: SourceInterpreter.java
@Override
public SourceValue unaryOperation(final AbstractInsnNode insn, final SourceValue value) {
  int size;
  switch (insn.getOpcode()) {
    case LNEG:
    case DNEG:
    case I2L:
    case I2D:
    case L2D:
    case F2L:
    case F2D:
    case D2L:
      size = 2;
      break;
    case GETFIELD:
      size = Type.getType(((FieldInsnNode) insn).desc).getSize();
      break;
    default:
      size = 1;
      break;
  }
  return new SourceValue(size, insn);
}
 
private ArrayList<String> findNeededContents(ClassNode cn, MethodNode mn) {
	ArrayList<String> neededContents = new ArrayList<>();
	for (AbstractInsnNode ain : mn.instructions.toArray()) {
		if (ain instanceof MethodInsnNode) {
			MethodInsnNode min = (MethodInsnNode) ain;
			if (min.owner.equals(cn.name) && !neededContents.contains(min.name + min.desc)) {
				neededContents.add(min.name + min.desc);
				neededContents.addAll(findNeededContents(cn, ClassUtils.getMethod(cn, min.name, min.desc)));
			}
		}
		if (ain instanceof FieldInsnNode) {
			FieldInsnNode fin = (FieldInsnNode) ain;
			if (fin.owner.equals(cn.name) && !neededContents.contains(fin.name + fin.desc)) {
				neededContents.add(fin.name + fin.desc);
			}
		}
	}
	return neededContents;
}
 
源代码8 项目: jumbune   文件: ConfigureMapReduceAdapter.java
/**
 * This method removes the jumbune mumber from threadLocal signifying that
 * jumbune doesn't need to log further information.
 *
 * @return InsnList list of instructions to be injected
 */
private InsnList stopJumbuneLogging() {
	LOGGER.debug("Removing jumbune from ThreadLocal");
	InsnList il = new InsnList();
	il.add(new LabelNode());

	String methodDesc = null;

	if (isOldApiClazz()) {
		il.add(new VarInsnNode(Opcodes.ALOAD, 0));
		il.add(new FieldInsnNode(Opcodes.GETFIELD, ConfigurationUtil
				.convertQualifiedClassNameToInternalName(getClassName()),
				InstrumentConstants.FIELD_UNLOADLOGGER, "Z"));

		methodDesc = Type.getMethodDescriptor(Type.VOID_TYPE,
				Type.BOOLEAN_TYPE);
	} else {
		methodDesc = EMPTY_PARAMETER_VOID_RETURN;
	}

	il.add(new MethodInsnNode(Opcodes.INVOKESTATIC,
			CLASSNAME_MAPREDUCEEXECUTIL, "stopJumbuneLogging", methodDesc));
	return il;
}
 
源代码9 项目: nuls-v2   文件: Getstatic.java
public static void getstatic(Frame frame) {
    FieldInsnNode fieldInsnNode = frame.fieldInsnNode();
    String className = fieldInsnNode.owner;
    String fieldName = fieldInsnNode.name;
    String fieldDesc = fieldInsnNode.desc;
    Object value = frame.heap.getStatic(className, fieldName);
    if (Descriptors.LONG_DESC.equals(fieldDesc)) {
        frame.operandStack.pushLong((long) value);
    } else if (Descriptors.DOUBLE_DESC.equals(fieldDesc)) {
        frame.operandStack.pushDouble((double) value);
    } else {
        frame.operandStack.push(value);
    }

    //Log.result(frame.getCurrentOpCode(), value, className, fieldName);
}
 
源代码10 项目: nuls-v2   文件: Putstatic.java
public static void putstatic(Frame frame) {
    FieldInsnNode fieldInsnNode = frame.fieldInsnNode();
    String className = fieldInsnNode.owner;
    String fieldName = fieldInsnNode.name;
    String fieldDesc = fieldInsnNode.desc;
    Object value;
    if (Descriptors.LONG_DESC.equals(fieldDesc)) {
        value = frame.operandStack.popLong();
    } else if (Descriptors.DOUBLE_DESC.equals(fieldDesc)) {
        value = frame.operandStack.popDouble();
    } else {
        value = frame.operandStack.pop();
    }
    frame.heap.putStatic(className, fieldName, value);

    //Log.result(frame.getCurrentOpCode(), value, className, fieldName);
}
 
源代码11 项目: uima-uimaj   文件: FeatureStructureClassGen.java
private void addFeatureGetSet() {
  for (boolean isGet : GET_SET) {
    MethodNode mn = new MethodNode(ASM5, ACC_PUBLIC,    //  Get for non-array value
        fi.getGetterSetterName(isGet), 
        isGet ? ("()" + rangeJavaDescriptor) 
              : "(" + rangeJavaDescriptor + ")V", 
        null, null);
    InsnList il = mn.instructions;
    il.add(new VarInsnNode(ALOAD,  0));
    if (isGet) {
      il.add(new FieldInsnNode(GETFIELD, typeJavaClassName, featureFieldName, rangeJavaDescriptor));
      il.add(new InsnNode(getReturnInst(fi)));
    } else {
      il.add(new VarInsnNode(getLoadInst(fi), 1));        // load ref, or primitive value
      il.add(new FieldInsnNode(PUTFIELD, typeJavaClassName, featureFieldName, rangeJavaDescriptor));
      il.add(new InsnNode(RETURN));
    }
    final boolean is2slotValue = ((TypeImpl) fi.getRange()).isLongOrDouble();
    mn.maxStack  = isGet ? 1 : is2slotValue ? 3 : 2;
    mn.maxLocals = isGet ? 1 : is2slotValue ? 3 : 2;
    cn.methods.add(mn);    
  }    
}
 
源代码12 项目: nuls   文件: Getstatic.java
public static void getstatic(Frame frame) {
    FieldInsnNode fieldInsnNode = frame.fieldInsnNode();
    String className = fieldInsnNode.owner;
    String fieldName = fieldInsnNode.name;
    String fieldDesc = fieldInsnNode.desc;
    Object value = frame.heap.getStatic(className, fieldName);
    if (Descriptors.LONG_DESC.equals(fieldDesc)) {
        frame.operandStack.pushLong((long) value);
    } else if (Descriptors.DOUBLE_DESC.equals(fieldDesc)) {
        frame.operandStack.pushDouble((double) value);
    } else {
        frame.operandStack.push(value);
    }

    //Log.result(frame.getCurrentOpCode(), value, className, fieldName);
}
 
源代码13 项目: nuls   文件: Putstatic.java
public static void putstatic(Frame frame) {
    FieldInsnNode fieldInsnNode = frame.fieldInsnNode();
    String className = fieldInsnNode.owner;
    String fieldName = fieldInsnNode.name;
    String fieldDesc = fieldInsnNode.desc;
    Object value;
    if (Descriptors.LONG_DESC.equals(fieldDesc)) {
        value = frame.operandStack.popLong();
    } else if (Descriptors.DOUBLE_DESC.equals(fieldDesc)) {
        value = frame.operandStack.popDouble();
    } else {
        value = frame.operandStack.pop();
    }
    frame.heap.putStatic(className, fieldName, value);

    //Log.result(frame.getCurrentOpCode(), value, className, fieldName);
}
 
源代码14 项目: javaide   文件: ApiDetector.java
private static MethodNode findEnumSwitchUsage(ClassNode classNode, String owner) {
    String target = ENUM_SWITCH_PREFIX + owner.replace('/', '$');
    @SuppressWarnings("rawtypes") // ASM API
    List methodList = classNode.methods;
    for (Object f : methodList) {
        MethodNode method = (MethodNode) f;
        InsnList nodes = method.instructions;
        for (int i = 0, n = nodes.size(); i < n; i++) {
            AbstractInsnNode instruction = nodes.get(i);
            if (instruction.getOpcode() == Opcodes.GETSTATIC) {
                FieldInsnNode field = (FieldInsnNode) instruction;
                if (field.name.equals(target)) {
                    return method;
                }
            }
        }
    }
    return null;
}
 
源代码15 项目: coroutines   文件: DebugGenerators.java
/**
 * Generates instructions for generating marker instructions. These marker instructions are meant to be is useful for debugging
 * instrumented code. For example, you can spot a specific portion of instrumented code by looking for specific markers in the assembly
 * output.
 * @param markerType marker type (determines what kind of instructions are generated)
 * @param text text to print out
 * @return instructions to call System.out.println with a string constant
 * @throws NullPointerException if any argument is {@code null}
 */
public static InsnList debugMarker(MarkerType markerType, String text) {
    Validate.notNull(markerType);
    Validate.notNull(text);
    
    InsnList ret = new InsnList();
    
    switch (markerType) {
        case NONE:
            break;
        case CONSTANT:
            ret.add(new LdcInsnNode(text));
            ret.add(new InsnNode(Opcodes.POP));
            break;
        case STDOUT:
            ret.add(new FieldInsnNode(Opcodes.GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;"));
            ret.add(new LdcInsnNode(text));
            ret.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V", false));
            break;
        default:
            throw new IllegalStateException();
    }

    return ret;
}
 
源代码16 项目: pinpoint   文件: ASMClassNodeAdapter.java
public void addSetterMethod(final String methodName, final ASMFieldNodeAdapter fieldNode) {
    Assert.requireNonNull(methodName, "methodName");
    Assert.requireNonNull(fieldNode, "fieldNode");


    // void is V.
    final String desc = "(" + fieldNode.getDesc() + ")V";
    final MethodNode methodNode = new MethodNode(Opcodes.ACC_PUBLIC, methodName, desc, null, null);
    final InsnList instructions = getInsnList(methodNode);
    // load this.
    instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
    final Type type = Type.getType(fieldNode.getDesc());
    // put field.
    instructions.add(new VarInsnNode(type.getOpcode(Opcodes.ILOAD), 1));
    instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, classNode.name, fieldNode.getName(), fieldNode.getDesc()));
    // return.
    instructions.add(new InsnNode(Opcodes.RETURN));

    addMethodNode0(methodNode);
}
 
源代码17 项目: bytecode-viewer   文件: ASMUtil_OLD.java
public static void renameFieldNode(String originalParentName,
                                   String originalFieldName, String originalFieldDesc,
                                   String newFieldParent, String newFieldName, String newFieldDesc) {
    for (ClassNode c : BytecodeViewer.getLoadedClasses()) {
        for (Object o : c.methods.toArray()) {
            MethodNode m = (MethodNode) o;
            for (AbstractInsnNode i : m.instructions.toArray()) {
                if (i instanceof FieldInsnNode) {
                    FieldInsnNode field = (FieldInsnNode) i;

                    if (field.owner.equals(originalParentName)
                            && field.name.equals(originalFieldName)
                            && field.desc.equals(originalFieldDesc)) {
                        if (newFieldParent != null)
                            field.owner = newFieldParent;
                        if (newFieldName != null)
                            field.name = newFieldName;
                        if (newFieldDesc != null)
                            field.desc = newFieldDesc;
                    }
                }
            }
        }
    }
}
 
源代码18 项目: JByteMod-Beta   文件: SourceInterpreter.java
@Override
public SourceValue unaryOperation(final AbstractInsnNode insn, final SourceValue value) {
  int size;
  switch (insn.getOpcode()) {
  case LNEG:
  case DNEG:
  case I2L:
  case I2D:
  case L2D:
  case F2L:
  case F2D:
  case D2L:
    size = 2;
    break;
  case GETFIELD:
    size = Type.getType(((FieldInsnNode) insn).desc).getSize();
    break;
  default:
    size = 1;
  }
  return new SourceValue(size, insn);
}
 
源代码19 项目: pinpoint   文件: ASMClassNodeAdapter.java
public void addGetterMethod(final String methodName, final ASMFieldNodeAdapter fieldNode) {
    Assert.requireNonNull(methodName, "methodName");
    Assert.requireNonNull(fieldNode, "fieldNode");


    // no argument is ().
    final String desc = "()" + fieldNode.getDesc();
    final MethodNode methodNode = new MethodNode(Opcodes.ACC_PUBLIC, methodName, desc, null, null);
    final InsnList instructions = getInsnList(methodNode);
    // load this.
    instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
    // get fieldNode.
    instructions.add(new FieldInsnNode(Opcodes.GETFIELD, classNode.name, fieldNode.getName(), fieldNode.getDesc()));
    // return of type.
    final Type type = Type.getType(fieldNode.getDesc());
    instructions.add(new InsnNode(type.getOpcode(Opcodes.IRETURN)));

    addMethodNode0(methodNode);
}
 
源代码20 项目: Mixin   文件: BeforeFieldAccess.java
@Override
protected boolean matchesInsn(AbstractInsnNode insn) {
    if (insn instanceof FieldInsnNode && (((FieldInsnNode) insn).getOpcode() == this.opcode || this.opcode == -1)) {
        if (this.arrOpcode == 0) {
            return true;
        }
        
        if (insn.getOpcode() != Opcodes.GETSTATIC && insn.getOpcode() != Opcodes.GETFIELD) {
            return false;
        }
        
        return Type.getType(((FieldInsnNode)insn).desc).getSort() == Type.ARRAY;
    }
    
    return false;
}
 
源代码21 项目: deobfuscator   文件: StringEncryptionTransformer.java
private boolean isSmokeMethod(MethodNode method)
  {
boolean containsArray = false;
int putstatic = 0;
int getstatic = 0;
  	for(AbstractInsnNode ain : method.instructions.toArray())
  		if(ain.getOpcode() == Opcodes.ANEWARRAY)
  			containsArray = true;
  		else if(ain.getOpcode() == Opcodes.PUTSTATIC || ain.getOpcode() == Opcodes.GETSTATIC)
  			if(((FieldInsnNode)ain).desc.equals("[Ljava/lang/String;"))
  			{
  				if(ain.getOpcode() == Opcodes.PUTSTATIC)
  					putstatic++;
  				else
  					getstatic++;
  			}
  			
  	return containsArray && putstatic == 2 && getstatic == 2;
  }
 
源代码22 项目: grappa   文件: GroupClassGenerator.java
protected static void convertXLoads(final InstructionGroup group)
{
    final String owner = group.getGroupClassType().getInternalName();

    InsnList insnList;

    for (final InstructionGraphNode node : group.getNodes()) {
        if (!node.isXLoad())
            continue;

        final VarInsnNode insn = (VarInsnNode) node.getInstruction();
        final FieldNode field = group.getFields().get(insn.var);
        final FieldInsnNode fieldNode = new FieldInsnNode(GETFIELD, owner,
            field.name, field.desc);

        insnList = group.getInstructions();

        // insert the correct GETFIELD after the xLoad
        insnList.insert(insn, fieldNode);
        // change the load to ALOAD 0
        insnList.set(insn, new VarInsnNode(ALOAD, 0));
    }
}
 
源代码23 项目: Diorite   文件: TransformerFieldInjector.java
private void trackFieldToInject(FieldInsnNode fieldInsnNode, InsnList insnList)
{
    // check if field is in this same class
    if (! fieldInsnNode.owner.equals(this.injectTransformer.classNode.name))
    {
        return;
    }
    // first check if field is injected
    TransformerFieldPair fieldPair = this.injectTransformer.getFieldPair(fieldInsnNode);
    if ((fieldPair == null) || (fieldPair.node == null) || (fieldPair.data == null))
    {
        return;
    }

    TransformerInjectTracker injectTracker = TransformerInjectTracker.trackFromField(this.injectTransformer, fieldInsnNode, insnList);
    fieldPair.placeholderType = injectTracker.getPlaceholderType();
    this.injectField(fieldPair, injectTracker);
}
 
源代码24 项目: Bats   文件: ReplacingInterpreter.java
@Override
public BasicValue unaryOperation(final AbstractInsnNode insn, final BasicValue value)
    throws AnalyzerException {
  /*
   * We're looking for the assignment of an operator member variable that's a holder to a local
   * objectref. If we spot that, we can't replace the local objectref (at least not
   * until we do the work to replace member variable holders).
   *
   * Note that a GETFIELD does not call newValue(), as would happen for a local variable, so we're
   * emulating that here.
   */
  if ((insn.getOpcode() == Opcodes.GETFIELD) && (value instanceof ReplacingBasicValue)) {
    final ReplacingBasicValue possibleThis = (ReplacingBasicValue) value;
    if (possibleThis.isThis()) {
      final FieldInsnNode fieldInsn = (FieldInsnNode) insn;
      if (HOLDERS.get(fieldInsn.desc) != null) {
        final BasicValue fetchedField = super.unaryOperation(insn, value);
        final ReplacingBasicValue replacingValue =
            ReplacingBasicValue.create(fetchedField.getType(), null, -1, valueList);
        replacingValue.setAssignedToMember();
        return replacingValue;
      }
    }
  }

  return super.unaryOperation(insn,  value);
}
 
源代码25 项目: jumbune   文件: ConfigureMapReduceAdapter.java
/**
 * <p>
 * This method provides instruction to inject method call to load the logger
 * </p>.
 *
 * @return InsnList Instructions
 */
private InsnList loadLogger() {
	LOGGER.debug(MessageFormat.format(InstrumentationMessageLoader
			.getMessage(MessageConstants.LOG_LOAD_LOGGER), getClassName()));

	InsnList il = new InsnList();
	il.add(new LabelNode());
	String logFileDir = workerLogLocation.substring(0, workerLogLocation.lastIndexOf('/') + 1);

	// getting task attempt id
	il.add(new LdcInsnNode(logFileDir));
	il.add(new VarInsnNode(Opcodes.ALOAD, 1));
	il.add(new LdcInsnNode(isMapperClass()));

	String methodDesc = null;

	if (isOldApiClazz()) {
		il.add(new VarInsnNode(Opcodes.ALOAD, 0));
		il.add(new FieldInsnNode(Opcodes.GETFIELD, ConfigurationUtil
				.convertQualifiedClassNameToInternalName(getClassName()),
				InstrumentConstants.FIELD_LOADLOGGER, "Z"));
		il.add(new VarInsnNode(Opcodes.ALOAD, 0));
		il.add(new FieldInsnNode(Opcodes.GETFIELD, ConfigurationUtil
				.convertQualifiedClassNameToInternalName(getClassName()),
				InstrumentConstants.FIELD_LOGGERNUMBER, "I"));

		methodDesc = Type.getMethodDescriptor(Type.VOID_TYPE, TYPE_STRING,
				TYPE_JOBCONF, Type.BOOLEAN_TYPE, Type.BOOLEAN_TYPE,
				Type.INT_TYPE);
	} else {
		methodDesc = Type.getMethodDescriptor(Type.VOID_TYPE, TYPE_STRING,
				TYPE_TASKINPUTOUTPUTCONTEXT, Type.BOOLEAN_TYPE);
	}
	il.add(new MethodInsnNode(Opcodes.INVOKESTATIC, Type
			.getInternalName(MapReduceExecutionUtil.class),
			"configureLogging", methodDesc));

	return il;
}
 
源代码26 项目: rscplus   文件: JClassPatcher.java
/**
 * TODO: Complete JavaDoc
 *
 * @param methodNode
 * @param owner The class of the variable to be hooked
 * @param var The variable to be hooked
 * @param desc
 * @param newClass The class the hooked variable will be stored in
 * @param newVar The variable name the hooked variable will be stored in
 * @param newDesc
 * @param canRead Specifies if the hooked variable should be readable
 * @param canWrite Specifies if the hooked variable should be writable
 */
private void hookClassVariable(
    MethodNode methodNode,
    String owner,
    String var,
    String desc,
    String newClass,
    String newVar,
    String newDesc,
    boolean canRead,
    boolean canWrite) {
  Iterator<AbstractInsnNode> insnNodeList = methodNode.instructions.iterator();
  while (insnNodeList.hasNext()) {
    AbstractInsnNode insnNode = insnNodeList.next();

    int opcode = insnNode.getOpcode();
    if (opcode == Opcodes.GETFIELD || opcode == Opcodes.PUTFIELD) {
      FieldInsnNode field = (FieldInsnNode) insnNode;
      if (field.owner.equals(owner) && field.name.equals(var) && field.desc.equals(desc)) {
        if (opcode == Opcodes.GETFIELD && canWrite) {
          methodNode.instructions.insert(
              insnNode, new FieldInsnNode(Opcodes.GETSTATIC, newClass, newVar, newDesc));
          methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.POP));
        } else if (opcode == Opcodes.PUTFIELD && canRead) {
          methodNode.instructions.insertBefore(insnNode, new InsnNode(Opcodes.DUP_X1));
          methodNode.instructions.insert(
              insnNode, new FieldInsnNode(Opcodes.PUTSTATIC, newClass, newVar, newDesc));
        }
      }
    }
  }
}
 
源代码27 项目: grappa   文件: CodeBlock.java
public CodeBlock visitFieldInsn(final int opcode, final String className,
    final String fieldName, final String fieldDesc)
{
    instructionList.add(new FieldInsnNode(opcode, className, fieldName,
        fieldDesc));
    return this;
}
 
源代码28 项目: TFC2   文件: InsnComparator.java
/**
 * Respects {@link #INT_WILDCARD} and {@link #WILDCARD} instruction properties.
 * Always returns true if {@code a} and {@code b} are label, line number, or frame instructions.
 * 
 * @return Whether or not the given instructions are equivalent.
 */
public boolean areInsnsEqual(AbstractInsnNode a, AbstractInsnNode b)
{
	if (a == b)
		return true;

	if (a == null || b == null)
		return false;

	if (a.equals(b))
		return true;

	if (a.getOpcode() != b.getOpcode())
		return false;

	switch (a.getType())
	{
		case AbstractInsnNode.VAR_INSN:
			return areVarInsnsEqual((VarInsnNode) a, (VarInsnNode) b);
		case AbstractInsnNode.TYPE_INSN:
			return areTypeInsnsEqual((TypeInsnNode) a, (TypeInsnNode) b);
		case AbstractInsnNode.FIELD_INSN:
			return areFieldInsnsEqual((FieldInsnNode) a, (FieldInsnNode) b);
		case AbstractInsnNode.METHOD_INSN:
			return areMethodInsnsEqual((MethodInsnNode) a, (MethodInsnNode) b);
		case AbstractInsnNode.LDC_INSN:
			return areLdcInsnsEqual((LdcInsnNode) a, (LdcInsnNode) b);
		case AbstractInsnNode.IINC_INSN:
			return areIincInsnsEqual((IincInsnNode) a, (IincInsnNode) b);
		case AbstractInsnNode.INT_INSN:
			return areIntInsnsEqual((IntInsnNode) a, (IntInsnNode) b);
		default:
			return true;
	}
}
 
源代码29 项目: Cafebabe   文件: OpcodeFormatting.java
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;
}
 
源代码30 项目: grappa   文件: CodeBlock.java
public CodeBlock getstatic(final String className, final String fieldName,
    final String fieldDesc)
{
    instructionList.add(new FieldInsnNode(GETSTATIC, className, fieldName,
        fieldDesc));
    return this;
}
 
 类所在包
 类方法
 同包方法