Ignore:
Timestamp:
Sep 16, 1999, 1:39:08 AM (26 years ago)
Author:
sandervl
Message:

Rewrite for new win32 image classes

File:
1 edited

Legend:

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

    r752 r956  
    1 /* $Id: winimgres.cpp,v 1.13 1999-08-31 14:36:46 sandervl Exp $ */
     1/* $Id: winimgres.cpp,v 1.14 1999-09-15 23:38:02 sandervl Exp $ */
    22
    33/*
     
    1010 *
    1111 * TODO: Check created resource objects before loading the resource!
     12 * TODO: Is the name id of the version resource always 1?
     13 * TODO: Once the resource handling in PE2LX/win32k is changed,
     14 *       getVersionStruct/Size can be moved into the Win32ImageBase class
    1215 *
    1316 */
     
    1821
    1922#include <misc.h>
    20 #include <nameid.h>
    21 #include <winimage.h>
    22 #include <windll.h>
    23 #include <winexe.h>
     23#include <winimagebase.h>
     24#include <winimagepe2lx.h>
     25#include <winimagepeldr.h>
     26#include <winimagelx.h>
    2427#include <winres.h>
    2528#include <winresmenu.h>
     
    2730#include <heapstring.h>
    2831#include "pefile.h"
    29 
    30 char *ResTypes[MAX_RES] =
    31       {"niks", "CURSOR", "BITMAP", "ICON", "MENU", "DIALOG", "STRING",
    32        "FONTDIR", "FONT", "ACCELERATOR", "RCDATA",  "MESSAGETABLE",
    33        "GROUP_CURSOR", "niks", "GROUP_ICON", "niks", "VERSION"};
    34 
     32#include "oslibmisc.h"
    3533
    3634//******************************************************************************
     
    3937//******************************************************************************
    4038PIMAGE_RESOURCE_DATA_ENTRY
    41  Win32Image::getPEResourceEntry(ULONG id, ULONG type, ULONG lang)
     39 Win32PeLdrImage::getPEResourceEntry(ULONG id, ULONG type, ULONG lang)
    4240{
    4341 PIMAGE_RESOURCE_DIRECTORY       prdType;
     
    126124//******************************************************************************
    127125PIMAGE_RESOURCE_DATA_ENTRY
    128     Win32Image::ProcessResSubDir(PIMAGE_RESOURCE_DIRECTORY prdType,
     126    Win32PeLdrImage::ProcessResSubDir(PIMAGE_RESOURCE_DIRECTORY prdType,
    129127                                 ULONG *nodeData, int level)
    130128{
     
    203201//******************************************************************************
    204202//******************************************************************************
    205 ULONG Win32Image::getPEResourceSize(ULONG id, ULONG type, ULONG lang)
     203ULONG Win32PeLdrImage::getPEResourceSize(ULONG id, ULONG type, ULONG lang)
    206204{
    207205 PIMAGE_RESOURCE_DATA_ENTRY      pData = NULL;
     
    209207  pData = getPEResourceEntry(id, type, lang);
    210208  if(pData == NULL) {
    211         dprintf(("Win32Image::getPEResourceSize: couldn't find resource %d (type %d, lang %d)", id, type, lang));
     209        dprintf(("Win32ImageBase::getPEResourceSize: couldn't find resource %d (type %d, lang %d)", id, type, lang));
    212210        return 0;
    213211  }
     
    216214//******************************************************************************
    217215//******************************************************************************
    218 Win32Resource *Win32Image::getPEResource(ULONG id, ULONG type, ULONG lang)
     216HRSRC Win32PeLdrImage::findResourceA(LPCSTR lpszName, LPSTR lpszType, ULONG lang)
    219217{
    220218 PIMAGE_RESOURCE_DATA_ENTRY      pData = NULL;
     
    222220 BOOL   fNumType;
    223221 char  *winres = NULL;
     222 ULONG  id, type;
    224223 int    i, stringid = -1, j;
    225224
    226225  fNumType = TRUE;    //assume numeric
    227   if(HIWORD(type) != 0) {//string id?
    228     for(i=0;i<MAX_RES;i++) {
    229          if(stricmp((char *)type, ResTypes[i]) == 0)
    230                 break;
    231     }
    232     if(i == MAX_RES) {//custom resource type
    233          fNumType = FALSE;
    234     }
    235     else type   = i;
    236   }
     226  if(HIWORD(lpszType) != 0) {//string id?
     227        for(i=0;i<MAX_RES;i++) {
     228                if(stricmp(lpszType, ResTypes[i]) == 0)
     229                        break;
     230        }
     231        if(i == MAX_RES) {//custom resource type
     232                fNumType = FALSE;
     233                type = (ULONG)lpszType;
     234        }
     235        else    type = i;
     236  }
     237  else  type = (ULONG)lpszType;
    237238
    238239  //String format: tables of 16 strings stored as one resource
     
    241242  if(fNumType) {
    242243    if(type == NTRT_STRING) {
    243         stringid = id & 0xF;
    244         id       = (id >> 4)+1;
    245     }
     244         stringid = (ULONG)lpszName & 0xF;
     245         id       = (((ULONG)lpszName) >> 4)+1;
     246    }
     247    else id = (ULONG)lpszName;
    246248  }
    247249  else {
    248250    if(stricmp((char *)type, ResTypes[NTRT_STRING]) == 0) {
    249         stringid = id & 0xF;
    250         id       = (id >> 4)+1;
    251     }
     251         stringid = (ULONG)lpszName & 0xF;
     252         id       = (((ULONG)lpszName) >> 4)+1;
     253    }
     254    else id = (ULONG)lpszName;
    252255  }
    253256
     
    255258  if(pData == NULL) {
    256259        if(HIWORD(id)) {
    257                 dprintf(("Win32Image::getPEResource: couldn't find resource %s (type %d, lang %d)", id, type, lang));
     260                dprintf(("Win32ImageBase::getPEResource: couldn't find resource %s (type %d, lang %d)", id, type, lang));
    258261        }
    259         else    dprintf(("Win32Image::getPEResource: couldn't find resource %d (type %d, lang %d)", id, type, lang));
     262        else    dprintf(("Win32ImageBase::getPEResource: couldn't find resource %d (type %d, lang %d)", id, type, lang));
    260263        return 0;
    261264  }
     
    287290  }
    288291
    289   return res;
    290 }
    291 //******************************************************************************
    292 //******************************************************************************
    293 HRSRC Win32Image::findResourceA(LPCSTR lpszName, LPSTR lpszType)
     292  return (HRSRC) res;
     293}
     294//******************************************************************************
     295//******************************************************************************
     296HRSRC Win32Pe2LxImage::findResourceA(LPCSTR lpszName, LPSTR lpszType, ULONG lang)
    294297{
    295298 Win32Resource *res = NULL;
     
    297300 int   i;
    298301 LPSTR szType = (LPSTR)lpszType;
    299 
    300     if(fNativePEImage == TRUE) {
    301         return (HRSRC) getPEResource((ULONG)lpszName, (ULONG)lpszType);
    302     }
    303     //else converted win32 exe/dll
    304302
    305303    if(HIWORD(lpszType) != 0) {//type name, translate to id
     
    347345                lpszName = (LPCSTR)atoi(&lpszName[1]);
    348346        }
    349         else    lpszName = (LPCSTR)ConvertNameId(hinstance, (char *)lpszName);
     347        else    lpszName = (LPCSTR)convertNameId((char *)lpszName);
    350348    }
    351349    else dprintf(("FindResource %d\n", (int)lpszName));
     
    377375}
    378376//******************************************************************************
    379 //******************************************************************************
    380 HRSRC Win32Image::findResourceW(LPWSTR lpszName, LPWSTR lpszType)
    381 {
    382  Win32Resource *res = NULL;
     377//TODO:
     378//******************************************************************************
     379HRSRC Win32LxImage::findResourceA(LPCSTR lpszName, LPSTR lpszType, ULONG lang)
     380{
     381    return 0;
     382}
     383//******************************************************************************
     384//******************************************************************************
     385HRSRC Win32ImageBase::findResourceW(LPWSTR lpszName, LPWSTR lpszType, ULONG lang)
     386{
    383387 HRSRC hres;
    384  LPSTR szType = (LPSTR)lpszType;
    385  int   i;
    386388 char *astring1 = NULL, *astring2 = NULL;
    387389
    388     if(fNativePEImage == TRUE) {//load resources directly from res section
    389         if(HIWORD(lpszType) != 0) {
    390                 char *resname = UnicodeToAsciiString(lpszType);
    391         }
    392         else    astring1 = (char *)lpszType;
    393 
    394         if(HIWORD(lpszName) != 0) {
    395                 astring2 = UnicodeToAsciiString(lpszName);
    396         }
    397         else    astring2 = (char *)lpszName;
    398 
    399         hres = (HRSRC) getPEResource((ULONG)astring1, (ULONG)astring1);
    400         if(astring1) FreeAsciiString(astring1);
    401         if(astring2) FreeAsciiString(astring2);
    402 
    403         return(hres);
    404     }
    405     //else converted win32 exe/dll
    406     if(HIWORD(lpszType) != 0) {//type name, translate to id
    407         char *resname = UnicodeToAsciiString(lpszType);
    408         for(i=0;i<MAX_RES;i++) {
    409             if(strcmp(resname, ResTypes[i]) == 0)
    410                 break;
    411         }
    412         if(i == MAX_RES) {//custom resource type, stored as rcdata
    413                 dprintf(("FindResourceW custom type %s\n", resname));
    414             i = NTRT_RCDATA;
    415         }
    416         FreeAsciiString(resname);
    417         lpszType = (LPWSTR)i;
    418 
    419         szType = (LPSTR)lpszType;
    420     }
    421     switch((int)szType) {
    422     case NTRT_GROUP_ICON:
    423         szType = (LPSTR)NTRT_ICON;
    424         break;
    425     case NTRT_GROUP_CURSOR:
    426         szType = (LPSTR)NTRT_CURSOR;
    427         break;
    428     case NTRT_VERSION:
    429         szType = (LPSTR)NTRT_RCDATA;
    430         break;
    431     case NTRT_STRING:
    432     case NTRT_MENU:
    433     case NTRT_ICON:
    434     case NTRT_BITMAP:
    435     case NTRT_CURSOR:
    436     case NTRT_DIALOG:
    437     case NTRT_RCDATA:
    438     case NTRT_ACCELERATORS:
    439         szType = (LPSTR)lpszType;
    440         break;
    441     default: //unknown are stored as rcdata
    442         szType = (LPSTR)NTRT_RCDATA;
    443         break;
    444     }
    445     dprintf(("FindResourceW type %d\n", szType));
    446 
    447     if(HIWORD(lpszName) != 0) {//convert string name identifier to numeric id
    448         astring1 = UnicodeToAsciiString(lpszName);
    449         dprintf(("FindResourceW %X %s\n", hinstance, astring1));
    450         if(astring1[0] == '#') {// #344
    451                 lpszName = (LPWSTR)atoi(&astring1[1]);
    452         }
    453         else    lpszName = (LPWSTR)ConvertNameId(hinstance, (char *)astring1);
    454     }
    455     else dprintf(("FindResourceW %X %d\n", hinstance, (int)lpszName));
    456 
    457     hres = O32_FindResource(hinstance, (LPCSTR)lpszName, (LPCSTR)szType);
    458     if(hres)
    459     {
    460         switch((ULONG)szType) {
    461         case NTRT_MENU:
    462                 res = new Win32MenuRes(this, hres, (ULONG)lpszName, (ULONG)szType);
    463                 break;
    464         default:
    465                 res = new Win32Resource(this, hres, (ULONG)lpszName, (ULONG)szType);
    466                 break;
    467         }
    468     }
    469 
    470     if(hres == NULL && HIWORD(lpszName) == 0 && (int)szType == NTRT_STRING) {
    471         hres = O32_FindResource(hinstance, (LPCSTR)(((ULONG)lpszName - 1)*16), (LPCSTR)NTRT_RCDATA);
    472         if(hres)
    473         {
    474                 res = new Win32Resource(this, hres, (ULONG)lpszName, (ULONG)szType);
    475         }
    476         else    dprintf(("FindResourceW can't find string %d\n", (int)lpszName));
    477     }
    478     if(astring1)    FreeAsciiString(astring1);
    479 
    480     dprintf(("FindResourceW returned %X (%X)\n", hres, GetLastError()));
    481 
    482     return (HRSRC)res;
    483 }
    484 //******************************************************************************
    485 //******************************************************************************
    486 ULONG Win32Image::getResourceSizeA(LPCSTR lpszName, LPSTR lpszType)
    487 {
    488     if(fNativePEImage == TRUE) {
    489         return getPEResourceSize((ULONG)lpszName, (ULONG)lpszType);
    490     }
     390    if(HIWORD(lpszType) != 0) {
     391                astring1 = UnicodeToAsciiString(lpszType);
     392    }
     393    else        astring1 = (char *)lpszType;
     394
     395    if(HIWORD(lpszName) != 0) {
     396                astring2 = UnicodeToAsciiString(lpszName);
     397    }
     398    else        astring2 = (char *)lpszName;
     399
     400    hres = (HRSRC) findResourceA(astring1, astring2);
     401    if(astring1) FreeAsciiString(astring1);
     402    if(astring2) FreeAsciiString(astring2);
     403
     404    return(hres);
     405}
     406//******************************************************************************
     407//TODO:
     408//******************************************************************************
     409ULONG Win32Pe2LxImage::getResourceSizeA(LPCSTR lpszName, LPSTR lpszType, ULONG lang)
     410{
    491411    DebugInt3();
    492412    return 0;
    493413}
    494414//******************************************************************************
    495 //******************************************************************************
    496 ULONG Win32Image::getResourceSizeW(LPCWSTR lpszName, LPWSTR lpszType)
     415//TODO:
     416//******************************************************************************
     417ULONG Win32LxImage::getResourceSizeA(LPCSTR lpszName, LPSTR lpszType, ULONG lang)
     418{
     419    DebugInt3();
     420    return 0;
     421}
     422//******************************************************************************
     423//******************************************************************************
     424ULONG Win32PeLdrImage::getResourceSizeA(LPCSTR lpszName, LPSTR lpszType, ULONG lang)
     425{
     426    return getPEResourceSize((ULONG)lpszName, (ULONG)lpszType, lang);
     427}
     428//******************************************************************************
     429//******************************************************************************
     430ULONG Win32ImageBase::getResourceSizeW(LPCWSTR lpszName, LPWSTR lpszType, ULONG lang)
    497431{
    498432 char *astring1 = NULL, *astring2 = NULL;
    499433 ULONG ressize;
    500434
    501     if(fNativePEImage == TRUE) {//load resources directly from res section
    502         if(HIWORD(lpszType) != 0) {
     435    if(HIWORD(lpszType) != 0) {
    503436                char *resname = UnicodeToAsciiString(lpszType);
    504         }
    505         else    astring1 = (char *)lpszType;
    506 
    507         if(HIWORD(lpszName) != 0) {
     437    }
     438    else        astring1 = (char *)lpszType;
     439
     440    if(HIWORD(lpszName) != 0) {
    508441                astring2 = UnicodeToAsciiString((LPWSTR)lpszName);
    509         }
    510         else    astring2 = (char *)lpszName;
    511 
    512         ressize =  getPEResourceSize((ULONG)astring1, (ULONG)astring1);
    513         if(astring1) FreeAsciiString(astring1);
    514         if(astring2) FreeAsciiString(astring2);
    515 
    516         return(ressize);
    517     }
    518     DebugInt3();
    519     return 0;
    520 }
    521 //******************************************************************************
    522 //******************************************************************************
     442    }
     443    else        astring2 = (char *)lpszName;
     444
     445    ressize =  getResourceSizeA(astring1, astring2, lang);
     446    if(astring1) FreeAsciiString(astring1);
     447    if(astring2) FreeAsciiString(astring2);
     448
     449    return(ressize);
     450}
     451//******************************************************************************
     452//******************************************************************************
     453ULONG Win32Pe2LxImage::getVersionSize()
     454{
     455    if(getVersionId() == -1) {
     456        dprintf(("GetVersionSize: %s has no version resource!\n", szModule));
     457        return(0);
     458    }
     459    return OSLibGetResourceSize(hinstance, getVersionId());
     460}
     461//******************************************************************************
     462//******************************************************************************
     463BOOL Win32Pe2LxImage::getVersionStruct(char *verstruct, ULONG bufLength)
     464{
     465    if(getVersionId() == -1) {
     466        dprintf(("GetVersionStruct: %s has no version resource!\n", szModule));
     467        return(FALSE);
     468    }
     469    return OSLibGetResource(hinstance, getVersionId(), verstruct, bufLength);
     470}
     471//******************************************************************************
     472//******************************************************************************
     473ULONG Win32PeLdrImage::getVersionSize()
     474{
     475    return getResourceSizeA((LPCSTR)1, (LPSTR)NTRT_VERSION);
     476}
     477//******************************************************************************
     478//******************************************************************************
     479BOOL Win32PeLdrImage::getVersionStruct(char *verstruct, ULONG bufLength)
     480{
     481 PIMAGE_RESOURCE_DATA_ENTRY      pData = NULL;
     482
     483  pData = getPEResourceEntry(1, NTRT_VERSION);
     484  if(pData == NULL) {
     485        dprintf(("Win32PeLdrImage::getVersionStruct: couldn't find version resource!"));
     486        return 0;
     487  }
     488  return pData->Size;
     489}
     490//******************************************************************************
     491//******************************************************************************
     492ULONG Win32LxImage::getVersionSize()
     493{
     494//    return getResourceSizeA((LPCSTR)1, (LPSTR)NTRT_VERSION);
     495  return 0;
     496}
     497//******************************************************************************
     498//******************************************************************************
     499BOOL Win32LxImage::getVersionStruct(char *verstruct, ULONG bufLength)
     500{
     501 PIMAGE_RESOURCE_DATA_ENTRY      pData = NULL;
     502
     503//  pData = getPEResourceEntry(1, NTRT_VERSION);
     504  if(pData == NULL) {
     505        dprintf(("Win32PeLdrImage::getVersionStruct: couldn't find version resource!"));
     506        return 0;
     507  }
     508  return pData->Size;
     509}
     510//******************************************************************************
     511//******************************************************************************
Note: See TracChangeset for help on using the changeset viewer.