Package ghidra.util.bytesearch
Class Pattern
java.lang.Object
ghidra.util.bytesearch.DittedBitSequence
ghidra.util.bytesearch.Pattern
- All Implemented Interfaces:
BytePattern
- Direct Known Subclasses:
GenericByteSequencePattern
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
ConstructorsChangeConstructorDescriptionPattern()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
ChangeModifier and TypeMethodDescriptionNEWbooleancheckPostRules(long offset) Check that the possible post rules are satisfiedintPostRule[]NEWintReturns the number of bytes in this pattern that represent a pre-sequence that must match before the official start of the matching pattern.static voidreadPatterns(ResourceFile file, ArrayList<Pattern> patlist, PatternFactory pfactory) Read patterns from specified filestatic voidreadPostPatterns(File file, ArrayList<Pattern> patternList, PatternFactory pfactory) Read just the post patterns from the<patternpair>tagsvoidrestoreXml(XmlPullParser parser, PatternFactory pfactory) static voidrestoreXmlAttributes(ArrayList<PostRule> postrulelist, ArrayList<MatchAction> actionlist, XmlPullParser parser, PatternFactory pfactory) Restore the PostRule and the MatchAction tagsvoidsetMatchActions(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
-
Constructor Details
-
Pattern
public Pattern()Construct an empty pattern. Use XML to initialize -
Pattern
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- DittedByteSequenceoffset- offset from the actual match location to report a matchpostArray- post set of rules to check for the matchmatchArray- MatchActions to apply when a match occurs
-
-
Method Details
-
getPostRules
-
getMatchActions
-
setMatchActions
-
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 tagspfactory- is the factory for the PostRule and MatchAction objects- Throws:
IOException
-
restoreXml
- 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 filepatlist- list for patterns to be added topfactory- optional factory for use in parsing PostRule and MatchAction elements. If null such elements may not be present.- Throws:
SAXExceptionIOException
-
readPostPatterns
public static void readPostPatterns(File file, ArrayList<Pattern> patternList, PatternFactory pfactory) throws SAXException, IOException Read just the post patterns from the<patternpair>tags- Parameters:
file- is the file to read frompatternList- collects the resulting Pattern objectspfactory- is the factory for constructing postrules and matchactions- Throws:
IOExceptionSAXException
-
checkPostRules NEW
public boolean checkPostRules(long offset) Check that the possible post rules are satisfied- Parameters:
offset- offset in stream to check postrules.- Returns:
- true if post rules are satisfied
-
getPreSequenceLength NEW
public int getPreSequenceLength()Description copied from interface:BytePatternReturns the number of bytes in this pattern that represent a pre-sequence that must match before the official start of the matching pattern. For example if looking for a pattern of "abcd", but only if it follows "xyz", then the pattern would be "xyzabcd", with a pre sequence length of 3. So when this pattern matches, we want the "match to be at the position where the "a" is and not the "x". This is know as "look behind" when using regular expressions.- Specified by:
getPreSequenceLengthin interfaceBytePattern- Overrides:
getPreSequenceLengthin classDittedBitSequence- Returns:
- the number of bytes in the pattern that represent a required pre sequence before the actual pattern we want to find the position of
-