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

Last change on this file since 4247 was 4217, checked in by bird, 25 years ago

Moved extract specific function out of probkrnl.
Removed all ring-3 debug stuff - replaced by win32ktst.

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