diff options
| author | Vladislav HrĨka <41523109+nofiv@users.noreply.github.com> | 2019-02-08 08:02:38 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-02-08 08:02:38 +0100 |
| commit | e7684d8523f51f99ee78745bb856c9a3ddfa6fcc (patch) | |
| tree | 1dac28b2e79264544847b20db3cc34591b41cd6e /miasm2 | |
| parent | 4c8a61e8baa33cee185ff2b086c7b3094f99824e (diff) | |
| download | miasm-e7684d8523f51f99ee78745bb856c9a3ddfa6fcc.tar.gz miasm-e7684d8523f51f99ee78745bb856c9a3ddfa6fcc.zip | |
Added function find_path_from_src
The function find_path_from_src does the same as function find_path, but it searches the paths from src to dst, not vice versa like find_path, which might be more efficient in some cases.
Diffstat (limited to 'miasm2')
| -rw-r--r-- | miasm2/core/graph.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/miasm2/core/graph.py b/miasm2/core/graph.py index f61d1e67..b7026953 100644 --- a/miasm2/core/graph.py +++ b/miasm2/core/graph.py @@ -157,6 +157,28 @@ class DiGraph(object): if path and path[0] == src: out.append(path + [dst]) return out + + def find_path_from_src(self, src, dst, cycles_count=0, done=None): + """ + This function does the same as function find_path. + But it searches the paths from src to dst, not vice versa like find_path. + This approach might be more efficient in some cases. + """ + + if done is None: + done = {} + if src == dst: + return [[src]] + if src in done and done[src] > cycles_count: + return [[]] + out = [] + for node in self.mlt_blck.successors(src): + done_n = dict(done) + done_n[src] = done_n.get(src, 0) + 1 + for path in self.find_path_from_src(node, dst, cycles_count, done_n): + if path and path[len(path)-1] == dst: + out.append([src] + path) + return out def nodeid(self, node): """ |