Changeset 12458


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

Implemented EnumResourceNamesA/W.

Location:
tags/trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified tags/trunk/include/winimagebase.h

    r12429 r12458  
    1 /* $Id: winimagebase.h,v 1.5 1999-11-26 00:04:33 sandervl Exp $ */
     1/* $Id: winimagebase.h,v 1.6 1999-11-29 00:05:03 bird Exp $ */
    22
    33/*
     
    2424#define ID_GETFIRST             LANG_GETFIRST
    2525#define IDLANG_GETFIRST         LANG_GETFIRST
     26
     27#ifndef ENUMRESNAMEPROC
     28    typedef BOOL (* CALLBACK ENUMRESTYPEPROCA)(HMODULE,LPSTR,LONG);
     29    typedef BOOL (* CALLBACK ENUMRESTYPEPROCW)(HMODULE,LPWSTR,LONG);
     30    typedef BOOL (* CALLBACK ENUMRESNAMEPROCA)(HMODULE,LPCSTR,LPSTR,LONG);
     31    typedef BOOL (* CALLBACK ENUMRESNAMEPROCW)(HMODULE,LPCWSTR,LPWSTR,LONG);
     32    typedef BOOL (* CALLBACK ENUMRESLANGPROCA)(HMODULE,LPCSTR,LPCSTR,WORD,LONG);
     33    typedef BOOL (* CALLBACK ENUMRESLANGPROCW)(HMODULE,LPCWSTR,LPCWSTR,WORD,LONG);
     34#endif
    2635
    2736class Win32Resource;
     
    5968virtual ULONG getResourceSizeA(LPCSTR lpszName, LPSTR lpszType, ULONG lang = LANG_GETFIRST);
    6069        ULONG getResourceSizeW(LPCWSTR lpszName, LPWSTR lpszType, ULONG lang = LANG_GETFIRST);
     70virtual BOOL  enumResourceNamesA(HMODULE hmod, LPCTSTR  lpszType, ENUMRESNAMEPROCA lpEnumFunc, LONG lParam);
     71virtual BOOL  enumResourceNamesW(HMODULE hmod, LPCWSTR  lpszType, ENUMRESNAMEPROCW lpEnumFunc, LONG lParam);
    6172
    6273virtual ULONG getVersionSize();
     
    7182        void  setTLSInitSize(ULONG dwTlsSize)           { tlsInitSize = dwTlsSize; };
    7283        void  setTLSTotalSize(ULONG dwTlsSize)          { tlsTotalSize = dwTlsSize; };
    73         void  setTLSCallBackAddr(PIMAGE_TLS_CALLBACK *dwTlsCallBackAddr)       
     84        void  setTLSCallBackAddr(PIMAGE_TLS_CALLBACK *dwTlsCallBackAddr)
    7485        {
    7586           tlsCallBackAddr = dwTlsCallBackAddr;
     
    8394
    8495virtual BOOL  isDll() = 0;
     96
     97static Win32ImageBase * findModule(HMODULE hModule);
    8598
    8699protected:
     
    110123        PIMAGE_RESOURCE_DATA_ENTRY ProcessResSubDir(PIMAGE_RESOURCE_DIRECTORY prdType,
    111124                                                    ULONG *nodeData, int level);
     125        PIMAGE_RESOURCE_DIRECTORY  getResSubDirW(PIMAGE_RESOURCE_DIRECTORY pResDir, LPCWSTR lpszName);
     126        PIMAGE_RESOURCE_DIRECTORY  getResSubDirA(PIMAGE_RESOURCE_DIRECTORY pResDir, LPCTSTR lpszName);
     127
    112128        PIMAGE_RESOURCE_DIRECTORY pResDir;
    113129
    114130        //substracted from RVA data offsets
    115         ULONG                     pResourceSectionStart;
     131        ULONG                     ulRVAResourceSection;
    116132
    117133private:
     
    121137};
    122138
    123 //SvL: This structure is placed at the end of the first page of the image (header 
     139//SvL: This structure is placed at the end of the first page of the image (header
    124140//     page), so we can determine the Win32Image pointer from a HINSTANCE variable
    125141//     (which is actually the address of the win32 module)
    126 typedef struct 
     142typedef struct
    127143{
    128   ULONG           magic1; 
     144  ULONG           magic1;
    129145  Win32ImageBase *image;
    130   ULONG           magic2; 
     146  ULONG           magic2;
    131147} WINIMAGE_LOOKUP;
    132148
  • TabularUnified tags/trunk/src/kernel32/makefile

    r12433 r12458  
    1 # $Id: makefile,v 1.63 1999-11-26 08:17:40 achimha Exp $
     1# $Id: makefile,v 1.64 1999-11-29 00:04:05 bird Exp $
    22
    33#
     
    7070        @echo Creating file <<$(@B).lrf
    7171$(OBJS)
     72$(PDWIN32_LIB)\odincrt.lib
    7273$(PDWIN32_LIB)\PMWINX.LIB
    7374$(PDWIN32_LIB)\LIBULS.LIB
    7475$(PDWIN32_LIB)\LIBCONV.LIB
    75 $(PDWIN32_LIB)\odincrt.lib
    7676OS2386.LIB
    7777$(RTLLIB_O)
  • TabularUnified tags/trunk/src/kernel32/resource.cpp

    r11548 r12458  
    1 /* $Id: resource.cpp,v 1.9 1999-09-15 23:38:01 sandervl Exp $ */
     1/* $Id: resource.cpp,v 1.10 1999-11-29 00:04:05 bird Exp $ */
    22
    33/*
     
    2727
    2828    dprintf(("FindResourceA %X", hModule));
    29     if(hModule == 0 || hModule == -1 || (WinExe != NULL && hModule ==
    30        WinExe->getInstanceHandle()))
    31     {
    32          module = (Win32ImageBase *)WinExe;
    33     }
    34     else module = (Win32ImageBase *)Win32DllBase::findModule(hModule);
    35 
     29    module = Win32ImageBase::findModule(hModule);
    3630    if(module == NULL)
    37         return(NULL);
     31      return(NULL);
    3832
    3933    return module->findResourceA(lpszName, (LPSTR)lpszType);
     
    4236//******************************************************************************
    4337HRSRC WIN32API FindResourceW(HINSTANCE hModule, LPCWSTR lpszName,
    44                              LPCWSTR lpszType)
     38                          LPCWSTR lpszType)
    4539{
    4640 Win32ImageBase *module;
    4741
    4842    dprintf(("FindResourceW %X", hModule));
    49     if(hModule == 0 || hModule == -1 || (WinExe != NULL && hModule ==
    50        WinExe->getInstanceHandle()))
    51     {
    52          module = (Win32ImageBase *)WinExe;
    53     }
    54     else module = (Win32ImageBase *)Win32DllBase::findModule(hModule);
    55 
     43    module = Win32ImageBase::findModule(hModule);
    5644    if(module == NULL)
    57         return(NULL);
     45        return(NULL);
    5846
    5947    return module->findResourceW((LPWSTR)lpszName, (LPWSTR)lpszType);
     
    7765  /* @@@PH */
    7866  if (HIWORD(res) == NULL) {
    79         dprintf(("LoadResource %x: invalid hRes %x", hModule, hRes));
    80         return 0;
     67   dprintf(("LoadResource %x: invalid hRes %x", hModule, hRes));
     68   return 0;
    8169  }
    8270  else  return (HGLOBAL)res->lockResource();
     
    9684}
    9785//******************************************************************************
    98 //******************************************************************************
    99 BOOL WIN32API EnumResourceNamesA(HINSTANCE hModule, LPCTSTR lpszType,
    100                     ENUMRESNAMEPROCA lpEnumFunc, LONG lParam)
     86
     87
     88
     89/**
     90 * The EnumResourceNames function searches a module for each
     91 * resource of the specified type and passes the name of each
     92 * resource it locates to an application-defined callback function
     93 *
     94 * @returns  If the function succeeds, the return value is nonzero.
     95 *           If the function fails, the return value is zero
     96 * @param    hModule       resource-module handling
     97 * @param    lpszType      pointer to resource type
     98 * @param    lpEnumFunc    pointer to callback function
     99 * @param    lParam        application-defined parameter
     100 * @status   stub
     101 * @author   knut st. osmundsen
     102 * @remark   The EnumResourceNames function continues to enumerate resource
     103 *           names until the callback function returns FALSE or all resource
     104 *           names have been enumerated
     105 */
     106BOOL WIN32API EnumResourceNamesA(HINSTANCE        hModule,
     107                                 LPCTSTR          lpszType,
     108                                 ENUMRESNAMEPROCA lpEnumFunc,
     109                                 LONG             lParam)
    101110{
    102     dprintf(("OS2EnumResourceNamesA - stub\n"));
    103     return(FALSE);
     111    Win32ImageBase *pModule;
     112
     113    dprintf(("KERNEL32:EnumResourceNamesA(%08x,%08x,%08x,%08x) not implemented\n",
     114              hModule, lpszType, lpEnumFunc, lParam
     115             ));
     116
     117    pModule = Win32ImageBase::findModule(hModule);
     118    if (pModule == NULL)
     119    {
     120        SetLastError(ERROR_RESOURCE_DATA_NOT_FOUND);
     121        return FALSE;
     122    }
     123
     124    return pModule->enumResourceNamesA(hModule, lpszType, lpEnumFunc, lParam);
    104125}
    105 //******************************************************************************
    106 //******************************************************************************
     126
     127
     128/**
     129 * The EnumResourceNames function searches a module for each
     130 * resource of the specified type and passes the name of each
     131 * resource it locates to an application-defined callback function
     132 *
     133 * @returns  If the function succeeds, the return value is nonzero.
     134 *           If the function fails, the return value is zero
     135 * @param    hModule       resource-module handling
     136 * @param    lpszType      pointer to resource type
     137 * @param    lpEnumFunc    pointer to callback function
     138 * @param    lParam        application-defined parameter
     139 * @status   stub
     140 * @author   knut st. osmundsen
     141 * @remark   The EnumResourceNames function continues to enumerate resource
     142 *           names until the callback function returns FALSE or all resource
     143 *           names have been enumerated
     144 */
     145BOOL WIN32API EnumResourceNamesW(HMODULE          hModule,
     146                                 LPCWSTR          lpszType,
     147                                 ENUMRESNAMEPROCW lpEnumFunc,
     148                                 LONG             lParam)
     149{
     150    Win32ImageBase *pModule;
     151
     152    dprintf(("KERNEL32:EnumResourceNamesW(%08x,%08x,%08x,%08x)\n",
     153              hModule, lpszType, lpEnumFunc, lParam));
     154
     155    pModule = Win32ImageBase::findModule(hModule);
     156    if (pModule == NULL)
     157    {
     158        SetLastError(ERROR_RESOURCE_DATA_NOT_FOUND);
     159        return FALSE;
     160    }
     161
     162    return pModule->enumResourceNamesW(hModule, lpszType, lpEnumFunc, lParam);
     163}
     164
  • TabularUnified tags/trunk/src/kernel32/stubs.cpp

    r11223 r12458  
    1 /* $Id: stubs.cpp,v 1.7 1999-08-21 16:29:28 sandervl Exp $ */
     1/* $Id: stubs.cpp,v 1.8 1999-11-29 00:04:05 bird Exp $ */
    22
    33/*
     
    15181518
    15191519
    1520 /*****************************************************************************
    1521  * Name      : BOOL WIN32API EnumResourceNamesW
    1522  * Purpose   : The EnumResourceNames function searches a module for each
    1523  *             resource of the specified type and passes the name of each
    1524  *             resource it locates to an application-defined callback function
    1525  * Parameters: HINSTANCE hModule             resource-module handling
    1526  *             LPCTSTR lpszType              pointer to resource type
    1527  *             ENUMRESNAMEPROC lpEnumFunc    pointer to callback function
    1528  *             LONG lParam                   application-defined parameter
    1529  * Variables :
    1530  * Result    : If the function succeeds, the return value is nonzero.
    1531  *             If the function fails, the return value is zero
    1532  * Remark    : The EnumResourceNames function continues to enumerate resource
    1533  *             names until the callback function returns FALSE or all resource
    1534  *             names have been enumerated
    1535  * Status    : UNTESTED STUB
    1536  *
    1537  * Author    : Markus Montkowski [Tha, 1998/05/21 17:46]
    1538  *****************************************************************************/
    1539 
    1540 BOOL WIN32API EnumResourceNamesW(HMODULE          hModule,
    1541                                  LPCWSTR          lpszType,
    1542                                  ENUMRESNAMEPROCW lpEnumFunc,
    1543                                  LONG             lParam)
    1544 {
    1545 
    1546   dprintf(("KERNEL32:EnumResourceNamesW(%08x,%08x,%08x,%08x) not implemented\n",
    1547            hModule,
    1548            lpszType,
    1549            lpEnumFunc,
    1550            lParam
    1551           ));
    1552 
    1553   return (FALSE);
    1554 }
    15551520
    15561521/*****************************************************************************
  • TabularUnified tags/trunk/src/kernel32/winimagebase.cpp

    r12249 r12458  
    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
  • TabularUnified tags/trunk/src/kernel32/winimagelx.cpp

    r12430 r12458  
    1 /* $Id: winimagelx.cpp,v 1.4 1999-11-26 00:05:19 sandervl Exp $ */
     1/* $Id: winimagelx.cpp,v 1.5 1999-11-29 00:04:06 bird Exp $ */
    22
    33/*
     
    4040//******************************************************************************
    4141//******************************************************************************
    42 Win32LxImage::Win32LxImage(HINSTANCE hInstance, PVOID pResData) 
     42Win32LxImage::Win32LxImage(HINSTANCE hInstance, PVOID pResData)
    4343               : Win32ImageBase(hInstance)
    4444{
     
    5656  pResDir = (PIMAGE_RESOURCE_DIRECTORY)pResData;
    5757
    58   //pResourceSectionStart contains the virtual address of the imagebase in the PE header
     58  //ulRVAResourceSection contains the virtual address of the imagebase in the PE header
    5959  //for the resource section (images loaded by the pe.exe)
    6060  //For LX images, this is 0 as OffsetToData contains a relative offset
    61   pResourceSectionStart = 0;
     61  ulRVAResourceSection = 0;
    6262}
    6363//******************************************************************************
     
    7474
    7575  rc = DosQueryProcAddr(hinstance, 0, name, (PFN *)&apiaddr);
    76   if(rc) 
     76  if(rc)
    7777  {
    78         if(rc == ERROR_INVALID_HANDLE) 
     78        if(rc == ERROR_INVALID_HANDLE)
    7979        {//handle invalid for some silly reason, so load module again (initterm entrypoint not called twice)
    8080                char szErrName[CCHMAXPATH];
     
    9797  rc = DosQueryProcAddr(hinstance, ordinal, NULL, (PFN *)&apiaddr);
    9898  if(rc) {
    99         if(rc == ERROR_INVALID_HANDLE)
    100         {//handle invalid for some silly reason, so load module again (initterm entrypoint not called twice)
     99        if(rc == ERROR_INVALID_HANDLE)
     100        {//SvL(?): handle invalid for some silly reason, so load module again (initterm entrypoint not called twice)
     101         //KSO: AFAIK you'll have to load the module calling DosLoadModule to use it's handle in API calls.
     102         //     CPREF->DosGetResource->hmod: ... A value other than zero is a module handle that was returned by DosLoadModule.
     103         //     You may consider adding a DosLoadModule call during RegisterLxDll or somewhere.
    101104                char szErrName[CCHMAXPATH];
    102105
  • TabularUnified tags/trunk/src/kernel32/winimagepe2lx.cpp

    r12430 r12458  
    1 /* $Id: winimagepe2lx.cpp,v 1.6 1999-11-26 00:05:19 sandervl Exp $ */
     1/* $Id: winimagepe2lx.cpp,v 1.7 1999-11-29 00:04:06 bird Exp $ */
    22
    33/*
     
    1616#define INCL_DOSERRORS          /* DOS Error values */
    1717#define INCL_DOSPROFILE         /* DosQuerySysState (Toolkit 4.5) */
    18 #define INCL_DOSMODULEMGR   /* DOS Module management */
     18#define INCL_DOSMODULEMGR       /* DOS Module management */
    1919
    2020#define ALIGN(a, alignment) (((a) + (alignment - 1UL)) & ~(alignment - 1UL))
     
    152152 *            Read the PE section table the set the RVAs in paSections.
    153153 *            Locate and set the entrypoint.
    154  *            Locate the resource directory (if any). (pResDir, pResourceSectionStart)
     154 *            Locate the resource directory (if any). (pResDir, ulRVAResourceSection)
    155155 *            TLS - FIXME!
    156156 * @status    completely implemented.
     
    236236        && pNtHdrs->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_RESOURCE].VirtualAddress > 0UL)
    237237    {
    238         pResourceSectionStart = pNtHdrs->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_RESOURCE].VirtualAddress;
    239         pResDir = (PIMAGE_RESOURCE_DIRECTORY)getPointerFromRVA(pResourceSectionStart);
     238        ulRVAResourceSection = pNtHdrs->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_RESOURCE].VirtualAddress;
     239        pResDir = (PIMAGE_RESOURCE_DIRECTORY)getPointerFromRVA(ulRVAResourceSection);
    240240    }
    241241
  • TabularUnified tags/trunk/src/kernel32/winimagepeldr.cpp

    r12439 r12458  
    1 /* $Id: winimagepeldr.cpp,v 1.18 1999-11-27 00:05:39 sandervl Exp $ */
     1/* $Id: winimagepeldr.cpp,v 1.19 1999-11-29 00:04:06 bird Exp $ */
    22
    33/*
     
    279279  nSections = NR_SECTIONS(win32file);
    280280
    281   if(loadType == REAL_LOAD) 
     281  if(loadType == REAL_LOAD)
    282282  {
    283283   imageSize = 0;
     
    389389  }
    390390  else {
    391         if(GetSectionHdrByName (win32file, &sh, ".rsrc")) 
     391        if(GetSectionHdrByName (win32file, &sh, ".rsrc"))
    392392        {
    393393            addSection(SECTION_RESOURCE, sh.PointerToRawData,
     
    407407        imageSize = imageVirtEnd - oh.ImageBase;
    408408  }
    409   if(imageSize < oh.SizeOfImage) { 
     409  if(imageSize < oh.SizeOfImage) {
    410410        imageSize = oh.SizeOfImage;
    411411  }
     
    416416  }
    417417  else {
    418         fout << "EntryPoint == NULL" << endl; 
     418        fout << "EntryPoint == NULL" << endl;
    419419        entryPoint = NULL;
    420420  }
     
    426426  }
    427427
    428   if(loadType == REAL_LOAD) 
     428  if(loadType == REAL_LOAD)
    429429  {
    430430   if(tlsDir != NULL) {
     
    485485        //get offset in resource object of directory entry
    486486        pResDir = (PIMAGE_RESOURCE_DIRECTORY)(sh.VirtualAddress + realBaseAddress);
    487         pResourceSectionStart = sh.VirtualAddress;
    488   }
    489 
    490   if (loadType == REAL_LOAD) 
     487        ulRVAResourceSection = sh.VirtualAddress;
     488  }
     489
     490  if (loadType == REAL_LOAD)
    491491  {
    492492   if(processImports((char *)win32file) == FALSE) {
     
    495495   }
    496496  }
    497  
     497
    498498  return(TRUE);
    499499failure:
     
    543543                fileoffset = section->rawoffset + section->rawsize + offset;
    544544        }
    545   } 
     545  }
    546546  else {
    547547        protflags   = section->pageflags;
     
    552552                size = 0;
    553553                fileoffset = -1;
    554         } 
     554        }
    555555        else {
    556556                size = section->rawsize-offset;
     
    709709        }
    710710  }
    711   if(index == -1) 
     711  if(index == -1)
    712712        return NULL;
    713713
     
    804804
    805805  for(i=0;i<nrsections;i++) {
    806         switch(section[i].type) 
     806        switch(section[i].type)
    807807        {
    808808        case SECTION_CODE:
     
    855855                        int fixupsize = 0;
    856856
    857                         switch(type) 
     857                        switch(type)
    858858                        {
    859859                        case IMAGE_REL_BASED_HIGHLOW:
     
    864864                                fixupsize = 2;
    865865                                break;
    866                         }                       
    867                         //If the fixup crosses the final page boundary, 
    868                         //then we have to load another page 
    869                         if(prel->VirtualAddress + offset + fixupsize > virtAddress + size) 
     866                        }
     867                        //If the fixup crosses the final page boundary,
     868                        //then we have to load another page
     869                        if(prel->VirtualAddress + offset + fixupsize > virtAddress + size)
    870870                        {
    871871                                newpage  = realBaseAddress + prel->VirtualAddress + offset + fixupsize;
     
    877877                                        dprintf(("::setFixups -> section == NULL!!"));
    878878                                        return FALSE;
    879                                 }               
     879                                }
    880880                                //SvL: Read page from disk
    881881                                commitPage(newpage, TRUE, SINGLE_PAGE);
     
    885885                        }
    886886
    887                         switch(type) 
     887                        switch(type)
    888888                        {
    889889                        case IMAGE_REL_BASED_ABSOLUTE:
     
    903903                                break;
    904904                        }
    905                         if(prel->VirtualAddress + offset + fixupsize > virtAddress + size) 
     905                        if(prel->VirtualAddress + offset + fixupsize > virtAddress + size)
    906906                        {
    907907                                //SvL: Restore original page protection flags
     
    13081308    {  //not found, so load it
    13091309        char modname[CCHMAXPATH];
    1310        
     1310
    13111311        strcpy(modname, pszCurModule);
    13121312        //rename dll if necessary (i.e. OLE32 -> OLE32OS2)
     
    14411441  NameExport *curexport;
    14421442  ULONG       ulAPIOrdinal;                      /* api requested by ordinal */
    1443  
     1443
    14441444  apilen = strlen(name) + 1;
    1445   if(apilen < 4) 
     1445  if(apilen < 4)
    14461446  {
    14471447        *(ULONG *)tmp = 0;
     
    14521452
    14531453  curexport = nameexports;
    1454   for(i=0; i<nrNameExports; i++) 
     1454  for(i=0; i<nrNameExports; i++)
    14551455  {
    1456     if(apilen == curexport->nlength && 
    1457        *(ULONG *)curexport->name == *(ULONG *)name) 
     1456    if(apilen == curexport->nlength &&
     1457       *(ULONG *)curexport->name == *(ULONG *)name)
    14581458    {
    1459         if(strcmp(curexport->name, name) == 0) 
     1459        if(strcmp(curexport->name, name) == 0)
    14601460                return(curexport->virtaddr);
    14611461    }
     
    14781478        curexport++;
    14791479  }
    1480   //Name exports also contain an ordinal, so check this 
     1480  //Name exports also contain an ordinal, so check this
    14811481  nexport = nameexports;
    14821482  for(i=0;i<nrNameExports;i++) {
  • TabularUnified tags/trunk/src/kernel32/winimgres.cpp

    r12201 r12458  
    1 /* $Id: winimgres.cpp,v 1.26 1999-11-05 12:54:50 sandervl Exp $ */
     1/* $Id: winimgres.cpp,v 1.27 1999-11-29 00:04:07 bird Exp $ */
    22
    33/*
     
    2222#include <misc.h>
    2323#include <winimagebase.h>
    24 #include <winimagepe2lx.h>
    25 #include <winimagepeldr.h>
    26 #include <winimagelx.h>
    2724#include <winres.h>
    2825#include <unicode.h>
     
    270267        return 0;
    271268    }
    272     //pResourceSectionStart contains the virtual address of the imagebase in the PE header
    273     //for the resource section (images loaded by the pe.exe)
     269    //ulRVAResourceSection contains the relative virtual address (relative to the start of the image)
     270    //for the resource section (images loaded by the pe.exe and pe2lx/win32k)
    274271    //For LX images, this is 0 as OffsetToData contains a relative offset
    275     char *resdata = (char *)((char *)pResDir + pData->OffsetToData - pResourceSectionStart);
     272    char *resdata = (char *)((char *)pResDir + pData->OffsetToData - ulRVAResourceSection);
    276273    res = new Win32Resource(this, id, type, pData->Size, resdata);
    277274
     
    385382        return 0;
    386383    }
    387     char *resdata = (char *)((char *)pResDir + pData->OffsetToData - pResourceSectionStart);
     384    char *resdata = (char *)((char *)pResDir + pData->OffsetToData - ulRVAResourceSection);
    388385    memcpy(verstruct, resdata, min(bufLength, pData->Size));
    389386    return TRUE;
    390387}
    391 //******************************************************************************
    392 //******************************************************************************
     388
     389
     390/**
     391 * The EnumResourceNames function searches a module for each
     392 * resource of the specified type and passes the name of each
     393 * resource it locates to an application-defined callback function
     394 *
     395 * @returns   If the function succeeds, the return value is nonzero.
     396 *            If the function fails, the return value is zero
     397 * @param     hmod          The specified module handle.
     398 * @param     lpszType      pointer to resource type
     399 * @param     lpEnumFunc    pointer to callback function
     400 * @param     lParam        application-defined parameter
     401 * @sketch    IF not resources in module THEN return fail.
     402 *            Validate parameters.
     403 *            Get the subdirectory for the specified type.
     404 *            IF found THEN
     405 *            BEGIN
     406 *                Find the number of directory entries.
     407 *                Find directory entries.
     408 *                LOOP thru all entries while the callback function returns true
     409 *                BEGIN
     410 *                    Name = pointer to ASCII name string or Id.
     411 *                    call callback function.
     412 *                END
     413 *            END
     414 *            ELSE
     415 *                fail.
     416 *            return
     417 * @status    completely implemented and tested.
     418 * @author    knut st. osmundsen
     419 * @remark    The EnumResourceNames function continues to enumerate resource
     420 *            names until the callback function returns FALSE or all resource
     421 *            names have been enumerated
     422 */
     423BOOL Win32ImageBase::enumResourceNamesA(HMODULE hmod,
     424                                        LPCTSTR  lpszType,
     425                                        ENUMRESNAMEPROCA lpEnumFunc,
     426                                        LONG lParam)
     427{
     428    BOOL                            fRet;
     429    PIMAGE_RESOURCE_DIRECTORY       pResDirOurType;
     430    PIMAGE_RESOURCE_DIRECTORY_ENTRY paResDirEntries;
     431
     432    if (pResDir == NULL)
     433    {
     434        /* SetLastError(?);? */
     435        return FALSE;
     436    }
     437
     438    /* validate parameters - FIXME... Exception handler??? */
     439    if ((unsigned)lpszType >= 0xc0000000) //....
     440    {
     441        SetLastError(ERROR_INVALID_PARAMETER);
     442        return FALSE;
     443    }
     444
     445    if ((unsigned)lpEnumFunc < 0x10000 || (unsigned)lpEnumFunc >= 0xc0000000)
     446    {
     447        SetLastError(ERROR_NOACCESS);
     448        return FALSE;
     449    }
     450
     451    //reminder:
     452    //1st level -> types
     453    //2nd level -> names
     454    //3rd level -> language
     455
     456    pResDirOurType = getResSubDirA(pResDir, lpszType);
     457    if (pResDirOurType != NULL)
     458    {
     459        char     *pszASCII = NULL;
     460        unsigned  cch = 0;
     461        unsigned  cResEntries;
     462        unsigned  i;
     463
     464        fRet = TRUE;
     465        cResEntries = pResDirOurType->NumberOfNamedEntries + pResDirOurType->NumberOfIdEntries;
     466        paResDirEntries = (PIMAGE_RESOURCE_DIRECTORY_ENTRY)((unsigned)pResDirOurType + sizeof(*pResDirOurType));
     467        for (i = 0; i < cResEntries && fRet; i++)
     468        {
     469            LPSTR lpszName;
     470
     471            if (paResDirEntries[i].u1.s.NameIsString)
     472            {
     473                PIMAGE_RESOURCE_DIR_STRING_U pResDirString =
     474                    (PIMAGE_RESOURCE_DIR_STRING_U)(paResDirEntries[i].u1.s.NameOffset + (unsigned)pResDir);
     475
     476                /* ASCII buffer allocation/adjustment? */
     477                if (cch <= pResDirString->Length)
     478                {
     479                    void *pszTmp;
     480                    cch = max(pResDirString->Length + 1, 32);
     481                    pszTmp = pszASCII != NULL ? realloc(pszASCII, cch) : malloc(cch);
     482                    if (pszTmp == NULL)
     483                    {
     484                        fRet = FALSE;
     485                        break;
     486                    }
     487                    pszASCII = (char*)pszTmp;
     488                }
     489                UnicodeToAsciiN(pResDirString->NameString, pszASCII, pResDirString->Length);
     490                lpszName = pszASCII;
     491            }
     492            else
     493                lpszName = (LPSTR)paResDirEntries[i].u1.Id;
     494
     495            fRet = lpEnumFunc(hmod, lpszType, lpszName, lParam);
     496        }
     497
     498        if (pszASCII != NULL)
     499            free(pszASCII);
     500    }
     501    else
     502    {
     503        SetLastError(ERROR_RESOURCE_TYPE_NOT_FOUND);
     504        fRet = FALSE;
     505    }
     506
     507    return fRet > 0 ? TRUE : FALSE;
     508}
     509
     510
     511/**
     512 * The EnumResourceNames function searches a module for each
     513 * resource of the specified type and passes the name of each
     514 * resource it locates to an application-defined callback function
     515 *
     516 * @returns   If the function succeeds, the return value is nonzero.
     517 *            If the function fails, the return value is zero
     518 * @param     hmod          The specified module handle.
     519 * @param     lpszType      pointer to resource type
     520 * @param     lpEnumFunc    pointer to callback function
     521 * @param     lParam        application-defined parameter
     522 * @sketch    IF not resources in module THEN return fail.
     523 *            Validate parameters.
     524 *            Get the subdirectory for the specified type.
     525 *            IF found THEN
     526 *            BEGIN
     527 *                Find the number of directory entries.
     528 *                Find directory entries.
     529 *                LOOP thru all entries while the callback function returns true
     530 *                BEGIN
     531 *                    Name = pointer to ASCII name string or Id.
     532 *                    call callback function.
     533 *                END
     534 *            END
     535 *            ELSE
     536 *                fail.
     537 *            return
     538 * @status    completely implemented and tested.
     539 * @author    knut st. osmundsen
     540 * @remark    The EnumResourceNames function continues to enumerate resource
     541 *            names until the callback function returns FALSE or all resource
     542 *            names have been enumerated
     543 */
     544BOOL Win32ImageBase::enumResourceNamesW(HMODULE hmod,
     545                                        LPCWSTR  lpszType,
     546                                        ENUMRESNAMEPROCW lpEnumFunc,
     547                                        LONG lParam)
     548{
     549    BOOL                            fRet;
     550    PIMAGE_RESOURCE_DIRECTORY       pResDirOurType;
     551    PIMAGE_RESOURCE_DIRECTORY_ENTRY paResDirEntries;
     552
     553    if (pResDir == NULL)
     554    {
     555        SetLastError(ERROR_RESOURCE_DATA_NOT_FOUND);
     556        return FALSE;
     557    }
     558
     559    /* validate parameters - FIXME... Exception handler??? */
     560    if ((unsigned)lpszType >= 0xc0000000) //....
     561    {
     562        SetLastError(ERROR_INVALID_PARAMETER);
     563        return FALSE;
     564    }
     565
     566    if ((unsigned)lpEnumFunc < 0x10000 || (unsigned)lpEnumFunc >= 0xc0000000)
     567    {
     568        SetLastError(ERROR_NOACCESS);
     569        return FALSE;
     570    }
     571
     572
     573    //reminder:
     574    //1st level -> types
     575    //2nd level -> names
     576    //3rd level -> language
     577
     578    pResDirOurType = getResSubDirW(pResDir, lpszType);
     579    if (pResDirOurType != NULL)
     580    {
     581        unsigned  cResEntries;
     582        unsigned  i;
     583
     584        fRet = TRUE;
     585        cResEntries = pResDirOurType->NumberOfNamedEntries + pResDirOurType->NumberOfIdEntries;
     586        paResDirEntries = (PIMAGE_RESOURCE_DIRECTORY_ENTRY)((unsigned)pResDirOurType + sizeof(*pResDirOurType));
     587        for (i = 0; i < cResEntries && fRet; i++)
     588        {
     589            LPWSTR lpszName;
     590
     591            if (paResDirEntries[i].u1.s.NameIsString)
     592                lpszName = (LPWSTR)(paResDirEntries[i].u1.s.NameOffset + (unsigned)pResDir + 2);
     593            else
     594                lpszName = (LPWSTR)paResDirEntries[i].u1.Id;
     595
     596            fRet = lpEnumFunc(hmod, lpszType, lpszName, lParam);
     597        }
     598    }
     599    else
     600    {
     601        SetLastError(ERROR_RESOURCE_TYPE_NOT_FOUND);
     602        fRet = FALSE;
     603    }
     604
     605    return fRet > 0;
     606}
     607
     608
     609
     610/**
     611 * This function finds a resource (sub)directory within a given resource directory.
     612 * @returns   Pointer to resource directory. NULL if not found or not a directory.
     613 * @param     pResDirToSearch  Pointer to resource directory to search. (any level)
     614 * @param     lpszName         Resource ID string.
     615 * @sketch
     616 * @status    completely implemented
     617 * @author    knut st. osmundsen
     618 */
     619PIMAGE_RESOURCE_DIRECTORY Win32ImageBase::getResSubDirW(PIMAGE_RESOURCE_DIRECTORY pResDirToSearch, LPCWSTR lpszName)
     620{
     621    PIMAGE_RESOURCE_DIRECTORY_ENTRY paResDirEntries;
     622    int     i;
     623    int     idName = -1;
     624
     625    /* lpszName */
     626    if (HIWORD(lpszName) != 0)
     627    {
     628        if (lpszName[0] == '#')
     629        {
     630            char szBuf[10];
     631            lstrcpynWtoA(szBuf, (WCHAR*)(lpszName + 1), sizeof(szBuf));
     632            idName = atoi(szBuf);
     633        }
     634    }
     635    else
     636        idName = (int)lpszName;
     637
     638    paResDirEntries = (PIMAGE_RESOURCE_DIRECTORY_ENTRY)((unsigned)pResDirToSearch + sizeof(*pResDirToSearch));
     639    if (idName != -1)
     640    {   /* idName */
     641        paResDirEntries += pResDirToSearch->NumberOfNamedEntries;
     642
     643        for (i = 0; i < pResDirToSearch->NumberOfIdEntries; i++)
     644            if (paResDirEntries[i].u1.Id == (WORD)idName)
     645                return paResDirEntries[i].u2.s.DataIsDirectory ?
     646                    (PIMAGE_RESOURCE_DIRECTORY) (paResDirEntries[i].u2.s.OffsetToDirectory + (unsigned)pResDir /*?*/
     647                                                 /*- ulRVAResourceSection*/)
     648                    : NULL;
     649    }
     650    else
     651    {   /* string name */
     652        int cusName = lstrlenW(lpszName);
     653
     654        for (i = 0; i < pResDirToSearch->NumberOfNamedEntries; i++)
     655        {
     656            PIMAGE_RESOURCE_DIR_STRING_U pResDirStr =
     657                (PIMAGE_RESOURCE_DIR_STRING_U)(paResDirEntries[i].u1.s.NameOffset + (unsigned)pResDir /*?*/);
     658
     659            if (pResDirStr->Length == cusName
     660                && UniStrncmp(pResDirStr->NameString, lpszName, cusName) == 0)
     661            {
     662                return paResDirEntries[i].u2.s.DataIsDirectory ?
     663                    (PIMAGE_RESOURCE_DIRECTORY) (paResDirEntries[i].u2.s.OffsetToDirectory + (unsigned)pResDir
     664                                                 /*- ulRVAResourceSection*/)
     665                    : NULL;
     666            }
     667        }
     668    }
     669
     670    return NULL;
     671}
     672
     673/**
     674 * This function finds a resource (sub)directory within a given resource directory.
     675 * @returns   Pointer to resource directory. NULL if not found or not a directory.
     676 * @param     pResDirToSearch  Pointer to resource directory to search. (any level)
     677 * @param     lpszName         Resource ID string.
     678 * @sketch
     679 * @status    completely implemented
     680 * @author    knut st. osmundsen
     681 */
     682PIMAGE_RESOURCE_DIRECTORY Win32ImageBase::getResSubDirA(PIMAGE_RESOURCE_DIRECTORY pResDirToSearch, LPCTSTR lpszName)
     683{
     684    PIMAGE_RESOURCE_DIRECTORY   pResDirRet;
     685    LPCWSTR                     lpszwName;
     686
     687    /* lpszName */
     688    if (HIWORD(lpszName) != 0)
     689    {
     690        lpszwName = AsciiToUnicodeString((char*)lpszName);
     691        if (lpszwName == NULL)
     692            return NULL;
     693    }
     694    else
     695        lpszwName = (LPWSTR)lpszName;
     696
     697    pResDirRet = getResSubDirW(pResDirToSearch, lpszwName);
     698
     699    if (HIWORD(lpszwName) != 0)
     700        free((void*)lpszwName);
     701
     702    return pResDirRet;
     703}
     704
Note: See TracChangeset for help on using the changeset viewer.