source: trunk/src/win32k/dev16/extract.c@ 5120

Last change on this file since 5120 was 5103, checked in by bird, 25 years ago

Added import name length check. Added support for revision up to 'E'. For Not-Required entries blank object number.

File size: 10.4 KB
Line 
1/* $Id: extract.c,v 1.5 2001-02-11 15:16:49 bird Exp $
2 *
3 * Description: SymDB entry generator.
4 * Builds SymDB entry from one or more symbol files.
5 *
6 * Copyright (c) 2000-2001 knut st. osmundsen (knut.stange.osmundsen@mynd.no)
7 *
8 * Project Odin Software License can be found in LICENSE.TXT
9 *
10 */
11
12/*******************************************************************************
13* Defined Constants And Macros *
14*******************************************************************************/
15/* Disable logging */
16#define NOLOGGING 1
17
18#define fclose(a) DosClose(a)
19#define SEEK_SET FILE_BEGIN
20#define SEEK_END FILE_END
21
22#define WORD unsigned short int
23#define DWORD unsigned long int
24
25#define INCL_BASE
26#define INCL_DOS
27#define INCL_NOPMAPI
28#define INCL_OS2KRNL_LDR
29
30/*******************************************************************************
31* Header Files *
32*******************************************************************************/
33#include <os2.h>
34
35#include <strat2.h>
36#include <reqpkt.h>
37
38#include "devSegDf.h"
39#undef DATA16_INIT
40#define DATA16_INIT
41#undef CODE16_INIT
42#define CODE16_INIT
43#include "os2Krnl.h" /* must be included before dev1632.h! */
44#include "probkrnl.h"
45#include "dev1632.h"
46#include "vprntf16.h"
47
48
49/*******************************************************************************
50* Global Variables *
51*******************************************************************************/
52/* Result from GetKernelInfo/ReadOS2Krnl. */
53extern unsigned char cObjects;
54extern POTE paKrnlOTEs;
55
56/* dummy replacement for SymDB.c */
57KRNLDBENTRY DATA16_INIT aKrnlSymDB[] = {{0}};
58
59/*******************************************************************************
60* Internal Functions *
61*******************************************************************************/
62int processFile(const char *pszFilename);
63
64/*******************************************************************************
65* External Functions *
66*******************************************************************************/
67/* Workers */
68extern int ProbeSymFile(const char *pszFilename);
69
70/* C-library replacements and additions. */
71extern void kmemcpy(char *psz1, const char *psz2, int cch);
72extern char * kstrstr(const char *psz1, const char *psz2);
73extern int kstrcmp(const char *psz1, const char *psz2);
74extern int kstrncmp(const char *psz1, const char *psz2, int cch);
75extern int kstrnicmp(const char *psz1, const char *psz2, int cch);
76extern int kstrlen(const char *psz);
77extern char * kstrcpy(char * pszTarget, const char * pszSource);
78extern int kargncpy(char *pszTarget, const char *pszArg, unsigned cchMaxlen);
79
80
81
82/**
83 * Dumps writes a KRNLDBENTRY struct to stderr for the given .sym-file.
84 * The filesnames are on this format:
85 * nnnn[n]tm[r].SYM
86 * Where: n - are the build number 4 or 5 digits.
87 * t - kernel type. R = retail, H = half strict, A = all strict.
88 * m - UNI or SMP. U = UNI processor kernel. S = SMP processor kernel. 4 = Warp 4 FP13+
89 * r - revision letter. Currently only 'A' is supported.
90 * @returns NO_ERROR on success. Untracable error code on error.
91 * @param pszFilename Pointer to read only filename of the .sym-file.
92 * @status completely implemented.
93 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
94 * @remark Currently only retail kernels are processed. See note below.
95 */
96static int processFile(const char *pszFilename)
97{
98 APIRET rc;
99 int cch;
100 int cchNum;
101 const char *psz = pszFilename + kstrlen(pszFilename);
102
103 /* find filename */
104 cch = 0;
105 while (psz >= pszFilename && *psz != '\\' && *psz != '/' && *psz != ':')
106 psz--, cch++;
107 psz++;
108 cch--;
109
110 /* Progress information */
111 DosWrite(2, (char*)pszFilename, cch, &rc);
112 DosWrite(2, "\r\n", 2, &rc);
113
114 /* Filename check */
115 cchNum = psz[0] > '2' ? 4 : 5; /* build number length. */
116 if (cch < 10 || cch > 12
117 || !(psz[0] >= '0' && psz[0] <= '9')
118 || !(psz[1] >= '0' && psz[1] <= '9')
119 || !(psz[2] >= '0' && psz[2] <= '9')
120 || !(psz[3] >= '0' && psz[3] <= '9')
121 || !(cchNum == 4 || (psz[4] >= '0' && psz[4] <= '9'))
122 || !(psz[cchNum] == 'A' || psz[cchNum] == 'H' || psz[cchNum] == 'R')
123 || !(psz[cchNum+1] == 'S' || psz[cchNum+1] == 'U' || psz[cchNum+1] == '4')
124/* || !(cch != 12 || psz[cchNum+2] == 'A') */
125 )
126 {
127 printf16("invalid filename: %s\n", pszFilename);
128 return 2;
129 }
130
131 /*
132 * Probe kernelfile
133 */
134 rc = ProbeSymFile(pszFilename);
135
136
137 /*
138 * on success dump a struct for this kernel
139 */
140 if (rc == 0)
141 {
142 int i;
143
144 /** @remark
145 * Currently information for retail kernels are usable, but we'll
146 * generate it for the debug kernels too, but this information
147 * is enclaved within an "#ifdef ALLKERNELS ... #endif".
148 */
149 if (psz[cchNum] != 'R')
150 printf16("#ifdef ALLKERNELS\n");
151
152 printf16(" { /* %s */\n"
153 " %.*s, ",
154 psz,
155 cchNum, &psz[0] /* build number */
156 );
157
158 switch (psz[cchNum + 1])
159 {
160 case 'S': printf16("KF_SMP"); break;
161 case '4': printf16("KF_UNI | KF_W4"); break;
162 case 'U': printf16("KF_UNI"); break;
163 }
164 switch (psz[cchNum])
165 {
166 case 'A': printf16(" | KF_ALLSTRICT"); break;
167 case 'H': printf16(" | KF_HALFSTRICT"); break;
168 }
169 if (psz[cchNum + 2] >= 'A' && psz[cchNum + 2] <= 'E')
170 printf16(" | KF_REV_%c", psz[cchNum + 2]);
171
172 printf16(", %d,\n"
173 " {\n",
174 aImportTab[0].iObject + 1); /* ASSUMES that DOSCODE32 is the last object. */
175
176 for (i = 0; i < NBR_OF_KRNLIMPORTS; i++)
177 {
178 char *psz = aImportTab[i].achName;
179 printf16(" {%-2d, 0x%08lx}, /* %s */\n",
180 aImportTab[i].fFound ? aImportTab[i].iObject : 0,
181 aImportTab[i].fFound ? aImportTab[i].offObject : 0xFFFFFFFFUL,
182 (char *)&aImportTab[i].achName[0]
183 );
184 }
185 printf16(" }\n"
186 " },\n");
187
188 /** @remark
189 * Currently information for retail kernels are usable, but we'll
190 * generate it for the debug kernels too, but this information
191 * is enclaved within an "#ifdef ALLKERNELS ... #endif".
192 */
193 if (psz[cchNum] != 'R')
194 printf16("#endif\n");
195 }
196 else
197 printf16("ProbeSymFile failed with rc=%d\n", rc);
198
199 return rc;
200}
201
202
203/**
204 * Extract program.
205 *
206 * This is some initial trial-and-error for creating an "database" of
207 * kernel entrypoints.
208 *
209 * Output to stderr the structs generated for the passed in *.sym file.
210 *
211 */
212int main(int argc, char **argv)
213{
214 APIRET rc;
215 const char * psz;
216 int i;
217
218 /*
219 * Set paKrnlOTEs to point to an zeroed array of OTEs.
220 */
221 static KRNLINFO DATA16_INIT KrnlInfo = {0};
222 paKrnlOTEs = &KrnlInfo.aObjects[0];
223
224 /*
225 * Check name lengths.
226 */
227 for (i = 0; i < NBR_OF_KRNLIMPORTS; i++)
228 {
229 if (kstrlen(aImportTab[i].achName) != (int)aImportTab[i].cchName)
230 {
231 printf16("internal error - bad length of entry %d - %s. %d should be %d.\n",
232 i, aImportTab[i].achName, aImportTab[i].cchName, kstrlen(aImportTab[i].achName));
233 return -1;
234 }
235 }
236
237 /*
238 * Do work.
239 */
240 if (argc > 1)
241 {
242 /*
243 * Arguments: extract.exe <symfiles...>
244 */
245 int i;
246 for (i = 1; i < argc; i++)
247 {
248 rc = processFile(argv[i]);
249 if (rc != NO_ERROR)
250 {
251 printf16("processFile failed with rc=%d for file %s\n",
252 rc, argv[i]);
253 if (psz = GetErrorMsg(rc))
254 printf16("%s\n", psz);
255 return rc;
256 }
257 }
258 }
259 else
260 {
261 /*
262 * Arguments: extract.exe
263 *
264 * Action: Scan current directory for *.sym files.
265 *
266 */
267 USHORT usSearch = 1;
268 HDIR hDir = HDIR_CREATE;
269 FILEFINDBUF ffb;
270 int i;
271
272 printf16("/* $Id: extract.c,v 1.5 2001-02-11 15:16:49 bird Exp $\n"
273 "*\n"
274 "* Autogenerated kernel symbol database.\n"
275 "*\n"
276 "* Copyright (c) 2000 knut st. osmundsen (knut.stange.osmundsen@mynd.no)\n"
277 "*\n"
278 "* Project Odin Software License can be found in LICENSE.TXT\n"
279 "*\n"
280 "*/\n");
281
282 printf16("\n"
283 "#define INCL_NOPMAPI\n"
284 "#define INCL_NOBASEAPI\n"
285 "#include <os2.h>\n"
286 "#include \"DevSegDf.h\"\n"
287 "#include \"probkrnl.h\"\n"
288 "#include \"options.h\"\n"
289 "\n");
290
291 printf16("KRNLDBENTRY DATA16_INIT aKrnlSymDB[] = \n"
292 "{\n");
293
294 rc = DosFindFirst("*.sym", &hDir, FILE_NORMAL,
295 &ffb, sizeof(ffb),
296 &usSearch, 0UL);
297 while (rc == NO_ERROR & usSearch > 0)
298 {
299 rc = processFile(&ffb.achName[0]);
300 if (rc != NO_ERROR)
301 {
302 printf16("processFile failed with rc=%d for file %s\n",
303 rc, &ffb.achName[0]);
304 if (psz = GetErrorMsg(rc))
305 printf16("%s\n", psz);
306 return rc;
307 }
308
309 /* next file */
310 rc = DosFindNext(hDir, &ffb, sizeof(ffb), &usSearch);
311 }
312 DosFindClose(hDir);
313
314 printf16(" { /* Terminating entry */\n"
315 " 0,0,0,\n"
316 " {\n");
317 for (i = 0; i < NBR_OF_KRNLIMPORTS; i++)
318 printf16(" {0,0},\n");
319 printf16(" }\n"
320 " }\n"
321 "}; /* end of aKrnlSymDB[] */\n"
322 );
323 }
324
325
326 return rc;
327}
328
Note: See TracBrowser for help on using the repository browser.