Changeset 589 for trunk/src


Ignore:
Timestamp:
Aug 19, 1999, 9:51:18 PM (26 years ago)
Author:
sandervl
Message:

More PE resource changes

Location:
trunk/src/kernel32
Files:
3 added
6 edited

Legend:

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

    r581 r589  
    1 /* $Id: cvticon.cpp,v 1.1 1999-08-19 14:19:14 sandervl Exp $ */
     1/* $Id: cvticon.cpp,v 1.2 1999-08-19 19:50:40 sandervl Exp $ */
    22
    33/*
     
    2727
    2828//******************************************************************************
     29//NOTE: offsetBits is the value added to the offBits bitmap structure members
     30//      (handy for converting icon groups)
    2931//******************************************************************************
    30 void *ConvertIcon(WINBITMAPINFOHEADER *bmpHdr, int size)
     32void *ConvertIcon(WINBITMAPINFOHEADER *bmpHdr, int size, int offsetBits)
    3133{
    3234 RGBQUAD *rgb;
     
    9294  iconhdr->yHotspot      = 0;
    9395  iconhdr->offBits       = 2*sizeof(BITMAPFILEHEADER2) +
    94                            2*sizeof(RGB2) + rgbsize;
     96                           2*sizeof(RGB2) + rgbsize + offsetBits;
    9597  iconhdr->bmp2.cbFix    = sizeof(BITMAPINFOHEADER2);
    9698  iconhdr->bmp2.cx       = (USHORT)bmpHdr->biWidth;
     
    109111  iconhdr2->yHotspot     = 0;
    110112  iconhdr2->offBits      = 2*sizeof(BITMAPFILEHEADER2) +
    111                            2*sizeof(RGB2) + rgbsize + 2*bwsize;
     113                           2*sizeof(RGB2) + rgbsize + 2*bwsize + offsetBits;
    112114  iconhdr2->bmp2.cbFix   = sizeof(BITMAPINFOHEADER2);
    113115  iconhdr2->bmp2.cx      = (USHORT)bmpHdr->biWidth;
  • trunk/src/kernel32/cvtresource.h

    r581 r589  
    1 /* $Id: cvtresource.h,v 1.1 1999-08-19 14:19:14 sandervl Exp $ */
     1/* $Id: cvtresource.h,v 1.2 1999-08-19 19:50:40 sandervl Exp $ */
    22
    33#ifndef _CVTRESOURCE_H_
     
    77#include <winicon.h>
    88#include <winaccel.h>
     9#include <wincursor.h>
     10#include <winimage.h>
    911
    1012void *ConvertAccelerator(WINACCEL *accdata, int size, int cp = 0);
    1113void *ConvertBitmap(WINBITMAPINFOHEADER *pBHdr, ULONG ulSize, PULONG pulSize);
     14void *ConvertCursor(CursorComponent *curHdr, int size, int offsetBits = 0);
     15void *ConvertCursorGroup(CursorHeader *chdr, int size, Win32Image *module);
     16void *ConvertIcon(WINBITMAPINFOHEADER *bmpHdr, int size, int offsetBits = 0);
     17void *ConvertIconGroup(IconHeader *ihdr, int size, Win32Image *module);
    1218void *ConvertMenu(MenuHeader *menu, int size, int cp = 0);
    13 void *ConvertIcon(WINBITMAPINFOHEADER *bmpHdr, int size);
    1419
    1520
  • trunk/src/kernel32/makefile

    r581 r589  
    1 # $Id: makefile,v 1.20 1999-08-19 14:19:15 sandervl Exp $
     1# $Id: makefile,v 1.21 1999-08-19 19:50:40 sandervl Exp $
    22
    33#
     
    1919
    2020
    21 OBJS = KERNEL32.OBJ \
    22        KOBJECTS.OBJ \
    23        CONSOLE.OBJ \
    24        CONIN.OBJ \
    25        CONBUFFER.OBJ \
    26        CONOUT.OBJ \
    27        UNICODE.OBJ \
    28        network.OBJ \
    29        DEVIO.OBJ \
    30        profile.obj \
     21OBJS = KERNEL32.OBJ KOBJECTS.OBJ CONSOLE.OBJ CONIN.OBJ CONBUFFER.OBJ \
     22       CONOUT.OBJ UNICODE.OBJ network.OBJ DEVIO.OBJ profile.obj \
    3123       THREAD.OBJ \
    3224       THUNK.OBJ \
     
    8072       cvtaccel.obj \
    8173       cvticon.obj \
     74       cvticongrp.obj \
     75       cvtcursor.obj \
     76       cvtcursorgrp.obj \
    8277       stubs.obj
    8378
     
    357352cvtaccel.obj: cvtaccel.cpp $(PDWIN32_INCLUDE)\winaccel.h $(PDWIN32_INCLUDE)\misc.h cvtresource.h
    358353cvticon.obj: cvticon.cpp $(PDWIN32_INCLUDE)\winicon.h $(PDWIN32_INCLUDE)\misc.h cvtresource.h
     354cvticongrp.obj: cvticongrp.cpp $(PDWIN32_INCLUDE)\winicon.h $(PDWIN32_INCLUDE)\misc.h cvtresource.h
     355cvtcursor.obj: cvtcursor.cpp $(PDWIN32_INCLUDE)\wincursor.h $(PDWIN32_INCLUDE)\winicon.h $(PDWIN32_INCLUDE)\misc.h cvtresource.h
     356cvtcursorgrp.obj: cvtcursorgrp.cpp $(PDWIN32_INCLUDE)\wincursor.h $(PDWIN32_INCLUDE)\winicon.h $(PDWIN32_INCLUDE)\misc.h cvtresource.h
    359357
    360358clean:
  • trunk/src/kernel32/resource.cpp

    r356 r589  
    1 /* $Id: resource.cpp,v 1.7 1999-07-21 11:45:21 sandervl Exp $ */
     1/* $Id: resource.cpp,v 1.8 1999-08-19 19:50:40 sandervl Exp $ */
    22
    33/*
     
    2727    dprintf(("FindResourceA %X", hModule));
    2828    if(hModule == 0 || hModule == -1 || (WinExe != NULL && hModule ==
    29        WinExe->getOS2InstanceHandle()))
     29       WinExe->getInstanceHandle()))
    3030    {
    3131         module = (Win32Image *)WinExe;
     
    4747    dprintf(("FindResourceW %X", hModule));
    4848    if(hModule == 0 || hModule == -1 || (WinExe != NULL && hModule ==
    49        WinExe->getOS2InstanceHandle()))
     49       WinExe->getInstanceHandle()))
    5050    {
    5151         module = (Win32Image *)WinExe;
     
    9292    return(0);
    9393
    94     return res->sizeofResource();
     94    return res->getSize();
    9595}
    9696//******************************************************************************
  • trunk/src/kernel32/winimgres.cpp

    r576 r589  
    1 /* $Id: winimgres.cpp,v 1.9 1999-08-19 12:53:18 sandervl Exp $ */
     1/* $Id: winimgres.cpp,v 1.10 1999-08-19 19:50:40 sandervl Exp $ */
    22
    33/*
     
    3434//PE spec says names & ids are sorted; keep on searching just to be sure
    3535//******************************************************************************
    36 Win32Resource *Win32Image::getPEResource(ULONG id, ULONG type, ULONG lang)
     36PIMAGE_RESOURCE_DATA_ENTRY
     37 Win32Image::getPEResourceEntry(ULONG id, ULONG type, ULONG lang)
    3738{
    3839 PIMAGE_RESOURCE_DIRECTORY       prdType;
    3940 PIMAGE_RESOURCE_DIRECTORY_ENTRY prde;
    4041 PIMAGE_RESOURCE_DATA_ENTRY      pData = NULL;
    41  Win32Resource                  *res;
    42  ULONG  nodeData[3];
     42 ULONG  nodeData[3], i, j;
    4343 BOOL  fFound = FALSE, fNumType;
    44  char  *winres = NULL;
    45  int    i, stringid = -1, j;
    4644
    4745  /* set pointer to first resource type entry */
     
    6664    }
    6765    else type   = i;
    68   }
    69 
    70   //String format: tables of 16 strings stored as one resource
    71   //upper 12 bits of resource id passed by user determines block (res id)
    72   //lower 4 bits are an index into the string table
    73   if(fNumType) {
    74     if(type == NTRT_STRING) {
    75         stringid = id & 0xF;
    76         id       = (id >> 4);
    77     }
    78   }
    79   else {
    80     if(stricmp((char *)type, ResTypes[NTRT_STRING]) == 0) {
    81         stringid = id & 0xF;
    82         id       = (id >> 4);
    83     }
    8466  }
    8567
     
    128110    prde++;
    129111  }
     112  return pData;
     113}
     114//******************************************************************************
     115//level: 2 ids
     116//       3 languages
     117//******************************************************************************
     118PIMAGE_RESOURCE_DATA_ENTRY
     119    Win32Image::ProcessResSubDir(PIMAGE_RESOURCE_DIRECTORY prdType,
     120                                 ULONG *nodeData, int level)
     121{
     122 PIMAGE_RESOURCE_DIRECTORY       prdType2;
     123 PIMAGE_RESOURCE_DIRECTORY_ENTRY prde;
     124 PIMAGE_RESOURCE_DIR_STRING_U    pstring;
     125 PIMAGE_RESOURCE_DATA_ENTRY      pData;
     126 BOOL  fFound = FALSE, fNumId;
     127 ULONG nrres;
     128 char *resname;
     129 int   i;
     130
     131  if(*nodeData == 0xFFFFFFFF) {//shouldn't happen!
     132        dprintf(("ProcessResSubDir: *nodeData == 0xFFFFFFFF!\n"));
     133        return(NULL);
     134  }
     135  prdType = (PIMAGE_RESOURCE_DIRECTORY)((ULONG)prdType & ~0x80000000);
     136  prde    = (PIMAGE_RESOURCE_DIRECTORY_ENTRY)((DWORD)prdType + sizeof(IMAGE_RESOURCE_DIRECTORY));
     137
     138  if(level == 3 && *nodeData == LANG_GETFIRST) {
     139        nrres  = prdType->NumberOfNamedEntries + prdType->NumberOfIdEntries;
     140        fNumId = (prdType->NumberOfNamedEntries == 0);
     141  }
     142  else {
     143        fNumId = HIWORD(*nodeData) == 0;
     144
     145        if(fNumId) {//numeric or string id?
     146                nrres = prdType->NumberOfIdEntries;
     147                prde += prdType->NumberOfNamedEntries;  //skip name entries
     148        }
     149        else    nrres = prdType->NumberOfNamedEntries;
     150  }
     151
     152  for(i=0;i<nrres;i++) {
     153        /* locate directory or each resource type */
     154        prdType2 = (PIMAGE_RESOURCE_DIRECTORY)((ULONG)pResDir + (ULONG)prde->u2.OffsetToData);
     155
     156        if(!fNumId) {//name or id entry?
     157                if(prde->u1.s.NameIsString) //unicode directory string /*PLF Sat  97-06-21 22:30:35*/
     158                        prde->u1.Name &= ~0x80000000;
     159
     160                pstring = (PIMAGE_RESOURCE_DIR_STRING_U)((ULONG)pResDir + (ULONG)prde->u1.Name);
     161                resname = UnicodeToAsciiStringN(pstring->NameString, pstring->Length);
     162                if(stricmp(resname, (char *)*nodeData) == 0) {
     163                        fFound = TRUE;
     164                }
     165                FreeAsciiString(resname);
     166        }
     167        else {
     168                if(*nodeData == prde->u1.Id)
     169                        fFound = TRUE;
     170        }
     171        if(*nodeData == LANG_GETFIRST)
     172                fFound = TRUE;
     173
     174        if(fFound) {
     175                if((ULONG)prdType2 & 0x80000000) {//subdirectory?
     176                        return ProcessResSubDir(prdType2, nodeData+1, 3);
     177                }
     178                else {
     179                        pData = (PIMAGE_RESOURCE_DATA_ENTRY)prdType2;
     180                        if(pData->Size) {//winamp17 winzip archive has resource with size 0
     181                                return(pData);
     182                        }
     183                        else    return(NULL);
     184                }
     185        }
     186        prde++;
     187  }
     188  return(NULL);
     189}
     190//******************************************************************************
     191//******************************************************************************
     192ULONG Win32Image::getPEResourceSize(ULONG id, ULONG type, ULONG lang)
     193{
     194 PIMAGE_RESOURCE_DATA_ENTRY      pData = NULL;
     195
     196  pData = getPEResourceEntry(id, type, lang);
    130197  if(pData == NULL) {
    131         dprintf(("getResource: res not found!\n"));
    132         return(NULL);
    133   }
    134 
    135   char *resdata = (char *)((char *)pResDir + pData->OffsetToData - pResSection->virtaddr);
     198        dprintf(("Win32Image::getPEResourceSize: couldn't find resource %d (type %d, lang %d)", id, type, lang));
     199        return 0;
     200  }
     201  return pData->Size;
     202}
     203//******************************************************************************
     204//******************************************************************************
     205Win32Resource *Win32Image::getPEResource(ULONG id, ULONG type, ULONG lang)
     206{
     207 PIMAGE_RESOURCE_DATA_ENTRY      pData = NULL;
     208 Win32Resource                  *res;
     209 BOOL   fNumType;
     210 char  *winres = NULL;
     211 int    i, stringid = -1, j;
     212
     213  fNumType = TRUE;    //assume numeric
     214  if(HIWORD(type) != 0) {//string id?
     215    for(i=0;i<MAX_RES;i++) {
     216         if(stricmp((char *)type, ResTypes[i]) == 0)
     217                break;
     218    }
     219    if(i == MAX_RES) {//custom resource type
     220         fNumType = FALSE;
     221    }
     222    else type   = i;
     223  }
     224
     225  //String format: tables of 16 strings stored as one resource
     226  //upper 12 bits of resource id passed by user determines block (res id)
     227  //lower 4 bits are an index into the string table
     228  if(fNumType) {
     229    if(type == NTRT_STRING) {
     230        stringid = id & 0xF;
     231        id       = (id >> 4);
     232    }
     233  }
     234  else {
     235    if(stricmp((char *)type, ResTypes[NTRT_STRING]) == 0) {
     236        stringid = id & 0xF;
     237        id       = (id >> 4);
     238    }
     239  }
     240
     241  pData = getPEResourceEntry(id, type, lang);
     242  if(pData == NULL) {
     243        dprintf(("Win32Image::getPEResource: couldn't find resource %d (type %d, lang %d)", id, type, lang));
     244        return 0;
     245  }
     246
     247  char *resdata = (char *)((char *)pResDir + pData->OffsetToData - (pResSection->virtaddr - oh.ImageBase));
    136248  if(stringid != -1) {//search for string in table
    137249        USHORT *unicodestr = (USHORT *)resdata;
     
    151263}
    152264//******************************************************************************
    153 //level: 2 ids
    154 //       3 languages
    155 //******************************************************************************
    156 PIMAGE_RESOURCE_DATA_ENTRY
    157     Win32Image::ProcessResSubDir(PIMAGE_RESOURCE_DIRECTORY prdType,
    158                                  ULONG *nodeData, int level)
    159 {
    160  PIMAGE_RESOURCE_DIRECTORY       prdType2;
    161  PIMAGE_RESOURCE_DIRECTORY_ENTRY prde;
    162  PIMAGE_RESOURCE_DIR_STRING_U    pstring;
    163  PIMAGE_RESOURCE_DATA_ENTRY      pData;
    164  BOOL  fFound = FALSE, fNumId;
    165  ULONG nrres;
    166  char *resname;
    167  int   i;
    168 
    169   if(*nodeData == 0xFFFFFFFF) {//shouldn't happen!
    170         dprintf(("ProcessResSubDir: *nodeData == 0xFFFFFFFF!\n"));
    171         return(NULL);
    172   }
    173   prdType = (PIMAGE_RESOURCE_DIRECTORY)((ULONG)prdType & ~0x80000000);
    174   prde    = (PIMAGE_RESOURCE_DIRECTORY_ENTRY)((DWORD)prdType + sizeof(IMAGE_RESOURCE_DIRECTORY));
    175 
    176   if(level == 3 && *nodeData == LANG_GETFIRST) {
    177         nrres  = prdType->NumberOfNamedEntries + prdType->NumberOfIdEntries;
    178         fNumId = (prdType->NumberOfNamedEntries != 0);
    179   }
    180   else {
    181         fNumId = HIWORD(*nodeData) == 0;
    182 
    183         if(fNumId) {//numeric or string id?
    184                 nrres = prdType->NumberOfIdEntries;
    185                 prde += prdType->NumberOfNamedEntries;  //skip name entries
    186         }
    187         else    nrres = prdType->NumberOfNamedEntries;
    188   }
    189 
    190   for(i=0;i<nrres;i++) {
    191         /* locate directory or each resource type */
    192         prdType2 = (PIMAGE_RESOURCE_DIRECTORY)((ULONG)pResDir + (ULONG)prde->u2.OffsetToData);
    193 
    194         if(!fNumId) {//name or id entry?
    195                 if(prde->u1.s.NameIsString) //unicode directory string /*PLF Sat  97-06-21 22:30:35*/
    196                         prde->u1.Name &= ~0x80000000;
    197 
    198                 pstring = (PIMAGE_RESOURCE_DIR_STRING_U)((ULONG)pResDir + (ULONG)prde->u1.Name);
    199                 resname = UnicodeToAsciiStringN(pstring->NameString, pstring->Length);
    200                 if(stricmp(resname, (char *)*nodeData) == 0) {
    201                         fFound = TRUE;
    202                 }
    203                 FreeAsciiString(resname);
    204         }
    205         else {
    206                 if(*nodeData == prde->u1.Id)
    207                         fFound = TRUE;
    208         }
    209         if(*nodeData == LANG_GETFIRST)
    210                 fFound = TRUE;
    211 
    212         if(fFound) {
    213                 if((ULONG)prdType2 & 0x80000000) {//subdirectory?
    214                         ProcessResSubDir(prdType2, nodeData+1, 3);
    215                 }
    216                 else {
    217                         pData = (PIMAGE_RESOURCE_DATA_ENTRY)prdType2;
    218                         if(pData->Size) {//winamp17 winzip archive has resource with size 0
    219                                 return(pData);
    220                         }
    221                         else    return(NULL);
    222                 }
    223         }
    224         prde++;
    225   }
    226   return(NULL);
    227 }
    228 //******************************************************************************
    229265//******************************************************************************
    230266HRSRC Win32Image::findResourceA(LPCSTR lpszName, LPSTR lpszType)
     
    240276    //else converted win32 exe/dll
    241277
    242     if((int)lpszType >> 16 != 0) {//type name, translate to id
     278    if(HIWORD(lpszType) != 0) {//type name, translate to id
    243279        for(i=0;i<MAX_RES;i++) {
    244280            if(strcmp(lpszType, ResTypes[i]) == 0)
     
    279315    dprintf(("FindResourceA from %X type %d (%X)\n", hinstance, szType, lpszType));
    280316
    281     if((int)lpszName >> 16 != 0) {//convert string name identifier to numeric id
     317    if(HIWORD(lpszName) != 0) {//convert string name identifier to numeric id
    282318        dprintf(("FindResource %s\n", lpszName));
    283319        if(lpszName[0] == '#') {// #344
     
    294330    }
    295331
    296     if(hres == NULL && (int)lpszName >> 16 == 0 && (int)szType == NTRT_STRING) {
     332    if(hres == NULL && HIWORD(lpszName) == 0 && (int)szType == NTRT_STRING) {
    297333        hres = O32_FindResource(hinstance, (LPCSTR)(((int)lpszName - 1)*16), (LPCSTR)NTRT_RCDATA);
    298334        if(hres)
     
    317353
    318354    if(fNativePEImage == TRUE) {//load resources directly from res section
    319         if((int)lpszType >> 16 != 0) {
     355        if(HIWORD(lpszType) != 0) {
    320356                char *resname = UnicodeToAsciiString(lpszType);
    321357        }
    322358        else    astring1 = (char *)lpszType;
    323359
    324         if((int)lpszName >> 16 != 0) {
     360        if(HIWORD(lpszName) != 0) {
    325361                astring2 = UnicodeToAsciiString(lpszName);
    326362        }
     
    334370    }
    335371    //else converted win32 exe/dll
    336     if((int)lpszType >> 16 != 0) {//type name, translate to id
     372    if(HIWORD(lpszType) != 0) {//type name, translate to id
    337373        char *resname = UnicodeToAsciiString(lpszType);
    338374        for(i=0;i<MAX_RES;i++) {
     
    375411    dprintf(("FindResourceW type %d\n", szType));
    376412
    377     if((int)lpszName >> 16 != 0) {//convert string name identifier to numeric id
     413    if(HIWORD(lpszName) != 0) {//convert string name identifier to numeric id
    378414        astring1 = UnicodeToAsciiString(lpszName);
    379415        dprintf(("FindResourceW %X %s\n", hinstance, astring1));
     
    391427    }
    392428
    393     if(hres == NULL && (int)lpszName >> 16 == 0 && (int)szType == NTRT_STRING) {
     429    if(hres == NULL && HIWORD(lpszName) == 0 && (int)szType == NTRT_STRING) {
    394430        hres = O32_FindResource(hinstance, (LPCSTR)(((ULONG)lpszName - 1)*16), (LPCSTR)NTRT_RCDATA);
    395431        if(hres)
     
    407443//******************************************************************************
    408444//******************************************************************************
     445ULONG Win32Image::getResourceSizeA(LPCSTR lpszName, LPSTR lpszType)
     446{
     447    if(fNativePEImage == TRUE) {
     448        return getPEResourceSize((ULONG)lpszName, (ULONG)lpszType);
     449    }
     450    DebugInt3();
     451    return 0;
     452}
     453//******************************************************************************
     454//******************************************************************************
     455ULONG Win32Image::getResourceSizeW(LPCWSTR lpszName, LPWSTR lpszType)
     456{
     457 char *astring1 = NULL, *astring2 = NULL;
     458 ULONG ressize;
     459
     460    if(fNativePEImage == TRUE) {//load resources directly from res section
     461        if(HIWORD(lpszType) != 0) {
     462                char *resname = UnicodeToAsciiString(lpszType);
     463        }
     464        else    astring1 = (char *)lpszType;
     465
     466        if(HIWORD(lpszName) != 0) {
     467                astring2 = UnicodeToAsciiString((LPWSTR)lpszName);
     468        }
     469        else    astring2 = (char *)lpszName;
     470
     471        ressize =  getPEResourceSize((ULONG)astring1, (ULONG)astring1);
     472        if(astring1) FreeAsciiString(astring1);
     473        if(astring2) FreeAsciiString(astring2);
     474
     475        return(ressize);
     476    }
     477    DebugInt3();
     478    return 0;
     479}
     480//******************************************************************************
     481//******************************************************************************
  • trunk/src/kernel32/winres.cpp

    r581 r589  
    1 /* $Id: winres.cpp,v 1.8 1999-08-19 14:19:15 sandervl Exp $ */
     1/* $Id: winres.cpp,v 1.9 1999-08-19 19:50:41 sandervl Exp $ */
    22
    33/*
     
    297297
    298298    case NTRT_CURSOR:
     299        return ConvertCursor((CursorComponent *)win32res, ressize);
     300
    299301    case NTRT_GROUP_CURSOR:
     302        return ConvertCursorGroup((CursorHeader *)win32res, ressize, module);
     303
    300304    case NTRT_GROUP_ICON:
     305        return ConvertIconGroup((IconHeader *)win32res, ressize, module);
     306
    301307    case NTRT_ICON:
    302308        return ConvertIcon((WINBITMAPINFOHEADER *)win32res, ressize);
Note: See TracChangeset for help on using the changeset viewer.