| 1861 | |
| 1862 | |
| 1863 | class Relocation: |
| 1864 | def __init__(self, handle: core.BNRelocationHandle): |
| 1865 | self.handle = handle |
| 1866 | |
| 1867 | def __del__(self): |
| 1868 | if core is not None: |
| 1869 | core.BNFreeRelocation(self.handle) |
| 1870 | |
| 1871 | def __repr__(self): |
| 1872 | if self.symbol is None: |
| 1873 | return f"<Relocation: {self.target:#x}>" |
| 1874 | try: |
| 1875 | return f"<Relocation: \"{self.symbol.full_name}\" @ {self.target:#x}>" |
| 1876 | except UnicodeDecodeError: |
| 1877 | return f"<Relocation: \"{self.symbol.raw_bytes}\" @ {self.target:#x}>" |
| 1878 | |
| 1879 | def __eq__(self, other): |
| 1880 | if not isinstance(other, self.__class__): |
| 1881 | return NotImplemented |
| 1882 | return ctypes.addressof(self.handle.contents) == ctypes.addressof(other.handle.contents) |
| 1883 | |
| 1884 | def __ne__(self, other): |
| 1885 | if not isinstance(other, self.__class__): |
| 1886 | return NotImplemented |
| 1887 | return not (self == other) |
| 1888 | |
| 1889 | def __hash__(self): |
| 1890 | return hash(ctypes.addressof(self.handle.contents)) |
| 1891 | |
| 1892 | @property |
| 1893 | def info(self) -> RelocationInfo: |
| 1894 | return RelocationInfo(core.BNRelocationGetInfo(self.handle)) |
| 1895 | |
| 1896 | @property |
| 1897 | def arch(self) -> Optional['architecture.Architecture']: |
| 1898 | """The architecture associated with the :py:class:`Relocation` (read/write)""" |
| 1899 | core_arch = core.BNRelocationGetArchitecture(self.handle) |
| 1900 | return architecture.CoreArchitecture._from_cache(handle=core_arch) |
| 1901 | |
| 1902 | @property |
| 1903 | def target(self) -> int: |
| 1904 | """Where the reloc needs to point to""" |
| 1905 | return core.BNRelocationGetTarget(self.handle) |
| 1906 | |
| 1907 | @property |
| 1908 | def reloc(self) -> int: |
| 1909 | """The actual pointer that needs to be relocated""" |
| 1910 | return core.BNRelocationGetReloc(self.handle) |
| 1911 | |
| 1912 | @property |
| 1913 | def symbol(self) -> Optional['_types.CoreSymbol']: |
| 1914 | core_symbol = core.BNRelocationGetSymbol(self.handle) |
| 1915 | if core_symbol is None: |
| 1916 | return None |
| 1917 | return _types.CoreSymbol(core_symbol) |
| 1918 | |
| 1919 | |
| 1920 | class _BinaryViewAssociatedDataStore(associateddatastore._AssociatedDataStore): |