pcode-graph 4.0.0__tar.gz → 4.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/CHANGELOG +4 -0
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/PKG-INFO +2 -1
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/pcode_graph/characterization.py +41 -49
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/pyproject.toml +2 -1
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/.github/workflows/release.yml +0 -0
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/.github/workflows/test.yml +0 -0
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/.gitignore +0 -0
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/LICENSE +0 -0
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/README.md +0 -0
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/pcode_graph/__init__.py +0 -0
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/pcode_graph/__main__.py +0 -0
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/pcode_graph/analysis/alias_analysis.py +0 -0
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/pcode_graph/analysis/cfg.py +0 -0
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/pcode_graph/analysis/def_use.py +0 -0
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/pcode_graph/analysis/load_store.py +0 -0
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/pcode_graph/analysis/native_pcode.py +0 -0
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/pcode_graph/analysis/pass_base.py +0 -0
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/pcode_graph/analysis/passes.py +0 -0
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/pcode_graph/analysis/program.py +0 -0
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/pcode_graph/analysis/unreachable.py +0 -0
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/pcode_graph/arch.py +0 -0
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/pcode_graph/asm.py +0 -0
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/pcode_graph/basic_blocks.py +0 -0
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/pcode_graph/bit_utils.py +0 -0
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/pcode_graph/checker.py +0 -0
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/pcode_graph/cli.py +0 -0
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/pcode_graph/emulator.py +0 -0
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/pcode_graph/gnn_exporter.py +0 -0
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/pcode_graph/graph.py +0 -0
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/pcode_graph/lief_importer.py +0 -0
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/pcode_graph/log.py +0 -0
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/pcode_graph/maker.py +0 -0
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/pcode_graph/nx_exporter.py +0 -0
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/pcode_graph/pcode.py +0 -0
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/pcode_graph/registers.py +0 -0
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/pcode_graph/simplifier.py +0 -0
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/pcode_graph/torch_utils.py +0 -0
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/pcode_graph/translator.py +0 -0
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/pcode_graph/view.py +0 -0
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/pcode_graph/visitor.py +0 -0
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/requirements.txt +0 -0
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/tests/__init__.py +0 -0
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/tests/analysis_test.py +0 -0
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/tests/basic_block_test.py +0 -0
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/tests/callother_test.py +0 -0
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/tests/charac_test.py +0 -0
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/tests/cli_test.py +0 -0
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/tests/conftest.py +0 -0
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/tests/emulator_test.py +0 -0
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/tests/exporter_test.py +0 -0
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/tests/fixtures.py +0 -0
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/tests/helpers.py +0 -0
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/tests/lief_importer_test.py +0 -0
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/tests/load_store_test.py +0 -0
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/tests/maker_test.py +0 -0
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/tests/memory_test.py +0 -0
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/tests/translator_test.py +0 -0
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/tests/utils_test.py +0 -0
- {pcode_graph-4.0.0 → pcode_graph-4.1.0}/todo.md +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: pcode_graph
|
|
3
|
-
Version: 4.
|
|
3
|
+
Version: 4.1.0
|
|
4
4
|
Summary: Build, display and vectorize semantic graphs from binary code
|
|
5
5
|
Project-URL: Homepage, https://github.com/quarkslab/pcode_graph
|
|
6
6
|
Project-URL: Issues, https://github.com/quarkslab/pcode_graph/issues
|
|
@@ -12,6 +12,7 @@ Classifier: Programming Language :: Python :: 3
|
|
|
12
12
|
Classifier: Topic :: Security
|
|
13
13
|
Requires-Python: >=3.12
|
|
14
14
|
Requires-Dist: docopt
|
|
15
|
+
Requires-Dist: igraph~=1.0.0
|
|
15
16
|
Requires-Dist: keystone-engine~=0.9.2
|
|
16
17
|
Requires-Dist: lief~=1.0.0
|
|
17
18
|
Requires-Dist: loguru
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
from enum import IntFlag, auto
|
|
2
|
-
from typing import NamedTuple
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
from typing import Callable, NamedTuple
|
|
3
|
+
import igraph
|
|
6
4
|
from pcode_graph.nx_exporter import export_to_networkx
|
|
7
|
-
from pcode_graph.graph import CDG, EdgeKinds, NodeKinds
|
|
5
|
+
from pcode_graph.graph import CDG, Edge, EdgeKinds, NodeKinds
|
|
8
6
|
from pcode_graph.pcode import OpCodes
|
|
9
7
|
|
|
10
8
|
|
|
@@ -29,51 +27,38 @@ def count_edges(cdg: CDG) -> GraphCharacteristics:
|
|
|
29
27
|
return GraphCharacteristics(data_only, len(cdg.edges) - data_only, len(cdg.edges))
|
|
30
28
|
|
|
31
29
|
|
|
32
|
-
def
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
def diameter(adjacency) -> int:
|
|
52
|
-
# Compute graph diameter with BFS
|
|
53
|
-
d = 0
|
|
54
|
-
for src in range(n):
|
|
55
|
-
dist = [-1] * n
|
|
56
|
-
dist[src] = 0
|
|
57
|
-
front = deque((src,))
|
|
58
|
-
while front:
|
|
59
|
-
current = front.popleft()
|
|
60
|
-
for neigbor in adjacency[current]:
|
|
61
|
-
if dist[neigbor] == -1:
|
|
62
|
-
dist[neigbor] = dist[current] + 1
|
|
63
|
-
front.append(neigbor)
|
|
64
|
-
d = max(d, max(dist))
|
|
65
|
-
return d
|
|
30
|
+
def get_graph_diameter(
|
|
31
|
+
cdg: CDG,
|
|
32
|
+
edge_filter: Callable[[Edge], bool] = lambda e: True,
|
|
33
|
+
) -> int:
|
|
34
|
+
"""Computes the undirected diameter of the given graph."""
|
|
35
|
+
|
|
36
|
+
undirected = igraph.Graph(
|
|
37
|
+
n=len(cdg.nodes),
|
|
38
|
+
edges=[
|
|
39
|
+
(edge.source_node, edge.destination_node)
|
|
40
|
+
for edge in cdg.edges
|
|
41
|
+
if edge_filter(edge)
|
|
42
|
+
],
|
|
43
|
+
directed=True,
|
|
44
|
+
)
|
|
45
|
+
undirected.simplify()
|
|
46
|
+
return undirected.diameter(directed=True, unconn=True)
|
|
47
|
+
|
|
66
48
|
|
|
49
|
+
def get_graph_diameters(
|
|
50
|
+
cdg: CDG,
|
|
51
|
+
) -> GraphCharacteristics:
|
|
67
52
|
return GraphCharacteristics(
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
53
|
+
data_only=get_graph_diameter(cdg, lambda e: e.kind == EdgeKinds.Data),
|
|
54
|
+
control_only=get_graph_diameter(cdg, lambda e: e.kind != EdgeKinds.Data),
|
|
55
|
+
both=get_graph_diameter(cdg),
|
|
71
56
|
)
|
|
72
57
|
|
|
73
58
|
|
|
74
59
|
class FunctionCharacteristics(IntFlag):
|
|
75
60
|
"""Helps evaluating the level of difficulty of a function,
|
|
76
|
-
regarding
|
|
61
|
+
regarding miscellaneous ML tasks."""
|
|
77
62
|
|
|
78
63
|
data = auto()
|
|
79
64
|
condition = auto()
|
|
@@ -83,18 +68,25 @@ class FunctionCharacteristics(IntFlag):
|
|
|
83
68
|
loop = auto()
|
|
84
69
|
|
|
85
70
|
|
|
71
|
+
def has_loops(cdg: CDG) -> bool:
|
|
72
|
+
"""Returns True if the given graph has loops."""
|
|
73
|
+
edges = []
|
|
74
|
+
for edge in cdg.edges:
|
|
75
|
+
if edge.kind == EdgeKinds.Control:
|
|
76
|
+
edges.append((edge.source_node, edge.destination_node))
|
|
77
|
+
elif edge.kind == EdgeKinds.BasicBlockMembership:
|
|
78
|
+
# Reverse membership to create cycles
|
|
79
|
+
edges.append((edge.destination_node, edge.source_node))
|
|
80
|
+
return not igraph.Graph(n=len(cdg.nodes), edges=edges, directed=True).is_dag()
|
|
81
|
+
|
|
82
|
+
|
|
86
83
|
def get_function_characteristics(graph: CDG) -> FunctionCharacteristics:
|
|
87
84
|
"""Characterizes a function regarding control flow features."""
|
|
88
85
|
|
|
89
86
|
# Every function contains data-flow easiest level
|
|
90
87
|
function_characteristics = FunctionCharacteristics.data
|
|
91
88
|
|
|
92
|
-
|
|
93
|
-
try:
|
|
94
|
-
nx.find_cycle(ng)
|
|
95
|
-
except nx.NetworkXNoCycle:
|
|
96
|
-
pass
|
|
97
|
-
else:
|
|
89
|
+
if has_loops(graph):
|
|
98
90
|
function_characteristics |= FunctionCharacteristics.loop
|
|
99
91
|
|
|
100
92
|
for n in graph.nodes:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|