(pointer)
return ei_class, Elfhdr
Returns an ehdr object for the ELF pointer points into.

    We expect the `pointer` to be an address from the binary.
Returns an ehdr object for the ELF pointer points into.
Returns an ehdr object for the ELF pointer points into .
def get_ehdr(pointer):
    """
    Returns an ehdr object for the ELF pointer points into.

    We expect the `pointer` to be an address from the binary.
    """

    # This just does not work :(
    if pwndbg.qemu.is_qemu():
        return None, None

    vmmap = pwndbg.vmmap.find(pointer)
    base = None

    # We first check if the beginning of the page contains the ELF magic
    if pwndbg.memory.read(vmmap.start, 4) == b'\x7fELF':
        base = vmmap.start

    # The page did not have ELF magic; it may be that .text and binary start are split
    # into two pages, so let's get the first page from the pointer's page objfile
    else:
        for v in pwndbg.vmmap.get():
            if v.objfile == vmmap.objfile:
                vmmap = v
                break

        if pwndbg.memory.read(vmmap.start, 4) == b'\x7fELF':
            base = vmmap.start

    if base is None:
        # For non linux ABI, the ELF header may not exist at all
        if pwndbg.abi.linux:
            print("ERROR: Could not find ELF base!")
        return None, None

    # Determine whether it's 32- or 64-bit
    ei_class = pwndbg.memory.byte(base+4)

    # Find out where the section headers start
    Elfhdr = read(Ehdr, base)
    return ei_class, Elfhdr
def get_ehdr ( pointer ) : # This just does not work :( if pwndbg . qemu . is_qemu ( ) : return None , None vmmap = pwndbg . vmmap . find ( pointer ) base = None # We first check if the beginning of the page contains the ELF magic if pwndbg . memory . read ( vmmap . start , 4 ) == b'\x7fELF' : base = vmmap . start # The page did not have ELF magic; it may be that .text and binary start are split # into two pages, so let's get the first page from the pointer's page objfile else : for v in pwndbg . vmmap . get ( ) : if v . objfile == vmmap . objfile : vmmap = v break if pwndbg . memory . read ( vmmap . start , 4 ) == b'\x7fELF' : base = vmmap . start if base is None : # For non linux ABI, the ELF header may not exist at all if pwndbg . abi . linux : print ( "ERROR: Could not find ELF base!" ) return None , None # Determine whether it's 32- or 64-bit ei_class = pwndbg . memory . byte ( base + 4 ) # Find out where the section headers start Elfhdr = read ( Ehdr , base ) return ei_class , Elfhdr