quarkslab / python-binexport

Python interface for Binexport, the Bindiff export format
Apache License 2.0
14 stars 2 forks source link

BinExport is trowing an exception #2

Closed Fenrisfulsur closed 10 months ago

Fenrisfulsur commented 1 year ago

BinExport is raising the following exception when trying to load a binexport file:

Traceback (most recent call last):
  File "test.py", line 18, in <module>
    main()
  File "test.py", line 7, in main
    p = qbindiff.Program(qbindiff.LoaderType.binexport, './firmware3v3.bin.BinExport')
  File "qbindiff/loader/program.py", line 38, in __init__
    self._backend = ProgramBackendBinExport(*args, **kwargs)
  File "qbindiff/loader/backend/binexport.py", line 362, in __init__
    self.be_prog = binexport.ProgramBinExport(file)
  File "binexport/program.py", line 92, in __init__
    self[src].children.add(self[dst])
KeyError: 20056

This is due to the filtering done here:

cg = self.proto.call_graph
for node in cg.vertex:                 # HERE  v
    if node.address not in self and node.type == cg.Vertex.IMPORTED:
        self[node.address] = FunctionBinExport(
             weakref.ref(self), is_import=True, addr=node.address
        )
    if node.address not in self:
         continue

Because of the second part of the condition some node (the ones with node.type != IMPORTED) are not added to the graph but can be later referenced in the callgraph.edge so a fix can be either to check for non existing node when trying to add them in the ProgramBinExport or to simply remove the second part of the check. The second option result in the following code:

cg = self.proto.call_graph
for node in cg.vertex:
    if node.address not in self:
          self[node.address] = FunctionBinExport(
                    weakref.ref(self), is_import=True, addr=node.address
          )
patacca commented 10 months ago

Fixed in #8. Feel free to open the issue again if the problem is still present.