Encapsulates information about an ELF file. Example: .. code-block:: python >>> bash = ELF(which('bash')) >>> hex(bash.symbols['read']) 0x41dac0 >>> hex(bash.plt['read']) 0x41dac0 >>> u32(bash.read(bash.got['read'], 4))
| 177 | raise AttributeError(name) |
| 178 | |
| 179 | class ELF(ELFFile): |
| 180 | """Encapsulates information about an ELF file. |
| 181 | |
| 182 | Example: |
| 183 | |
| 184 | .. code-block:: python |
| 185 | |
| 186 | >>> bash = ELF(which('bash')) |
| 187 | >>> hex(bash.symbols['read']) |
| 188 | 0x41dac0 |
| 189 | >>> hex(bash.plt['read']) |
| 190 | 0x41dac0 |
| 191 | >>> u32(bash.read(bash.got['read'], 4)) |
| 192 | 0x41dac6 |
| 193 | >>> print(bash.disasm(bash.plt.read, 16)) |
| 194 | 0: ff 25 1a 18 2d 00 jmp QWORD PTR [rip+0x2d181a] # 0x2d1820 |
| 195 | 6: 68 59 00 00 00 push 0x59 |
| 196 | b: e9 50 fa ff ff jmp 0xfffffffffffffa60 |
| 197 | """ |
| 198 | |
| 199 | # These class-level intitializers are only for ReadTheDocs |
| 200 | bits = 32 |
| 201 | bytes = 4 |
| 202 | path = '/path/to/the/file' |
| 203 | symbols = {} |
| 204 | got = {} |
| 205 | plt = {} |
| 206 | functions = {} |
| 207 | endian = 'little' |
| 208 | address = 0x400000 |
| 209 | linker = None |
| 210 | |
| 211 | # Whether to fill gaps in memory with zeroed pages |
| 212 | _fill_gaps = True |
| 213 | |
| 214 | |
| 215 | def __init__(self, path, checksec=True): |
| 216 | # elftools uses the backing file for all reads and writes |
| 217 | # in order to permit writing without being able to write to disk, |
| 218 | # mmap() the file. |
| 219 | |
| 220 | #: :class:`file`: Open handle to the ELF file on disk |
| 221 | self.file = open(path,'rb') |
| 222 | |
| 223 | #: :class:`mmap.mmap`: Memory-mapped copy of the ELF file on disk |
| 224 | self.mmap = mmap.mmap(self.file.fileno(), 0, access=mmap.ACCESS_COPY) |
| 225 | |
| 226 | super(ELF,self).__init__(self.mmap) |
| 227 | |
| 228 | #: :class:`str`: Path to the file |
| 229 | self.path = packing._need_text(os.path.abspath(path)) |
| 230 | |
| 231 | #: :class:`dotdict` of ``name`` to ``address`` for all symbols in the ELF |
| 232 | self.symbols = dotdict() |
| 233 | |
| 234 | #: :class:`dotdict` of ``name`` to ``address`` for all Global Offset Table (GOT) entries |
| 235 | self.got = dotdict() |
| 236 |
no outgoing calls
no test coverage detected