Package ghidra.util.bytesearch

# Class Pattern

java.lang.Object
ghidra.util.bytesearch.DittedBitSequence
ghidra.util.bytesearch.Pattern

Direct Known Subclasses:
  `GenericByteSequencePattern`

public class Pattern extends DittedBitSequence
Pattern is an association of a DittedBitSequence to match, a set of post rules after a match is found that must be satisfied, and a set of actions to be taken if the pattern matches. These patterns can be restored from an XML file.

- ## Field Summary

  ### Fields inherited from class ghidra.util.bytesearch.DittedBitSequence

  `popcount`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Pattern()`
  Construct an empty pattern.
  `Pattern(DittedBitSequence seq, int offset, PostRule[] postArray, MatchAction[] matchArray)`
  Construct the pattern based on a DittedByteSequence a match offset, post matching rules, and a set of actions to take when the match occurs.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `int`
  `getMarkOffset()`
  `MatchAction[]`
  `getMatchActions()`
  `PostRule[]`
  `getPostRules()`
  `static void`
  `readPatterns(ResourceFile file, ArrayList<Pattern> patlist, PatternFactory pfactory)`
  Read patterns from specified file
  `static void`
  `readPostPatterns(File file, ArrayList<Pattern> patternList, PatternFactory pfactory)`
  Read just the post patterns from the tags
  `void`
  `restoreXml(XmlPullParser parser, PatternFactory pfactory)`
  `static void`
  `restoreXmlAttributes(ArrayList<PostRule> postrulelist, ArrayList<MatchAction> actionlist, XmlPullParser parser, PatternFactory pfactory)`
  Restore the PostRule and the MatchAction tags
  `void`
  `setMatchActions(MatchAction[] actions)`

  ### Methods inherited from class ghidra.util.bytesearch.DittedBitSequence

  `concatenate, equals, getHexString, getIndex, getMaskBytes, getNumFixedBits, getNumInitialFixedBits, getNumUncertainBits, getSize, getValueBytes, hashCode, isMatch, restoreXmlData, setIndex, toString, writeBits`

  ### Methods inherited from class java.lang.Object

  `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### Pattern

    public Pattern()
    Construct an empty pattern. Use XML to initialize

  - ### Pattern

    public Pattern(DittedBitSequence seq, int offset, PostRule[] postArray, MatchAction[] matchArray)
    Construct the pattern based on a DittedByteSequence a match offset, post matching rules, and a set of actions to take when the match occurs.
    Parameters:
      `seq` - DittedByteSequence
      `offset` - offset from the actual match location to report a match
      `postArray` - post set of rules to check for the match
      `matchArray` - MatchActions to apply when a match occurs

- ## Method Details

  - ### getPostRules

    public PostRule[] getPostRules()

  - ### getMatchActions

    public MatchAction[] getMatchActions()

  - ### setMatchActions

    public void setMatchActions(MatchAction[] actions)

  - ### getMarkOffset

    public int getMarkOffset()

  - ### restoreXmlAttributes

    public static void restoreXmlAttributes(ArrayList<PostRule> postrulelist, ArrayList<MatchAction> actionlist, XmlPullParser parser, PatternFactory pfactory) throws IOException
    Restore the PostRule and the MatchAction tags
    Parameters:
      `parser` - is the parser at the start of tags
      `pfactory` - is the factory for the PostRule and MatchAction objects
    Throws:
      `IOException`

  - ### restoreXml

    public void restoreXml(XmlPullParser parser, PatternFactory pfactory) throws IOException
    Throws:
      `IOException`

  - ### readPatterns

    public static void readPatterns(ResourceFile file, ArrayList<Pattern> patlist, PatternFactory pfactory) throws SAXException, IOException
    Read patterns from specified file
    Parameters:
      `file` - pattern file
      `patlist` - list for patterns to be added to
      `pfactory` - optional factory for use in parsing PostRule and MatchAction elements. If null such elements may not be present.
    Throws:
      `SAXException`
      `IOException`

  - ### readPostPatterns

    public static void readPostPatterns(File file, ArrayList<Pattern> patternList, PatternFactory pfactory) throws SAXException, IOException
    Read just the post patterns from the tags
    Parameters:
      `file` - is the file to read from
      `patternList` - collects the resulting Pattern objects
      `pfactory` - is the factory for constructing postrules and matchactions
    Throws:
      `IOException`
      `SAXException`