MCPcopy
hub / github.com/Gallopsled/pwntools / ELF

Class ELF

pwnlib/elf/elf.py:179–2508  ·  view source on GitHub ↗

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))

Source from the content-addressed store, hash-verified

177 raise AttributeError(name)
178
179class 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

Callers 15

__init__Method · 0.90
libcMethod · 0.90
lookupMethod · 0.90
provider_local_systemFunction · 0.90
unstrip_libcFunction · 0.90
download_librariesFunction · 0.90
__init__Method · 0.90
binaryMethod · 0.90
libcMethod · 0.90
__on_enoexecMethod · 0.90
libcMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected