pcode-graph 3.0.0__py3-none-any.whl → 3.0.2__py3-none-any.whl

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.
@@ -170,6 +170,10 @@ def iter_functions(binary: Path | lief.Binary) -> Iterator[FunctionCode]:
170
170
  cache: dict[Any, tuple[bytes, int]] = {}
171
171
  sym: lief.ELF.Symbol
172
172
 
173
+ # In relocatable objects, symbol values are offsets in their section, whereas
174
+ # in executables and shared libraries they are virtual addresses.
175
+ relocatable = binary.header.file_type == lief.ELF.Header.FILE_TYPE.REL # type: ignore
176
+
173
177
  for sym in binary.symtab_symbols: # type: ignore
174
178
  if sym.type != lief.ELF.Symbol.TYPE.FUNC or sym.size == 0:
175
179
  continue
@@ -182,12 +186,16 @@ def iter_functions(binary: Path | lief.Binary) -> Iterator[FunctionCode]:
182
186
  cache[section_id] = (bytes(section.content), section.virtual_address)
183
187
 
184
188
  section_content, section_address = cache[section_id]
189
+ offset = sym.value if relocatable else sym.value - section_address
190
+ if offset < 0 or offset + sym.size > len(section_content):
191
+ logger.warning(f"Skip function {sym.name}: out of section {section_id}")
192
+ continue
185
193
 
186
194
  assert isinstance(sym.name, str)
187
195
  yield FunctionCode(
188
196
  sym.name,
189
- section_address + sym.value,
190
- section_content[sym.value : sym.value + sym.size],
197
+ section_address + offset,
198
+ section_content[offset : offset + sym.size],
191
199
  )
192
200
 
193
201
 
pcode_graph/simplifier.py CHANGED
@@ -13,6 +13,9 @@ from pathlib import Path
13
13
 
14
14
 
15
15
  class GraphSimplifier:
16
+ """This simplifier is built to work with flat CFG, Basic Block nodes
17
+ and Membership edges are not taken into account.
18
+ """
16
19
 
17
20
  def __init__(
18
21
  self,
@@ -64,27 +67,23 @@ class GraphSimplifier:
64
67
  self.graph.nodes[index].kind == NodeKinds.Phi and len(set(data_preds)) == 1
65
68
  ), "More than one data predecessor to the node to remove"
66
69
 
67
- for i, e in enumerate(self.graph.edges):
68
- if e is None:
69
- continue
70
- remove = False
71
- if e.source_node == index:
72
- if e.kind == EdgeKinds.Data:
73
- self._proxy[e.source_node].out_edge_indexes.remove(i)
74
- e.source_node = data_preds[0]
75
- self._proxy[e.source_node].out_edge_indexes.append(i)
76
- else:
77
- remove = True
78
-
79
- if e.destination_node == index:
80
- if e.kind == EdgeKinds.Control:
81
- self._proxy[e.destination_node].in_edge_indexes.remove(i)
82
- e.destination_node = control_succs[0]
83
- self._proxy[e.destination_node].in_edge_indexes.append(i)
84
- else:
85
- remove = True
86
-
87
- if remove:
70
+
71
+ for i in list(proxy.out_edge_indexes):
72
+ e = self.graph.edges[i]
73
+ if e.kind == EdgeKinds.Data:
74
+ self._proxy[e.source_node].out_edge_indexes.remove(i)
75
+ e.source_node = data_preds[0]
76
+ self._proxy[e.source_node].out_edge_indexes.append(i)
77
+ else:
78
+ self._remove_edge(i)
79
+
80
+ for i in list(proxy.in_edge_indexes):
81
+ e = self.graph.edges[i]
82
+ if e.kind == EdgeKinds.Control:
83
+ self._proxy[e.destination_node].in_edge_indexes.remove(i)
84
+ e.destination_node = control_succs[0]
85
+ self._proxy[e.destination_node].in_edge_indexes.append(i)
86
+ else:
88
87
  self._remove_edge(i)
89
88
 
90
89
  # Patch the graph
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: pcode_graph
3
- Version: 3.0.0
3
+ Version: 3.0.2
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
@@ -30,6 +30,14 @@ Description-Content-Type: text/markdown
30
30
  This library helps to build, display and vectorize the Control-Data Graph (CDG) of a
31
31
  chunk of binary code, using Ghidra P-Code representation.
32
32
 
33
+ It ams at producing compact graphs, with a diameter as low as possible, but without losing the accurate semantics of the code.
34
+
35
+ Analyses remain low-level: no assumption is done on the used ABI in order to support exotic code for various task:
36
+ - semantic-based similarity research
37
+ - static code deobfuscation
38
+ - ROP gadget chaining
39
+
40
+
33
41
  ## Command-line interface
34
42
 
35
43
  A `cdg` tool is provided to play with binary of assembly files.
@@ -11,20 +11,20 @@ pcode_graph/cli.py,sha256=hTOnu0L6yTIOHzUTt5SqFP5dV5O5xjlB07ohbzjg0Qk,7213
11
11
  pcode_graph/emulator.py,sha256=7r1aMoTKDc6j_cT8V2vCcts4Mg2FMmvdoP8Y3H12RDY,13366
12
12
  pcode_graph/gnn_exporter.py,sha256=fd0Mz_2NJaQhYQ196nE7CEM0U1cG_9pjCA4yPrJnJHk,7356
13
13
  pcode_graph/graph.py,sha256=gLHkVg7bN6Jrleu7C-n9DQDjkIXeq6g9c-fN3wKZrlc,7614
14
- pcode_graph/lief_importer.py,sha256=SOgUhF4hjgVetfXjzUQn1M3HAWb-Eo08bTJq_H7i8H0,9910
14
+ pcode_graph/lief_importer.py,sha256=K8qq-bEkgyhX--0TkUwR-o3UTvgOHRx6n4rfpfWGENI,10393
15
15
  pcode_graph/log.py,sha256=qo6gh8bHsl-4-dnzsbHsB5rGism-MtjLJmQ-uBQwOIk,1035
16
16
  pcode_graph/maker.py,sha256=gvc9vi20slimzfEi19wEhR8xwk6hL2jw42ig0bxMvdY,16244
17
17
  pcode_graph/memory.py,sha256=5SdPZF3XajdWNv0iS0PLOLjCsn2eQpLV8BV9wkqxVxY,10269
18
18
  pcode_graph/nx_exporter.py,sha256=lSczsuuyD9XNE_8PgqCEvPdbMMXSdKLLt6YNPsGF-Zk,629
19
19
  pcode_graph/pcode.py,sha256=OPLZriOUUBHOlolvgCPYJO8CXg7rcUjyoorTZO8lebw,4593
20
20
  pcode_graph/registers.py,sha256=Grw4Ypr8GldG5nR1YeDG4rMf13gvzugSngvq2y51xjk,58328
21
- pcode_graph/simplifier.py,sha256=NAnPcfJi9XfwZ6VADc02S64tsR0fSH7cs7PZ3mP5WZk,6730
21
+ pcode_graph/simplifier.py,sha256=4aD6RJ5hhSqV8mI3ACjDWAzmUXRVO83UytZ9L-sINys,6761
22
22
  pcode_graph/torch_utils.py,sha256=GwVjWKL5Lqhm94b69o-rCilzNRu237gyJo6T6xWQHQc,966
23
23
  pcode_graph/translator.py,sha256=h90ay8VnCsgWRpK9fcYa0iu6CKXY0YDKl8CtH_gIx3U,7619
24
24
  pcode_graph/view.py,sha256=UybFV8xSDTJdqzzqop-U-90qnyKxiO5q_5B1Ef8DaiQ,2501
25
25
  pcode_graph/visitor.py,sha256=bxaQ9q0lTw8ysPOrta5G7LeHZYnq3IBxMafM_-8FruM,6990
26
- pcode_graph-3.0.0.dist-info/METADATA,sha256=wReA0vphJrcxomhHQTUkpX-l95NULvatd3IQe0ilUQ0,6230
27
- pcode_graph-3.0.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
28
- pcode_graph-3.0.0.dist-info/entry_points.txt,sha256=7pTTgqjYSRYwmBdA0GwJYXPfOmdk8I_mGsJOHHx-PXQ,45
29
- pcode_graph-3.0.0.dist-info/licenses/LICENSE,sha256=iVkUrjpGBX_59jOK6a7mKkvjHUCGfiCFQRgrziEh-nY,1066
30
- pcode_graph-3.0.0.dist-info/RECORD,,
26
+ pcode_graph-3.0.2.dist-info/METADATA,sha256=4_-k8Ej68qibPcLitfA2EMMdsrUYLKoZ9KxCEmUh72M,6568
27
+ pcode_graph-3.0.2.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
28
+ pcode_graph-3.0.2.dist-info/entry_points.txt,sha256=7pTTgqjYSRYwmBdA0GwJYXPfOmdk8I_mGsJOHHx-PXQ,45
29
+ pcode_graph-3.0.2.dist-info/licenses/LICENSE,sha256=iVkUrjpGBX_59jOK6a7mKkvjHUCGfiCFQRgrziEh-nY,1066
30
+ pcode_graph-3.0.2.dist-info/RECORD,,