Read the section data structures
(read-section_data_sz_structures nsects sz rest-of-the-file acc mach-o) → (mv new-acc file-bytes new-mach-o)
Function:
(defun read-section_data_sz_structures (nsects sz rest-of-the-file acc mach-o) (declare (xargs :stobjs (mach-o))) (declare (xargs :guard (and (natp nsects) (byte-listp rest-of-the-file) (true-listp acc)))) (declare (xargs :guard (and (or (and (equal sz 4) (<= (* nsects 68) (len rest-of-the-file))) (and (equal sz 8) (<= (* nsects 80) (len rest-of-the-file))))))) (let ((__function__ 'read-section_data_sz_structures)) (declare (ignorable __function__)) (if (zp nsects) (mv (reverse acc) rest-of-the-file mach-o) (b* (((mv sectbytes rest-of-the-file) (split-bytes 16 rest-of-the-file)) ((mv segbytes rest-of-the-file) (split-bytes 16 rest-of-the-file)) ((mv addr rest-of-the-file) (merge-first-split-bytes sz rest-of-the-file)) ((mv size rest-of-the-file) (merge-first-split-bytes sz rest-of-the-file)) ((mv offset rest-of-the-file) (merge-first-split-bytes 4 rest-of-the-file)) ((mv align rest-of-the-file) (merge-first-split-bytes 4 rest-of-the-file)) ((mv reloff rest-of-the-file) (merge-first-split-bytes 4 rest-of-the-file)) ((mv nreloc rest-of-the-file) (merge-first-split-bytes 4 rest-of-the-file)) ((mv flags rest-of-the-file) (merge-first-split-bytes 4 rest-of-the-file)) ((mv reserved1 rest-of-the-file) (merge-first-split-bytes 4 rest-of-the-file)) ((mv reserved2 rest-of-the-file) (merge-first-split-bytes 4 rest-of-the-file)) (sectname (bytes->string sectbytes)) (segname (bytes->string segbytes)) (sect (merge-bytes (take-till-zero sectbytes))) (seg (merge-bytes (take-till-zero segbytes))) ((mv reserved3 rest-of-the-file) (if (equal sz 8) (merge-first-split-bytes 4 rest-of-the-file) (mv nil rest-of-the-file))) (mach-o (cond ((equal seg *mach-o-text*) (cond ((equal sect *text-text*) (b* ((mach-o (!text-text-section-addr addr mach-o)) (mach-o (!text-text-section-size size mach-o)) (mach-o (!text-text-section-offset offset mach-o))) mach-o)) ((equal sect *text-cstring*) (b* ((mach-o (!text-cstring-section-addr addr mach-o)) (mach-o (!text-cstring-section-size size mach-o)) (mach-o (!text-cstring-section-offset offset mach-o))) mach-o)) ((equal sect *text-const*) (b* ((mach-o (!text-const-section-addr addr mach-o)) (mach-o (!text-const-section-size size mach-o)) (mach-o (!text-const-section-offset offset mach-o))) mach-o)) (t mach-o))) ((equal seg *mach-o-data*) (cond ((equal sect *data-data*) (b* ((mach-o (!data-data-section-addr addr mach-o)) (mach-o (!data-data-section-size size mach-o)) (mach-o (!data-data-section-offset offset mach-o))) mach-o)) ((equal sect *data-dyld*) (b* ((mach-o (!data-dyld-section-addr addr mach-o)) (mach-o (!data-dyld-section-size size mach-o)) (mach-o (!data-dyld-section-offset offset mach-o))) mach-o)) ((equal sect *data-const*) (b* ((mach-o (!data-const-section-addr addr mach-o)) (mach-o (!data-const-section-size size mach-o)) (mach-o (!data-const-section-offset offset mach-o))) mach-o)) ((equal sect *data-bss*) (b* ((mach-o (!data-bss-section-addr addr mach-o)) (mach-o (!data-bss-section-size size mach-o)) (mach-o (!data-bss-section-offset offset mach-o))) mach-o)) ((equal sect *data-common*) (b* ((mach-o (!data-common-section-addr addr mach-o)) (mach-o (!data-common-section-size size mach-o)) (mach-o (!data-common-section-offset offset mach-o))) mach-o)) (t mach-o))) (t mach-o)))) (read-section_data_sz_structures (1- nsects) sz rest-of-the-file (cons (list (cons 'sectname sectname) (cons 'segname segname) (cons 'addr addr) (cons 'size size) (cons 'offset offset) (cons 'align align) (cons 'reloff reloff) (cons 'nreloc nreloc) (cons 'flags flags) (cons 'reserved1 reserved1) (cons 'reserved2 reserved2) (cons 'reserved3 reserved3)) acc) mach-o)))))
Theorem:
(defthm byte-listp-of-read-section_data_sz_structures.file-bytes (implies (byte-listp rest-of-the-file) (b* (((mv ?new-acc ?file-bytes ?new-mach-o) (read-section_data_sz_structures nsects sz rest-of-the-file acc mach-o))) (byte-listp file-bytes))) :rule-classes :rewrite)
Theorem:
(defthm good-mach-o-p-of-read-section_data_sz_structures.new-mach-o (implies (good-mach-o-p mach-o) (b* (((mv ?new-acc ?file-bytes ?new-mach-o) (read-section_data_sz_structures nsects sz rest-of-the-file acc mach-o))) (good-mach-o-p new-mach-o))) :rule-classes :rewrite)
Theorem:
(defthm len-mv-nth-1-read-section_data_sz_structures-sz=4 (implies (and (natp nsects) (and (equal sz 4) (<= (* nsects 68) (len (double-rewrite rest-of-the-file)))) (byte-listp (double-rewrite rest-of-the-file))) (<= (- (len (double-rewrite rest-of-the-file)) (* nsects 68)) (len (mv-nth 1 (read-section_data_sz_structures nsects sz rest-of-the-file acc mach-o))))) :rule-classes :linear)
Theorem:
(defthm len-mv-nth-1-read-section_data_sz_structures-sz=8 (implies (and (natp nsects) (and (equal sz 8) (<= (* nsects 80) (len (double-rewrite rest-of-the-file)))) (byte-listp (double-rewrite rest-of-the-file))) (<= (- (len (double-rewrite rest-of-the-file)) (* nsects 80)) (len (mv-nth 1 (read-section_data_sz_structures nsects sz rest-of-the-file acc mach-o))))) :rule-classes :linear)