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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.