Ignore:
Timestamp:
Nov 29, 1999, 1:05:03 AM (26 years ago)
Author:
bird
Message:

Implemented EnumResourceNamesA/W.

File:
1 edited

Legend:

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

    r1663 r1872  
    1 /* $Id: winimagebase.cpp,v 1.4 1999-11-09 14:19:47 sandervl Exp $ */
     1/* $Id: winimagebase.cpp,v 1.5 1999-11-29 00:04:06 bird Exp $ */
    22
    33/*
     
    4242Win32ImageBase::Win32ImageBase(HINSTANCE hInstance) :
    4343    errorState(NO_ERROR), entryPoint(0), fullpath(NULL),
    44     tlsAddress(0), tlsIndexAddr(0), tlsInitSize(0), tlsTotalSize(0), 
     44    tlsAddress(0), tlsIndexAddr(0), tlsInitSize(0), tlsTotalSize(0),
    4545    tlsCallBackAddr(0), tlsIndex(-1), winres(NULL), pResDir(NULL),
    46     pResourceSectionStart(0)
     46    ulRVAResourceSection(0)
    4747{
    4848#ifdef DEBUG
     
    5151
    5252  if(hInstance != -1) {
    53         this->hinstance = hInstance;
    54 
    55         char *name = OSLibGetDllName(hinstance);
    56         strcpy(szFileName, name);
    57         strupr(szFileName);
    58 
    59         //rename dll (os/2 -> win32) if necessary (i.e. OLE32OS2 -> OLE32)
    60         Win32DllBase::renameDll(szFileName, FALSE);
    61 
    62         name = strrchr(szFileName, '\\')+1;
    63         strcpy(szModule, name);
    64 
    65         char *dot = strrchr(szModule, '.');
    66         if(dot)
    67                 *dot = 0;
     53    this->hinstance = hInstance;
     54
     55    char *name = OSLibGetDllName(hinstance);
     56    strcpy(szFileName, name);
     57    strupr(szFileName);
     58
     59    //rename dll (os/2 -> win32) if necessary (i.e. OLE32OS2 -> OLE32)
     60    Win32DllBase::renameDll(szFileName, FALSE);
     61
     62    name = strrchr(szFileName, '\\')+1;
     63    strcpy(szModule, name);
     64
     65    char *dot = strrchr(szModule, '.');
     66    if(dot)
     67        *dot = 0;
    6868  }
    6969  else {
    70         szModule[0] = 0;
    71         this->hinstance = -1;
     70    szModule[0] = 0;
     71    this->hinstance = -1;
    7272  }
    7373}
     
    8080  while(winres)
    8181  {
    82         res    = winres->next;
    83         delete(winres);
    84         winres = res;
     82        res    = winres->next;
     83        delete(winres);
     84        winres = res;
    8585  }
    8686  if(fullpath)
    87         free(fullpath);
     87        free(fullpath);
    8888}
    8989//******************************************************************************
     
    116116  strupr(filename);
    117117  if(!strchr(filename, (int)'.')) {
    118         strcat(filename,".DLL");
     118    strcat(filename,".DLL");
    119119  }
    120120  dllfile = OSLibDosOpen(filename, OSLIB_ACCESS_READONLY|OSLIB_ACCESS_SHAREDENYNONE);
    121121  if(dllfile == NULL) {//search in libpath for dll
    122         strcpy(modname, kernel32Path);
    123         strcat(modname, filename);
    124         strcpy(filename, modname);
    125   }
    126   else  OSLibDosClose(dllfile);
     122    strcpy(modname, kernel32Path);
     123    strcat(modname, filename);
     124    strcpy(filename, modname);
     125  }
     126  else  OSLibDosClose(dllfile);
    127127
    128128  rc = DosOpen(filename,                       /* File path name */
     
    140140  if (rc != NO_ERROR)
    141141  {
    142         dprintf(("KERNEL32:Win32ImageBase::isPEImage(%s) failed with %u\n",
    143                   szFileName, rc));
    144         return(FALSE);
     142        dprintf(("KERNEL32:Win32ImageBase::isPEImage(%s) failed with %u\n",
     143                  szFileName, rc));
     144        return(FALSE);
    145145  }
    146146
     
    150150  IMAGE_DOS_HEADER *pdoshdr = (IMAGE_DOS_HEADER *)malloc(sizeof(IMAGE_DOS_HEADER));
    151151  if(pdoshdr == NULL)   {
    152         DosClose(win32handle);                /* Close the file */
    153         return(FALSE);
     152        DosClose(win32handle);                /* Close the file */
     153        return(FALSE);
    154154  }
    155155  rc = DosRead(win32handle, pdoshdr, sizeof(IMAGE_DOS_HEADER), &ulRead);
    156156  if(rc != NO_ERROR) {
    157         DosClose(win32handle);                /* Close the file */
    158         return(FALSE);
     157        DosClose(win32handle);                /* Close the file */
     158        return(FALSE);
    159159  }
    160160  ULONG hdrsize = pdoshdr->e_lfanew + SIZE_OF_NT_SIGNATURE + sizeof(IMAGE_FILE_HEADER);
     
    166166  win32file = malloc(hdrsize);
    167167  if(win32file == NULL) {
    168         DosClose(win32handle);                /* Close the file */
    169         return(FALSE);
     168        DosClose(win32handle);                /* Close the file */
     169        return(FALSE);
    170170  }
    171171  rc = DosRead(win32handle, win32file, hdrsize, &ulRead);
    172172  if(rc != NO_ERROR) {
    173         goto failure;
     173        goto failure;
    174174  }
    175175
    176176  if(GetPEFileHeader (win32file, &fh) == FALSE) {
    177         goto failure;
     177        goto failure;
    178178  }
    179179
    180180  if(!(fh.Characteristics & IMAGE_FILE_EXECUTABLE_IMAGE)) {//not valid
    181         goto failure;
     181        goto failure;
    182182  }
    183183  if(fh.Machine != IMAGE_FILE_MACHINE_I386) {
    184         goto failure;
     184        goto failure;
    185185  }
    186186  //IMAGE_FILE_SYSTEM == only drivers (device/file system/video etc)?
    187187  if(fh.Characteristics & IMAGE_FILE_SYSTEM) {
    188         goto failure;
     188        goto failure;
    189189  }
    190190  DosClose(win32handle);
     
    198198//******************************************************************************
    199199//******************************************************************************
     200/**
     201 * Static helper which finds the Win32ImageBase object corresponding to hModule.
     202 * @returns   Pointer to Win32ImageBase object corresponding to hModule.
     203 * @param     hModule  Odin32 modulehandler. 0 and -1 is aliases for the executable module
     204 * @status    completely implemented and tested.
     205 * @author    knut st. osmundsen
     206 */
     207Win32ImageBase * Win32ImageBase::findModule(HMODULE hModule)
     208{
     209    Win32ImageBase *pRet;
     210
     211    if (hModule == -1 || hModule == 0 ||       /* note: WinNt 4, SP4 don't accept -1 as the EXE handle.*/
     212        (WinExe != NULL && hModule == WinExe->getInstanceHandle())
     213        )
     214        pRet = WinExe;
     215    else
     216        pRet = Win32DllBase::findModule(hModule);
     217
     218    if (pRet == NULL)
     219    {
     220        if (WinExe == NULL)
     221            dprintf(("Win32ImageBase::findModule: Module not found. WinExe is NULL, hModule=%#x\n", hModule));
     222        else
     223            dprintf(("Win32ImageBase::findModule: Module not found, hModule=%#x\n", hModule));
     224    }
     225
     226    return pRet;
     227}
     228
     229
Note: See TracChangeset for help on using the changeset viewer.