| 1 | /* $Id: winexepe2lx.cpp,v 1.5 2000-03-09 19:03:22 sandervl Exp $ */ | 
|---|
| 2 |  | 
|---|
| 3 | /* | 
|---|
| 4 | * Win32 PE2LX Exe class | 
|---|
| 5 | * | 
|---|
| 6 | * Copyright 1998-1999 Sander van Leeuwen (sandervl@xs4all.nl) | 
|---|
| 7 | * Copyright 1999 knut st. osmundsen (knut.stange.osmundsen@pmsc.no) | 
|---|
| 8 | * | 
|---|
| 9 | * Project Odin Software License can be found in LICENSE.TXT | 
|---|
| 10 | * | 
|---|
| 11 | */ | 
|---|
| 12 |  | 
|---|
| 13 | /******************************************************************************* | 
|---|
| 14 | *   Defined Constants And Macros                                               * | 
|---|
| 15 | *******************************************************************************/ | 
|---|
| 16 | #define INCL_DOSERRORS      /* DOS Error values         */ | 
|---|
| 17 |  | 
|---|
| 18 |  | 
|---|
| 19 | /******************************************************************************* | 
|---|
| 20 | *   Header Files                                                               * | 
|---|
| 21 | *******************************************************************************/ | 
|---|
| 22 | #include <os2wrap.h>        //Odin32 OS/2 api wrappers | 
|---|
| 23 |  | 
|---|
| 24 | #include <stdlib.h>         //getenv | 
|---|
| 25 |  | 
|---|
| 26 | #include <misc.h> | 
|---|
| 27 | #include <win32type.h> | 
|---|
| 28 | #include <winexepe2lx.h> | 
|---|
| 29 |  | 
|---|
| 30 | #include "cio.h"            // I/O | 
|---|
| 31 | #include "oslibmisc.h"      // OSLibGetDllName | 
|---|
| 32 | #include "conwin.h"         // Windows Header for console only | 
|---|
| 33 | #include "console.h" | 
|---|
| 34 |  | 
|---|
| 35 | #define DBG_LOCALLOG    DBG_winexepe2lx | 
|---|
| 36 | #include "dbglocal.h" | 
|---|
| 37 |  | 
|---|
| 38 |  | 
|---|
| 39 | BOOL fPe2Lx = FALSE; | 
|---|
| 40 |  | 
|---|
| 41 | /** | 
|---|
| 42 | * Register a Pe2Lx Executable module. | 
|---|
| 43 | * This is called from the TIBFix code in the Pe2Lx exe. It creates the WinExe object from | 
|---|
| 44 | * the instance handle passed in. | 
|---|
| 45 | * @param     ulPe2LxVersion   Pe2Lx version number. | 
|---|
| 46 | * @param     hinstance        Module handle. | 
|---|
| 47 | * @param     ulReserved       Reserved. | 
|---|
| 48 | * @sketch    I/O init. | 
|---|
| 49 | *            Check that pe2lx version matches the version of kernel32.dll. | 
|---|
| 50 | *            Frees WinExe if is not NULL - should never happen! | 
|---|
| 51 | *            Write info to the log. | 
|---|
| 52 | *            Create Pe2Lx Exe object. | 
|---|
| 53 | *            Call start (which calls the entry point). | 
|---|
| 54 | * @status    completely implemented. | 
|---|
| 55 | * @author    Sander van Leeuwen, knut st. osmundsen | 
|---|
| 56 | */ | 
|---|
| 57 | void WIN32API RegisterPe2LxExe(ULONG ulPe2LxVersion, HINSTANCE hinstance, ULONG ulReserved) | 
|---|
| 58 | { | 
|---|
| 59 | Win32Pe2LxExe *pWinPe2LxExe; | 
|---|
| 60 |  | 
|---|
| 61 | fPe2Lx = TRUE; | 
|---|
| 62 |  | 
|---|
| 63 | /* I/O init. */ | 
|---|
| 64 | if (getenv("WIN32_IOPL2")) | 
|---|
| 65 | io_init1(); | 
|---|
| 66 |  | 
|---|
| 67 | /* Check that pe2lx version matches the version of kernel32.dll. */ | 
|---|
| 68 | CheckVersion(ulPe2LxVersion & ~0x80000000UL, OSLibGetDllName(hinstance)); | 
|---|
| 69 |  | 
|---|
| 70 | /* Frees WinExe if is not NULL - should never happen! */ | 
|---|
| 71 | if (WinExe != NULL) | 
|---|
| 72 | { | 
|---|
| 73 | dprintf(("RegisterPe2LxExe: WinExe != NULL\n")); | 
|---|
| 74 | delete(WinExe); | 
|---|
| 75 | } | 
|---|
| 76 |  | 
|---|
| 77 | /* Write info to the log. */ | 
|---|
| 78 | dprintf(("RegisterPe2LxExe: ulPe2LxVersion = %#x\n", ulPe2LxVersion)); | 
|---|
| 79 | dprintf(("RegisterPe2LxExe: hinstance = %#x\n", hinstance)); | 
|---|
| 80 | dprintf(("RegisterPe2LxExe: ulReserved = %#x\n", ulReserved)); | 
|---|
| 81 | dprintf(("RegisterPe2LxExe: name = %s\n", OSLibGetDllName(hinstance))); | 
|---|
| 82 |  | 
|---|
| 83 | /* Create Pe2Lx Exe object. */ | 
|---|
| 84 | pWinPe2LxExe = new Win32Pe2LxExe(hinstance, (ulPe2LxVersion & 0x80000000UL) == 0x80000000UL); | 
|---|
| 85 | if (pWinPe2LxExe == NULL) | 
|---|
| 86 | { | 
|---|
| 87 | eprintf(("RegisterPe2LxExe: new returned a NULL-pointer\n")); | 
|---|
| 88 | return; | 
|---|
| 89 | } | 
|---|
| 90 | if (!pWinPe2LxExe->init()) | 
|---|
| 91 | { | 
|---|
| 92 | eprintf(("RegisterPe2LxExe: init-method failed.\n")); | 
|---|
| 93 | delete pWinPe2LxExe; | 
|---|
| 94 | return; | 
|---|
| 95 | } | 
|---|
| 96 |  | 
|---|
| 97 | /* Call start (which calls the entry point). */ | 
|---|
| 98 | /*DebugInt3();*/ | 
|---|
| 99 | pWinPe2LxExe->start(); | 
|---|
| 100 | } | 
|---|
| 101 |  | 
|---|
| 102 |  | 
|---|
| 103 | /** | 
|---|
| 104 | * Constructor - creates an pe2lx exe object from a module handle to a pe2lx exe module. | 
|---|
| 105 | * @param     hinstance   Module handle. | 
|---|
| 106 | * @param     fWin32k     TRUE:  Win32k module. | 
|---|
| 107 | *                        FALSE: Pe2Lx module. | 
|---|
| 108 | * @status    completely implmented. | 
|---|
| 109 | * @author    Sander van Leeuwen, knut st. osmundsen | 
|---|
| 110 | * @remark    Win32Pe2LxImage may throw an exception! | 
|---|
| 111 | */ | 
|---|
| 112 | Win32Pe2LxExe::Win32Pe2LxExe(HINSTANCE hinstance, BOOL fWin32k) | 
|---|
| 113 | : Win32ImageBase(hinstance), | 
|---|
| 114 | Win32ExeBase(hinstance), | 
|---|
| 115 | Win32Pe2LxImage(hinstance, fWin32k) | 
|---|
| 116 | { | 
|---|
| 117 | } | 
|---|
| 118 |  | 
|---|
| 119 |  | 
|---|
| 120 | /** | 
|---|
| 121 | * Destructor - does nothing. | 
|---|
| 122 | * @status    completely implemented. | 
|---|
| 123 | * @author    Sander van Leeuwen | 
|---|
| 124 | */ | 
|---|
| 125 | Win32Pe2LxExe::~Win32Pe2LxExe() | 
|---|
| 126 | { | 
|---|
| 127 |  | 
|---|
| 128 | } | 
|---|
| 129 |  | 
|---|
| 130 |  | 
|---|
| 131 | /** | 
|---|
| 132 | * Init object. | 
|---|
| 133 | * Must be called immedeately after the object construction. | 
|---|
| 134 | * @returns   Success indicator. (TRUE == success) | 
|---|
| 135 | * @sketch | 
|---|
| 136 | * @status    completely implemented. | 
|---|
| 137 | * @author    knut st. osmundsen | 
|---|
| 138 | */ | 
|---|
| 139 | BOOL Win32Pe2LxExe::init() | 
|---|
| 140 | { | 
|---|
| 141 | if (Win32Pe2LxImage::init()) | 
|---|
| 142 | { | 
|---|
| 143 | fConsoleApp = pNtHdrs->OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI; | 
|---|
| 144 |  | 
|---|
| 145 | /* console app? */ | 
|---|
| 146 | if (fConsoleApp) | 
|---|
| 147 | { | 
|---|
| 148 | APIRET rc; | 
|---|
| 149 |  | 
|---|
| 150 | dprintf(("Console application!\n")); | 
|---|
| 151 |  | 
|---|
| 152 | rc = iConsoleInit();    /* initialize console subsystem */ | 
|---|
| 153 | if (rc != NO_ERROR)     /* check for errors */ | 
|---|
| 154 | dprintf(("KERNEL32:Win32Image:Init ConsoleInit failed with %u.\n", rc)); | 
|---|
| 155 | } | 
|---|
| 156 | } | 
|---|
| 157 | else | 
|---|
| 158 | return FALSE; | 
|---|
| 159 | return TRUE; | 
|---|
| 160 | } | 
|---|
| 161 |  | 
|---|