- Timestamp:
- Dec 20, 2002, 12:39:43 PM (23 years ago)
- Location:
- trunk/src/kernel32
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/KERNEL32.DEF
r9496 r9537 1 ; $Id: KERNEL32.DEF,v 1.14 6 2002-12-13 16:46:43sandervl Exp $1 ; $Id: KERNEL32.DEF,v 1.147 2002-12-20 11:39:40 sandervl Exp $ 2 2 3 3 ;Basis is Windows95 KERNEL32 … … 1077 1077 _RegisterPe2LxDll@12 @1209 1078 1078 1079 _CreateWin32PeLdrExe@ 28@12361079 _CreateWin32PeLdrExe@36 @1236 1080 1080 1081 1081 _RegisterLxExe@8 @1237 -
trunk/src/kernel32/kernel32dbg.def
r9496 r9537 1 ; $Id: kernel32dbg.def,v 1.2 1 2002-12-13 16:46:44sandervl Exp $1 ; $Id: kernel32dbg.def,v 1.22 2002-12-20 11:39:41 sandervl Exp $ 2 2 3 3 ;Basis is Windows95 KERNEL32 … … 1077 1077 _RegisterPe2LxDll@12 @1209 1078 1078 1079 _CreateWin32PeLdrExe@ 28@12361079 _CreateWin32PeLdrExe@36 @1236 1080 1080 1081 1081 _RegisterLxExe@8 @1237 -
trunk/src/kernel32/winexepeldr.cpp
r9533 r9537 1 /* $Id: winexepeldr.cpp,v 1.2 0 2002-12-20 10:38:58sandervl Exp $ */1 /* $Id: winexepeldr.cpp,v 1.21 2002-12-20 11:39:41 sandervl Exp $ */ 2 2 3 3 /* … … 46 46 47 47 48 extern char szErrorTitle[];49 48 extern char szErrorModule[]; 50 49 … … 58 57 // (not other options available at this time) 59 58 //****************************************************************************** 60 BOOL WIN32API CreateWin32PeLdrExe(char *szFileName, char *szCmdLine, 61 char *peoptions, 62 ULONG reservedMem, ULONG ulPEOffset, 63 BOOL fConsoleApp, BOOL fVioConsole) 59 DWORD WIN32API CreateWin32PeLdrExe(char *szFileName, char *szCmdLine, 60 char *peoptions, 61 ULONG reservedMem, ULONG ulPEOffset, 62 BOOL fConsoleApp, BOOL fVioConsole, 63 char *pszErrorModule, ULONG cbErrorModule) 64 64 { 65 65 APIRET rc; … … 76 76 rc = DosGetInfoBlocks(&ptib, &ppib); 77 77 if(rc) { 78 WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szInteralErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE); 79 delete WinExe; 80 return FALSE; 78 delete WinExe; 79 return LDRERROR_INTERNAL; 81 80 } 82 81 //Handle special pe cmd line options here (/OPT:[x1=y,x2=z,..]) … … 123 122 if(WinExe->isConsoleApp()) 124 123 { 125 124 dprintf(("Console application!\n")); 126 125 127 APIRETrc = iConsoleInit(fVioConsole); /* initialize console subsystem */128 129 126 rc = iConsoleInit(fVioConsole); /* initialize console subsystem */ 127 if (rc != NO_ERROR) /* check for errors */ 128 dprintf(("KERNEL32:Win32Image:Init ConsoleInit failed with %u.\n", rc)); 130 129 } 131 130 132 131 OS2SetExceptionHandler(&exceptFrame); 133 if(WinExe->init(reservedMem, ulPEOffset) == FALSE) 132 rc = WinExe->init(reservedMem, ulPEOffset); 133 if(rc != LDRERROR_SUCCESS) 134 134 { 135 135 if(szErrorModule[0] != 0) { 136 char szErrorMsg[128]; 137 138 sprintf(szErrorMsg, "Can't execute %s due to bad or missing %s", OSLibStripPath(szFileName), szErrorModule); 139 WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE); 136 strncpy(pszErrorModule, szErrorModule, cbErrorModule-1); 137 pszErrorModule[cbErrorModule-1] = 0; 140 138 } 141 139 delete WinExe; 142 140 OS2UnsetExceptionHandler(&exceptFrame); 143 return FALSE;141 return rc; 144 142 } 145 143 OS2UnsetExceptionHandler(&exceptFrame); … … 158 156 delete WinExe; 159 157 160 return TRUE;158 return LDRERROR_SUCCESS; 161 159 } 162 160 //****************************************************************************** … … 167 165 Win32PeLdrImage(szFileName, TRUE) 168 166 { 169 dprintf(("Win32PeLdrExe ctor: %s", szFileName));170 this->fConsoleApp = fConsoleApp;167 dprintf(("Win32PeLdrExe ctor: %s", szFileName)); 168 this->fConsoleApp = fConsoleApp; 171 169 172 //SvL: set temporary full path here as console init needs it173 setFullPath(szFileName);170 //SvL: set temporary full path here as console init needs it 171 setFullPath(szFileName); 174 172 } 175 173 //****************************************************************************** -
trunk/src/kernel32/winexepeldr.h
r8913 r9537 1 /* $Id: winexepeldr.h,v 1. 7 2002-07-23 13:51:48sandervl Exp $ */1 /* $Id: winexepeldr.h,v 1.8 2002-12-20 11:39:41 sandervl Exp $ */ 2 2 3 3 /* … … 15 15 #include <winexebase.h> 16 16 #include <winimagepeldr.h> 17 18 typedef BOOL (* WIN32API WIN32CTOR)(char *, char *, char *, ULONG, ULONG, BOOL, BOOL);19 17 20 18 //Class for executables run by the ring 3 PE loader -
trunk/src/kernel32/winimagebase.h
r7811 r9537 1 /* $Id: winimagebase.h,v 1.2 1 2002-02-06 16:33:39sandervl Exp $ */1 /* $Id: winimagebase.h,v 1.22 2002-12-20 11:39:41 sandervl Exp $ */ 2 2 3 3 /* … … 16 16 #include <peexe.h> 17 17 #include "queue.h" 18 #include <odinpe.h> 18 19 #ifdef OS2_INCLUDED 19 20 #include <winconst.h> … … 29 30 30 31 #define ID_GETFIRST 0xF0000000 31 32 #ifndef ENUMRESNAMEPROC33 typedef BOOL (* CALLBACK ENUMRESTYPEPROCA)(HMODULE,LPSTR,LONG);34 typedef BOOL (* CALLBACK ENUMRESTYPEPROCW)(HMODULE,LPWSTR,LONG);35 typedef BOOL (* CALLBACK ENUMRESNAMEPROCA)(HMODULE,LPCSTR,LPSTR,LONG);36 typedef BOOL (* CALLBACK ENUMRESNAMEPROCW)(HMODULE,LPCWSTR,LPWSTR,LONG);37 typedef BOOL (* CALLBACK ENUMRESLANGPROCA)(HMODULE,LPCSTR,LPCSTR,WORD,LONG);38 typedef BOOL (* CALLBACK ENUMRESLANGPROCW)(HMODULE,LPCWSTR,LPCWSTR,WORD,LONG);39 #endif40 32 41 33 class Win32Resource; -
trunk/src/kernel32/winimagepe2lx.cpp
r8589 r9537 1 /* $Id: winimagepe2lx.cpp,v 1.2 0 2002-06-08 00:26:59 birdExp $ */1 /* $Id: winimagepe2lx.cpp,v 1.21 2002-12-20 11:39:42 sandervl Exp $ */ 2 2 3 3 /* … … 179 179 * Initiates the object. 180 180 * Must be called immediately after the object construction. 181 * @returns Success indicator, TRUE == success; FALSE = failure.181 * @returns Error value, LDRERROR_SUCCESS == success; failure otherwise. 182 182 * @sketch Get section placement and sizes for this module. (paSections, cSections) 183 183 * Verify that there is at least one section - the header section. … … 194 194 * @remark Object must be destroyed if failure! 195 195 */ 196 BOOLWin32Pe2LxImage::init()196 DWORD Win32Pe2LxImage::init() 197 197 { 198 198 APIRET rc; … … 204 204 dprintf(("Win32Pe2LxImage::Win32Pe2LxImage: error - getSection failed with rc=%d\n", 205 205 rc)); 206 return FALSE;206 return LDRERROR_INVALID_HEADER; 207 207 } 208 208 … … 211 211 { 212 212 dprintf(("Win32Pe2LxImage::Win32Pe2LxImage: no header section, cSections is 0\n")); 213 return FALSE;213 return LDRERROR_INVALID_HEADER; 214 214 } 215 215 … … 224 224 { 225 225 dprintf(("Win32Pe2LxImage::Win32Pe2LxImage: Not a pe2lx image!(?)\n")); 226 return FALSE;226 return LDRERROR_INVALID_HEADER; 227 227 } 228 228 … … 245 245 { 246 246 dprintf(("Win32Pe2LxImage::Win32Pe2LxImage: Not a pe2lx image!(?)\n")); 247 return FALSE;247 return LDRERROR_INVALID_HEADER; 248 248 } 249 249 … … 253 253 { 254 254 dprintf(("Win32Pe2LxImage::Win32Pe2LxImage: setSectionRVAs failed with rc=%d\n", rc)); 255 return FALSE;255 return LDRERROR_INVALID_HEADER; 256 256 } 257 257 … … 268 268 dprintf(("Win32Pe2LxImage::Win32Pe2LxImage: entrypoint is incorrect, AddrOfEP=0x%08x, entryPoint=0x%08x\n", 269 269 pNtHdrs->OptionalHeader.AddressOfEntryPoint, entryPoint)); 270 return FALSE;270 return LDRERROR_NO_ENTRYPOINT; 271 271 } 272 272 … … 367 367 eprintf(("Win32Pe2LxImage::init: invalid RVA to TLS AddressOfIndex - %#8x.\n", 368 368 pTLSDir->AddressOfIndex)); 369 return FALSE;369 return LDRERROR_INVALID_HEADER; 370 370 } 371 371 setTLSIndexAddr((LPDWORD)pv); … … 387 387 eprintf(("Win32Pe2LxImage::init: invalid pointer to TLS AddressOfCallBacks - %#8x.\n", 388 388 pTLSDir->AddressOfIndex)); 389 return FALSE;389 return LDRERROR_INVALID_HEADER; 390 390 } 391 391 setTLSCallBackAddr((PIMAGE_TLS_CALLBACK*)pv); … … 398 398 eprintf(("Win32Pe2LxImage::init: invalid RVA to TLS Dir - %#8x. (getPointerFromRVA failed)\n", 399 399 pNtHdrs->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_TLS].VirtualAddress)); 400 return FALSE;400 return LDRERROR_INVALID_HEADER; 401 401 } 402 402 } 403 return TRUE;403 return LDRERROR_SUCCESS; 404 404 } 405 405 -
trunk/src/kernel32/winimagepe2lx.h
r6302 r9537 1 /* $Id: winimagepe2lx.h,v 1. 8 2001-07-10 20:18:49 birdExp $ */1 /* $Id: winimagepe2lx.h,v 1.9 2002-12-20 11:39:42 sandervl Exp $ */ 2 2 3 3 /* … … 41 41 Win32Pe2LxImage(HINSTANCE hinstance, BOOL fWin32k); 42 42 virtual ~Win32Pe2LxImage(); 43 virtual BOOLinit();43 virtual DWORD init(); 44 44 45 45 /** @cat Exports */ -
trunk/src/kernel32/winimagepeldr.cpp
r8918 r9537 1 /* $Id: winimagepeldr.cpp,v 1.10 1 2002-07-26 10:46:56sandervl Exp $ */1 /* $Id: winimagepeldr.cpp,v 1.102 2002-12-20 11:39:42 sandervl Exp $ */ 2 2 3 3 /* … … 66 66 //#endif 67 67 68 char szErrorTitle[] = "Odin"; 69 char szMemErrorMsg[] = "Memory allocation failure"; 70 char szFileErrorMsg[] = "File IO error"; 71 char szPEErrorMsg[] = "Not a valid win32 exe. (perhaps 16 bits windows)"; 72 char szCPUErrorMsg[] = "Executable doesn't run on x86 machines"; 73 char szExeErrorMsg[] = "File isn't an executable"; 74 char szInteralErrorMsg[]= "Internal Error"; 75 char szErrorModule[128] = ""; 68 char szErrorModule[260] = ""; 76 69 77 70 #ifdef DEBUG … … 175 168 //****************************************************************************** 176 169 //****************************************************************************** 177 BOOLWin32PeLdrImage::init(ULONG reservedMem, ULONG ulPEOffset)170 DWORD Win32PeLdrImage::init(ULONG reservedMem, ULONG ulPEOffset) 178 171 { 179 172 LPVOID win32file = NULL; … … 186 179 IMAGE_DOS_HEADER doshdr; 187 180 ULONG signature; 181 DWORD lasterror = LDRERROR_INTERNAL; 188 182 189 183 //offset in executable image where real PE file starts (default 0) … … 199 193 if(ulPEOffset) { 200 194 if(OSLibDosSetFilePtr(hFile, ulPEOffset, OSLIB_SETPTR_FILE_BEGIN) == -1) { 195 lasterror = LDRERROR_INVALID_MODULE; 201 196 goto failure; 202 197 } … … 206 201 strcpy(szErrorModule, OSLibStripPath(szFileName)); 207 202 if(hFile == NULL) { 203 lasterror = LDRERROR_INTERNAL; 208 204 goto failure; 209 205 } 210 206 //read dos header 211 207 if(DosRead(hFile, (LPVOID)&doshdr, sizeof(doshdr), &ulRead)) { 208 lasterror = LDRERROR_INVALID_MODULE; 212 209 goto failure; 213 210 } 214 211 if(OSLibDosSetFilePtr(hFile, ulPEOffset+doshdr.e_lfanew, OSLIB_SETPTR_FILE_BEGIN) == -1) { 212 lasterror = LDRERROR_INVALID_MODULE; 215 213 goto failure; 216 214 } 217 215 //read signature dword 218 216 if(DosRead(hFile, (LPVOID)&signature, sizeof(signature), &ulRead)) { 217 lasterror = LDRERROR_INVALID_MODULE; 219 218 goto failure; 220 219 } 221 220 //read pe header 222 221 if(DosRead(hFile, (LPVOID)&fh, sizeof(fh), &ulRead)) { 222 lasterror = LDRERROR_INVALID_MODULE; 223 223 goto failure; 224 224 } 225 225 //read optional header 226 226 if(DosRead(hFile, (LPVOID)&oh, sizeof(oh), &ulRead)) { 227 lasterror = LDRERROR_INVALID_MODULE; 227 228 goto failure; 228 229 } 229 230 if(doshdr.e_magic != IMAGE_DOS_SIGNATURE || signature != IMAGE_NT_SIGNATURE) { 230 231 dprintf((LOG, "Not a valid PE file (probably a 16 bits windows exe/dll)!")); 231 WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szPEErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE);232 lasterror = LDRERROR_INVALID_MODULE; 232 233 goto failure; 233 234 } … … 241 242 if(allocSections(reservedMem) == FALSE) { 242 243 dprintf((LOG, "Failed to allocate image memory for %s at %x, rc %d", szFileName, oh.ImageBase, errorState));; 244 lasterror = LDRERROR_MEMORY; 243 245 goto failure; 244 246 } … … 246 248 memmap = new Win32MemMap(this, realBaseAddress, imageSize); 247 249 if(memmap == NULL || !memmap->Init()) { 250 lasterror = LDRERROR_MEMORY; 248 251 goto failure; 249 252 } … … 256 259 if(!(fh.Characteristics & IMAGE_FILE_EXECUTABLE_IMAGE)) {//not valid 257 260 dprintf((LOG, "Not a valid PE file!")); 258 WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szPEErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE);261 lasterror = LDRERROR_INVALID_MODULE; 259 262 goto failure; 260 263 } 261 264 if(fh.Machine != IMAGE_FILE_MACHINE_I386) { 262 265 dprintf((LOG, "Doesn't run on x86 processors!")); 263 WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szCPUErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE);266 lasterror = LDRERROR_INVALID_CPU; 264 267 goto failure; 265 268 } … … 267 270 if(fh.Characteristics & IMAGE_FILE_SYSTEM) { 268 271 dprintf((LOG, "Can't convert system files")); 269 WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szExeErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE);272 lasterror = LDRERROR_FILE_SYSTEM; 270 273 goto failure; 271 274 } … … 303 306 if(section == NULL) { 304 307 DebugInt3(); 308 lasterror = LDRERROR_MEMORY; 305 309 goto failure; 306 310 } … … 423 427 } 424 428 dprintf((LOG, "Unknown section" )); 429 lasterror = LDRERROR_INVALID_SECTION; 425 430 goto failure; 426 431 } … … 455 460 if(setMemFlags() == FALSE) { 456 461 dprintf((LOG, "Failed to set memory protection" )); 457 goto failure;462 lasterror = LDRERROR_MEMORY; 458 463 } 459 464 … … 486 491 if(sect == NULL) { 487 492 dprintf((LOG, "Couldn't find TLS section!!" )); 493 lasterror = LDRERROR_INVALID_HEADER; 488 494 goto failure; 489 495 } … … 502 508 if(sect == NULL) { 503 509 dprintf((LOG, "Couldn't find TLS AddressOfIndex section!!" )); 510 lasterror = LDRERROR_INVALID_HEADER; 504 511 goto failure; 505 512 } … … 524 531 if(sect == NULL) { 525 532 dprintf((LOG, "Couldn't find TLS AddressOfCallBacks section!!" )); 533 lasterror = LDRERROR_INVALID_HEADER; 526 534 goto failure; 527 535 } … … 547 555 if(sect == NULL) { 548 556 dprintf((LOG, "Couldn't find TLS callback section!!" )); 557 lasterror = LDRERROR_INVALID_HEADER; 549 558 goto failure; 550 559 } … … 609 618 if(processExports((char *)win32file) == FALSE) { 610 619 dprintf((LOG, "Failed to process exported apis" )); 620 lasterror = LDRERROR_EXPORTS; 611 621 goto failure; 612 622 } … … 649 659 if(processImports((char *)win32file) == FALSE) { 650 660 dprintf((LOG, "Failed to process imports!" )); 661 lasterror = LDRERROR_IMPORTS; 651 662 goto failure; 652 663 } 653 664 } 654 return (TRUE);665 return LDRERROR_SUCCESS; 655 666 656 667 failure: … … 664 675 } 665 676 errorState = ERROR_INTERNAL; 666 return FALSE;677 return lasterror; 667 678 } 668 679 //****************************************************************************** … … 1606 1617 if(pedll == NULL) { 1607 1618 dprintf((LOG, "pedll: Error allocating memory" )); 1608 WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szMemErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE);1609 1619 errorState = ERROR_INTERNAL; 1610 1620 return NULL; … … 1613 1623 dprintf((LOG, "********************** Loading Module *********************" )); 1614 1624 dprintf((LOG, "**********************************************************************" )); 1615 if(pedll->init(0) == FALSE) {1625 if(pedll->init(0) != LDRERROR_SUCCESS) { 1616 1626 dprintf((LOG, "Internal WinDll error ", pedll->getError() )); 1617 1627 delete pedll; … … 2069 2079 do { 2070 2080 r = WinMessageBox(HWND_DESKTOP, NULLHANDLE, message, 2071 "Internal OdinError", 0, MB_ABORTRETRYIGNORE | MB_ICONEXCLAMATION | MB_MOVEABLE);2081 "Internal Error", 0, MB_ABORTRETRYIGNORE | MB_ICONEXCLAMATION | MB_MOVEABLE); 2072 2082 } 2073 2083 while(r == MBID_RETRY); //giggle -
trunk/src/kernel32/winimagepeldr.h
r8913 r9537 1 /* $Id: winimagepeldr.h,v 1.1 7 2002-07-23 13:51:49sandervl Exp $ */1 /* $Id: winimagepeldr.h,v 1.18 2002-12-20 11:39:43 sandervl Exp $ */ 2 2 3 3 /* … … 80 80 // loaded at a low address) 81 81 //ulPEOffset: offset in file where real PE image starts 82 virtual BOOLinit(ULONG reservedMem, ULONG ulPEOffset = 0);82 virtual DWORD init(ULONG reservedMem, ULONG ulPEOffset = 0); 83 83 84 84 virtual BOOL insideModule(ULONG address);
Note:
See TracChangeset
for help on using the changeset viewer.