source: trunk/src/win32k/ldr/myldrCheckInternalName.cpp@ 4779

Last change on this file since 4779 was 4779, checked in by bird, 25 years ago

Support for long DLL names and DLL extentions different from .DLL.

File size: 5.1 KB
Line 
1/* $Id: myldrCheckInternalName.cpp,v 1.1 2000-12-11 06:31:52 bird Exp $
2 *
3 * ldrCheckInternalName - ldrCheckInternalName replacement with support for
4 * long DLL names and no .DLL-extention dependency.
5 *
6 * Copyright (c) 1999-2000 knut st. osmundsen (knut.stange.osmundsen@mynd.no)
7 *
8 * Project Odin Software License can be found in LICENSE.TXT
9 *
10 */
11
12
13/*******************************************************************************
14* Defined Constants And Macros *
15*******************************************************************************/
16#define INCL_DOSERRORS
17#define INCL_NOPMAPI
18
19
20/*******************************************************************************
21* Header Files *
22*******************************************************************************/
23#include <os2.h>
24
25#include <memory.h>
26#include <stdlib.h>
27#include <string.h>
28
29#include "devSegDf.h" /* Win32k segment definitions. */
30#include "log.h"
31#include "avl.h"
32#include <peexe.h>
33#include <exe386.h>
34#include "OS2Krnl.h"
35#include "dev32.h"
36#include "ldr.h"
37#include "ldrCalls.h"
38#include "options.h"
39
40
41/**
42 * Checks if the internal name (first name in the resident nametable) matches
43 * the filename.
44 *
45 * This replacement will support DLLs with non DLL extention
46 * and names that are longer than 8 chars.
47 *
48 * @returns NO_ERROR on success (the name matched).
49 * ERROR_INVALID_NAME if mismatch.
50 * @param pMTE Pointer to the MTE of the module to check.<br>
51 * Assumes! that the filename for this module is present in ldrpFileNameBuf.
52 * @sketch Check if library module - this check only applies to library modules (ie. DLLs).
53 * Uppercase filename.
54 * Parse filename - get the length of the name including any extention different from .DLL.
55 * Compare internal name and filename returning NO_ERROR if matches and errorcode if mismatch.
56 * If this module is not in the GLOBAL CLASS we don't compare the extention.
57 *
58 * @remark This function will have to change slightly when we're starting to
59 * support ELF shared libraries.
60 */
61ULONG LDRCALL myldrCheckInternalName(PMTE pMTE)
62{
63 /* Check if this feature is enabled */
64 if (isDllFixesDisabled())
65 {
66 #ifdef DEBUG
67 APIRET rc = ldrCheckInternalName(pMTE);
68 kprintf(("ldrCheckInternalName: pMTE=0x%08x intname=%.*s path=%s rc=%d (original)\n",
69 pMTE, *(PCHAR)pMTE->mte_swapmte->smte_restab, (PCHAR)pMTE->mte_swapmte->smte_restab + 1, ldrpFileNameBuf, rc));
70 return rc;
71 #else
72 return ldrCheckInternalName(pMTE);
73 #endif
74 }
75
76 /* Local Variables */
77 PCHAR pachName; /* Pointer to the name part of pachFilename. */
78 int cchName; /* Length of the name part of pachFilename.
79 * Includes extention if extention is not .DLL.
80 * this is the length relative to pachName used to match the internal name. */
81 PCHAR pachExt; /* Pointer to the extention part of pachFilename. (not dot!) */
82 int cchExt; /* Length of the extention part of pachFilename. (not dot!) */
83 PSMTE pSMTE; /* Pointer to swap mte. */
84
85 /* Return successfully if not library module. */
86 if (!(pMTE->mte_flags1 & LIBRARYMOD))
87 return NO_ERROR;
88
89 /* Uppercase and parse filename in ldrpFileNameBuf */
90 cchName = (int)ldrGetFileName2(ldrpFileNameBuf, (PCHAR*)SSToDS(&pachName), (PCHAR*)SSToDS(&pachExt));
91 cchExt = (pachExt) ? strlen(pachExt) : 0;
92 ldrUCaseString(pachName, cchName + cchExt + 1);
93 if ((pMTE->mte_flags1 & CLASS_MASK) == CLASS_GLOBAL && (cchExt != 3 || memcmp(pachExt, "DLL", 3)))
94 cchName += cchExt + 1; /* Internal name includes extention if the extention is not .DLL! */
95 /* If no extention the '.' should still be there! */
96
97 /* Compare the internal name with the filename and return accordingly. */
98 pSMTE = pMTE->mte_swapmte;
99 #ifdef DEBUG
100 APIRET rc =
101 #else
102 return
103 #endif
104 ( pSMTE->smte_restab != NULL
105 && *(PCHAR)pSMTE->smte_restab == cchName
106 && (cchExt == 0 && (pMTE->mte_flags1 & CLASS_MASK) == CLASS_GLOBAL
107 ? !memcmp(pachName, (PCHAR)pSMTE->smte_restab + 1, cchName - 1) /* No extention. Internal name should have a signle dot at the end then. */
108 && ((PCHAR)pSMTE->smte_restab)[cchName] == '.'
109 : !memcmp(pachName, (PCHAR)pSMTE->smte_restab + 1, cchName) /* Extention, .DLL or not global class. */
110 )
111 )
112 ? NO_ERROR
113 : ERROR_INVALID_NAME;
114 #ifdef DEBUG
115 kprintf(("myldrCheckInternalName: pMTE=0x%08x intname=%.*s path=%s rc=%d\n",
116 pMTE, *(PCHAR)pMTE->mte_swapmte->smte_restab, (PCHAR)pMTE->mte_swapmte->smte_restab + 1, ldrpFileNameBuf, rc));
117 return rc;
118 #endif
119}
120
Note: See TracBrowser for help on using the repository browser.