Initialize the Mach-O stobj with
(populate-mach-o-contents file-byte-list mach-o state) → (mv err new-mach-o new-state)
Function:
(defun populate-mach-o-contents (file-byte-list mach-o state) (declare (xargs :stobjs (mach-o state))) (declare (xargs :guard (byte-listp file-byte-list))) (let ((__function__ 'populate-mach-o-contents)) (declare (ignorable __function__)) (b* ((file-size (len file-byte-list)) (mach-o (!mach-o-file-size file-size mach-o)) (file-header (take 32 file-byte-list)) ((when (not (byte-listp file-header))) (cw "Header could not be read.~%") (mv t mach-o state)) ((mach-o-header header) (read-mach_header file-header)) (magic header.magic) ((when (and (not (equal magic *mh_magic*)) (not (equal magic *mh_cigam*)) (not (equal magic *mh_magic_64*)) (not (equal magic *mh_cigam_64*)))) (cw "Error: Not a Mach-O object file (as suggested by the magic number).~%") (mv t mach-o state)) ((when (not (unsigned-byte-p 64 header.sizeofcmds))) (cw "Mach-O File Read Error: Sizeofcmds ~x0 ill-formed~%" header.sizeofcmds) (mv t mach-o state)) (mach-o (!load-cmds-size header.sizeofcmds mach-o)) (mach-o-header-size (if (and (or (equal magic *mh_magic*) (equal magic *mh_cigam*)) (equal header.reserved nil)) 28 32)) (mach-o (!mach-o-header-size mach-o-header-size mach-o)) (file-byte-list (nthcdr mach-o-header-size file-byte-list)) (ncmds (nfix header.ncmds)) ((mv cmds remaining-file mach-o) (read-load_commands ncmds file-byte-list nil mach-o)) (h-size (@mach-o-header-size mach-o)) (lc-size (@load-cmds-size mach-o)) ((mv flg mach-o state) (fill-text-segment-bytes h-size lc-size remaining-file mach-o state)) ((when flg) (mv flg mach-o state)) ((mv flg mach-o state) (fill-data-segment-bytes h-size lc-size remaining-file mach-o state)) ((when flg) (mv flg mach-o state))) (mv (list 'header header (list 'cmds cmds)) mach-o state))))
Theorem:
(defthm good-mach-o-p-of-populate-mach-o-contents.new-mach-o (implies (good-mach-o-p mach-o) (b* (((mv ?err ?new-mach-o ?new-state) (populate-mach-o-contents file-byte-list mach-o state))) (good-mach-o-p new-mach-o))) :rule-classes :rewrite)
Theorem:
(defthm state-p-of-populate-mach-o-contents.new-state (implies (state-p state) (b* (((mv ?err ?new-mach-o ?new-state) (populate-mach-o-contents file-byte-list mach-o state))) (state-p new-state))) :rule-classes :rewrite)