- Timestamp:
- Sep 13, 2000, 12:45:19 AM (25 years ago)
- Location:
- trunk/src/kernel32
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/winimagebase.cpp
r4003 r4249 1 /* $Id: winimagebase.cpp,v 1.2 5 2000-08-12 16:58:40 sandervlExp $ */1 /* $Id: winimagebase.cpp,v 1.26 2000-09-12 22:45:19 bird Exp $ */ 2 2 3 3 /* … … 5 5 * 6 6 * Copyright 1998-1999 Sander van Leeuwen (sandervl@xs4all.nl) 7 * Copyright 1998 Knut St. Osmundsen7 * Copyright 1998-2000 knut st. osmundsen (knut.stange.osmundsen@mynd.no) 8 8 * 9 9 * Project Odin Software License can be found in LICENSE.TXT … … 39 39 #include <winconst.h> 40 40 41 #define DBG_LOCALLOG 41 #define DBG_LOCALLOG DBG_winimagebase 42 42 #include "dbglocal.h" 43 43 … … 107 107 item = loadedDlls.Head(); 108 108 while(item) { 109 110 111 112 } 113 109 if(loadedDlls.getItem(item) == (ULONG)image) { 110 ret = TRUE; 111 break; 112 } 113 item = loadedDlls.getNext(item); 114 114 } 115 115 dlllistmutex.leave(); … … 147 147 //****************************************************************************** 148 148 //****************************************************************************** 149 BOOL Win32ImageBase::findDll(const char *szFileName, char *szFullName, 149 BOOL Win32ImageBase::findDll(const char *szFileName, char *szFullName, 150 150 int cchFullFileName, const char *pszAltPath) 151 151 { … … 157 157 strupr(szFullName); 158 158 if(!strchr(szFullName, (int)'.')) { 159 159 strcat(szFullName,".DLL"); 160 160 } 161 161 … … 167 167 //5) path 168 168 if(WinExe) { 169 170 171 172 173 174 175 169 strcpy(modname, WinExe->getFullPath()); 170 //remove file name from full path 171 imagepath = modname + strlen(modname) - 1; 172 while(*imagepath != '\\') imagepath--; 173 imagepath[1] = 0; 174 strcat(modname, szFullName); 175 dllfile = OSLibDosOpen(modname, OSLIB_ACCESS_READONLY|OSLIB_ACCESS_SHAREDENYNONE); 176 176 } 177 177 if(dllfile == NULL) { 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 178 strcpy(modname, szFullName); 179 dllfile = OSLibDosOpen(szFullName, OSLIB_ACCESS_READONLY|OSLIB_ACCESS_SHAREDENYNONE); 180 if(dllfile == NULL) { 181 strcpy(modname, InternalGetSystemDirectoryA()); 182 strcat(modname, "\\"); 183 strcat(modname, szFullName); 184 dllfile = OSLibDosOpen(modname, OSLIB_ACCESS_READONLY|OSLIB_ACCESS_SHAREDENYNONE); 185 if(dllfile == NULL) { 186 strcpy(modname, InternalGetWindowsDirectoryA()); 187 strcat(modname, "\\"); 188 strcat(modname, szFullName); 189 dllfile = OSLibDosOpen(modname, OSLIB_ACCESS_READONLY|OSLIB_ACCESS_SHAREDENYNONE); 190 if(dllfile == NULL) { 191 if(OSLibDosSearchPath(OSLIB_SEARCHENV, "PATH", szFullName, modname, sizeof(modname)) == 0) { 192 return FALSE; 193 } 194 } 195 } 196 } 197 197 } 198 198 strcpy(szFullName, modname); … … 200 200 return TRUE; 201 201 } 202 202 203 //****************************************************************************** 203 204 //returns ERROR_SUCCESS or error code … … 252 253 rc = DosRead(win32handle, pdoshdr, sizeof(IMAGE_DOS_HEADER), &ulRead); 253 254 if(rc != NO_ERROR || ulRead != sizeof(IMAGE_DOS_HEADER)) { 254 255 free(pdoshdr); 255 256 DosClose(win32handle); /* Close the file */ 256 257 return ERROR_INVALID_EXE_SIGNATURE_W; 257 258 } 258 259 if(pdoshdr->e_magic != IMAGE_DOS_SIGNATURE) { 259 260 free(pdoshdr); 260 261 DosClose(win32handle); /* Close the file */ 261 262 return ERROR_INVALID_EXE_SIGNATURE_W; … … 331 332 332 333 334 /** 335 * Matches a given filename or module name with the module name of 336 * this object. 337 * @returns TRUE: The modulenames matches. 338 * FALSE: Don't match. 339 * @param pszFilename Pointer to filename or module name. 340 * @status completely implemented. 341 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no) 342 * @remark Just a clarification: 343 * A module name is the filename of a executable image without 344 * path and without extention. 345 */ 346 BOOL Win32ImageBase::matchModName(const char *pszFilename) const 347 { 348 const char *pszModName; /* Pointer to the modulename. */ 349 const char *pszModNameEnd = NULL; /* Pointer to the dot starting the extention. (if any) */ 350 register char ch; 351 352 /** @sketch 353 * Search the filename string finding the modulename start and end. 354 * The loop ends when we have passed one char left of the module name. 355 */ 356 pszModName = pszFilename + strlen(pszFilename) - 1; 357 while (pszModName >= pszFilename 358 && (ch = *pszModName) != '\\' 359 && ch != '/' 360 && ch != ':' 361 ) 362 { 363 if (ch == '.' && pszModNameEnd != NULL) 364 pszModName = pszModName; 365 pszModName--; 366 } 367 pszModName++; 368 369 /** @sketch 370 * Compare the names caseinsensitivly. 371 */ 372 if (pszModNameEnd) 373 return strnicmp(pszModName, szModule, pszModNameEnd - pszModName) == 0; 374 return stricmp(pszModName, szModule) == 0; 375 } -
trunk/src/kernel32/winimagebase.h
r4224 r4249 1 /* $Id: winimagebase.h,v 1.1 5 2000-09-08 18:07:51 sandervlExp $ */1 /* $Id: winimagebase.h,v 1.16 2000-09-12 22:45:19 bird Exp $ */ 2 2 3 3 /* … … 5 5 * 6 6 * Copyright 1998-1999 Sander van Leeuwen (sandervl@xs4all.nl) 7 * Copyright 1999-2000 knut st. osmundsen (knut.stange.osmundsen@mynd.no) 7 8 * 8 9 * … … 41 42 class Win32DllBase; 42 43 44 43 45 class Win32ImageBase 44 46 { … … 46 48 DWORD magic; 47 49 public: 48 49 50 if(magic != MAGIC_WINIMAGE) {51 52 53 54 50 void checkObject() 51 { 52 if (magic != MAGIC_WINIMAGE) { 53 eprintf(("Corrupt this pointer %X %X!!", this, magic)); 54 DebugInt3(); 55 } 56 }; 55 57 56 58 public: … … 59 61 virtual ~Win32ImageBase(); 60 62 61 62 63 ULONG getError() { return errorState; }; 64 HINSTANCE getInstanceHandle() { return hinstance; }; 63 65 64 66 //Returns required OS version for this image … … 66 68 67 69 virtual void setFullPath(char *name); 68 char *getFullPath() { return fullpath; }; 69 70 char *getModuleName() { return szModule; }; 70 char *getFullPath() { return fullpath; }; 71 char *getModuleName() { return szModule; }; 71 72 72 73 //findResource returns the pointer of the resource's IMAGE_RESOURCE_DATA_ENTRY structure 73 74 74 HRSRC findResourceA(LPCSTR lpszName, LPSTR lpszType, ULONG lang = MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL)); 75 HRSRC findResourceW(LPWSTR lpszName, LPWSTR lpszType, ULONG lang = MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL)); 75 76 76 77 78 79 80 BOOL enumResourceTypesA(HMODULE hmod, ENUMRESTYPEPROCA lpEnumFunc, 81 82 BOOL enumResourceTypesW(HMODULE hmod, ENUMRESTYPEPROCW lpEnumFunc, 83 84 BOOL enumResourceLanguagesA(HMODULE hmod, LPCSTR lpType, LPCSTR lpName, 85 86 BOOL enumResourceLanguagesW(HMODULE hmod, LPCWSTR lpType, LPCWSTR lpName, 87 77 ULONG getResourceSizeA(LPSTR lpszName, LPSTR lpszType, ULONG lang = MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL)); 78 ULONG getResourceSizeW(LPWSTR lpszName, LPWSTR lpszType, ULONG lang = MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL)); 79 BOOL enumResourceNamesA(HMODULE hmod, LPCTSTR lpszType, ENUMRESNAMEPROCA lpEnumFunc, LONG lParam); 80 BOOL enumResourceNamesW(HMODULE hmod, LPCWSTR lpszType, ENUMRESNAMEPROCW lpEnumFunc, LONG lParam); 81 BOOL enumResourceTypesA(HMODULE hmod, ENUMRESTYPEPROCA lpEnumFunc, 82 LONG lParam); 83 BOOL enumResourceTypesW(HMODULE hmod, ENUMRESTYPEPROCW lpEnumFunc, 84 LONG lParam); 85 BOOL enumResourceLanguagesA(HMODULE hmod, LPCSTR lpType, LPCSTR lpName, 86 ENUMRESLANGPROCA lpEnumFunc, LONG lParam); 87 BOOL enumResourceLanguagesW(HMODULE hmod, LPCWSTR lpType, LPCWSTR lpName, 88 ENUMRESLANGPROCW lpEnumFunc, LONG lParam); 88 89 89 90 90 ULONG getVersionSize(); 91 BOOL getVersionStruct(char *verstruct, ULONG bufLength); 91 92 92 93 94 93 //Returns pointer to data of resource handle 94 char *getResourceAddr(HRSRC hResource); 95 ULONG getResourceSize(HRSRC hResource); 95 96 96 97 //returns ERROR_SUCCESS or error code 97 98 static ULONG isPEImage(char *szFileName); 98 99 static BOOL findDll(const char *pszFileName, char *pszFullName, 99 100 int cchFullName, const char *pszAltPath = NULL); 100 101 101 void setEntryPoint(ULONG startAddress){ entryPoint = startAddress; };102 void setEntryPoint(ULONG startAddress) { entryPoint = startAddress; }; 102 103 103 void setTLSAddress(LPVOID dwTlsAddress){ tlsAddress = dwTlsAddress; };104 void setTLSIndexAddr(LPDWORD dwTlsIndexAddr){ tlsIndexAddr = dwTlsIndexAddr; };105 void setTLSInitSize(ULONG dwTlsSize){ tlsInitSize = dwTlsSize; };106 void setTLSTotalSize(ULONG dwTlsSize){ tlsTotalSize = dwTlsSize; };107 108 109 110 104 void setTLSAddress(LPVOID dwTlsAddress) { tlsAddress = dwTlsAddress; }; 105 void setTLSIndexAddr(LPDWORD dwTlsIndexAddr) { tlsIndexAddr = dwTlsIndexAddr; }; 106 void setTLSInitSize(ULONG dwTlsSize) { tlsInitSize = dwTlsSize; }; 107 void setTLSTotalSize(ULONG dwTlsSize) { tlsTotalSize = dwTlsSize; }; 108 void setTLSCallBackAddr(PIMAGE_TLS_CALLBACK *dwTlsCallBackAddr) 109 { 110 tlsCallBackAddr = dwTlsCallBackAddr; 111 }; 111 112 112 void tlsAttachThread();//setup TLS structures for new thread113 void tlsDetachThread();//destroy TLS structures113 void tlsAttachThread(); //setup TLS structures for new thread 114 void tlsDetachThread(); //destroy TLS structures 114 115 115 116 virtual BOOL insideModule(ULONG address); 116 117 virtual BOOL insideModuleCode(ULONG address); 117 118 118 virtual 119 virtual ULONG getApi(char *name) = 0; 119 120 virtual ULONG getApi(int ordinal) = 0; 120 121 … … 124 125 125 126 static Win32ImageBase * findModule(HMODULE hModule); 127 BOOL matchModName(const char *pszFilename) const; 126 128 127 //Add image to dependency list of this image 128 void addDependency(Win32DllBase *dll); 129 BOOL dependsOn(Win32DllBase *dll); 129 /* @cat Depencies */ 130 //Add image to dependency list of this image 131 void addDependency(Win32DllBase *dll); 132 BOOL dependsOn(Win32DllBase *dll); 130 133 131 134 protected: 132 void tlsAlloc();//Allocate TLS index for this module133 void tlsDelete();//Destroy TLS index for this module135 void tlsAlloc(); //Allocate TLS index for this module 136 void tlsDelete(); //Destroy TLS index for this module 134 137 135 ULONG errorState, entryPoint; 138 ULONG errorState, 139 entryPoint; 136 140 137 char *fullpath;138 charszModule[CCHMAXPATH];139 charszFileName[CCHMAXPATH];141 char * fullpath; 142 char szModule[CCHMAXPATH]; 143 char szFileName[CCHMAXPATH]; 140 144 141 HINSTANCEhinstance;145 HINSTANCE hinstance; 142 146 143 LPVOID tlsAddress;//address of TLS data144 LPDWORD tlsIndexAddr;//address of DWORD that receives the TLS index145 ULONG tlsInitSize;//size of initialized TLS memory block146 ULONG tlsTotalSize;//size of TLS memory block147 PIMAGE_TLS_CALLBACK *tlsCallBackAddr;//ptr to TLS callback array148 ULONG tlsIndex;//module TLS index147 LPVOID tlsAddress; //address of TLS data 148 LPDWORD tlsIndexAddr; //address of DWORD that receives the TLS index 149 ULONG tlsInitSize; //size of initialized TLS memory block 150 ULONG tlsTotalSize; //size of TLS memory block 151 PIMAGE_TLS_CALLBACK * tlsCallBackAddr; //ptr to TLS callback array 152 ULONG tlsIndex; //module TLS index 149 153 150 151 154 PIMAGE_RESOURCE_DIRECTORY getResSubDirW(PIMAGE_RESOURCE_DIRECTORY pResDir, LPCWSTR lpszName); 155 PIMAGE_RESOURCE_DIRECTORY getResSubDirA(PIMAGE_RESOURCE_DIRECTORY pResDir, LPCTSTR lpszName); 152 156 153 157 PIMAGE_RESOURCE_DATA_ENTRY getResDataLang(PIMAGE_RESOURCE_DIRECTORY pResDir, ULONG language, BOOL fGetDefault = FALSE); 154 158 155 156 157 159 HRSRC getResourceLang(PIMAGE_RESOURCE_DIRECTORY pResDirToSearch); 160 HRSRC getResourceLangEx(PIMAGE_RESOURCE_DIRECTORY pResDirToSearch, 161 DWORD lang); 158 162 159 PIMAGE_RESOURCE_DIRECTORYpResRootDir;163 PIMAGE_RESOURCE_DIRECTORY pResRootDir; 160 164 161 162 ULONGulRVAResourceSection;165 //substracted from RVA data offsets 166 ULONG ulRVAResourceSection; 163 167 164 //linked list of dlls loaded on behalf of this executable image (dll or exe) 165 Queue loadedDlls; 168 //linked list of dlls loaded on behalf of this executable image (dll or exe) 169 Queue loadedDlls; 170 166 171 private: 167 168 friend class Win32Resource; 169 friend ULONG SYSTEM GetVersionSize(char *modname); 172 friend class Win32Resource; 173 friend ULONG SYSTEM GetVersionSize(char *modname); 170 174 }; 171 175 … … 180 184 } WINIMAGE_LOOKUP; 181 185 182 #define WINIMAGE_LOOKUPADDR(a) 186 #define WINIMAGE_LOOKUPADDR(a) (WINIMAGE_LOOKUP *)((ULONG)a + PAGE_SIZE - sizeof(WINIMAGE_LOOKUP)) 183 187 184 188 #endif //__WINIMAGEBASE_H__
Note:
See TracChangeset
for help on using the changeset viewer.