source: trunk/src/win32k/pe2lx/pe2lxmain.cpp@ 1467

Last change on this file since 1467 was 1467, checked in by bird, 26 years ago

Corrections to make win32k work.
(And now it does work, at least at my test machine...)

File size: 8.9 KB
Line 
1/* $Id: pe2lxmain.cpp,v 1.3 1999-10-27 02:03:01 bird Exp $
2 *
3 * Pe2Lx main program. (Ring 3 only!)
4 *
5 * Copyright (c) 1999 knut st. osmundsen
6 *
7 */
8
9/*******************************************************************************
10* Defined Constants And Macros *
11*******************************************************************************/
12#define FOR_EXEHDR 1
13#define INCL_BASE
14#define INCL_DOSFILEMGR
15#define INCL_DOSERRORS
16
17
18/*******************************************************************************
19* Header Files *
20*******************************************************************************/
21#include <os2.h>
22#include <peexe.h>
23#include <neexe.h>
24#include <newexe.h>
25#include <exe386.h>
26#include <malloc.h>
27#include <string.h>
28#include <stdlib.h>
29#include "OS2Krnl.h"
30#include "pe2lx.h"
31#include <stdio.h>
32#include <versionos2.h>
33
34
35/*******************************************************************************
36* Global Variables *
37*******************************************************************************/
38char szBackupWin32Filename[CCHMAXPATH]; /* too save stack/heap */
39
40
41/*******************************************************************************
42* Internal Functions *
43*******************************************************************************/
44static void syntax();
45
46
47/**
48 * Main function of the Pe2Lx utillity.
49 * @returns 0 on success.
50 * 1 Help.
51 * 2 Syntax error: Invalid argument, '<arg>'.
52 * 3 Syntax error: Too many filenames.
53 * 4 Syntax error: No Win32-file specified.
54 * 80 Fatal error: Can't find Win32-file, <filename>.
55 * 81 Fatal error: Failed to rename the Win32-file, <from> -> <to>
56 * 82 Fatal error: Failed to open Win32-file, <filename>. rc=<rc>
57 * 83 Fatal error: Failed to convertert the file. rc=<rc from init(..)>
58 * 84 Fatal error: Failed to write the Lx-file. rc=<rc from writeLXFile(..)>
59 * @param argc Count of arguments.
60 * @param argv Array of argument pointers. argc entries.
61 * @status completely implemented.
62 * @author knut st. osmundsen
63 */
64int main(int argc, char **argv)
65{
66 APIRET rc;
67 ULONG ulAction = 0;
68 PCSZ pszWin32Filename = NULL;
69 PCSZ pszOdin32Filename = NULL;
70 PCSZ psz;
71 int argi;
72
73 /* read parameters */
74 for (argi = 1; argi < argc; argi++)
75 {
76 /* check if option or filname */
77 if (argv[argi][0] == '-' || argv[argi][0] == '/')
78 { /* option */
79 switch (argv[argi][1])
80 {
81 case 'h': /* syntax help */
82 case 'H':
83 case '?':
84 syntax();
85 return 1;
86
87 case 'w': /* warning level */
88 case 'W':
89 psz = argv[argi] + (argv[argi][2] == ':' || argv[argi][2] == '=') + 2;
90 if (*psz >= '0' && *psz <= '4' && psz[1] == '\0')
91 {
92 switch (*psz)
93 {
94 case '0': Pe2Lx::ulInfoLevel = Pe2Lx::Quiet; break;
95 case '1': Pe2Lx::ulInfoLevel = Pe2Lx::Error; break;
96 case '2': Pe2Lx::ulInfoLevel = Pe2Lx::Warning; break;
97 case '3': Pe2Lx::ulInfoLevel = Pe2Lx::Info; break;
98 case '4': Pe2Lx::ulInfoLevel = Pe2Lx::InfoAll; break;
99 }
100 }
101 else
102 {
103 printf("Syntax error: Incorrect use of argument '%.2s'.\n\n", argv[argi]);
104 return 5;
105 }
106 break;
107
108 default:
109 printf("Syntax error: Invalid argument, '%s'\n", argv[argi]);
110 syntax();
111 return 2;
112 }
113 }
114 else
115 {
116 if (pszWin32Filename == NULL)
117 {
118 pszWin32Filename = argv[argi];
119 /* check if exists */
120 rc = DosQueryPathInfo(pszWin32Filename,FIL_QUERYFULLNAME,
121 &szBackupWin32Filename[0], sizeof(szBackupWin32Filename));
122 if (rc != NO_ERROR)
123 {
124 printf("Fatal error: Can't find Win32-file, '%s'.\n", pszWin32Filename);
125 return 80;
126 }
127 }
128 else if (pszOdin32Filename == NULL)
129 pszOdin32Filename = argv[argi];
130 else
131 {
132 printf("Syntax error: Too many filenames!\n");
133 syntax();
134 return 3;
135 }
136 }
137 } /* for */
138
139 /* check if enough arguments */
140 if (pszWin32Filename == NULL)
141 {
142 printf("Syntax error: No Win32-file specified.\n\n");
143 syntax();
144 return 4;
145 }
146
147 /* rename files? */
148 if (pszOdin32Filename == NULL)
149 {
150 char *pszExt = strrchr(pszWin32Filename, '.');
151 if (pszExt == NULL)
152 {
153 printf("warning: Win32-file don't have an extention\n");
154 strcpy(szBackupWin32Filename, pszWin32Filename);
155 strcat(szBackupWin32Filename, "wbk");
156 }
157 else
158 {
159 memset(szBackupWin32Filename, 0, sizeof(szBackupWin32Filename));
160 if (stricmp(pszExt + 1, "exe") == 0)
161 {
162 strncpy(szBackupWin32Filename, pszWin32Filename, pszExt - pszWin32Filename + 1);
163 strcat(szBackupWin32Filename, "exf");
164 }
165 else
166 {
167 strncpy(szBackupWin32Filename, pszWin32Filename, pszExt - pszWin32Filename + 3);
168 strcat(szBackupWin32Filename, "k");
169 }
170 }
171 rc = DosMove(pszWin32Filename, szBackupWin32Filename);
172 if (rc != NO_ERROR)
173 {
174 printf("Fatal error: Failed to rename the Win32-file, %s -> %s\n",
175 pszWin32Filename, szBackupWin32Filename);
176 return 81;
177 }
178 printInf(("Backuped %s to %s\n", pszWin32Filename, szBackupWin32Filename));
179
180 /* switch name */
181 pszOdin32Filename = pszWin32Filename;
182 pszWin32Filename = szBackupWin32Filename;
183 }
184
185 /* open input file */
186 HFILE hFileWin32;
187
188 rc = DosOpen(pszWin32Filename, &hFileWin32, &ulAction, 0UL,
189 FILE_NORMAL,
190 OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,
191 OPEN_FLAGS_RANDOMSEQUENTIAL | OPEN_ACCESS_READONLY | OPEN_SHARE_DENYWRITE,
192 NULL);
193 if (rc == NO_ERROR)
194 {
195 Pe2Lx pe2lx(hFileWin32);
196 rc = pe2lx.init(pszOdin32Filename);
197 if (rc == NO_ERROR)
198 {
199 rc = pe2lx.writeLxFile(pszOdin32Filename);
200 if (rc != NO_ERROR)
201 {
202 printf("Fatal error: Failed to write the Lx-file. rc=%d\n", rc);
203 rc = 84;
204 }
205 pe2lx.dumpVirtualLxFile();
206 }
207 else
208 {
209 printf("Fatal error: Failed to convertert the file. rc=%d\n", rc);
210 rc = 83;
211 }
212 DosClose(hFileWin32);
213 }
214 else
215 {
216 printf("Fatal error: Failed to open Win32-file, %s. rc=%d\n",
217 pszWin32Filename, rc);
218 rc = 82;
219 }
220 return (int)rc;
221}
222
223
224/**
225 * Display syntax for this program.
226 * @status completely implemented.
227 * @author knut st. osmundsen
228 */
229static void syntax()
230{
231 printf("Syntax: pe2lx.exe -W<0|1|2|3> <Win32File> [Odin32File]\n"
232 "\n"
233 " -W<0|1|2|3|4> Message filter level.\n"
234 " -W0: Output only severe and unrecoverable error messages.\n"
235 " -W1: Output error, severe and unrecoverable error messages.\n"
236 " -W2: Output warning, error, severe and unrecoverable error\n"
237 " messages.\n"
238 " -W3: Output nearly all messages.\n"
239 " -W4: Output absolutely all messages.\n"
240 " Default: -W3\n"
241 " Win32File Input Win32 Exe, Dll or other Win32 PE file.\n"
242 " Odin32File Output Odin32-file. If not specified the Win32-file is\n"
243 " renamed and the Odin32-file will use the original name\n"
244 " of the Win32-file.\n"
245 " Pe2Lx version 0.%02d\n",
246 PE2LX_VERSION
247 );
248}
249
250
251
252#if 0
253/**
254 * Debug - see how much of the stack that have been used.
255 * Padd stack, and look in the debug storage view on program end.
256 * @param
257 * @status
258 * @author knut st. osmundsen
259 */
260static void initStack()
261{
262 PTIB pTib;
263 PPIB pPib;
264
265 DosGetInfoBlocks(&pTib, &pPib);
266 memset((PVOID)pTib->tib_pstack, 'k', (size_t)&pTib - 0x30 - (size_t)pTib->tib_pstack);
267}
268#endif
Note: See TracBrowser for help on using the repository browser.