Repository navigation
Feature MatchGraph - #310
Merged
Merged
Conversation
Conflicts: test/core/graph.py
Conflicts: miasm2/core/asmbloc.py
commial
force-pushed
the
feature-matchgraph
branch
from
January 27, 2016 10:12
82ea9af to
f95130b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Introduce
MatchGraph, which aims to be the counterpart ofMatchExprfor graphs.It is composed of
MatchGraphJoker, which are joker for nodes, giving custom restrictions.From the corresponding docstring:
Then, one can iterate over solutions using
matcher.match(graph), an iterator on dictionnary joker ->matched graph node.Restrictions can be applied on jokers, for instance:
restrict_in: if not set, the corresponding node can have more predecessors than in the pattern (for instance, in pattern heads)restrict_out: idem, for successorsfilt: a boolean function taking the candidate node in argument and applying a pre-filter.In the previous example, if one wants to only catch basic blocks starting with a
PUSHin j1, he can write:Operating on
MatchGraphJokers is a quick way to buildMatchGraphinstance, specifying only edges (j1 >> j2means an edge fromj1toj2).As
MatchGraphinherits fromDiGraph, one can use.dot()to visualize the built pattern.The algorithm uses for pattern matching is naive, but oriented to quickly provides solutions. In others word, it may have a lot of work between two yielded solutions but a first solution should appear quickly (as the difference between a Depth-first search and a Breadth-first search).
This choice has been made because its seems that a common use case is the retrieve of just one match. For instance, in a
DiGraphSimplifier, one should only iterate once if he modifies the graph between two match (they might finish incoherent).In reasonable graph size, as program functions CFG, the algorithm is fast enough to be usable.