lief-project / LIEF

LIEF - Library to Instrument Executable Formats (C++, Python, Rust)
https://lief.re
Apache License 2.0
4.5k stars 624 forks source link

Fix bug in Python PE Binary bindings caused by copy #1108

Closed mikenawrocki closed 2 months ago

mikenawrocki commented 2 months ago

Python: mark add_relocation return value as reference Makes the return value from the PE::Binary add_relocation method an internal reference.

Without this, the object returned by add_relocation is a copy of the one held by Binary, so modifications to that object are independent.

This is similar to #1106

Test case:

import lief
b = lief.PE.Binary(lief.PE.PE_TYPE.PE32)
r = lief.PE.Relocation()
s = b.add_relocation(r)
assert r is not s
assert list(b.relocations)[0] is s