1 | /* $Id: winexepe2lx.cpp,v 1.3 1999-10-17 01:49:09 bird 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 |
|
---|
36 | /**
|
---|
37 | * Register a Pe2Lx Executable module.
|
---|
38 | * This is called from the TIBFix code in the Pe2Lx exe. It creates the WinExe object from
|
---|
39 | * the instance handle passed in.
|
---|
40 | * @param ulPe2LxVersion Pe2Lx version number.
|
---|
41 | * @param hinstance Module handle.
|
---|
42 | * @param ulReserved Reserved.
|
---|
43 | * @sketch I/O init.
|
---|
44 | * Check that pe2lx version matches the version of kernel32.dll.
|
---|
45 | * Frees WinExe if is not NULL - should never happen!
|
---|
46 | * Write info to the log.
|
---|
47 | * Create Pe2Lx Exe object.
|
---|
48 | * Call start (which calls the entry point).
|
---|
49 | * @status completely implemented.
|
---|
50 | * @author Sander van Leeuwen, knut st. osmundsen
|
---|
51 | */
|
---|
52 | void WIN32API RegisterPe2LxExe(ULONG ulPe2LxVersion, HINSTANCE hinstance, ULONG ulReserved)
|
---|
53 | {
|
---|
54 | Win32Pe2LxExe *pWinPe2LxExe;
|
---|
55 |
|
---|
56 | /* I/O init. */
|
---|
57 | if (getenv("WIN32_IOPL2"))
|
---|
58 | io_init1();
|
---|
59 |
|
---|
60 | /* Check that pe2lx version matches the version of kernel32.dll. */
|
---|
61 | CheckVersion(ulPe2LxVersion & ~0x80000000UL, OSLibGetDllName(hinstance));
|
---|
62 |
|
---|
63 | /* Frees WinExe if is not NULL - should never happen! */
|
---|
64 | if (WinExe != NULL)
|
---|
65 | {
|
---|
66 | dprintf(("RegisterPe2LxExe: WinExe != NULL\n"));
|
---|
67 | delete(WinExe);
|
---|
68 | }
|
---|
69 |
|
---|
70 | /* Write info to the log. */
|
---|
71 | dprintf(("RegisterPe2LxExe: ulPe2LxVersion = %#x\n", ulPe2LxVersion));
|
---|
72 | dprintf(("RegisterPe2LxExe: hinstance = %#x\n", hinstance));
|
---|
73 | dprintf(("RegisterPe2LxExe: ulReserved = %#x\n", ulReserved));
|
---|
74 | dprintf(("RegisterPe2LxExe: name = %s\n", OSLibGetDllName(hinstance)));
|
---|
75 |
|
---|
76 | /* Create Pe2Lx Exe object. */
|
---|
77 | pWinPe2LxExe = new Win32Pe2LxExe(hinstance, (ulPe2LxVersion & 0x80000000UL) == 0x80000000UL);
|
---|
78 | if (pWinPe2LxExe == NULL)
|
---|
79 | {
|
---|
80 | eprintf(("RegisterPe2LxExe: new returned a NULL-pointer\n"));
|
---|
81 | return;
|
---|
82 | }
|
---|
83 | if (!pWinPe2LxExe->init())
|
---|
84 | {
|
---|
85 | eprintf(("RegisterPe2LxExe: init-method failed.\n"));
|
---|
86 | delete pWinPe2LxExe;
|
---|
87 | return;
|
---|
88 | }
|
---|
89 |
|
---|
90 | /* Call start (which calls the entry point). */
|
---|
91 | /*DebugInt3();*/
|
---|
92 | pWinPe2LxExe->start();
|
---|
93 | }
|
---|
94 |
|
---|
95 |
|
---|
96 | /**
|
---|
97 | * Constructor - creates an pe2lx exe object from a module handle to a pe2lx exe module.
|
---|
98 | * @param hinstance Module handle.
|
---|
99 | * @param fWin32k TRUE: Win32k module.
|
---|
100 | * FALSE: Pe2Lx module.
|
---|
101 | * @status completely implmented.
|
---|
102 | * @author Sander van Leeuwen, knut st. osmundsen
|
---|
103 | * @remark Win32Pe2LxImage may throw an exception!
|
---|
104 | */
|
---|
105 | Win32Pe2LxExe::Win32Pe2LxExe(HINSTANCE hinstance, BOOL fWin32k)
|
---|
106 | : Win32ImageBase(hinstance),
|
---|
107 | Win32ExeBase(hinstance),
|
---|
108 | Win32Pe2LxImage(hinstance, fWin32k)
|
---|
109 | {
|
---|
110 | }
|
---|
111 |
|
---|
112 |
|
---|
113 | /**
|
---|
114 | * Destructor - does nothing.
|
---|
115 | * @status completely implemented.
|
---|
116 | * @author Sander van Leeuwen
|
---|
117 | */
|
---|
118 | Win32Pe2LxExe::~Win32Pe2LxExe()
|
---|
119 | {
|
---|
120 |
|
---|
121 | }
|
---|
122 |
|
---|
123 |
|
---|
124 | /**
|
---|
125 | * Init object.
|
---|
126 | * Must be called immedeately after the object construction.
|
---|
127 | * @returns Success indicator. (TRUE == success)
|
---|
128 | * @sketch
|
---|
129 | * @status completely implemented.
|
---|
130 | * @author knut st. osmundsen
|
---|
131 | */
|
---|
132 | BOOL Win32Pe2LxExe::init()
|
---|
133 | {
|
---|
134 | if (Win32Pe2LxImage::init())
|
---|
135 | {
|
---|
136 | fConsoleApp = pNtHdrs->OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI;
|
---|
137 |
|
---|
138 | /* console app? */
|
---|
139 | if (fConsoleApp)
|
---|
140 | {
|
---|
141 | APIRET rc;
|
---|
142 |
|
---|
143 | dprintf(("Console application!\n"));
|
---|
144 |
|
---|
145 | rc = iConsoleInit(); /* initialize console subsystem */
|
---|
146 | if (rc != NO_ERROR) /* check for errors */
|
---|
147 | dprintf(("KERNEL32:Win32Image:Init ConsoleInit failed with %u.\n", rc));
|
---|
148 | }
|
---|
149 | }
|
---|
150 | else
|
---|
151 | return FALSE;
|
---|
152 | return TRUE;
|
---|
153 | }
|
---|
154 |
|
---|