Ignore:
Timestamp:
Jan 15, 2004, 11:39:15 AM (22 years ago)
Author:
sandervl
Message:

Loader updates

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/winimagelx.cpp

    r9971 r10397  
    1 /* $Id: winimagelx.cpp,v 1.20 2003-04-02 11:03:33 sandervl Exp $ */
     1/* $Id: winimagelx.cpp,v 1.21 2004-01-15 10:39:11 sandervl Exp $ */
    22
    33/*
     
    55 *
    66 * Copyright 1999-2000 Sander van Leeuwen (sandervl@xs4all.nl)
     7 * Copyright 2003 Innotek Systemberatung GmbH (sandervl@innotek.de)
     8 *
     9 * header adjustment & fixup_rva_ptrs borrowed from Wine (Rewind)
     10 * Copyright 2000 Alexandre Julliard
    711 *
    812 * TODO: headers not complete
    9  * 
     13 *
    1014 * Project Odin Software License can be found in LICENSE.TXT
    1115 *
     
    6266
    6367//******************************************************************************
     68/* adjust an array of pointers to make them into RVAs */
     69//******************************************************************************
     70static inline void fixup_rva_ptrs( void *array, void *base, int count )
     71{
     72    void **ptr = (void **)array;
     73    while (count--)
     74    {
     75        if (*ptr) *ptr = (void *)((char *)*ptr - (char *)base);
     76        ptr++;
     77    }
     78}
     79//******************************************************************************
    6480//******************************************************************************
    6581Win32LxImage::Win32LxImage(HINSTANCE hInstance, PVOID pResData)
    66                : Win32ImageBase(hInstance), header(0)
     82               : Win32ImageBase(hInstance), header(0), pCustomPEHeader(0)
    6783{
    6884    APIRET rc;
     
    7187    szFileName[0] = 0;
    7288
    73     this->lpszExportPrefix = NULL;
    74     if(lpszCustomDllName) {
    75        name = lpszCustomDllName;
    76        this->dwOrdinalBase    = ::dwOrdinalBase;
    77      
    78        if(lpszCustomExportPrefix) {
    79            this->lpszExportPrefix = strdup(::lpszCustomExportPrefix);
    80        }
     89    if (lpszCustomDllName) {
     90       name            = lpszCustomDllName;
     91       pCustomPEHeader = lpCustomDllPEHdr;
     92
     93       hinstance = (DWORD)pCustomPEHeader;
     94       if (pCustomPEHeader) {
     95           //Calculate address of optional header
     96           poh = (PIMAGE_OPTIONAL_HEADER)OPTHEADEROFF(pCustomPEHeader);
     97
     98           //Update the header data to reflect the new load address
     99           poh->ImageBase = hinstance;
     100
     101           PIMAGE_EXPORT_DIRECTORY pExpDir;
     102           pExpDir = (PIMAGE_EXPORT_DIRECTORY)((char*)hinstance
     103                + poh->DataDirectory[IMAGE_FILE_EXPORT_DIRECTORY].VirtualAddress);
     104           fixup_rva_ptrs((char*)hinstance + (unsigned)pExpDir->AddressOfFunctions,
     105                          (LPVOID)hinstance,
     106                          pExpDir->NumberOfFunctions );
     107        }
    81108    }
    82109    else {
    83110       name = OSLibGetDllName(hinstance);
    84        this->dwOrdinalBase    = 0;
    85111    }
    86112
     
    102128Win32LxImage::~Win32LxImage()
    103129{
    104     if(lpszExportPrefix) free(lpszExportPrefix);
    105 
    106130    if(header) {
    107131        DosFreeMem(header);
     
    115139    ULONG       apiaddr;
    116140
    117     if(lpszExportPrefix)
    118     {//if this dll exports by name with a prefix, then concatenate the prefix
    119      //with the export name to get the OS/2 export name
    120         char *lpszNewName = (char *)alloca(strlen(name) + strlen(lpszExportPrefix)+1);
    121         if(lpszNewName == NULL) {
    122             DebugInt3();
    123             return 0;
    124         }
    125         strcpy(lpszNewName, lpszExportPrefix);
    126         strcat(lpszNewName, name);
    127         rc = DosQueryProcAddr(hinstanceOS2, 0, lpszNewName, (PFN *)&apiaddr);
    128         if(rc == NO_ERROR) {
    129             return(apiaddr);
    130         }
    131         //else try with the normal name
    132     }
     141    if(pCustomPEHeader) return Win32ImageBase::getApi(name);
     142
    133143    rc = DosQueryProcAddr(hinstanceOS2, 0, name, (PFN *)&apiaddr);
    134144    if(rc)
     
    146156    ULONG       apiaddr;
    147157
    148     rc = DosQueryProcAddr(hinstanceOS2, dwOrdinalBase+ordinal, NULL, (PFN *)&apiaddr);
     158    if(pCustomPEHeader) return Win32ImageBase::getApi(ordinal);
     159
     160    rc = DosQueryProcAddr(hinstanceOS2, ordinal, NULL, (PFN *)&apiaddr);
    149161    if(rc) {
    150162        dprintf(("Win32LxImage::getApi %x %d -> rc = %d", hinstanceOS2, ordinal, rc));
     
    155167//******************************************************************************
    156168//******************************************************************************
     169ULONG Win32LxImage::setApi(char *name, ULONG pfnNewProc)
     170{
     171    if(pCustomPEHeader) return Win32ImageBase::setApi(name, pfnNewProc);
     172
     173    return -1;
     174}
     175//******************************************************************************
     176//******************************************************************************
     177ULONG Win32LxImage::setApi(int ordinal, ULONG pfnNewProc)
     178{
     179    if(pCustomPEHeader) return Win32ImageBase::setApi(ordinal, pfnNewProc);
     180
     181    return -1;
     182}
     183//******************************************************************************
     184//******************************************************************************
    157185LPVOID Win32LxImage::buildHeader(DWORD MajorImageVersion, DWORD MinorImageVersion,
    158                                  DWORD Subsystem) 
     186                                 DWORD Subsystem)
    159187{
    160188    APIRET rc;
    161189    IMAGE_DOS_HEADER *pdosheader;
    162     PIMAGE_OPTIONAL_HEADER poh;
    163     PIMAGE_FILE_HEADER     pfh;
     190    PIMAGE_OPTIONAL_HEADER  poh;
     191    PIMAGE_FILE_HEADER      pfh;
     192    PIMAGE_SECTION_HEADER   psh;
     193    PIMAGE_EXPORT_DIRECTORY ped;
     194
     195    if(pCustomPEHeader)
     196    {
     197        return (LPVOID)pCustomPEHeader;
     198    }
     199
    164200    DWORD *ntsig;
    165201
     
    180216    pfh->NumberOfSymbols      = 0;
    181217    pfh->SizeOfOptionalHeader = sizeof(IMAGE_OPTIONAL_HEADER);
    182     pfh->Characteristics      = IMAGE_FILE_DLL | IMAGE_FILE_32BIT_MACHINE | 
    183                                 IMAGE_FILE_DEBUG_STRIPPED | IMAGE_FILE_EXECUTABLE_IMAGE | 
     218    pfh->Characteristics      = IMAGE_FILE_DLL | IMAGE_FILE_32BIT_MACHINE |
     219                                IMAGE_FILE_DEBUG_STRIPPED | IMAGE_FILE_EXECUTABLE_IMAGE |
    184220                                IMAGE_FILE_RELOCS_STRIPPED;
    185221    poh    = (PIMAGE_OPTIONAL_HEADER)(pfh+1);
     
    214250    poh->LoaderFlags                 = 0;
    215251    poh->NumberOfRvaAndSizes         = 0;
    216 //  poh->DataDirectory[0]
    217252
    218253    return header;
Note: See TracChangeset for help on using the changeset viewer.