Changeset 1872 for trunk/src/kernel32/winimagebase.cpp
- Timestamp:
- Nov 29, 1999, 1:05:03 AM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/winimagebase.cpp
r1663 r1872 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
Note:
See TracChangeset
for help on using the changeset viewer.