@Override public MatchResult match(InstructionHandle handle, ConstantPoolGen cpg, ValueNumberFrame before, ValueNumberFrame after, BindingSet bindingSet) throws DataflowAnalysisException { Variable field; Instruction ins = handle.getInstruction(); FieldInstruction fieldIns; // The instruction must be GETFIELD or GETSTATIC if (ins instanceof GETFIELD) { fieldIns = (GETFIELD) ins; ValueNumber ref = before.getTopValue(); field = new FieldVariable(ref, fieldIns.getClassName(cpg), fieldIns.getFieldName(cpg), fieldIns.getSignature(cpg)); } else if (ins instanceof GETSTATIC) { fieldIns = (GETSTATIC) ins; field = new FieldVariable(fieldIns.getClassName(cpg), fieldIns.getFieldName(cpg), fieldIns.getSignature(cpg)); } else { return null; } Variable result = snarfFieldValue(fieldIns, cpg, after); return checkConsistent(field, result, bindingSet); } }
public static XField createXField(FieldInstruction fieldInstruction, ConstantPoolGen cpg) { String className = fieldInstruction.getClassName(cpg); String fieldName = fieldInstruction.getName(cpg); String fieldSig = fieldInstruction.getSignature(cpg); int opcode = fieldInstruction.getOpcode(); return createXField(className, fieldName, fieldSig, opcode == Const.GETSTATIC || opcode == Const.PUTSTATIC); }
/** * Return whether the given FieldInstruction accesses a long or double * field. * * @param fieldIns * the FieldInstruction * @param cpg * the ConstantPoolGen for the method */ protected static boolean isLongOrDouble(FieldInstruction fieldIns, ConstantPoolGen cpg) { Type type = fieldIns.getFieldType(cpg); int code = type.getType(); return code == Const.T_LONG || code == Const.T_DOUBLE; }
/** * Is the given instruction a read of a field? * * @param ins * the Instruction to check * @param cpg * ConstantPoolGen of the method containing the instruction * @return the Field if the instruction is a read of a field, null otherwise */ public static FieldAnnotation isRead(Instruction ins, ConstantPoolGen cpg) { if (ins instanceof GETFIELD || ins instanceof GETSTATIC) { FieldInstruction fins = (FieldInstruction) ins; String className = fins.getClassName(cpg); return new FieldAnnotation(className, fins.getName(cpg), fins.getSignature(cpg), fins instanceof GETSTATIC); } else { return null; } }
/** * Look up the field referenced by given FieldInstruction, returning it as * an {@link XField XField} object. * * @param fins * the FieldInstruction * @param cpg * the ConstantPoolGen used by the class containing the * instruction * @return an XField object representing the field, or null if no such field * could be found */ public static @CheckForNull XField findXField(FieldInstruction fins, @Nonnull ConstantPoolGen cpg) { String className = fins.getClassName(cpg); String fieldName = fins.getFieldName(cpg); String fieldSig = fins.getSignature(cpg); boolean isStatic = (fins.getOpcode() == Const.GETSTATIC || fins.getOpcode() == Const.PUTSTATIC); XField xfield = findXField(className, fieldName, fieldSig, isStatic); short opcode = fins.getOpcode(); if (xfield != null && xfield.isResolved() && xfield.isStatic() == (opcode == Const.GETSTATIC || opcode == Const.PUTSTATIC)) { return xfield; } else { return null; } }
public void visitFieldInstruction(FieldInstruction i) { short opcode = i.getOpcode(); String class_name = i.getClassName(_cp); String field_name = i.getFieldName(_cp); Type type = i.getFieldType(_cp); _out.println("il.append(_factory.createFieldAccess(\"" + class_name + "\", \"" + field_name + "\", " + BCELifier.printType(type) + ", " + "Constants." + Constants.OPCODE_NAMES[opcode].toUpperCase() + "));"); }
String childFName = ((FieldInstruction) childin).getFieldName(childPoolGen); String parentFName = ((FieldInstruction) parentin).getFieldName(parentPoolGen); if (!childFName.equals(parentFName)) { return false; String childFSig = ((FieldInstruction) childin).getSignature(childPoolGen); String parentFSig = ((FieldInstruction) parentin).getSignature(parentPoolGen); if (!childFSig.equals(parentFSig)) { return false; ReferenceType childRefType = ((FieldInstruction) childin).getReferenceType(childPoolGen); ReferenceType parentRefType = ((FieldInstruction) parentin).getReferenceType(parentPoolGen); if (!childRefType.getSignature().equals(parentRefType.getSignature())) { return false;
indexValid(o, o.getIndex()); Constant c = cpg.getConstant(o.getIndex()); if (! (c instanceof ConstantFieldref)){ constraintViolated(o, "Indexing a constant that's not a CONSTANT_Fieldref but a '"+c+"'."); String field_name = o.getFieldName(cpg); JavaClass jc = Repository.lookupClass(o.getClassType(cpg).getClassName()); Field[] fields = jc.getFields(); Field f = null; Type o_type = o.getType(cpg);
private void handleLoad(FieldInstruction obj) { consumeStack(obj); Type type = obj.getType(getCPG()); if (!STRING_SIGNATURE.equals(type.getSignature())) { throw new IllegalArgumentException("type is not String: " + type); } try { String className = obj.getClassName(getCPG()); String fieldName = obj.getName(getCPG()); Field field = Hierarchy.findField(className, fieldName); if (field != null) { // If the field is final, we'll assume that the String value // is static. if (field.isFinal()) { pushValue(staticStringTypeInstance); } else { pushValue(type); } return; } } catch (ClassNotFoundException ex) { lookupFailureCallback.reportMissingClass(ex); } pushValue(type); } }
public boolean checkCode(InstructionHandle[] code) { FieldInstruction ctrlFieldInstr = null; if (code[0].getInstruction() instanceof GETSTATIC) { ctrlFieldInstr = (FieldInstruction) code[0].getInstruction(); } else { ctrlFieldInstr = (FieldInstruction) code[code.length - 2].getInstruction(); } String className = ctrlFieldInstr.getName(cpg); String fieldName = ctrlFieldInstr.getFieldName(cpg); return className.equals(controlClass) && fieldName.equals(controlField.getName()); } });
public void visitFieldInstruction(final FieldInstruction o) { try { indexValid(o, o.getIndex()); final Constant c = cpg.getConstant(o.getIndex()); if (! (c instanceof ConstantFieldref)) { constraintViolated(o, "Indexing a constant that's not a CONSTANT_Fieldref but a '"+c+"'."); final String field_name = o.getFieldName(cpg); if (field.getName().equals(field_name)) { final Type f_type = Type.getType(field.getSignature()); final Type o_type = o.getType(cpg); if (field.getName().equals(field_name)) { final Type f_type = Type.getType(field.getSignature()); final Type o_type = o.getType(cpg); if (f_type.equals(o_type)) { f = field; o.getType(cpg);
if (ins instanceof FieldInstruction) { FieldInstruction fi = (FieldInstruction) ins; if (fi.getReferenceType(cpg).getSignature().equals(clsSig)) { String fieldName = fi.getFieldName(cpg); FieldInfo finfo = localizableFields.get(fieldName);
} else if (ins instanceof FieldInstruction) { FieldInstruction i = (FieldInstruction) ins; System.out.println(formatName(ins) +" "+i.getFieldName(cpg) + ""); } else if (ins instanceof IfInstruction) { IfInstruction i = (IfInstruction) ins;
/** @return type of field */ public Type getFieldType( final ConstantPoolGen cpg ) { return Type.getType(getSignature(cpg)); }
/** * Ensures the general preconditions of a FieldInstruction instance. */ public void visitFieldInstruction(FieldInstruction o){ // visitLoadClass(o) has been called before: Every FieldOrMethod // implements LoadClass. // visitCPInstruction(o) has been called before. // A FieldInstruction may be: GETFIELD, GETSTATIC, PUTFIELD, PUTSTATIC Constant c = cpg.getConstant(o.getIndex()); if (!(c instanceof ConstantFieldref)){ constraintViolated(o, "Index '"+o.getIndex()+"' should refer to a CONSTANT_Fieldref_info structure, but refers to '"+c+"'."); } // the o.getClassType(cpg) type has passed pass 2; see visitLoadClass(o). Type t = o.getType(cpg); if (t instanceof ObjectType){ String name = ((ObjectType)t).getClassName(); Verifier v = VerifierFactory.getVerifier( name ); VerificationResult vr = v.doPass2(); if (vr.getStatus() != VerificationResult.VERIFIED_OK){ constraintViolated((Instruction) o, "Class '"+name+"' is referenced, but cannot be loaded and resolved: '"+vr+"'."); } } }
/** @return name of referenced field. */ public String getFieldName( final ConstantPoolGen cpg ) { return getName(cpg); } }
Type fieldType = fins.getType(cpg); if (!(fieldType instanceof ReferenceType)) { continue;
isLocal = fins.getClassName(cpg).equals(classContext.getJavaClass().getClassName()); if (DEBUG) { System.out.println("Handling field access: " + location.getHandle() + " (frame="
private ObjectType getObjectType(final FieldInstruction o) { final ReferenceType rt = o.getReferenceType(cpg); if(rt instanceof ObjectType) { return (ObjectType)rt; } constraintViolated(o, "expecting ObjectType but got "+rt); return null; }
/** * Look up the field referenced by given FieldInstruction, returning it as * an {@link XField XField} object. * * @param fins * the FieldInstruction * @param cpg * the ConstantPoolGen used by the class containing the * instruction * @return an XField object representing the field, or null if no such field * could be found */ public static @CheckForNull XField findXField(FieldInstruction fins, @Nonnull ConstantPoolGen cpg) { String className = fins.getClassName(cpg); String fieldName = fins.getFieldName(cpg); String fieldSig = fins.getSignature(cpg); boolean isStatic = (fins.getOpcode() == Constants.GETSTATIC || fins.getOpcode() == Constants.PUTSTATIC); XField xfield = findXField(className, fieldName, fieldSig, isStatic); short opcode = fins.getOpcode(); if (xfield != null && xfield.isResolved() && xfield.isStatic() == (opcode == Constants.GETSTATIC || opcode == Constants.PUTSTATIC)) { return xfield; } else { return null; } }