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

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

GetFileAttributes, pe loader & command line fixes

File size: 4.0 KB
Line 
1/* $Id: winexepeldr.cpp,v 1.8 2000-04-14 22:35:28 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 szFullCmdLine = (char *)malloc(strlen(szFileName) + 1 + strlen(szCmdLine) + 1);
70 strcpy(szFullCmdLine, szFileName);
71 strcat(szFullCmdLine, " ");
72 strcat(szFullCmdLine, szCmdLine);
73 WinExe->setCommandLine(szFullCmdLine);
74 dprintf(("Cmd line: %s", szFullCmdLine));
75 free(szFullCmdLine);
76
77 if(getenv("WIN32_IOPL2")) {
78 io_init1();
79 }
80
81 OS2SetExceptionHandler(&exceptFrame);
82 if(WinExe->init(reservedMem) == FALSE) {
83 if(szErrorModule[0] != 0) {
84 char szErrorMsg[128];
85
86 sprintf(szErrorMsg, "Can't execute %s due to bad or missing %s", OSLibStripPath(szFileName), szErrorModule);
87 WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE);
88 }
89 delete WinExe;
90 return FALSE;
91 }
92 OS2UnsetExceptionHandler(&exceptFrame);
93 if(WinExe->isConsoleApp()) {
94 dprintf(("Console application!\n"));
95
96 APIRET rc = iConsoleInit(); /* initialize console subsystem */
97 if (rc != NO_ERROR) /* check for errors */
98 dprintf(("KERNEL32:Win32Image:Init ConsoleInit failed with %u.\n", rc));
99 }
100
101 WinExe->start();
102
103 delete WinExe;
104
105 return TRUE;
106}
107//******************************************************************************
108//******************************************************************************
109Win32PeLdrExe::Win32PeLdrExe(char *szFileName) :
110 Win32ImageBase(-1),
111 Win32ExeBase(-1),
112 Win32PeLdrImage(szFileName, TRUE)
113{
114 dprintf(("Win32PeLdrExe ctor: %s", szFileName));
115}
116//******************************************************************************
117//******************************************************************************
118Win32PeLdrExe::~Win32PeLdrExe()
119{
120}
121//******************************************************************************
122//******************************************************************************
123BOOL Win32PeLdrExe::init(ULONG reservedMem)
124{
125 BOOL rc;
126
127 rc = Win32PeLdrImage::init(reservedMem);
128 fConsoleApp = (oh.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI);
129 return rc;
130}
131//******************************************************************************
132//******************************************************************************
Note: See TracBrowser for help on using the repository browser.