Changeset 10397 for trunk/src/kernel32/winimagelx.cpp
- Timestamp:
- Jan 15, 2004, 11:39:15 AM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/winimagelx.cpp
r9971 r10397 1 /* $Id: winimagelx.cpp,v 1.2 0 2003-04-02 11:03:33sandervl Exp $ */1 /* $Id: winimagelx.cpp,v 1.21 2004-01-15 10:39:11 sandervl Exp $ */ 2 2 3 3 /* … … 5 5 * 6 6 * Copyright 1999-2000 Sander van Leeuwen (sandervl@xs4all.nl) 7 * Copyright 2003 Innotek Systemberatung GmbH (sandervl@innotek.de) 8 * 9 * header adjustment & fixup_rva_ptrs borrowed from Wine (Rewind) 10 * Copyright 2000 Alexandre Julliard 7 11 * 8 12 * TODO: headers not complete 9 * 13 * 10 14 * Project Odin Software License can be found in LICENSE.TXT 11 15 * … … 62 66 63 67 //****************************************************************************** 68 /* adjust an array of pointers to make them into RVAs */ 69 //****************************************************************************** 70 static inline void fixup_rva_ptrs( void *array, void *base, int count ) 71 { 72 void **ptr = (void **)array; 73 while (count--) 74 { 75 if (*ptr) *ptr = (void *)((char *)*ptr - (char *)base); 76 ptr++; 77 } 78 } 79 //****************************************************************************** 64 80 //****************************************************************************** 65 81 Win32LxImage::Win32LxImage(HINSTANCE hInstance, PVOID pResData) 66 : Win32ImageBase(hInstance), header(0) 82 : Win32ImageBase(hInstance), header(0), pCustomPEHeader(0) 67 83 { 68 84 APIRET rc; … … 71 87 szFileName[0] = 0; 72 88 73 this->lpszExportPrefix = NULL; 74 if(lpszCustomDllName) { 75 name = lpszCustomDllName; 76 this->dwOrdinalBase = ::dwOrdinalBase; 77 78 if(lpszCustomExportPrefix) { 79 this->lpszExportPrefix = strdup(::lpszCustomExportPrefix); 80 } 89 if (lpszCustomDllName) { 90 name = lpszCustomDllName; 91 pCustomPEHeader = lpCustomDllPEHdr; 92 93 hinstance = (DWORD)pCustomPEHeader; 94 if (pCustomPEHeader) { 95 //Calculate address of optional header 96 poh = (PIMAGE_OPTIONAL_HEADER)OPTHEADEROFF(pCustomPEHeader); 97 98 //Update the header data to reflect the new load address 99 poh->ImageBase = hinstance; 100 101 PIMAGE_EXPORT_DIRECTORY pExpDir; 102 pExpDir = (PIMAGE_EXPORT_DIRECTORY)((char*)hinstance 103 + poh->DataDirectory[IMAGE_FILE_EXPORT_DIRECTORY].VirtualAddress); 104 fixup_rva_ptrs((char*)hinstance + (unsigned)pExpDir->AddressOfFunctions, 105 (LPVOID)hinstance, 106 pExpDir->NumberOfFunctions ); 107 } 81 108 } 82 109 else { 83 110 name = OSLibGetDllName(hinstance); 84 this->dwOrdinalBase = 0;85 111 } 86 112 … … 102 128 Win32LxImage::~Win32LxImage() 103 129 { 104 if(lpszExportPrefix) free(lpszExportPrefix);105 106 130 if(header) { 107 131 DosFreeMem(header); … … 115 139 ULONG apiaddr; 116 140 117 if(lpszExportPrefix) 118 {//if this dll exports by name with a prefix, then concatenate the prefix 119 //with the export name to get the OS/2 export name 120 char *lpszNewName = (char *)alloca(strlen(name) + strlen(lpszExportPrefix)+1); 121 if(lpszNewName == NULL) { 122 DebugInt3(); 123 return 0; 124 } 125 strcpy(lpszNewName, lpszExportPrefix); 126 strcat(lpszNewName, name); 127 rc = DosQueryProcAddr(hinstanceOS2, 0, lpszNewName, (PFN *)&apiaddr); 128 if(rc == NO_ERROR) { 129 return(apiaddr); 130 } 131 //else try with the normal name 132 } 141 if(pCustomPEHeader) return Win32ImageBase::getApi(name); 142 133 143 rc = DosQueryProcAddr(hinstanceOS2, 0, name, (PFN *)&apiaddr); 134 144 if(rc) … … 146 156 ULONG apiaddr; 147 157 148 rc = DosQueryProcAddr(hinstanceOS2, dwOrdinalBase+ordinal, NULL, (PFN *)&apiaddr); 158 if(pCustomPEHeader) return Win32ImageBase::getApi(ordinal); 159 160 rc = DosQueryProcAddr(hinstanceOS2, ordinal, NULL, (PFN *)&apiaddr); 149 161 if(rc) { 150 162 dprintf(("Win32LxImage::getApi %x %d -> rc = %d", hinstanceOS2, ordinal, rc)); … … 155 167 //****************************************************************************** 156 168 //****************************************************************************** 169 ULONG Win32LxImage::setApi(char *name, ULONG pfnNewProc) 170 { 171 if(pCustomPEHeader) return Win32ImageBase::setApi(name, pfnNewProc); 172 173 return -1; 174 } 175 //****************************************************************************** 176 //****************************************************************************** 177 ULONG Win32LxImage::setApi(int ordinal, ULONG pfnNewProc) 178 { 179 if(pCustomPEHeader) return Win32ImageBase::setApi(ordinal, pfnNewProc); 180 181 return -1; 182 } 183 //****************************************************************************** 184 //****************************************************************************** 157 185 LPVOID Win32LxImage::buildHeader(DWORD MajorImageVersion, DWORD MinorImageVersion, 158 DWORD Subsystem) 186 DWORD Subsystem) 159 187 { 160 188 APIRET rc; 161 189 IMAGE_DOS_HEADER *pdosheader; 162 PIMAGE_OPTIONAL_HEADER poh; 163 PIMAGE_FILE_HEADER pfh; 190 PIMAGE_OPTIONAL_HEADER poh; 191 PIMAGE_FILE_HEADER pfh; 192 PIMAGE_SECTION_HEADER psh; 193 PIMAGE_EXPORT_DIRECTORY ped; 194 195 if(pCustomPEHeader) 196 { 197 return (LPVOID)pCustomPEHeader; 198 } 199 164 200 DWORD *ntsig; 165 201 … … 180 216 pfh->NumberOfSymbols = 0; 181 217 pfh->SizeOfOptionalHeader = sizeof(IMAGE_OPTIONAL_HEADER); 182 pfh->Characteristics = IMAGE_FILE_DLL | IMAGE_FILE_32BIT_MACHINE | 183 IMAGE_FILE_DEBUG_STRIPPED | IMAGE_FILE_EXECUTABLE_IMAGE | 218 pfh->Characteristics = IMAGE_FILE_DLL | IMAGE_FILE_32BIT_MACHINE | 219 IMAGE_FILE_DEBUG_STRIPPED | IMAGE_FILE_EXECUTABLE_IMAGE | 184 220 IMAGE_FILE_RELOCS_STRIPPED; 185 221 poh = (PIMAGE_OPTIONAL_HEADER)(pfh+1); … … 214 250 poh->LoaderFlags = 0; 215 251 poh->NumberOfRvaAndSizes = 0; 216 // poh->DataDirectory[0]217 252 218 253 return header;
Note:
See TracChangeset
for help on using the changeset viewer.