• Top
    • Documentation
    • Books
    • Recursion-and-induction
    • Boolean-reasoning
    • Debugging
    • Projects
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
    • Software-verification
      • Kestrel-books
      • X86isa
      • Execloader
        • Elf-reader
          • Elf64_sym
          • Elf32_sym
          • Elf-header
          • Elf-section-header
          • Elf64-segment-header
          • Elf32-segment-header
          • Elf_bits32
          • Elf_bits8
          • Elf_bits64
          • Elf_bits16
          • Section-info
          • Read-elf-header
          • Read-section-headers
          • Read-segment-headers-64
          • Read-segment-headers-32
          • Read-section-names
          • Elf64_sym-info
          • Elf32_sym-info
          • Parse-symtab-entries
          • Is-elf-content-p
            • Populate-elf-contents
            • Get-string-section-data
            • Get-section-info1
            • Set-elf-stobj-fields
            • Get-named-section-headers
            • Elf-read-mem-null-term
            • Get-section-info
            • Find-label-address-from-elf-symtab-info
            • Section-names
            • Get-symtab-entries
            • Populate-elf
            • Get-label-addresses
            • Get-label-address
            • Elf-read-string-null-term
            • Good-elf-p
            • Elf64_sym-equiv-under-mask
            • Elf64-segment-headers
            • Elf32_sym-equiv-under-mask
            • Elf32-segment-headers
            • Section-info-list
            • Elf64_sym-info-list
            • Elf32_sym-info-list
            • Elf-section-headers
            • Elf64_sym-debug
            • Elf32_sym-debug
          • Mach-o-reader
          • Merge-first-split-bytes
          • Split-bytes
          • Charlist->bytes
          • Take-till-zero
          • Merge-bytes
          • Bytes->charlist
          • Bytes->string
          • String->bytes
        • Axe
      • Testing-utilities
      • Math
    • Elf-reader

    Is-elf-content-p

    Check if contents represent a valid ELF binary (in bytes, LSB-first); if so, return the ELF header

    Signature
    (is-elf-content-p contents state) 
      → 
    (mv is-elf-file header state)
    Arguments
    contents — Guard (byte-listp contents).
    Returns
    is-elf-file — Type (booleanp is-elf-file).
    header — Type (elf-header-p header).

    Definitions and Theorems

    Function: is-elf-content-p

    (defun
     is-elf-content-p (contents state)
     (declare (xargs :stobjs (state)))
     (declare (xargs :guard (byte-listp contents)))
     (let
      ((__function__ 'is-elf-content-p))
      (declare (ignorable __function__))
      (b*
        (((unless (<= 64 (len contents)))
          (prog2$ (raise "Error reading ELF contents!")
                  (mv nil (make-elf-header) state)))
         (bytes contents)
         (file-header (take 64 bytes))
         ((elf-header header)
          (read-elf-header file-header))
         (magic (merge-bytes header.magic))
         (class header.class)
         ((when (or (not (equal magic *elfmag*))
                    (not (member class '(1 2)))))
          (prog2$ (raise "Error:  Invalid ELF header! ~% Header: ~x0 ~%"
                         header)
                  (mv nil (make-elf-header) state))))
        (mv t header state))))

    Theorem: booleanp-of-is-elf-content-p.is-elf-file

    (defthm booleanp-of-is-elf-content-p.is-elf-file
            (b* (((mv ?is-elf-file acl2::?header acl2::?state)
                  (is-elf-content-p contents state)))
                (booleanp is-elf-file))
            :rule-classes :type-prescription)

    Theorem: elf-header-p-of-is-elf-content-p.header

    (defthm elf-header-p-of-is-elf-content-p.header
            (b* (((mv ?is-elf-file acl2::?header acl2::?state)
                  (is-elf-content-p contents state)))
                (elf-header-p header))
            :rule-classes :rewrite)