Changeset 12766


Ignore:
Timestamp:
Sep 4, 2009, 11:09:49 PM (10 years ago)
Author:
gb
Message:

I thought that I'd checked this in already: in %PREPEND-FILE, change
PEF to PE (and add a comment explaining why.) Try to use the FFI to
generate some magic constants (structure sizes, field offsets) for us.
(I'd been concerned that this code might be broken on Win64, but the
relevant sizes/offsets that're used here happened to be OK.)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/lib/dumplisp.lisp

    r12676 r12766  
    193193                    header-pos))))))))))
    194194                 
    195  
     195;;; Note that Windows executable files are in what they call "PE"
     196;;; (= "Portable Executable") format, not to be confused with the "PEF"
     197;;; (= "PowerPC Executable Format" or "Preferred Executable Format")
     198;;; executable format that Apple used on Classic MacOS.
    196199(defun %prepend-file (out-fd in-fd len #+windows-target application-type)
    197200  (declare (fixnum out-fd in-fd len))
     
    211214                                         (:console #$IMAGE_SUBSYSTEM_WINDOWS_CUI)
    212215                                         (:gui #$IMAGE_SUBSYSTEM_WINDOWS_GUI)))
    213                      (offset (%get-long buf #x3c)))
    214                 (assert (< offset bufsize) () "PEF header not within first ~D bytes" bufsize)
     216                     (offset (%get-long buf (get-field-offset #>IMAGE_DOS_HEADER.lfanew))))
     217                (assert (< offset bufsize) () "PE header not within first ~D bytes" bufsize)
    215218                (assert (= (%get-byte buf (+ offset 0)) (char-code #\P)) ()
    216                         "File does not appear to be a PEF file")
     219                        "File does not appear to be a PE file")
    217220                (assert (= (%get-byte buf (+ offset 1)) (char-code #\E)) ()
    218                         "File does not appear to be a PEF file")
     221                        "File does not appear to be a PE file")
    219222                (assert (= (%get-byte buf (+ offset 2)) 0) ()
    220                         "File does not appear to be a PEF file")
     223                        "File does not appear to be a PE file")
    221224                (assert (= (%get-byte buf (+ offset 3)) 0) ()
    222                         "File does not appear to be a PEF file")
    223                 ;; File is a PEF file -- Windows subsystem byte goes at offset 68 in the
     225                        "File does not appear to be a PE file")
     226                ;; File is a PE file -- Windows subsystem byte goes at offset 68 in the
    224227                ;;  "optional header" which appears right after the standard header (20 bytes)
    225                 ;;  and the PEF cookie (4 bytes)
     228                ;;  and the PE cookie (4 bytes)
    226229                (setf (%get-byte buf (+ offset 4 20 68)) application-byte)))
    227230            (let* ((nwritten (fd-write out-fd buf nread)))
Note: See TracChangeset for help on using the changeset viewer.