Class TransformContext

java.lang.Object
org.jboss.byteman.agent.TransformContext

public class TransformContext extends Object
Class used to localise the context information employed when creating a rule from a rule script and using it to transform a method
  • Field Details

    • JAVA_METHOD_SPEC_PATTERN

      private static final String JAVA_METHOD_SPEC_PATTERN
      pattern used to identify target method specs which include a return type preceding the method name and parameter type list. note that we can only handle a return type in cases where the parameter type list is also specified.
      See Also:
    • TOFU

      public static final String TOFU
      See Also:
    • transformer

      private Transformer transformer
    • ruleScript

      private RuleScript ruleScript
    • triggerClassName

      private String triggerClassName
    • targetMethodName

      private String targetMethodName
    • targetDescriptor

      private String targetDescriptor
    • loader

      private ClassLoader loader
    • helperManager

      private HelperManager helperManager
    • accessEnabler

      private AccessEnabler accessEnabler
    • failed

      private boolean failed
    • ruleMap

      private HashMap<String,Rule> ruleMap
      a hashmap indexing Rule instances using key classname.methodnameandsig@loaderhashcode. rules are added to this map when they are created and removed when the transform is recorded as having succeeded or failed. a method check adapter will create a rule when it begins a method scan and a method trigger adpater will look it up in order to reuse it
    • firstRule

      private Rule firstRule
  • Constructor Details

  • Method Details

    • transform

      public byte[] transform(byte[] targetClassBytes)
    • parseRule

      public void parseRule() throws Exception
      Throws:
      Exception
    • lookupRule

      public Rule lookupRule(String triggerMethodName, String triggerMethodDescriptor)
      called by a trigger adapter to find a rule specific to a given trigger method, expects to find a rule created by the corresponding check adapter. if no rule is found then injection must be bypassed for this method
      Parameters:
      triggerMethodName - the name of a candidate method for injection
      triggerMethodDescriptor - the descriptor of a candidate method for injection
      Returns:
      the rule if it exists or NULL if not
    • createRule

      public Rule createRule(String triggerMethodName, String triggerMethodDescriptor)
      called by a check adapter to create a rule specific to a given trigger method. the first such call reuses the rule created by the intiial parse. subsequent calls create a new rule.
      Parameters:
      triggerMethodName - the name of a candidate method for injection
      triggerMethodDescriptor - the descriptor of a candidate method for injection
      Returns:
      the new rule
    • warn

      public void warn(String triggerMethodName, String triggerMethodDescriptor, String warningMessage)
      called by a check adapter to warn that a transform was not possible for a potential match target. this inhibits injection into the method being warned about allowing other injection operations to continue.
      Parameters:
      triggerMethodName - the name of a candidate method for injection
      triggerMethodDescriptor - the descriptor of a candidate method for injection
      warningMessage - details of the warning
    • fail

      public void fail(String failMessage, String triggerMethodName, String triggerMethodDescriptor)
      called by a check or trigger adapter to fail a transform because of a type issue. this aborts all injection into the current class not just injection into the current method.
      Parameters:
      failMessage - details of the failure
      triggerMethodName - the name of a candidate method for injection
      triggerMethodDescriptor - the descriptor of a candidate method for injection
    • recordFailedTransform

      public void recordFailedTransform(Throwable th)
    • matchTargetMethod

      public boolean matchTargetMethod(int access, String name, String desc)
    • injectIntoMethod

      public boolean injectIntoMethod(String name, String desc)
    • getTriggerClassName

      public String getTriggerClassName()
    • notifyRules

      private boolean notifyRules()
      this gets called when a transform attempt completes without any exceptions. if there are rules left in the rule map then they will belong successful injections.
    • purgeRules

      private void purgeRules()
      this gets called when a transform attempt fails. if there are rules left in the rule map then they will belong either to earlier successful injections or to the failed transform. in any case they need to be purged.
    • getRuleKey

      private String getRuleKey(String triggerMethodName, String triggerMethodDescriptor)
      return a unique string key identifying a specific rule compiled against some class and method/signature in the context of a specific class loader
      Returns:
      a unique string key
    • getKeyTriggerMethodName

      private String getKeyTriggerMethodName(String key)
      return the trigger method name used to construct the supplied rule key
      Parameters:
      key -
      Returns:
      the trigger method name
    • getKeyTriggerMethodDescriptor

      private String getKeyTriggerMethodDescriptor(String key)
      return the trigger method descriptor used to construct the supplied rule key
      Parameters:
      key -
      Returns:
      the trigger method descriptor
    • mungeMethodSpecReturnType

      private String mungeMethodSpecReturnType(String targetMethodSpec)
      detect a method specification which includes a return type preceding the method name and transform it so that the return type is at the end.
      Parameters:
      targetMethodSpec -
      Returns:
      the method spec in the desired format
    • getNonLoadingClassWriter

      private org.objectweb.asm.ClassWriter getNonLoadingClassWriter(int flags)
      get a class writer which will not attempt to load classes. The default classwriter tries this when a reference type local var frame slot aligns with a slot of reference type in a successor block's frame. This is merely so it can optimize a slot out of the frame change set in the special case where f1[slot].type invalid input: '<' f2[slot].type or vice versa by using the least common supereclass. We have to use the Transformer to reuse existing loaded classes and, where a class has not been loaded, to attempt to load the bytecode as a resource and identify supers via the bytecode.
      Parameters:
      flags -
      Returns:
      a non-loading class writer
    • findLeastCommonSuper

      public String findLeastCommonSuper(String t1, String t2)
    • listInterfaces

      private LinkedList<String> listInterfaces(ClassChecker checker)
    • listSupers

      private LinkedList<String> listSupers(ClassChecker checker)