- Timestamp:
- Oct 19, 1999, 2:51:25 PM (26 years ago)
- Location:
- trunk/src/kernel32
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/winimgres.cpp
r1274 r1356 1 /* $Id: winimgres.cpp,v 1.2 3 1999-10-14 01:37:56 birdExp $ */1 /* $Id: winimgres.cpp,v 1.24 1999-10-19 12:51:25 sandervl Exp $ */ 2 2 3 3 /* … … 12 12 * TODO: Once the resource handling in PE2LX/win32k is changed, 13 13 * getVersionStruct/Size can be moved into the Win32ImageBase class 14 * TODO: Support for 'DIB' resource type (VPBuddy) 14 15 * 15 16 */ … … 31 32 #include "oslibmisc.h" 32 33 34 //SvL: VPBuddy bugfix, seems to load bitmaps with type name 'DIB' 35 #define BITMAP_TYPENAME2 "DIB" 36 33 37 //****************************************************************************** 34 38 //Assuming names are case insensitive … … 63 67 if(HIWORD(type) != 0) {//string id? 64 68 for(i=0;i<MAX_RES;i++) { 65 69 if(stricmp((char *)type, ResTypes[i]) == 0) 66 70 break; 67 71 } 72 //TODO: 73 #if 0 74 if(stricmp((char *)type, BITMAP_TYPENAME2) == 0) { 75 i = (int)RT_BITMAPA; 76 } 77 #endif 78 68 79 if(i == MAX_RES) {//custom resource type 69 80 fNumType = FALSE; … … 79 90 {//name or id entry? 80 91 //SvL: 30-10-'97, high bit is set, so clear to get real offset 81 nameOffset = prde->u1.Name & ~0x80000000;92 nameOffset = prde->u1.Name & ~0x80000000; 82 93 83 94 pstring = (PIMAGE_RESOURCE_DIR_STRING_U)((ULONG)pResDir + nameOffset); 84 char *typename = (char *)malloc(pstring->Length+1);95 char *typename = (char *)malloc(pstring->Length+1); 85 96 lstrcpynWtoA(typename, pstring->NameString, pstring->Length+1); 86 typename[pstring->Length] = 0;97 typename[pstring->Length] = 0; 87 98 88 99 if(!fNumType) { … … 100 111 } 101 112 } 102 free(typename);113 free(typename); 103 114 } 104 115 else { … … 171 182 else 172 183 if(!fNumId) {//name or id entry? 173 nameOffset = prde->u1.Name;184 nameOffset = prde->u1.Name; 174 185 if(prde->u1.s.NameIsString) //unicode directory string /*PLF Sat 97-06-21 22:30:35*/ 175 186 nameOffset &= ~0x80000000; … … 177 188 pstring = (PIMAGE_RESOURCE_DIR_STRING_U)((ULONG)pResDir + nameOffset); 178 189 179 resname = (char *)malloc(pstring->Length+1);190 resname = (char *)malloc(pstring->Length+1); 180 191 lstrcpynWtoA(resname, pstring->NameString, pstring->Length+1); 181 resname[pstring->Length] = 0;192 resname[pstring->Length] = 0; 182 193 if(stricmp(resname, (char *)*nodeData) == 0) { 183 194 fFound = TRUE; 184 195 } 185 free(resname);196 free(resname); 186 197 } 187 198 else { … … 190 201 } 191 202 192 if(fFound) {203 if(fFound) { 193 204 if((ULONG)prdType2 & 0x80000000) {//subdirectory? 194 205 return ProcessResSubDir(prdType2, nodeData+1, 3); … … 197 208 pData = (PIMAGE_RESOURCE_DATA_ENTRY)prdType2; 198 209 if(pData->Size) {//winamp17 winzip archive has resource with size 0 199 return(pData);210 return(pData); 200 211 } 201 212 else return(NULL); … … 212 223 PIMAGE_RESOURCE_DATA_ENTRY pData = NULL; 213 224 214 pData = getPEResourceEntry(id, type, lang);215 if(pData == NULL) {216 dprintf(("Win32ImageBase::getPEResourceSize: couldn't find resource %d (type %d, lang %d)", id, type, lang));217 return 0;218 }219 return pData->Size;225 pData = getPEResourceEntry(id, type, lang); 226 if(pData == NULL) { 227 dprintf(("Win32ImageBase::getPEResourceSize: couldn't find resource %d (type %d, lang %d)", id, type, lang)); 228 return 0; 229 } 230 return pData->Size; 220 231 } 221 232 //****************************************************************************** … … 230 241 int i, stringid = -1, j; 231 242 232 fNumType = TRUE; //assume numeric233 if(HIWORD(lpszType) != 0) {//string id?243 fNumType = TRUE; //assume numeric 244 if(HIWORD(lpszType) != 0) {//string id? 234 245 for(i=0;i<MAX_RES;i++) { 235 246 if(stricmp(lpszType, ResTypes[i]) == 0) 236 247 break; 237 248 } 249 //TODO: 250 #if 0 251 if(stricmp((char *)lpszType, BITMAP_TYPENAME2) == 0) { 252 i = (int)RT_BITMAPA; 253 } 254 #endif 238 255 if(i == MAX_RES) {//custom resource type 239 256 fNumType = FALSE; 240 type = (ULONG)lpszType;241 } 242 else 243 }244 else type = (ULONG)lpszType;245 246 //String format: tables of 16 strings stored as one resource247 //upper 12 bits of resource id passed by user determines block (res id)248 //lower 4 bits are an index into the string table249 if(fNumType) {250 if(type == NTRT_STRING) {251 stringid = (ULONG)lpszName & 0xF;252 id = (((ULONG)lpszName) >> 4)+1;253 }254 else id = (ULONG)lpszName;255 }256 else {257 if(stricmp((char *)type, ResTypes[NTRT_STRING]) == 0) {258 stringid = (ULONG)lpszName & 0xF;259 id = (((ULONG)lpszName) >> 4)+1;260 }261 else id = (ULONG)lpszName;262 }263 264 pData = getPEResourceEntry(id, type, lang);265 if(pData == NULL) {266 if(HIWORD(id)) {257 type = (ULONG)lpszType; 258 } 259 else type = i; 260 } 261 else type = (ULONG)lpszType; 262 263 //String format: tables of 16 strings stored as one resource 264 //upper 12 bits of resource id passed by user determines block (res id) 265 //lower 4 bits are an index into the string table 266 if(fNumType) { 267 if(type == NTRT_STRING) { 268 stringid = (ULONG)lpszName & 0xF; 269 id = (((ULONG)lpszName) >> 4)+1; 270 } 271 else id = (ULONG)lpszName; 272 } 273 else { 274 if(stricmp((char *)type, ResTypes[NTRT_STRING]) == 0) { 275 stringid = (ULONG)lpszName & 0xF; 276 id = (((ULONG)lpszName) >> 4)+1; 277 } 278 else id = (ULONG)lpszName; 279 } 280 281 pData = getPEResourceEntry(id, type, lang); 282 if(pData == NULL) { 283 if(HIWORD(id)) { 267 284 dprintf(("Win32ImageBase::getPEResource %s: couldn't find resource %s (type %d, lang %d)", szModule, id, type, lang)); 268 }285 } 269 286 else dprintf(("Win32ImageBase::getPEResource %s: couldn't find resource %d (type %d, lang %d)", szModule, id, type, lang)); 270 return 0;271 }272 //pResourceSectionStart contains the virtual address of the imagebase in the PE header273 //for the resource section (images loaded by the pe.exe)274 //For LX images, this is 0 as OffsetToData contains a relative offset275 char *resdata = (char *)((char *)pResDir + pData->OffsetToData - pResourceSectionStart);276 if(stringid != -1) {//search for string in table287 return 0; 288 } 289 //pResourceSectionStart contains the virtual address of the imagebase in the PE header 290 //for the resource section (images loaded by the pe.exe) 291 //For LX images, this is 0 as OffsetToData contains a relative offset 292 char *resdata = (char *)((char *)pResDir + pData->OffsetToData - pResourceSectionStart); 293 if(stringid != -1) {//search for string in table 277 294 USHORT *unicodestr = (USHORT *)resdata; 278 295 … … 286 303 return(NULL); 287 304 } 288 } 289 else { 290 switch(type) { 291 case NTRT_MENU: 305 } 306 else 307 { 308 switch(type) { 309 case NTRT_MENU: 292 310 res = new Win32MenuRes(this, id, type, pData->Size, resdata); 293 break;294 default:311 break; 312 default: 295 313 res = new Win32Resource(this, id, type, pData->Size, resdata); 296 break; 297 } 298 299 } 300 301 return (HRSRC) res; 302 } 303 //****************************************************************************** 304 //****************************************************************************** 305 #if 0 306 HRSRC Win32Pe2LxImage::findResourceA(LPCSTR lpszName, LPSTR lpszType, ULONG lang) 307 { 308 Win32Resource *res = NULL; 309 HRSRC hres; 310 int i; 311 LPSTR szType = (LPSTR)lpszType; 312 313 if(HIWORD(lpszType) != 0) {//type name, translate to id 314 for(i=0;i<MAX_RES;i++) { 315 if(strcmp(lpszType, ResTypes[i]) == 0) 316 break; 317 } 318 if(i == MAX_RES) {//custom resource type, stored as rcdata 319 dprintf(("FindResourceA custom type %s\n", lpszType)); 320 lpszType = (LPSTR)NTRT_RCDATA; 321 } 322 else lpszType = (LPSTR)i; 323 324 szType = (LPSTR)lpszType; 325 } 326 switch((int)szType) { 327 case NTRT_GROUP_ICON: 328 szType = (LPSTR)NTRT_ICON; 329 break; 330 case NTRT_GROUP_CURSOR: 331 szType = (LPSTR)NTRT_CURSOR; 332 break; 333 case NTRT_VERSION: 334 szType = (LPSTR)NTRT_RCDATA; 335 break; 336 case NTRT_STRING: 337 case NTRT_MENU: 338 case NTRT_ICON: 339 case NTRT_BITMAP: 340 case NTRT_CURSOR: 341 case NTRT_DIALOG: 342 case NTRT_RCDATA: 343 case NTRT_ACCELERATORS: 344 szType = lpszType; 345 break; 346 default: //unknown are stored as rcdata 347 szType = (LPSTR)NTRT_RCDATA; 348 break; 349 } 350 dprintf(("FindResourceA from %X type %d (%X)\n", hinstance, szType, lpszType)); 351 352 if(HIWORD(lpszName) != 0) {//convert string name identifier to numeric id 353 dprintf(("FindResource %s\n", lpszName)); 354 if(lpszName[0] == '#') {// #344 355 lpszName = (LPCSTR)atoi(&lpszName[1]); 356 } 357 else lpszName = (LPCSTR)convertNameId((char *)lpszName); 358 } 359 else dprintf(("FindResource %d\n", (int)lpszName)); 360 361 hres = O32_FindResource(hinstance, lpszName, szType); 362 if(hres) 363 { 364 switch((ULONG)szType) { 365 case NTRT_MENU: 366 res = new Win32MenuRes(this, hres, (ULONG)lpszName, (ULONG)szType); 367 break; 368 default: 369 res = new Win32Resource(this, hres, (ULONG)lpszName, (ULONG)szType); 370 break; 371 } 372 } 373 374 if(hres == NULL && HIWORD(lpszName) == 0 && (int)szType == NTRT_STRING) { 375 hres = O32_FindResource(hinstance, (LPCSTR)(((int)lpszName - 1)*16), (LPCSTR)NTRT_RCDATA); 376 if(hres) 377 { 378 res = new Win32Resource(this, hres, (ULONG)lpszName, (ULONG)szType); 379 } 380 else dprintf(("FindResourceA can't find string %d\n", (int)lpszName)); 381 } 382 dprintf(("FindResourceA returned %X (%X)\n", hres, GetLastError())); 383 384 return (HRSRC)res; 385 } 386 #endif 314 break; 315 } 316 317 } 318 319 return (HRSRC) res; 320 } 387 321 //****************************************************************************** 388 322 //****************************************************************************** … … 483 417 PIMAGE_RESOURCE_DATA_ENTRY pData = NULL; 484 418 485 if(verstruct == NULL || bufLength == 0) {486 SetLastError(ERROR_INVALID_PARAMETER);487 return FALSE;488 }489 pData = getPEResourceEntry(ID_GETFIRST, NTRT_VERSION);490 if(pData == NULL) {491 dprintf(("Win32PeLdrImage::getVersionStruct: couldn't find version resource!"));492 return 0;493 }494 char *resdata = (char *)((char *)pResDir + pData->OffsetToData - pResourceSectionStart);495 memcpy(verstruct, resdata, min(bufLength, pData->Size));496 return TRUE;497 } 498 //****************************************************************************** 499 //****************************************************************************** 419 if(verstruct == NULL || bufLength == 0) { 420 SetLastError(ERROR_INVALID_PARAMETER); 421 return FALSE; 422 } 423 pData = getPEResourceEntry(ID_GETFIRST, NTRT_VERSION); 424 if(pData == NULL) { 425 dprintf(("Win32PeLdrImage::getVersionStruct: couldn't find version resource!")); 426 return 0; 427 } 428 char *resdata = (char *)((char *)pResDir + pData->OffsetToData - pResourceSectionStart); 429 memcpy(verstruct, resdata, min(bufLength, pData->Size)); 430 return TRUE; 431 } 432 //****************************************************************************** 433 //****************************************************************************** -
trunk/src/kernel32/winres.cpp
r956 r1356 1 /* $Id: winres.cpp,v 1. 19 1999-09-15 23:38:02sandervl Exp $ */1 /* $Id: winres.cpp,v 1.20 1999-10-19 12:51:25 sandervl Exp $ */ 2 2 3 3 /* … … 16 16 #define INCL_BITMAPFILEFORMAT 17 17 #define INCL_DOSMODULEMGR 18 #include <os2wrap.h> 18 #include <os2wrap.h> //Odin32 OS/2 api wrappers 19 19 #include <stdarg.h> 20 20 #ifdef __IBMCPP__ … … 107 107 //resources are in Unicode format by default; indirectly created resources 108 108 //can also be in ascii format 109 isUnicode = TRUE; 109 isUnicode = TRUE; 110 110 } 111 111 //****************************************************************************** … … 129 129 case NTRT_NEWBITMAP: 130 130 case NTRT_BITMAP: 131 131 orgos2type = RT_BITMAP; 132 132 break; 133 133 case NTRT_CURSOR: … … 135 135 case NTRT_GROUP_ICON: 136 136 case NTRT_ICON: 137 138 137 orgos2type = RT_POINTER; 138 break; 139 139 case NTRT_ACCELERATORS: 140 141 140 orgos2type = RT_ACCELTABLE; 141 break; 142 142 case NTRT_NEWMENU: 143 143 case NTRT_MENU: 144 145 144 orgos2type = RT_MENU; 145 break; 146 146 case NTRT_NEWDIALOG: 147 147 case NTRT_DIALOG: 148 149 148 orgos2type = RT_DIALOG; 149 break; 150 150 case NTRT_FONTDIR: 151 151 case NTRT_FONT: … … 166 166 } 167 167 //resources are in Unicode format by default 168 isUnicode = TRUE; 168 isUnicode = TRUE; 169 169 } 170 170 //****************************************************************************** … … 192 192 193 193 if(type == NTRT_STRING) { 194 195 196 } 197 else 194 memcpy(winresdata, resdata, size-sizeof(WCHAR)); 195 ((USHORT *)winresdata)[size/sizeof(WCHAR)-1] = 0; 196 } 197 else memcpy(winresdata, resdata, size); 198 198 199 199 //resources are in Unicode format by default 200 isUnicode = TRUE; 200 isUnicode = TRUE; 201 201 } 202 202 //****************************************************************************** … … 208 208 //returned by DosGetResource, so we don't (and mustn't) free it 209 209 if(os2resdata && (resType == RSRC_PELOADER || resType == RSRC_CUSTOMINDIRECT)) 210 210 free(os2resdata); 211 211 212 212 if(winresdata) free(winresdata); … … 235 235 236 236 dprintf(("Win32Resource::lockResource %d\n", id)); 237 237 238 if(winresdata) 238 239 return(winresdata); … … 290 291 winresdata = malloc(ressize+sizeof(WCHAR)); 291 292 memcpy(winresdata, resdata, ressize); 292 293 *(USHORT *)(&((char *)winresdata)[ressize]) = 0; 293 294 DosFreeResource(resdata); 294 295 return((PVOID)((ULONG)winresdata+2)); //skip length word … … 303 304 304 305 if(winresdata == NULL) { 305 306 307 308 309 310 311 306 rc = DosGetResource((HMODULE)module->hinstance, os2type, id, (PPVOID)&resdata); 307 if(rc) { 308 dprintf(("Can't find original resource!!!\n")); 309 return(NULL); 310 } 311 winresdata = (char *)malloc(ressize); 312 memcpy(winresdata, resdata, ressize); 312 313 } 313 314 if(resdata) 314 315 DosFreeResource(resdata); 315 316 316 317 return winresdata; … … 325 326 dprintf(("Win32Resource::lockOS2Resource %d\n", id)); 326 327 if(os2resdata == NULL) { 327 328 329 330 331 332 333 334 328 if(resType == RSRC_PELOADER || resType == RSRC_CUSTOMINDIRECT) { 329 os2resdata = convertResource(winresdata); 330 } 331 else { 332 rc = DosGetResource((HMODULE)module->hinstance, orgos2type, id, (PPVOID)&resdata); 333 if(rc) return(NULL); 334 os2resdata = resdata; 335 } 335 336 } 336 337 return os2resdata; … … 344 345 case NTRT_NEWBITMAP: 345 346 case NTRT_BITMAP: 346 347 return QueryConvertedBitmapSize((WINBITMAPINFOHEADER *)winresdata, ressize); 347 348 348 349 case NTRT_CURSOR: 349 350 return QueryConvertedCursorSize((CursorComponent *)winresdata, ressize); 350 351 351 352 case NTRT_ICON: 352 353 return QueryConvertedIconSize((WINBITMAPINFOHEADER *)winresdata, ressize); 353 354 354 355 case NTRT_GROUP_ICON: … … 366 367 case NTRT_STRING: 367 368 default: 368 369 369 dprintf(("Win32Resource::getOS2Size SHOULDN'T BE CALLED for this resource type (%d) (NOT IMPLEMENTED)!!", type)); 370 break; 370 371 } 371 372 return 0; … … 380 381 case NTRT_NEWBITMAP: 381 382 case NTRT_BITMAP: 382 383 return ConvertBitmap((WINBITMAPINFOHEADER *)win32res, ressize, &ressize); 383 384 384 385 case NTRT_CURSOR: 385 386 return ConvertCursor((CursorComponent *)win32res, ressize, &cvtressize); 386 387 387 388 case NTRT_GROUP_CURSOR: 388 389 return ConvertCursorGroup((CursorHeader *)win32res, ressize, module); 389 390 390 391 case NTRT_GROUP_ICON: 391 392 return ConvertIconGroup((IconHeader *)win32res, ressize, module); 392 393 393 394 case NTRT_ICON: 394 395 return ConvertIcon((WINBITMAPINFOHEADER *)win32res, ressize, &cvtressize); 395 396 396 397 case NTRT_ACCELERATORS: 397 398 return ConvertAccelerator((WINACCEL *)win32res, ressize); 398 399 399 400 case NTRT_NEWMENU: 400 401 case NTRT_MENU: 401 402 return ConvertMenu((MenuHeader *)win32res, ressize, isUnicode); 402 403 403 404 case NTRT_NEWDIALOG: 404 405 case NTRT_DIALOG: 405 406 break; 406 407 case NTRT_FONTDIR: 407 408 case NTRT_FONT: … … 410 411 case NTRT_VERSION: 411 412 case NTRT_STRING: 412 413 break; 413 414 414 415 default:
Note:
See TracChangeset
for help on using the changeset viewer.