Changeset 956 for trunk/src/kernel32/winimgres.cpp
- Timestamp:
- Sep 16, 1999, 1:39:08 AM (26 years ago)
- File:
-
- 1 edited
-
trunk/src/kernel32/winimgres.cpp (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/winimgres.cpp
r752 r956 1 /* $Id: winimgres.cpp,v 1.1 3 1999-08-31 14:36:46sandervl Exp $ */1 /* $Id: winimgres.cpp,v 1.14 1999-09-15 23:38:02 sandervl Exp $ */ 2 2 3 3 /* … … 10 10 * 11 11 * 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 12 15 * 13 16 */ … … 18 21 19 22 #include <misc.h> 20 #include < nameid.h>21 #include <winimage .h>22 #include <win dll.h>23 #include <win exe.h>23 #include <winimagebase.h> 24 #include <winimagepe2lx.h> 25 #include <winimagepeldr.h> 26 #include <winimagelx.h> 24 27 #include <winres.h> 25 28 #include <winresmenu.h> … … 27 30 #include <heapstring.h> 28 31 #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" 35 33 36 34 //****************************************************************************** … … 39 37 //****************************************************************************** 40 38 PIMAGE_RESOURCE_DATA_ENTRY 41 Win32 Image::getPEResourceEntry(ULONG id, ULONG type, ULONG lang)39 Win32PeLdrImage::getPEResourceEntry(ULONG id, ULONG type, ULONG lang) 42 40 { 43 41 PIMAGE_RESOURCE_DIRECTORY prdType; … … 126 124 //****************************************************************************** 127 125 PIMAGE_RESOURCE_DATA_ENTRY 128 Win32 Image::ProcessResSubDir(PIMAGE_RESOURCE_DIRECTORY prdType,126 Win32PeLdrImage::ProcessResSubDir(PIMAGE_RESOURCE_DIRECTORY prdType, 129 127 ULONG *nodeData, int level) 130 128 { … … 203 201 //****************************************************************************** 204 202 //****************************************************************************** 205 ULONG Win32 Image::getPEResourceSize(ULONG id, ULONG type, ULONG lang)203 ULONG Win32PeLdrImage::getPEResourceSize(ULONG id, ULONG type, ULONG lang) 206 204 { 207 205 PIMAGE_RESOURCE_DATA_ENTRY pData = NULL; … … 209 207 pData = getPEResourceEntry(id, type, lang); 210 208 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)); 212 210 return 0; 213 211 } … … 216 214 //****************************************************************************** 217 215 //****************************************************************************** 218 Win32Resource *Win32Image::getPEResource(ULONG id, ULONG type, ULONG lang)216 HRSRC Win32PeLdrImage::findResourceA(LPCSTR lpszName, LPSTR lpszType, ULONG lang) 219 217 { 220 218 PIMAGE_RESOURCE_DATA_ENTRY pData = NULL; … … 222 220 BOOL fNumType; 223 221 char *winres = NULL; 222 ULONG id, type; 224 223 int i, stringid = -1, j; 225 224 226 225 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; 237 238 238 239 //String format: tables of 16 strings stored as one resource … … 241 242 if(fNumType) { 242 243 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; 246 248 } 247 249 else { 248 250 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; 252 255 } 253 256 … … 255 258 if(pData == NULL) { 256 259 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)); 258 261 } 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)); 260 263 return 0; 261 264 } … … 287 290 } 288 291 289 return res;290 } 291 //****************************************************************************** 292 //****************************************************************************** 293 HRSRC Win32 Image::findResourceA(LPCSTR lpszName, LPSTR lpszType)292 return (HRSRC) res; 293 } 294 //****************************************************************************** 295 //****************************************************************************** 296 HRSRC Win32Pe2LxImage::findResourceA(LPCSTR lpszName, LPSTR lpszType, ULONG lang) 294 297 { 295 298 Win32Resource *res = NULL; … … 297 300 int i; 298 301 LPSTR szType = (LPSTR)lpszType; 299 300 if(fNativePEImage == TRUE) {301 return (HRSRC) getPEResource((ULONG)lpszName, (ULONG)lpszType);302 }303 //else converted win32 exe/dll304 302 305 303 if(HIWORD(lpszType) != 0) {//type name, translate to id … … 347 345 lpszName = (LPCSTR)atoi(&lpszName[1]); 348 346 } 349 else lpszName = (LPCSTR) ConvertNameId(hinstance,(char *)lpszName);347 else lpszName = (LPCSTR)convertNameId((char *)lpszName); 350 348 } 351 349 else dprintf(("FindResource %d\n", (int)lpszName)); … … 377 375 } 378 376 //****************************************************************************** 379 //****************************************************************************** 380 HRSRC Win32Image::findResourceW(LPWSTR lpszName, LPWSTR lpszType) 381 { 382 Win32Resource *res = NULL; 377 //TODO: 378 //****************************************************************************** 379 HRSRC Win32LxImage::findResourceA(LPCSTR lpszName, LPSTR lpszType, ULONG lang) 380 { 381 return 0; 382 } 383 //****************************************************************************** 384 //****************************************************************************** 385 HRSRC Win32ImageBase::findResourceW(LPWSTR lpszName, LPWSTR lpszType, ULONG lang) 386 { 383 387 HRSRC hres; 384 LPSTR szType = (LPSTR)lpszType;385 int i;386 388 char *astring1 = NULL, *astring2 = NULL; 387 389 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 //****************************************************************************** 409 ULONG Win32Pe2LxImage::getResourceSizeA(LPCSTR lpszName, LPSTR lpszType, ULONG lang) 410 { 491 411 DebugInt3(); 492 412 return 0; 493 413 } 494 414 //****************************************************************************** 495 //****************************************************************************** 496 ULONG Win32Image::getResourceSizeW(LPCWSTR lpszName, LPWSTR lpszType) 415 //TODO: 416 //****************************************************************************** 417 ULONG Win32LxImage::getResourceSizeA(LPCSTR lpszName, LPSTR lpszType, ULONG lang) 418 { 419 DebugInt3(); 420 return 0; 421 } 422 //****************************************************************************** 423 //****************************************************************************** 424 ULONG Win32PeLdrImage::getResourceSizeA(LPCSTR lpszName, LPSTR lpszType, ULONG lang) 425 { 426 return getPEResourceSize((ULONG)lpszName, (ULONG)lpszType, lang); 427 } 428 //****************************************************************************** 429 //****************************************************************************** 430 ULONG Win32ImageBase::getResourceSizeW(LPCWSTR lpszName, LPWSTR lpszType, ULONG lang) 497 431 { 498 432 char *astring1 = NULL, *astring2 = NULL; 499 433 ULONG ressize; 500 434 501 if(fNativePEImage == TRUE) {//load resources directly from res section 502 if(HIWORD(lpszType) != 0) { 435 if(HIWORD(lpszType) != 0) { 503 436 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) { 508 441 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 //****************************************************************************** 453 ULONG 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 //****************************************************************************** 463 BOOL 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 //****************************************************************************** 473 ULONG Win32PeLdrImage::getVersionSize() 474 { 475 return getResourceSizeA((LPCSTR)1, (LPSTR)NTRT_VERSION); 476 } 477 //****************************************************************************** 478 //****************************************************************************** 479 BOOL 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 //****************************************************************************** 492 ULONG Win32LxImage::getVersionSize() 493 { 494 // return getResourceSizeA((LPCSTR)1, (LPSTR)NTRT_VERSION); 495 return 0; 496 } 497 //****************************************************************************** 498 //****************************************************************************** 499 BOOL 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.
