source: trunk/src/kernel32/winexepeldr.cpp@ 4351

Last change on this file since 4351 was 4351, checked in by sandervl, 25 years ago

cmd line fix for pe loader

File size: 4.2 KB
Line 
1/* $Id: winexepeldr.cpp,v 1.11 2000-10-01 12:05:57 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#include "oslibmisc.h"
37
38#define DBG_LOCALLOG DBG_winexepeldr
39#include "dbglocal.h"
40
41extern char szErrorTitle[];
42extern char szErrorModule[];
43
44BOOL fPeLoader = FALSE;
45
46//******************************************************************************
47//Called by ring 3 pe loader to create win32 executable
48//******************************************************************************
49BOOL WIN32API CreateWin32PeLdrExe(char *szFileName, char *szCmdLine, ULONG reservedMem)
50{
51 APIRET rc;
52 PPIB ppib;
53 PTIB ptib;
54 WINEXCEPTION_FRAME exceptFrame;
55 Win32PeLdrExe *WinExe;
56 char *szFullCmdLine;
57
58 fPeLoader = TRUE;
59
60 WinExe = new Win32PeLdrExe(szFileName);
61
62 rc = DosGetInfoBlocks(&ptib, &ppib);
63 if(rc) {
64 WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szInteralErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE);
65 delete WinExe;
66 return FALSE;
67 }
68
69 //exe length + space + (possibly) 2x'"' + cmd line length + 0 terminator
70 szFullCmdLine = (char *)malloc(strlen(szFileName) + 3 + strlen(szCmdLine) + 1);
71 //Enclose executable name in quotes if it (or it's directory) contains spaces
72 if(strchr(szFileName, ' ') != NULL) {
73 sprintf(szFullCmdLine, "\"%s\"", szFileName);
74 }
75 else strcpy(szFullCmdLine, szFileName);
76 strcat(szFullCmdLine, " ");
77 strcat(szFullCmdLine, szCmdLine);
78 InitCommandLine(szFullCmdLine);
79 dprintf(("Cmd line: %s", szFullCmdLine));
80 free(szFullCmdLine);
81
82 if(getenv("WIN32_IOPL2")) {
83 io_init1();
84 }
85
86 OS2SetExceptionHandler(&exceptFrame);
87 if(WinExe->init(reservedMem) == FALSE) {
88 if(szErrorModule[0] != 0) {
89 char szErrorMsg[128];
90
91 sprintf(szErrorMsg, "Can't execute %s due to bad or missing %s", OSLibStripPath(szFileName), szErrorModule);
92 WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE);
93 }
94 delete WinExe;
95 return FALSE;
96 }
97
98 OS2UnsetExceptionHandler(&exceptFrame);
99 if(WinExe->isConsoleApp()) {
100 dprintf(("Console application!\n"));
101
102 APIRET rc = iConsoleInit(); /* initialize console subsystem */
103 if (rc != NO_ERROR) /* check for errors */
104 dprintf(("KERNEL32:Win32Image:Init ConsoleInit failed with %u.\n", rc));
105 }
106
107 WinExe->start();
108
109 delete WinExe;
110
111 return TRUE;
112}
113//******************************************************************************
114//******************************************************************************
115Win32PeLdrExe::Win32PeLdrExe(char *szFileName) :
116 Win32ImageBase(-1),
117 Win32ExeBase(-1),
118 Win32PeLdrImage(szFileName, TRUE)
119{
120 dprintf(("Win32PeLdrExe ctor: %s", szFileName));
121}
122//******************************************************************************
123//******************************************************************************
124Win32PeLdrExe::~Win32PeLdrExe()
125{
126}
127//******************************************************************************
128//******************************************************************************
129BOOL Win32PeLdrExe::init(ULONG reservedMem)
130{
131 BOOL rc;
132
133 rc = Win32PeLdrImage::init(reservedMem);
134 fConsoleApp = (oh.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI);
135 return rc;
136}
137//******************************************************************************
138//******************************************************************************
Note: See TracBrowser for help on using the repository browser.