Ignore:
Timestamp:
Nov 1, 1999, 12:57:09 AM (26 years ago)
Author:
bird
Message:

Updated option/argument handling.
Corrected a few bugs.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/win32k/ldr/myldrOpen.cpp

    r1467 r1535  
    1 /* $Id: myldrOpen.cpp,v 1.3 1999-10-27 02:02:58 bird Exp $
     1/* $Id: myldrOpen.cpp,v 1.4 1999-10-31 23:57:06 bird Exp $
    22 *
    33 * myldrOpen - _ldrOpen.
     
    2323#include <stdlib.h>
    2424
    25 
    2625#include "log.h"
    2726#include <peexe.h>
     
    3332#include "ldr.h"
    3433#include "ldrCalls.h"
     34#include "options.h"
    3535
    3636
     
    5252        kprintf(("_ldrOpen:  phFile=%#.4x, flags=%#.8x, pszFn=%s\n", *phFile, param3, pszFilename));
    5353
    54     if (rc == NO_ERROR)
     54    if (rc == NO_ERROR && (options.fElf || options.fPE != FLAGS_PE_NOT || options.fScript))
    5555    {
    5656        static char achBuffer[sizeof(IMAGE_DOS_HEADER)];
    5757        PIMAGE_DOS_HEADER   pMzHdr = (PIMAGE_DOS_HEADER)&achBuffer[0];
     58        PIMAGE_NT_HEADERS   pNtHdrs = (PIMAGE_NT_HEADERS)&achBuffer[0]; /* oops. Last accessible field is OptionalHeader.FileAlignment */
    5859        char               *pach = &achBuffer[0];
    5960
     
    6263         * This costs up to two disk reads!
    6364         */
    64         rc = _ldrRead(*phFile, 0UL, pMzHdr, 0UL, sizeof(*pMzHdr), NULL);
     65        rc = _ldrRead(*phFile, 0UL, pMzHdr, 0UL, sizeof(IMAGE_DOS_HEADER), NULL);
    6566        if (rc == NO_ERROR)
    6667        {
    67             if (pMzHdr->e_magic == IMAGE_DOS_SIGNATURE &&
    68                 pMzHdr->e_lfanew > sizeof(IMAGE_DOS_HEADER) && pMzHdr->e_lfanew < 0x04000000UL) /* Larger than 64 bytes and less that 64MB. */
    69             {   /* MZ header found */
    70                 /* read */
    71                 rc = _ldrRead(*phFile, pMzHdr->e_lfanew, pMzHdr, 0UL, 4UL, NULL);
     68            if ((pMzHdr->e_magic == IMAGE_DOS_SIGNATURE &&
     69                 pMzHdr->e_lfanew > sizeof(IMAGE_DOS_HEADER) && pMzHdr->e_lfanew < 0x04000000UL) /* Larger than 64 bytes and less that 64MB. */
     70                || *(PULONG)pach == IMAGE_NT_SIGNATURE)
     71            {   /* MZ or PE header found */
     72                if (options.fPE == FLAGS_PE_NOT)
     73                    return NO_ERROR;
     74
     75                if (*(PULONG)pach != IMAGE_NT_SIGNATURE)
     76                    rc = _ldrRead(*phFile, pMzHdr->e_lfanew, pach, 0UL, sizeof(achBuffer), NULL);
     77
    7278                if (rc == NO_ERROR && *(PULONG)pach == IMAGE_NT_SIGNATURE)
    7379                {   /* PE signature found */
    74                     PMODULE pMod;
    75 
    7680                    kprintf(("_ldrOpen: PE executable...\n"));
    77                     #pragma info(none)
    78                     if (/* invoke pe.exe or do conversion now? */ 1)
    79                     {   /* pe2lx - win32k */
    80                     #pragma info(restore)
     81                    if (options.fPE == FLAGS_PE_PE2LX
     82                        || (options.fPE == FLAGS_PE_MIXED
     83                            && !((pNtHdrs->FileHeader.Characteristics & IMAGE_FILE_DLL == 0UL)
     84                                 && pNtHdrs->OptionalHeader.ImageBase >= 0x04000000UL /* 64MB */
     85                                 )
     86                            )
     87                        )
     88                    {   /* pe2lx */
    8189                        Pe2Lx * pPe2Lx = new Pe2Lx(*phFile);
    8290                        if (pPe2Lx != NULL)
     
    101109                    }
    102110                    else
    103                     {   /* pe.exe */
    104                         kprintf(("_ldrOpen: pe.exe - opening\n"));
    105                         _ldrClose(*phFile);
    106                         rc = _ldrOpen(phFile, "pe.exe", param3);  /* path....! problems! */
    107                         kprintf(("_ldrOpen: pe.exe - open returned with rc = %d\n", rc));
    108                     }
     111                        if (options.fPE == FLAGS_PE_PE || options.fPE == FLAGS_PE_MIXED)
     112                        {   /* pe.exe */
     113                            kprintf(("_ldrOpen: pe.exe - opening\n"));
     114                            _ldrClose(*phFile);
     115                            rc = _ldrOpen(phFile, "pe.exe", param3);  /* path....! problems! */
     116                            kprintf(("_ldrOpen: pe.exe - open returned with rc = %d\n", rc));
     117                            return rc;
     118                        }
    109119                }
    110120                rc = NO_ERROR;
     
    112122            else
    113123            {
    114                 if (*pach == '#')
    115                 {
    116                     /* unix styled script...? must be more than 64 bytes long.... */
    117                     char *pszStart = pach+1;
    118                     char *pszEnd;
    119                     kprintf(("_ldrOpen: unix script?\n"));
    120                     /* skip blanks */
    121                     while (*pszStart != '\0' && (*pszStart == ' ' || *pszStart == '\t'))
    122                         pszStart++;
    123                     if (*pszStart != '\0' && *pszStart != '\r' && *pszStart != '\n')
    124                     {   /* find end-of-word */
    125                         while (*pszEnd != '\0' && *pszEnd != '\n' && *pszEnd != '\r'
    126                                && *pszEnd != '\t' && *pszEnd != ' ')
    127                             pszEnd++;
    128                         *pszEnd = '\0';
    129                         kprintf(("_ldrOpen: unix script - opening %s\n", pszStart));
    130                         _ldrClose(*phFile);
    131                         rc = _ldrOpen(phFile, pszStart, param3);
    132                         kprintf(("_ldrOpen: unix script - open returned with rc = %d\n", rc));
    133                     }
    134                     else
    135                         kprintf(("_ldrOpen: unix script - unexpected end of line/file. (line: %.10s\n", pach));
    136                 }
    137                 else if (pach[0] == ELFMAG0 && pach[1] == ELFMAG1 && pach[2] == ELFMAG2 && pach[3] == ELFMAG3)
     124                if (pach[0] == ELFMAG0 && pach[1] == ELFMAG1 && pach[2] == ELFMAG2 && pach[3] == ELFMAG3)
    138125                {
    139126                    /* ELF signature found */
    140127                    kprintf(("_ldrOpen: ELF executable! - not implemented yet!\n"));
    141128                }
     129                else
     130                    if (*pach == '#')
     131                    {
     132                        /* unix styled script...? Must be more than 64 bytes long? No options. firstline < 64 bytes. */
     133                        char *pszStart = pach+1;
     134                        char *pszEnd;
     135                        kprintf(("_ldrOpen: unix script?\n"));
     136
     137                        achBuffer[sizeof(achBuffer)-1] = '\0'; /* just to make sure we don't read to much... */
     138
     139                        /* skip blanks */
     140                        while (*pszStart != '\0' && (*pszStart == ' ' || *pszStart == '\t'))
     141                            pszStart++;
     142                        if (*pszStart != '\0' && *pszStart != '\r' && *pszStart != '\n')
     143                        {   /* find end-of-word */
     144                            while (*pszEnd != '\0' && *pszEnd != '\n' && *pszEnd != '\r'
     145                                   && *pszEnd != '\t' && *pszEnd != ' ')
     146                                pszEnd++;
     147                            *pszEnd = '\0';
     148                            if (*pszEnd != '\0')
     149                            {
     150                                kprintf(("_ldrOpen: unix script - opening %s\n", pszStart));
     151                                _ldrClose(*phFile);
     152                                rc = _ldrOpen(phFile, pszStart, param3);
     153                                kprintf(("_ldrOpen: unix script - open returned with rc = %d\n", rc));
     154                            }
     155                        }
     156                        else
     157                            kprintf(("_ldrOpen: unix script - unexpected end of line/file. (line: %.10s\n", pach));
     158                    }
    142159            }
    143160        }
Note: See TracChangeset for help on using the changeset viewer.