Changeset 9537 for trunk/src


Ignore:
Timestamp:
Dec 20, 2002, 12:39:43 PM (23 years ago)
Author:
sandervl
Message:

Don't display message boxes for module load errors. Pass errors back to the PE loader.

Location:
trunk/src/kernel32
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/KERNEL32.DEF

    r9496 r9537  
    1 ; $Id: KERNEL32.DEF,v 1.146 2002-12-13 16:46:43 sandervl Exp $
     1; $Id: KERNEL32.DEF,v 1.147 2002-12-20 11:39:40 sandervl Exp $
    22
    33;Basis is Windows95 KERNEL32
     
    10771077    _RegisterPe2LxDll@12                                          @1209
    10781078
    1079     _CreateWin32PeLdrExe@28                                       @1236
     1079    _CreateWin32PeLdrExe@36                                       @1236
    10801080
    10811081    _RegisterLxExe@8                                              @1237
  • trunk/src/kernel32/kernel32dbg.def

    r9496 r9537  
    1 ; $Id: kernel32dbg.def,v 1.21 2002-12-13 16:46:44 sandervl Exp $
     1; $Id: kernel32dbg.def,v 1.22 2002-12-20 11:39:41 sandervl Exp $
    22
    33;Basis is Windows95 KERNEL32
     
    10771077    _RegisterPe2LxDll@12                                          @1209
    10781078
    1079     _CreateWin32PeLdrExe@28                                       @1236
     1079    _CreateWin32PeLdrExe@36                                       @1236
    10801080
    10811081    _RegisterLxExe@8                                              @1237
  • trunk/src/kernel32/winexepeldr.cpp

    r9533 r9537  
    1 /* $Id: winexepeldr.cpp,v 1.20 2002-12-20 10:38:58 sandervl Exp $ */
     1/* $Id: winexepeldr.cpp,v 1.21 2002-12-20 11:39:41 sandervl Exp $ */
    22
    33/*
     
    4646
    4747
    48 extern char szErrorTitle[];
    4948extern char szErrorModule[];
    5049
     
    5857//   (not other options available at this time)
    5958//******************************************************************************
    60 BOOL WIN32API CreateWin32PeLdrExe(char *szFileName, char *szCmdLine,
    61                                   char *peoptions,
    62                                   ULONG reservedMem, ULONG ulPEOffset,
    63                                   BOOL fConsoleApp, BOOL fVioConsole)
     59DWORD WIN32API CreateWin32PeLdrExe(char *szFileName, char *szCmdLine,
     60                                   char *peoptions,
     61                                   ULONG reservedMem, ULONG ulPEOffset,
     62                                   BOOL fConsoleApp, BOOL fVioConsole,
     63                                   char *pszErrorModule, ULONG cbErrorModule)
    6464{
    6565 APIRET  rc;
     
    7676  rc = DosGetInfoBlocks(&ptib, &ppib);
    7777  if(rc) {
    78         WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szInteralErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE);
    79         delete WinExe;
    80         return FALSE;
     78      delete WinExe;
     79      return LDRERROR_INTERNAL;
    8180  }
    8281  //Handle special pe cmd line options here (/OPT:[x1=y,x2=z,..])
     
    123122  if(WinExe->isConsoleApp())
    124123  {
    125         dprintf(("Console application!\n"));
     124      dprintf(("Console application!\n"));
    126125
    127         APIRET rc = iConsoleInit(fVioConsole);                /* initialize console subsystem */
    128         if (rc != NO_ERROR)                                  /* check for errors */
    129                 dprintf(("KERNEL32:Win32Image:Init ConsoleInit failed with %u.\n", rc));
     126     rc = iConsoleInit(fVioConsole);                /* initialize console subsystem */
     127      if (rc != NO_ERROR)                                  /* check for errors */
     128          dprintf(("KERNEL32:Win32Image:Init ConsoleInit failed with %u.\n", rc));
    130129  }
    131130
    132131  OS2SetExceptionHandler(&exceptFrame);
    133   if(WinExe->init(reservedMem, ulPEOffset) == FALSE)
     132  rc = WinExe->init(reservedMem, ulPEOffset);
     133  if(rc != LDRERROR_SUCCESS)
    134134  {
    135135        if(szErrorModule[0] != 0) {
    136                 char szErrorMsg[128];
    137 
    138                 sprintf(szErrorMsg, "Can't execute %s due to bad or missing %s", OSLibStripPath(szFileName), szErrorModule);
    139                 WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE);
     136            strncpy(pszErrorModule, szErrorModule, cbErrorModule-1);
     137            pszErrorModule[cbErrorModule-1] = 0;
    140138        }
    141139        delete WinExe;
    142140        OS2UnsetExceptionHandler(&exceptFrame);
    143         return FALSE;
     141        return rc;
    144142  }
    145143  OS2UnsetExceptionHandler(&exceptFrame);
     
    158156  delete WinExe;
    159157
    160   return TRUE;
     158  return LDRERROR_SUCCESS;
    161159}
    162160//******************************************************************************
     
    167165                   Win32PeLdrImage(szFileName, TRUE)
    168166{
    169   dprintf(("Win32PeLdrExe ctor: %s", szFileName));
    170   this->fConsoleApp = fConsoleApp;
     167    dprintf(("Win32PeLdrExe ctor: %s", szFileName));
     168    this->fConsoleApp = fConsoleApp;
    171169
    172   //SvL: set temporary full path here as console init needs it
    173   setFullPath(szFileName);
     170    //SvL: set temporary full path here as console init needs it
     171    setFullPath(szFileName);
    174172}
    175173//******************************************************************************
  • trunk/src/kernel32/winexepeldr.h

    r8913 r9537  
    1 /* $Id: winexepeldr.h,v 1.7 2002-07-23 13:51:48 sandervl Exp $ */
     1/* $Id: winexepeldr.h,v 1.8 2002-12-20 11:39:41 sandervl Exp $ */
    22
    33/*
     
    1515#include <winexebase.h>
    1616#include <winimagepeldr.h>
    17 
    18 typedef BOOL (* WIN32API WIN32CTOR)(char *, char *, char *, ULONG, ULONG, BOOL, BOOL);
    1917
    2018//Class for executables run by the ring 3 PE loader
  • trunk/src/kernel32/winimagebase.h

    r7811 r9537  
    1 /* $Id: winimagebase.h,v 1.21 2002-02-06 16:33:39 sandervl Exp $ */
     1/* $Id: winimagebase.h,v 1.22 2002-12-20 11:39:41 sandervl Exp $ */
    22
    33/*
     
    1616#include <peexe.h>
    1717#include "queue.h"
     18#include <odinpe.h>
    1819#ifdef OS2_INCLUDED
    1920#include <winconst.h>
     
    2930
    3031#define ID_GETFIRST             0xF0000000
    31 
    32 #ifndef ENUMRESNAMEPROC
    33     typedef BOOL (* CALLBACK ENUMRESTYPEPROCA)(HMODULE,LPSTR,LONG);
    34     typedef BOOL (* CALLBACK ENUMRESTYPEPROCW)(HMODULE,LPWSTR,LONG);
    35     typedef BOOL (* CALLBACK ENUMRESNAMEPROCA)(HMODULE,LPCSTR,LPSTR,LONG);
    36     typedef BOOL (* CALLBACK ENUMRESNAMEPROCW)(HMODULE,LPCWSTR,LPWSTR,LONG);
    37     typedef BOOL (* CALLBACK ENUMRESLANGPROCA)(HMODULE,LPCSTR,LPCSTR,WORD,LONG);
    38     typedef BOOL (* CALLBACK ENUMRESLANGPROCW)(HMODULE,LPCWSTR,LPCWSTR,WORD,LONG);
    39 #endif
    4032
    4133class Win32Resource;
  • trunk/src/kernel32/winimagepe2lx.cpp

    r8589 r9537  
    1 /* $Id: winimagepe2lx.cpp,v 1.20 2002-06-08 00:26:59 bird Exp $ */
     1/* $Id: winimagepe2lx.cpp,v 1.21 2002-12-20 11:39:42 sandervl Exp $ */
    22
    33/*
     
    179179 * Initiates the object.
    180180 * Must be called immediately after the object construction.
    181  * @returns   Success indicator, TRUE == success; FALSE = failure.
     181 * @returns   Error value, LDRERROR_SUCCESS == success; failure otherwise.
    182182 * @sketch    Get section placement and sizes for this module. (paSections, cSections)
    183183 *            Verify that there is at least one section - the header section.
     
    194194 * @remark    Object must be destroyed if failure!
    195195 */
    196 BOOL Win32Pe2LxImage::init()
     196DWORD Win32Pe2LxImage::init()
    197197{
    198198    APIRET rc;
     
    204204        dprintf(("Win32Pe2LxImage::Win32Pe2LxImage: error - getSection failed with rc=%d\n",
    205205                 rc));
    206         return FALSE;
     206        return LDRERROR_INVALID_HEADER;
    207207    }
    208208
     
    211211    {
    212212        dprintf(("Win32Pe2LxImage::Win32Pe2LxImage: no header section, cSections is 0\n"));
    213         return FALSE;
     213        return LDRERROR_INVALID_HEADER;
    214214    }
    215215
     
    224224    {
    225225        dprintf(("Win32Pe2LxImage::Win32Pe2LxImage: Not a pe2lx image!(?)\n"));
    226         return FALSE;
     226        return LDRERROR_INVALID_HEADER;
    227227    }
    228228
     
    245245    {
    246246        dprintf(("Win32Pe2LxImage::Win32Pe2LxImage: Not a pe2lx image!(?)\n"));
    247         return FALSE;
     247        return LDRERROR_INVALID_HEADER;
    248248    }
    249249
     
    253253    {
    254254        dprintf(("Win32Pe2LxImage::Win32Pe2LxImage: setSectionRVAs failed with rc=%d\n", rc));
    255         return FALSE;
     255        return LDRERROR_INVALID_HEADER;
    256256    }
    257257
     
    268268        dprintf(("Win32Pe2LxImage::Win32Pe2LxImage: entrypoint is incorrect, AddrOfEP=0x%08x, entryPoint=0x%08x\n",
    269269                 pNtHdrs->OptionalHeader.AddressOfEntryPoint, entryPoint));
    270         return FALSE;
     270        return LDRERROR_NO_ENTRYPOINT;
    271271    }
    272272
     
    367367                            eprintf(("Win32Pe2LxImage::init: invalid RVA to TLS AddressOfIndex - %#8x.\n",
    368368                                     pTLSDir->AddressOfIndex));
    369                             return FALSE;
     369                            return LDRERROR_INVALID_HEADER;
    370370                        }
    371371                        setTLSIndexAddr((LPDWORD)pv);
     
    387387                            eprintf(("Win32Pe2LxImage::init: invalid pointer to TLS AddressOfCallBacks - %#8x.\n",
    388388                                     pTLSDir->AddressOfIndex));
    389                             return FALSE;
     389                            return LDRERROR_INVALID_HEADER;
    390390                        }
    391391                        setTLSCallBackAddr((PIMAGE_TLS_CALLBACK*)pv);
     
    398398            eprintf(("Win32Pe2LxImage::init: invalid RVA to TLS Dir - %#8x. (getPointerFromRVA failed)\n",
    399399                     pNtHdrs->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_TLS].VirtualAddress));
    400             return FALSE;
     400            return LDRERROR_INVALID_HEADER;
    401401        }
    402402    }
    403     return TRUE;
     403    return LDRERROR_SUCCESS;
    404404}
    405405
  • trunk/src/kernel32/winimagepe2lx.h

    r6302 r9537  
    1 /* $Id: winimagepe2lx.h,v 1.8 2001-07-10 20:18:49 bird Exp $ */
     1/* $Id: winimagepe2lx.h,v 1.9 2002-12-20 11:39:42 sandervl Exp $ */
    22
    33/*
     
    4141    Win32Pe2LxImage(HINSTANCE hinstance, BOOL fWin32k);
    4242    virtual         ~Win32Pe2LxImage();
    43     virtual BOOL    init();
     43    virtual DWORD   init();
    4444
    4545    /** @cat Exports */
  • trunk/src/kernel32/winimagepeldr.cpp

    r8918 r9537  
    1 /* $Id: winimagepeldr.cpp,v 1.101 2002-07-26 10:46:56 sandervl Exp $ */
     1/* $Id: winimagepeldr.cpp,v 1.102 2002-12-20 11:39:42 sandervl Exp $ */
    22
    33/*
     
    6666//#endif
    6767
    68 char szErrorTitle[]     = "Odin";
    69 char szMemErrorMsg[]    = "Memory allocation failure";
    70 char szFileErrorMsg[]   = "File IO error";
    71 char szPEErrorMsg[]     = "Not a valid win32 exe. (perhaps 16 bits windows)";
    72 char szCPUErrorMsg[]    = "Executable doesn't run on x86 machines";
    73 char szExeErrorMsg[]    = "File isn't an executable";
    74 char szInteralErrorMsg[]= "Internal Error";
    75 char szErrorModule[128] = "";
     68char szErrorModule[260] = "";
    7669
    7770#ifdef DEBUG
     
    175168//******************************************************************************
    176169//******************************************************************************
    177 BOOL Win32PeLdrImage::init(ULONG reservedMem, ULONG ulPEOffset)
     170DWORD Win32PeLdrImage::init(ULONG reservedMem, ULONG ulPEOffset)
    178171{
    179172 LPVOID win32file = NULL;
     
    186179 IMAGE_DOS_HEADER doshdr;
    187180 ULONG  signature;
     181 DWORD  lasterror = LDRERROR_INTERNAL;
    188182
    189183    //offset in executable image where real PE file starts (default 0)
     
    199193    if(ulPEOffset) {
    200194        if(OSLibDosSetFilePtr(hFile, ulPEOffset, OSLIB_SETPTR_FILE_BEGIN) == -1) {
     195            lasterror = LDRERROR_INVALID_MODULE;
    201196            goto failure;
    202197        }
     
    206201    strcpy(szErrorModule, OSLibStripPath(szFileName));
    207202    if(hFile == NULL) {
     203        lasterror = LDRERROR_INTERNAL;
    208204        goto failure;
    209205    }
    210206    //read dos header
    211207    if(DosRead(hFile, (LPVOID)&doshdr, sizeof(doshdr), &ulRead)) {
     208        lasterror = LDRERROR_INVALID_MODULE;
    212209        goto failure;
    213210    }
    214211    if(OSLibDosSetFilePtr(hFile, ulPEOffset+doshdr.e_lfanew, OSLIB_SETPTR_FILE_BEGIN) == -1) {
     212        lasterror = LDRERROR_INVALID_MODULE;
    215213        goto failure;
    216214    }
    217215    //read signature dword
    218216    if(DosRead(hFile, (LPVOID)&signature, sizeof(signature), &ulRead)) {
     217        lasterror = LDRERROR_INVALID_MODULE;
    219218        goto failure;
    220219    }
    221220    //read pe header
    222221    if(DosRead(hFile, (LPVOID)&fh, sizeof(fh), &ulRead)) {
     222        lasterror = LDRERROR_INVALID_MODULE;
    223223        goto failure;
    224224    }
    225225    //read optional header
    226226    if(DosRead(hFile, (LPVOID)&oh, sizeof(oh), &ulRead)) {
     227        lasterror = LDRERROR_INVALID_MODULE;
    227228        goto failure;
    228229    }
    229230    if(doshdr.e_magic != IMAGE_DOS_SIGNATURE || signature != IMAGE_NT_SIGNATURE) {
    230231        dprintf((LOG, "Not a valid PE file (probably a 16 bits windows exe/dll)!"));
    231         WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szPEErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE);
     232        lasterror = LDRERROR_INVALID_MODULE;
    232233        goto failure;
    233234    }
     
    241242    if(allocSections(reservedMem) == FALSE) {
    242243        dprintf((LOG, "Failed to allocate image memory for %s at %x, rc %d", szFileName, oh.ImageBase, errorState));;
     244        lasterror = LDRERROR_MEMORY;
    243245        goto failure;
    244246    }
     
    246248    memmap = new Win32MemMap(this, realBaseAddress, imageSize);
    247249    if(memmap == NULL || !memmap->Init()) {
     250        lasterror = LDRERROR_MEMORY;
    248251        goto failure;
    249252    }
     
    256259    if(!(fh.Characteristics & IMAGE_FILE_EXECUTABLE_IMAGE)) {//not valid
    257260        dprintf((LOG, "Not a valid PE file!"));
    258         WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szPEErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE);
     261        lasterror = LDRERROR_INVALID_MODULE;
    259262        goto failure;
    260263    }
    261264    if(fh.Machine != IMAGE_FILE_MACHINE_I386) {
    262265        dprintf((LOG, "Doesn't run on x86 processors!"));
    263         WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szCPUErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE);
     266        lasterror = LDRERROR_INVALID_CPU;
    264267        goto failure;
    265268    }
     
    267270    if(fh.Characteristics & IMAGE_FILE_SYSTEM) {
    268271        dprintf((LOG, "Can't convert system files"));
    269         WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szExeErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE);
     272        lasterror = LDRERROR_FILE_SYSTEM;
    270273        goto failure;
    271274    }
     
    303306    if(section == NULL) {
    304307        DebugInt3();
     308        lasterror = LDRERROR_MEMORY;
    305309        goto failure;
    306310    }
     
    423427            }
    424428            dprintf((LOG, "Unknown section" ));
     429            lasterror = LDRERROR_INVALID_SECTION;
    425430            goto failure;
    426431        }
     
    455460    if(setMemFlags() == FALSE) {
    456461        dprintf((LOG, "Failed to set memory protection" ));
    457         goto failure;
     462        lasterror = LDRERROR_MEMORY;
    458463    }
    459464
     
    486491            if(sect == NULL) {
    487492                dprintf((LOG, "Couldn't find TLS section!!" ));
     493                lasterror = LDRERROR_INVALID_HEADER;
    488494                goto failure;
    489495            }
     
    502508            if(sect == NULL) {
    503509                dprintf((LOG, "Couldn't find TLS AddressOfIndex section!!" ));
     510                lasterror = LDRERROR_INVALID_HEADER;
    504511                goto failure;
    505512            }
     
    524531                if(sect == NULL) {
    525532                    dprintf((LOG, "Couldn't find TLS AddressOfCallBacks section!!" ));
     533                    lasterror = LDRERROR_INVALID_HEADER;
    526534                    goto failure;
    527535                }
     
    547555                    if(sect == NULL) {
    548556                        dprintf((LOG, "Couldn't find TLS callback section!!" ));
     557                        lasterror = LDRERROR_INVALID_HEADER;
    549558                        goto failure;
    550559                    }
     
    609618        if(processExports((char *)win32file) == FALSE) {
    610619            dprintf((LOG, "Failed to process exported apis" ));
     620            lasterror = LDRERROR_EXPORTS;
    611621            goto failure;
    612622        }
     
    649659        if(processImports((char *)win32file) == FALSE) {
    650660            dprintf((LOG, "Failed to process imports!" ));
     661            lasterror = LDRERROR_IMPORTS;
    651662            goto failure;
    652663        }
    653664    }
    654     return(TRUE);
     665    return LDRERROR_SUCCESS;
    655666
    656667failure:
     
    664675    }
    665676    errorState = ERROR_INTERNAL;
    666     return FALSE;
     677    return lasterror;
    667678}
    668679//******************************************************************************
     
    16061617            if(pedll == NULL) {
    16071618                dprintf((LOG, "pedll: Error allocating memory" ));
    1608                 WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szMemErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE);
    16091619                errorState = ERROR_INTERNAL;
    16101620                return NULL;
     
    16131623            dprintf((LOG, "**********************     Loading Module        *********************" ));
    16141624            dprintf((LOG, "**********************************************************************" ));
    1615             if(pedll->init(0) == FALSE) {
     1625            if(pedll->init(0) != LDRERROR_SUCCESS) {
    16161626                dprintf((LOG, "Internal WinDll error ", pedll->getError() ));
    16171627                delete pedll;
     
    20692079    do {
    20702080        r = WinMessageBox(HWND_DESKTOP, NULLHANDLE, message,
    2071                           "Internal Odin Error", 0, MB_ABORTRETRYIGNORE | MB_ICONEXCLAMATION | MB_MOVEABLE);
     2081                          "Internal Error", 0, MB_ABORTRETRYIGNORE | MB_ICONEXCLAMATION | MB_MOVEABLE);
    20722082    }
    20732083    while(r == MBID_RETRY); //giggle
  • trunk/src/kernel32/winimagepeldr.h

    r8913 r9537  
    1 /* $Id: winimagepeldr.h,v 1.17 2002-07-23 13:51:49 sandervl Exp $ */
     1/* $Id: winimagepeldr.h,v 1.18 2002-12-20 11:39:43 sandervl Exp $ */
    22
    33/*
     
    8080    //             loaded at a low address)
    8181    //ulPEOffset:  offset in file where real PE image starts
    82     virtual BOOL init(ULONG reservedMem, ULONG ulPEOffset = 0);
     82    virtual DWORD init(ULONG reservedMem, ULONG ulPEOffset = 0);
    8383
    8484    virtual BOOL  insideModule(ULONG address);
Note: See TracChangeset for help on using the changeset viewer.