Class BeforeFieldAccess


  • public class BeforeFieldAccess
    extends BeforeInvoke

    This injection point searches for GETFIELD and PUTFIELD (and static equivalent) opcodes matching its arguments and returns a list of insns immediately prior to matching instructions. It accepts the following parameters from At:

    target
    A Target Selector which identifies the target field.
    opcode
    The opcode of the field access, must be one of GETSTATIC, PUTSTATIC, GETFIELD or PUTFIELD.
    ordinal
    The ordinal position of the field access to match. For example if the field is referenced 3 times and you want to match the 3rd then you can specify an ordinal of 2 (ordinals are zero-indexed). The default value is -1 which supresses ordinal matching
    named argument: array
    For matching accesses to an array field element following a GETFIELD or GETSTATIC. Specify get, set or length to match the desired operation.
    named argument: fuzz
    When matching array operations using array the injection point will by default search up to 8 instructions after the matched field insn. However in some cases the array operation may be further from the matched GETFIELD or GETSTATIC and the amount to search (the "fuzz factor" can be specified using this argument. Likewise to optimise the search against false positives, this value can be specified as a lower value if desired. Has no effect if array is not specified.

    Example:

    @At(value = "FIELD", target="field_59_z:I", opcode = Opcodes.GETFIELD)

    Matching array access:

    For array fields, it is possible to match field accesses followed by a corresponding array element get, set or length operation. To enable this behaviour specify the array named-argument with the desired operation:

    @At(value = "FIELD", target="myIntArray:[I", opcode = Opcodes.GETFIELD, args = "array=get")

    See Redirect for information on array element redirection.

    Note that like all standard injection points, this class matches the insn itself, putting the injection point immediately before the access in question. Use At.shift() specifier to adjust the matched opcode as necessary.

    • Field Detail

      • ARRAY_SEARCH_FUZZ_DEFAULT

        public static final int ARRAY_SEARCH_FUZZ_DEFAULT
        Default fuzz factor for searching for array access opcodes
        See Also:
        Constant Field Values
    • Method Detail

      • getFuzzFactor

        public int getFuzzFactor()
      • getArrayOpcode

        public int getArrayOpcode()
      • matchesInsn

        protected boolean matchesInsn​(org.objectweb.asm.tree.AbstractInsnNode insn)
        Overrides:
        matchesInsn in class BeforeInvoke
      • addInsn

        protected boolean addInsn​(org.objectweb.asm.tree.InsnList insns,
                                  java.util.Collection<org.objectweb.asm.tree.AbstractInsnNode> nodes,
                                  org.objectweb.asm.tree.AbstractInsnNode insn)
        Overrides:
        addInsn in class BeforeInvoke
      • findArrayNode

        public static org.objectweb.asm.tree.AbstractInsnNode findArrayNode​(org.objectweb.asm.tree.InsnList insns,
                                                                            org.objectweb.asm.tree.FieldInsnNode fieldNode,
                                                                            int opcode,
                                                                            int searchRange)
        Searches for an array access instruction in the supplied instruction list which is within searchRange instructions of the supplied field instruction. Searching halts if the search range is exhausted, if an Opcodes.ARRAYLENGTH opcode is encountered immediately after the specified access, if a matching field access is found, or if the end of the method is reached.
        Parameters:
        insns - Instruction list to search
        fieldNode - Field instruction to search from
        opcode - array access opcode to search for
        searchRange - search range
        Returns:
        matching opcode or null if not matched