Changeset 12458
- Timestamp:
- Nov 29, 1999, 1:05:03 AM (25 years ago)
- 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 sandervlExp $ */1 /* $Id: winimagebase.h,v 1.6 1999-11-29 00:05:03 bird Exp $ */ 2 2 3 3 /* … … 24 24 #define ID_GETFIRST LANG_GETFIRST 25 25 #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 26 35 27 36 class Win32Resource; … … 59 68 virtual ULONG getResourceSizeA(LPCSTR lpszName, LPSTR lpszType, ULONG lang = LANG_GETFIRST); 60 69 ULONG getResourceSizeW(LPCWSTR lpszName, LPWSTR lpszType, ULONG lang = LANG_GETFIRST); 70 virtual BOOL enumResourceNamesA(HMODULE hmod, LPCTSTR lpszType, ENUMRESNAMEPROCA lpEnumFunc, LONG lParam); 71 virtual BOOL enumResourceNamesW(HMODULE hmod, LPCWSTR lpszType, ENUMRESNAMEPROCW lpEnumFunc, LONG lParam); 61 72 62 73 virtual ULONG getVersionSize(); … … 71 82 void setTLSInitSize(ULONG dwTlsSize) { tlsInitSize = dwTlsSize; }; 72 83 void setTLSTotalSize(ULONG dwTlsSize) { tlsTotalSize = dwTlsSize; }; 73 void setTLSCallBackAddr(PIMAGE_TLS_CALLBACK *dwTlsCallBackAddr) 84 void setTLSCallBackAddr(PIMAGE_TLS_CALLBACK *dwTlsCallBackAddr) 74 85 { 75 86 tlsCallBackAddr = dwTlsCallBackAddr; … … 83 94 84 95 virtual BOOL isDll() = 0; 96 97 static Win32ImageBase * findModule(HMODULE hModule); 85 98 86 99 protected: … … 110 123 PIMAGE_RESOURCE_DATA_ENTRY ProcessResSubDir(PIMAGE_RESOURCE_DIRECTORY prdType, 111 124 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 112 128 PIMAGE_RESOURCE_DIRECTORY pResDir; 113 129 114 130 //substracted from RVA data offsets 115 ULONG pResourceSectionStart;131 ULONG ulRVAResourceSection; 116 132 117 133 private: … … 121 137 }; 122 138 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 124 140 // page), so we can determine the Win32Image pointer from a HINSTANCE variable 125 141 // (which is actually the address of the win32 module) 126 typedef struct 142 typedef struct 127 143 { 128 ULONG magic1; 144 ULONG magic1; 129 145 Win32ImageBase *image; 130 ULONG magic2; 146 ULONG magic2; 131 147 } WINIMAGE_LOOKUP; 132 148 -
TabularUnified tags/trunk/src/kernel32/makefile ¶
r12433 r12458 1 # $Id: makefile,v 1.6 3 1999-11-26 08:17:40 achimhaExp $1 # $Id: makefile,v 1.64 1999-11-29 00:04:05 bird Exp $ 2 2 3 3 # … … 70 70 @echo Creating file <<$(@B).lrf 71 71 $(OBJS) 72 $(PDWIN32_LIB)\odincrt.lib 72 73 $(PDWIN32_LIB)\PMWINX.LIB 73 74 $(PDWIN32_LIB)\LIBULS.LIB 74 75 $(PDWIN32_LIB)\LIBCONV.LIB 75 $(PDWIN32_LIB)\odincrt.lib76 76 OS2386.LIB 77 77 $(RTLLIB_O) -
TabularUnified tags/trunk/src/kernel32/resource.cpp ¶
r11548 r12458 1 /* $Id: resource.cpp,v 1. 9 1999-09-15 23:38:01 sandervlExp $ */1 /* $Id: resource.cpp,v 1.10 1999-11-29 00:04:05 bird Exp $ */ 2 2 3 3 /* … … 27 27 28 28 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); 36 30 if(module == NULL) 37 31 return(NULL); 38 32 39 33 return module->findResourceA(lpszName, (LPSTR)lpszType); … … 42 36 //****************************************************************************** 43 37 HRSRC WIN32API FindResourceW(HINSTANCE hModule, LPCWSTR lpszName, 44 38 LPCWSTR lpszType) 45 39 { 46 40 Win32ImageBase *module; 47 41 48 42 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); 56 44 if(module == NULL) 57 45 return(NULL); 58 46 59 47 return module->findResourceW((LPWSTR)lpszName, (LPWSTR)lpszType); … … 77 65 /* @@@PH */ 78 66 if (HIWORD(res) == NULL) { 79 80 67 dprintf(("LoadResource %x: invalid hRes %x", hModule, hRes)); 68 return 0; 81 69 } 82 70 else return (HGLOBAL)res->lockResource(); … … 96 84 } 97 85 //****************************************************************************** 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 */ 106 BOOL WIN32API EnumResourceNamesA(HINSTANCE hModule, 107 LPCTSTR lpszType, 108 ENUMRESNAMEPROCA lpEnumFunc, 109 LONG lParam) 101 110 { 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); 104 125 } 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 */ 145 BOOL 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 sandervlExp $ */1 /* $Id: stubs.cpp,v 1.8 1999-11-29 00:04:05 bird Exp $ */ 2 2 3 3 /* … … 1518 1518 1519 1519 1520 /*****************************************************************************1521 * Name : BOOL WIN32API EnumResourceNamesW1522 * Purpose : The EnumResourceNames function searches a module for each1523 * resource of the specified type and passes the name of each1524 * resource it locates to an application-defined callback function1525 * Parameters: HINSTANCE hModule resource-module handling1526 * LPCTSTR lpszType pointer to resource type1527 * ENUMRESNAMEPROC lpEnumFunc pointer to callback function1528 * LONG lParam application-defined parameter1529 * Variables :1530 * Result : If the function succeeds, the return value is nonzero.1531 * If the function fails, the return value is zero1532 * Remark : The EnumResourceNames function continues to enumerate resource1533 * names until the callback function returns FALSE or all resource1534 * names have been enumerated1535 * Status : UNTESTED STUB1536 *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 lParam1551 ));1552 1553 return (FALSE);1554 }1555 1520 1556 1521 /***************************************************************************** -
TabularUnified tags/trunk/src/kernel32/winimagebase.cpp ¶
r12249 r12458 1 /* $Id: winimagebase.cpp,v 1. 4 1999-11-09 14:19:47 sandervlExp $ */1 /* $Id: winimagebase.cpp,v 1.5 1999-11-29 00:04:06 bird Exp $ */ 2 2 3 3 /* … … 42 42 Win32ImageBase::Win32ImageBase(HINSTANCE hInstance) : 43 43 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), 45 45 tlsCallBackAddr(0), tlsIndex(-1), winres(NULL), pResDir(NULL), 46 pResourceSectionStart(0)46 ulRVAResourceSection(0) 47 47 { 48 48 #ifdef DEBUG … … 51 51 52 52 if(hInstance != -1) { 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 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; 68 68 } 69 69 else { 70 71 70 szModule[0] = 0; 71 this->hinstance = -1; 72 72 } 73 73 } … … 80 80 while(winres) 81 81 { 82 83 84 82 res = winres->next; 83 delete(winres); 84 winres = res; 85 85 } 86 86 if(fullpath) 87 87 free(fullpath); 88 88 } 89 89 //****************************************************************************** … … 116 116 strupr(filename); 117 117 if(!strchr(filename, (int)'.')) { 118 118 strcat(filename,".DLL"); 119 119 } 120 120 dllfile = OSLibDosOpen(filename, OSLIB_ACCESS_READONLY|OSLIB_ACCESS_SHAREDENYNONE); 121 121 if(dllfile == NULL) {//search in libpath for dll 122 123 124 125 } 126 else 122 strcpy(modname, kernel32Path); 123 strcat(modname, filename); 124 strcpy(filename, modname); 125 } 126 else OSLibDosClose(dllfile); 127 127 128 128 rc = DosOpen(filename, /* File path name */ … … 140 140 if (rc != NO_ERROR) 141 141 { 142 143 144 142 dprintf(("KERNEL32:Win32ImageBase::isPEImage(%s) failed with %u\n", 143 szFileName, rc)); 144 return(FALSE); 145 145 } 146 146 … … 150 150 IMAGE_DOS_HEADER *pdoshdr = (IMAGE_DOS_HEADER *)malloc(sizeof(IMAGE_DOS_HEADER)); 151 151 if(pdoshdr == NULL) { 152 153 152 DosClose(win32handle); /* Close the file */ 153 return(FALSE); 154 154 } 155 155 rc = DosRead(win32handle, pdoshdr, sizeof(IMAGE_DOS_HEADER), &ulRead); 156 156 if(rc != NO_ERROR) { 157 158 157 DosClose(win32handle); /* Close the file */ 158 return(FALSE); 159 159 } 160 160 ULONG hdrsize = pdoshdr->e_lfanew + SIZE_OF_NT_SIGNATURE + sizeof(IMAGE_FILE_HEADER); … … 166 166 win32file = malloc(hdrsize); 167 167 if(win32file == NULL) { 168 169 168 DosClose(win32handle); /* Close the file */ 169 return(FALSE); 170 170 } 171 171 rc = DosRead(win32handle, win32file, hdrsize, &ulRead); 172 172 if(rc != NO_ERROR) { 173 173 goto failure; 174 174 } 175 175 176 176 if(GetPEFileHeader (win32file, &fh) == FALSE) { 177 177 goto failure; 178 178 } 179 179 180 180 if(!(fh.Characteristics & IMAGE_FILE_EXECUTABLE_IMAGE)) {//not valid 181 181 goto failure; 182 182 } 183 183 if(fh.Machine != IMAGE_FILE_MACHINE_I386) { 184 184 goto failure; 185 185 } 186 186 //IMAGE_FILE_SYSTEM == only drivers (device/file system/video etc)? 187 187 if(fh.Characteristics & IMAGE_FILE_SYSTEM) { 188 188 goto failure; 189 189 } 190 190 DosClose(win32handle); … … 198 198 //****************************************************************************** 199 199 //****************************************************************************** 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 */ 207 Win32ImageBase * 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 sandervlExp $ */1 /* $Id: winimagelx.cpp,v 1.5 1999-11-29 00:04:06 bird Exp $ */ 2 2 3 3 /* … … 40 40 //****************************************************************************** 41 41 //****************************************************************************** 42 Win32LxImage::Win32LxImage(HINSTANCE hInstance, PVOID pResData) 42 Win32LxImage::Win32LxImage(HINSTANCE hInstance, PVOID pResData) 43 43 : Win32ImageBase(hInstance) 44 44 { … … 56 56 pResDir = (PIMAGE_RESOURCE_DIRECTORY)pResData; 57 57 58 // pResourceSectionStartcontains the virtual address of the imagebase in the PE header58 //ulRVAResourceSection contains the virtual address of the imagebase in the PE header 59 59 //for the resource section (images loaded by the pe.exe) 60 60 //For LX images, this is 0 as OffsetToData contains a relative offset 61 pResourceSectionStart= 0;61 ulRVAResourceSection = 0; 62 62 } 63 63 //****************************************************************************** … … 74 74 75 75 rc = DosQueryProcAddr(hinstance, 0, name, (PFN *)&apiaddr); 76 if(rc) 76 if(rc) 77 77 { 78 if(rc == ERROR_INVALID_HANDLE) 78 if(rc == ERROR_INVALID_HANDLE) 79 79 {//handle invalid for some silly reason, so load module again (initterm entrypoint not called twice) 80 80 char szErrName[CCHMAXPATH]; … … 97 97 rc = DosQueryProcAddr(hinstance, ordinal, NULL, (PFN *)&apiaddr); 98 98 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. 101 104 char szErrName[CCHMAXPATH]; 102 105 -
TabularUnified tags/trunk/src/kernel32/winimagepe2lx.cpp ¶
r12430 r12458 1 /* $Id: winimagepe2lx.cpp,v 1. 6 1999-11-26 00:05:19 sandervlExp $ */1 /* $Id: winimagepe2lx.cpp,v 1.7 1999-11-29 00:04:06 bird Exp $ */ 2 2 3 3 /* … … 16 16 #define INCL_DOSERRORS /* DOS Error values */ 17 17 #define INCL_DOSPROFILE /* DosQuerySysState (Toolkit 4.5) */ 18 #define INCL_DOSMODULEMGR /* DOS Module management */18 #define INCL_DOSMODULEMGR /* DOS Module management */ 19 19 20 20 #define ALIGN(a, alignment) (((a) + (alignment - 1UL)) & ~(alignment - 1UL)) … … 152 152 * Read the PE section table the set the RVAs in paSections. 153 153 * Locate and set the entrypoint. 154 * Locate the resource directory (if any). (pResDir, pResourceSectionStart)154 * Locate the resource directory (if any). (pResDir, ulRVAResourceSection) 155 155 * TLS - FIXME! 156 156 * @status completely implemented. … … 236 236 && pNtHdrs->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_RESOURCE].VirtualAddress > 0UL) 237 237 { 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); 240 240 } 241 241 -
TabularUnified tags/trunk/src/kernel32/winimagepeldr.cpp ¶
r12439 r12458 1 /* $Id: winimagepeldr.cpp,v 1.1 8 1999-11-27 00:05:39 sandervlExp $ */1 /* $Id: winimagepeldr.cpp,v 1.19 1999-11-29 00:04:06 bird Exp $ */ 2 2 3 3 /* … … 279 279 nSections = NR_SECTIONS(win32file); 280 280 281 if(loadType == REAL_LOAD) 281 if(loadType == REAL_LOAD) 282 282 { 283 283 imageSize = 0; … … 389 389 } 390 390 else { 391 if(GetSectionHdrByName (win32file, &sh, ".rsrc")) 391 if(GetSectionHdrByName (win32file, &sh, ".rsrc")) 392 392 { 393 393 addSection(SECTION_RESOURCE, sh.PointerToRawData, … … 407 407 imageSize = imageVirtEnd - oh.ImageBase; 408 408 } 409 if(imageSize < oh.SizeOfImage) { 409 if(imageSize < oh.SizeOfImage) { 410 410 imageSize = oh.SizeOfImage; 411 411 } … … 416 416 } 417 417 else { 418 fout << "EntryPoint == NULL" << endl; 418 fout << "EntryPoint == NULL" << endl; 419 419 entryPoint = NULL; 420 420 } … … 426 426 } 427 427 428 if(loadType == REAL_LOAD) 428 if(loadType == REAL_LOAD) 429 429 { 430 430 if(tlsDir != NULL) { … … 485 485 //get offset in resource object of directory entry 486 486 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) 491 491 { 492 492 if(processImports((char *)win32file) == FALSE) { … … 495 495 } 496 496 } 497 497 498 498 return(TRUE); 499 499 failure: … … 543 543 fileoffset = section->rawoffset + section->rawsize + offset; 544 544 } 545 } 545 } 546 546 else { 547 547 protflags = section->pageflags; … … 552 552 size = 0; 553 553 fileoffset = -1; 554 } 554 } 555 555 else { 556 556 size = section->rawsize-offset; … … 709 709 } 710 710 } 711 if(index == -1) 711 if(index == -1) 712 712 return NULL; 713 713 … … 804 804 805 805 for(i=0;i<nrsections;i++) { 806 switch(section[i].type) 806 switch(section[i].type) 807 807 { 808 808 case SECTION_CODE: … … 855 855 int fixupsize = 0; 856 856 857 switch(type) 857 switch(type) 858 858 { 859 859 case IMAGE_REL_BASED_HIGHLOW: … … 864 864 fixupsize = 2; 865 865 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) 870 870 { 871 871 newpage = realBaseAddress + prel->VirtualAddress + offset + fixupsize; … … 877 877 dprintf(("::setFixups -> section == NULL!!")); 878 878 return FALSE; 879 } 879 } 880 880 //SvL: Read page from disk 881 881 commitPage(newpage, TRUE, SINGLE_PAGE); … … 885 885 } 886 886 887 switch(type) 887 switch(type) 888 888 { 889 889 case IMAGE_REL_BASED_ABSOLUTE: … … 903 903 break; 904 904 } 905 if(prel->VirtualAddress + offset + fixupsize > virtAddress + size) 905 if(prel->VirtualAddress + offset + fixupsize > virtAddress + size) 906 906 { 907 907 //SvL: Restore original page protection flags … … 1308 1308 { //not found, so load it 1309 1309 char modname[CCHMAXPATH]; 1310 1310 1311 1311 strcpy(modname, pszCurModule); 1312 1312 //rename dll if necessary (i.e. OLE32 -> OLE32OS2) … … 1441 1441 NameExport *curexport; 1442 1442 ULONG ulAPIOrdinal; /* api requested by ordinal */ 1443 1443 1444 1444 apilen = strlen(name) + 1; 1445 if(apilen < 4) 1445 if(apilen < 4) 1446 1446 { 1447 1447 *(ULONG *)tmp = 0; … … 1452 1452 1453 1453 curexport = nameexports; 1454 for(i=0; i<nrNameExports; i++) 1454 for(i=0; i<nrNameExports; i++) 1455 1455 { 1456 if(apilen == curexport->nlength && 1457 *(ULONG *)curexport->name == *(ULONG *)name) 1456 if(apilen == curexport->nlength && 1457 *(ULONG *)curexport->name == *(ULONG *)name) 1458 1458 { 1459 if(strcmp(curexport->name, name) == 0) 1459 if(strcmp(curexport->name, name) == 0) 1460 1460 return(curexport->virtaddr); 1461 1461 } … … 1478 1478 curexport++; 1479 1479 } 1480 //Name exports also contain an ordinal, so check this 1480 //Name exports also contain an ordinal, so check this 1481 1481 nexport = nameexports; 1482 1482 for(i=0;i<nrNameExports;i++) { -
TabularUnified tags/trunk/src/kernel32/winimgres.cpp ¶
r12201 r12458 1 /* $Id: winimgres.cpp,v 1.2 6 1999-11-05 12:54:50 sandervlExp $ */1 /* $Id: winimgres.cpp,v 1.27 1999-11-29 00:04:07 bird Exp $ */ 2 2 3 3 /* … … 22 22 #include <misc.h> 23 23 #include <winimagebase.h> 24 #include <winimagepe2lx.h>25 #include <winimagepeldr.h>26 #include <winimagelx.h>27 24 #include <winres.h> 28 25 #include <unicode.h> … … 270 267 return 0; 271 268 } 272 // pResourceSectionStart contains the virtual address of the imagebase in the PE header273 //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) 274 271 //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); 276 273 res = new Win32Resource(this, id, type, pData->Size, resdata); 277 274 … … 385 382 return 0; 386 383 } 387 char *resdata = (char *)((char *)pResDir + pData->OffsetToData - pResourceSectionStart);384 char *resdata = (char *)((char *)pResDir + pData->OffsetToData - ulRVAResourceSection); 388 385 memcpy(verstruct, resdata, min(bufLength, pData->Size)); 389 386 return TRUE; 390 387 } 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 */ 423 BOOL 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 */ 544 BOOL 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 */ 619 PIMAGE_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 */ 682 PIMAGE_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.