Parse Mach-O header
(read-mach_header file-header) → header
Function:
(defun read-mach_header (file-header) (declare (xargs :guard (byte-listp file-header))) (let ((__function__ 'read-mach_header)) (declare (ignorable __function__)) (b* (((unless (or (= (len file-header) 28) (= (len file-header) 32))) (prog2$ (raise "Mach-O header's length should be either 28 or 32, but it is ~x0 instead!" (len file-header)) (make-mach-o-header))) ((mv magic file-header) (merge-first-split-bytes 4 file-header)) ((mv cputype file-header) (merge-first-split-bytes 4 file-header)) ((mv cpusubtype file-header) (merge-first-split-bytes 4 file-header)) ((mv filetype file-header) (merge-first-split-bytes 4 file-header)) ((mv ncmds file-header) (merge-first-split-bytes 4 file-header)) ((mv sizeofcmds file-header) (merge-first-split-bytes 4 file-header)) ((mv flags file-header) (merge-first-split-bytes 4 file-header)) ((mv reserved ?file-header) (if (or (equal magic *mh_magic_64*) (equal magic *mh_cigam_64*)) (merge-first-split-bytes 4 file-header) (mv nil file-header)))) (make-mach-o-header :magic magic :cputype cputype :cpusubtype cpusubtype :filetype filetype :ncmds ncmds :sizeofcmds sizeofcmds :flags flags :reserved reserved))))
Theorem:
(defthm mach-o-header-p-of-read-mach_header (b* ((header (read-mach_header file-header))) (mach-o-header-p header)) :rule-classes :rewrite)