Ignore:
Timestamp:
Oct 14, 1999, 3:25:39 AM (26 years ago)
Author:
bird
Message:

Pe2Lx rewrite changes in win32k.
Pluss some makefile/depend changes.

File:
1 edited

Legend:

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

    r847 r1273  
    1 /* $Id: myldrOpen.cpp,v 1.1 1999-09-06 02:20:01 bird Exp $
     1/* $Id: myldrOpen.cpp,v 1.2 1999-10-14 01:25:38 bird Exp $
    22 *
    33 * myldrOpen - _ldrOpen.
     
    1919#include <os2.h>
    2020
    21 #include <string.h>
     21#include "malloc.h"
     22#include <memory.h>
     23#include <stdlib.h>
    2224
     25
     26#include "log.h"
     27#include <peexe.h>
     28#include <exe386.h>
    2329#include "OS2Krnl.h"
    24 #include "log.h"
    25 #include "malloc.h"
    26 #if 0
    27     #include "lxFile.h"
    28 #else
    29     #define LXFile class { public: BOOL queryIsModuleName(const char *) {return FALSE;}}
    30 #endif
     30#include "pe2lx.h"
    3131#include "ldr.h"
    3232#include "ldrCalls.h"
    3333
    34 
     34#include "elf.h"
    3535
    3636/**
     
    5353    if (rc == NO_ERROR)
    5454    {
    55         i = getFreeUncertainEntry();
    56         if (i != -1)
     55        static char achBuffer[sizeof(IMAGE_DOS_HEADER)];
     56        PIMAGE_DOS_HEADER   pMzHdr = (PIMAGE_DOS_HEADER)&achBuffer[0];
     57        char               *pach = &achBuffer[0];
     58
     59        /**
     60         * See if this is an recognizable module format.
     61         * This costs up to two disk reads!
     62         */
     63        rc = _ldrRead(*phFile, 0UL, pMzHdr, 0UL, sizeof(*pMzHdr), NULL);
     64        if (rc == NO_ERROR)
    5765        {
    58             ahUncertain[i].offsetNEHdr = 0;
    59             ahUncertain[i].fMZ = 0;
    60             ahUncertain[i].fPE = 0;
    61             ahUncertain[i].hFile = *phFile;
    62             ahUncertain[i].pszName = (char*)malloc(strlen(pszFilename)+1);
    63             if (ahUncertain[i].pszName != NULL)
    64             {
    65                 strcpy(ahUncertain[i].pszName, pszFilename);
    66                 SetState(*phFile, HSTATE_CHECK);
     66            if (pMzHdr->e_magic == IMAGE_DOS_SIGNATURE &&
     67                pMzHdr->e_lfanew > sizeof(IMAGE_DOS_HEADER) && pMzHdr->e_lfanew < 0x04000000UL) /* Larger than 64 bytes and less that 64MB. */
     68            {   /* MZ header found */
     69                /* read */
     70                rc = _ldrRead(*phFile, pMzHdr->e_lfanew, pMzHdr, 0UL, 4UL, NULL);
     71                if (rc == NO_ERROR && *(PULONG)pach == IMAGE_NT_SIGNATURE)
     72                {   /* PE signature found */
     73                    PPENODE pNode;
     74
     75                    kprintf(("_ldrOpen: PE executable!(?)\n"));
     76                    #pragma info(none)
     77                    if (/* invoke pe.exe or do conversion now? */ 1)
     78                    {   /* pe2lx - win32k */
     79                    #pragma info(restore)
     80                        pNode = allocateNode();
     81                        if (pNode != NULL)
     82                        {
     83                            pNode->pPe2Lx = new Pe2Lx(*phFile);
     84                            if (pNode->pPe2Lx != NULL)
     85                            {
     86                                rc = pNode->pPe2Lx->init(pszFilename);
     87                                if (rc == NO_ERROR)
     88                                {
     89                                    kprintf(("_ldrOpen: Successfully init of Pe2Lx object.\n"));
     90                                    rc = insertNode(pNode);
     91                                    if (rc != NO_ERROR)
     92                                    {
     93                                        kprintf(("_ldrOpen: Failed to insert PeNode into tree. rc=%d\n"));
     94                                        delete pNode->pPe2Lx;
     95                                        pNode->pPe2Lx = NULL;
     96                                        freeNode(pNode);
     97                                        SetState(*phFile, HSTATE_OUR);
     98                                    }
     99                                }
     100                                else
     101                                {
     102                                    kprintf(("_ldrOpen: Failed to init Pe2Lx object. rc=%d\n"));
     103                                    delete pNode->pPe2Lx;
     104                                    pNode->pPe2Lx = NULL;
     105                                    freeNode(pNode);
     106                                }
     107                            }
     108                            else
     109                            {
     110                                kprintf(("_ldrOpen: Failed to allocate Pe2Lx object.\n"));
     111                                freeNode(pNode);
     112                            }
     113                        }
     114                        else
     115                            kprintf(("_ldrOpen: Failed to allocate node.\n"));
     116                    }
     117                    else
     118                    {   /* pe.exe */
     119                        kprintf(("_ldrOpen: pe.exe - opening\n"));
     120                        _ldrClose(*phFile);
     121                        rc = _ldrOpen(phFile, "pe.exe", param3);  /* path....! problems! */
     122                        kprintf(("_ldrOpen: pe.exe - open returned with rc = %d\n", rc));
     123                    }
     124                }
     125                rc = NO_ERROR;
    67126            }
    68127            else
    69128            {
    70                 kprintf(("myldrOpen: warning - malloc returned NULL\n"));
    71                 freeUncertainEntry(*phFile);
    72                 SetState(*phFile, HSTATE_NOT_PE);
     129                if (*pach == '#')
     130                {
     131                    /* unix styled script...? must be more than 64 bytes long.... */
     132                    char *pszStart = pach+1;
     133                    char *pszEnd;
     134                    kprintf(("_ldrOpen: unix script?\n"));
     135                    /* skip blanks */
     136                    while (*pszStart != '\0' && (*pszStart == ' ' || *pszStart == '\t'))
     137                        pszStart++;
     138                    if (*pszStart != '\0' && *pszStart != '\r' && *pszStart != '\n')
     139                    {   /* find end-of-word */
     140                        while (*pszEnd != '\0' && *pszEnd != '\n' && *pszEnd != '\r'
     141                               && *pszEnd != '\t' && *pszEnd != ' ')
     142                            pszEnd++;
     143                        *pszEnd = '\0';
     144                        kprintf(("_ldrOpen: unix script - opening %s\n", pszStart));
     145                        _ldrClose(*phFile);
     146                        rc = _ldrOpen(phFile, pszStart, param3);
     147                        kprintf(("_ldrOpen: unix script - open returned with rc = %d\n", rc));
     148                    }
     149                    else
     150                        kprintf(("_ldrOpen: unix script - unexpected end of line/file. (line: %.10s\n", pach));
     151                }
     152                else if (pach[0] == ELFMAG0 && pach[1] == ELFMAG1 && pach[2] == ELFMAG2 && pach[3] == ELFMAG3)
     153                {
     154                    /* ELF signature found */
     155                    kprintf(("_ldrOpen: ELF executable! - not implemented yet!\n"));
     156                }
    73157            }
    74158        }
    75159        else
    76             kprintf(("getFreeUncertainEntry failed\n"));
     160        {
     161            kprintf(("_ldrOpen: _ldrRead failed with rc=%d when reading DosHdr.\n", rc));
     162            rc = NO_ERROR;
     163        }
    77164    }
    78165    return rc;
Note: See TracChangeset for help on using the changeset viewer.