source: trunk/src/peldr/pe.cpp@ 1002

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

Update for new kernel32 images classes

File size: 4.4 KB
Line 
1/* $Id: pe.cpp,v 1.9 1999-09-21 18:35:01 sandervl Exp $ */
2
3/*
4 * PELDR main exe loader code
5 *
6 * Copyright 1998 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_DOSMODULEMGR
17#define INCL_WIN
18#include <os2.h>
19#include <bseord.h>
20#include <stdio.h>
21#include <string.h>
22#include <stdlib.h>
23#include <string.h>
24#include <assert.h>
25#include <win32type.h>
26#include <misc.h>
27#include <winexepeldr.h>
28#include <wprocess.h>
29#include "pe.h"
30
31char INFO_BANNER[] = "Usage: PE winexe commandline";
32char szErrorTitle[] = "Odin";
33char szMemErrorMsg[] = "Memory allocation failure";
34char szFileErrorMsg[] = "File IO error";
35char szPEErrorMsg[] = "Not a valid win32 exe. (perhaps 16 bits windows)";
36char szCPUErrorMsg[] = "Executable doesn't run on x86 machines";
37char szExeErrorMsg[] = "File isn't an executable";
38char szInteralErrorMsg[]= "Internal Error";
39
40char fullpath[CCHMAXPATH];
41
42typedef HAB (* APIENTRY WININITIALIZEPROC)(ULONG flOptions);
43typedef BOOL (* APIENTRY WINTERMINATEPROC)(HAB hab);
44typedef HMQ (* APIENTRY WINCREATEMSGQUEUEPROC) (HAB hab, LONG cmsg);
45typedef BOOL (* APIENTRY WINDESTROYMSGQUEUEPROC) (HMQ hmq);
46typedef ULONG (* APIENTRY WINMESSAGEBOXPROC) (HWND hwndParent,
47 HWND hwndOwner,
48 PCSZ pszText,
49 PCSZ pszCaption,
50 ULONG idWindow,
51 ULONG flStyle);
52typedef void (* KRNL32EXCEPTPROC) (void *exceptframe);
53
54WININITIALIZEPROC MyWinInitialize = 0;
55WINTERMINATEPROC MyWinTerminate = 0;
56WINCREATEMSGQUEUEPROC MyWinCreateMsgQueue = 0;
57WINDESTROYMSGQUEUEPROC MyWinDestroyMsgQueue = 0;
58WINMESSAGEBOXPROC MyWinMessageBox = 0;
59KRNL32EXCEPTPROC Krnl32SetExceptionHandler = 0;
60KRNL32EXCEPTPROC Krnl32UnsetExceptionHandler = 0;
61
62WIN32CTOR CreateWin32Exe = 0;
63
64int main(int argc, char *argv[])
65{
66 HAB hab = 0; /* PM anchor block handle */
67 HMQ hmq = 0; /* Message queue handle */
68 char exeName[CCHMAXPATH];
69 APIRET rc;
70 HMODULE hmodPMWin = 0, hmodKernel32 = 0;
71
72 rc = DosLoadModule(exeName, sizeof(exeName), "PMWIN.DLL", &hmodPMWin);
73 rc = DosQueryProcAddr(hmodPMWin, ORD_WIN32INITIALIZE, NULL, (PFN *)&MyWinInitialize);
74 rc = DosQueryProcAddr(hmodPMWin, ORD_WIN32TERMINATE, NULL, (PFN *)&MyWinTerminate);
75 rc = DosQueryProcAddr(hmodPMWin, ORD_WIN32CREATEMSGQUEUE, NULL, (PFN *)&MyWinCreateMsgQueue);
76 rc = DosQueryProcAddr(hmodPMWin, ORD_WIN32DESTROYMSGQUEUE, NULL, (PFN *)&MyWinDestroyMsgQueue);
77 rc = DosQueryProcAddr(hmodPMWin, ORD_WIN32MESSAGEBOX, NULL, (PFN *)&MyWinMessageBox);
78
79 rc = DosLoadModule(exeName, sizeof(exeName), "KERNEL32.DLL", &hmodKernel32);
80 rc = DosQueryProcAddr(hmodKernel32, 0, "_CreateWin32PeLdrExe@8", (PFN *)&CreateWin32Exe);
81
82 if ((hab = MyWinInitialize(0)) == 0L) /* Initialize PM */
83 goto fail;
84
85 hmq = MyWinCreateMsgQueue(hab, 0);
86
87 if(argc < 2) {
88 MyWinMessageBox(HWND_DESKTOP, NULL, INFO_BANNER, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE);
89 goto fail;
90 }
91
92 strcpy(exeName, argv[1]);
93 strupr(exeName);
94 if(strstr(exeName, ".EXE") == NULL) {
95 strcat(exeName, ".EXE");
96 }
97 if(CreateWin32Exe(exeName, ReserveMem()) == FALSE) {
98 MyWinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szMemErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE);
99 goto fail;
100 }
101
102 if(hmq) MyWinDestroyMsgQueue( hmq ); /* Tidy up... */
103 MyWinTerminate( hab ); /* Terminate the application */
104
105 DosFreeModule(hmodPMWin);
106 DosFreeModule(hmodKernel32);
107 return 0;
108
109fail:
110 if(hmq) MyWinDestroyMsgQueue( hmq ); /* Tidy up... */
111 if(hab) MyWinTerminate( hab ); /* Terminate the application */
112
113 if(hmodPMWin) DosFreeModule(hmodPMWin);
114 if(hmodKernel32) DosFreeModule(hmodKernel32);
115 return(1);
116}
117//******************************************************************************
118//******************************************************************************
Note: See TracBrowser for help on using the repository browser.