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

Last change on this file since 2007 was 1833, checked in by sandervl, 26 years ago

exe loader fixes + updates

File size: 3.8 KB
Line 
1/* $Id: winexepeldr.cpp,v 1.5 1999-11-24 19:31:23 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
38extern char szErrorTitle[];
39extern char szErrorModule[];
40
41//******************************************************************************
42//Called by ring 3 pe loader to create win32 executable
43//******************************************************************************
44BOOL WIN32API CreateWin32PeLdrExe(char *szFileName, ULONG reservedMem)
45{
46 APIRET rc;
47 PPIB ppib;
48 PTIB ptib;
49 WINEXCEPTION_FRAME exceptFrame;
50 Win32PeLdrExe *WinExe;
51 char *szCmdLine;
52
53 WinExe = new Win32PeLdrExe(szFileName);
54
55 rc = DosGetInfoBlocks(&ptib, &ppib);
56 if(rc) {
57 WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szInteralErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE);
58 delete WinExe;
59 return FALSE;
60 }
61 //TODO: Create full path for executable?
62 szCmdLine = ppib->pib_pchcmd + strlen(ppib->pib_pchcmd) + 1;
63 while(*szCmdLine != 0 && *szCmdLine == ' ')
64 szCmdLine++;
65
66 WinExe->setCommandLine(szCmdLine);
67
68 if(getenv("WIN32_IOPL2")) {
69 io_init1();
70 }
71
72 OS2SetExceptionHandler(&exceptFrame);
73 if(WinExe->init(reservedMem) == FALSE) {
74 if(szErrorModule[0] != 0) {
75 char szErrorMsg[128];
76
77 sprintf(szErrorMsg, "Can't execute %s due to bad or missing %s", OSLibStripPath(szFileName), szErrorModule);
78 WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE);
79 }
80 delete WinExe;
81 return FALSE;
82 }
83 OS2UnsetExceptionHandler(&exceptFrame);
84 if(WinExe->isConsoleApp()) {
85 dprintf(("Console application!\n"));
86
87 APIRET rc = iConsoleInit(); /* initialize console subsystem */
88 if (rc != NO_ERROR) /* check for errors */
89 dprintf(("KERNEL32:Win32Image:Init ConsoleInit failed with %u.\n", rc));
90 }
91
92 WinExe->start();
93
94 delete WinExe;
95
96 return TRUE;
97}
98//******************************************************************************
99//******************************************************************************
100Win32PeLdrExe::Win32PeLdrExe(char *szFileName) :
101 Win32ImageBase(-1),
102 Win32ExeBase(-1),
103 Win32PeLdrImage(szFileName, TRUE)
104{
105 dprintf(("Win32PeLdrExe ctor: %s", szFileName));
106}
107//******************************************************************************
108//******************************************************************************
109Win32PeLdrExe::~Win32PeLdrExe()
110{
111}
112//******************************************************************************
113//******************************************************************************
114BOOL Win32PeLdrExe::init(ULONG reservedMem)
115{
116 BOOL rc;
117
118 rc = Win32PeLdrImage::init(reservedMem);
119 fConsoleApp = (oh.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI);
120 return rc;
121}
122//******************************************************************************
123//******************************************************************************
Note: See TracBrowser for help on using the repository browser.