GTIRB  v2.1.0
GrammaTech Intermediate Representation for Binaries
data-symbols.py

Open an IR and print every symbol pointing to data.

1 #!/usr/bin/python
2 #
3 # An example program which opens an IR and prints information about all
4 # symbols pointing to data.
5 #
6 # To run this example, do the following.
7 #
8 # 1. Install the gtirb package from Pypi.
9 #
10 # 2. Run ddisasm to disassemble a binary to GTIRB.
11 #
12 # $ echo 'main(){puts("hello world");}'|gcc -x c - -o /tmp/hello
13 # $ ddisasm /tmp/hello --ir /tmp/hello.gtirb
14 #
15 # 3. Execute the following command to run the program on the
16 # serialized GTIRB data.
17 #
18 # $ ./doc/examples/data-symbols.py /tmp/hello.gtirb
19 import sys
20 
21 import gtirb
22 
23 if len(sys.argv) < 2:
24  print(f"Usage: {sys.argv[0]} /path/to/file.gtirb")
25  quit(1)
26 
27 ir = gtirb.ir.IR.load_protobuf(sys.argv[1])
28 
29 for m in ir.modules:
30  for s in m.symbols:
31  ref = s.referent
32  if isinstance(ref, gtirb.block.DataBlock):
33  print(s.name)