| 1 | /* $Id: winexepeldr.cpp,v 1.3 1999-10-14 09:57:34 sandervl Exp $ */
|
|---|
| 2 |
|
|---|
| 3 | /*
|
|---|
| 4 | * Win32 PE loader Exe class
|
|---|
| 5 | *
|
|---|
| 6 | * Copyright 1998-1999 Sander van Leeuwen (sandervl@xs4all.nl)
|
|---|
| 7 | *
|
|---|
| 8 | *
|
|---|
| 9 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 10 | *
|
|---|
| 11 | */
|
|---|
| 12 | #define INCL_DOSFILEMGR /* File Manager values */
|
|---|
| 13 | #define INCL_DOSERRORS /* DOS Error values */
|
|---|
| 14 | #define INCL_DOSPROCESS /* DOS Process values */
|
|---|
| 15 | #define INCL_DOSMISC /* DOS Miscellanous values */
|
|---|
| 16 | #define INCL_WIN
|
|---|
| 17 | #include <os2wrap.h> //Odin32 OS/2 api wrappers
|
|---|
| 18 | #include <stdio.h>
|
|---|
| 19 | #include <string.h>
|
|---|
| 20 | #include <stdlib.h>
|
|---|
| 21 | #include <iostream.h>
|
|---|
| 22 | #include <fstream.h>
|
|---|
| 23 | #include <misc.h>
|
|---|
| 24 | #include <win32type.h>
|
|---|
| 25 | #include <winexepeldr.h>
|
|---|
| 26 | #include <wprocess.h>
|
|---|
| 27 | #include <pefile.h>
|
|---|
| 28 |
|
|---|
| 29 | #include "conwin.h" // Windows Header for console only
|
|---|
| 30 | #include "console.h"
|
|---|
| 31 |
|
|---|
| 32 | #include "exceptions.h"
|
|---|
| 33 | #include "exceptutil.h"
|
|---|
| 34 |
|
|---|
| 35 | #include "cio.h"
|
|---|
| 36 |
|
|---|
| 37 | //******************************************************************************
|
|---|
| 38 | //Called by ring 3 pe loader to create win32 executable
|
|---|
| 39 | //******************************************************************************
|
|---|
| 40 | BOOL WIN32API CreateWin32PeLdrExe(char *szFileName, ULONG reservedMem)
|
|---|
| 41 | {
|
|---|
| 42 | APIRET rc;
|
|---|
| 43 | PPIB ppib;
|
|---|
| 44 | PTIB ptib;
|
|---|
| 45 | WINEXCEPTION_FRAME exceptFrame;
|
|---|
| 46 | Win32PeLdrExe *WinExe;
|
|---|
| 47 | char *szCmdLine;
|
|---|
| 48 |
|
|---|
| 49 | WinExe = new Win32PeLdrExe(szFileName);
|
|---|
| 50 |
|
|---|
| 51 | rc = DosGetInfoBlocks(&ptib, &ppib);
|
|---|
| 52 | if(rc) {
|
|---|
| 53 | WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szInteralErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE);
|
|---|
| 54 | delete WinExe;
|
|---|
| 55 | return FALSE;
|
|---|
| 56 | }
|
|---|
| 57 | //TODO: Create full path for executable?
|
|---|
| 58 | szCmdLine = ppib->pib_pchcmd + strlen(ppib->pib_pchcmd) + 1;
|
|---|
| 59 | while(*szCmdLine != 0 && *szCmdLine == ' ')
|
|---|
| 60 | szCmdLine++;
|
|---|
| 61 |
|
|---|
| 62 | WinExe->setCommandLine(szCmdLine);
|
|---|
| 63 |
|
|---|
| 64 | if(getenv("WIN32_IOPL2")) {
|
|---|
| 65 | io_init1();
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 | OS2SetExceptionHandler(&exceptFrame);
|
|---|
| 69 | if(WinExe->init(reservedMem) == FALSE) {
|
|---|
| 70 | delete WinExe;
|
|---|
| 71 | return FALSE;
|
|---|
| 72 | }
|
|---|
| 73 | OS2UnsetExceptionHandler(&exceptFrame);
|
|---|
| 74 | if(WinExe->isConsoleApp()) {
|
|---|
| 75 | dprintf(("Console application!\n"));
|
|---|
| 76 |
|
|---|
| 77 | APIRET rc = iConsoleInit(); /* initialize console subsystem */
|
|---|
| 78 | if (rc != NO_ERROR) /* check for errors */
|
|---|
| 79 | dprintf(("KERNEL32:Win32Image:Init ConsoleInit failed with %u.\n", rc));
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | WinExe->start();
|
|---|
| 83 |
|
|---|
| 84 | delete WinExe;
|
|---|
| 85 |
|
|---|
| 86 | return TRUE;
|
|---|
| 87 | }
|
|---|
| 88 | //******************************************************************************
|
|---|
| 89 | //******************************************************************************
|
|---|
| 90 | Win32PeLdrExe::Win32PeLdrExe(char *szFileName) :
|
|---|
| 91 | Win32ImageBase(-1),
|
|---|
| 92 | Win32ExeBase(-1),
|
|---|
| 93 | Win32PeLdrImage(szFileName)
|
|---|
| 94 | {
|
|---|
| 95 | dprintf(("Win32PeLdrExe ctor: %s", szFileName));
|
|---|
| 96 | }
|
|---|
| 97 | //******************************************************************************
|
|---|
| 98 | //******************************************************************************
|
|---|
| 99 | Win32PeLdrExe::~Win32PeLdrExe()
|
|---|
| 100 | {
|
|---|
| 101 | }
|
|---|
| 102 | //******************************************************************************
|
|---|
| 103 | //******************************************************************************
|
|---|
| 104 | BOOL Win32PeLdrExe::init(ULONG reservedMem)
|
|---|
| 105 | {
|
|---|
| 106 | BOOL rc;
|
|---|
| 107 |
|
|---|
| 108 | rc = Win32PeLdrImage::init(reservedMem);
|
|---|
| 109 | fConsoleApp = (oh.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI);
|
|---|
| 110 | return rc;
|
|---|
| 111 | }
|
|---|
| 112 | //******************************************************************************
|
|---|
| 113 | //******************************************************************************
|
|---|