1 | /* $Id: probkrnl.c,v 1.23 2000-09-08 14:48:40 bird Exp $
|
---|
2 | *
|
---|
3 | * Description: Autoprobes the os2krnl file and os2krnl[*].sym files.
|
---|
4 | * Another Hack!
|
---|
5 | *
|
---|
6 | * 16-bit inittime code.
|
---|
7 | *
|
---|
8 | * All data has to be initiated because this is 16-bit C code
|
---|
9 | * and is to be linked with 32-bit C/C++ code. Uninitiazlied
|
---|
10 | * data ends up in the BSS segment, and that segment can't
|
---|
11 | * both be 32-bit and 16-bit. I have not found any other way
|
---|
12 | * around this problem that initiating all data.
|
---|
13 | *
|
---|
14 | * How this works:
|
---|
15 | * 1. parses the device-line parameters and collects some "SysInfo".
|
---|
16 | * 2. gets the kernel object table and kernel info like build no. (elf$)
|
---|
17 | * 3. if non-debug kernel the symbol database is scanned to get the syms
|
---|
18 | * 4. if Syms not found THEN locates and scans the symbol-file(s) for the
|
---|
19 | * entrypoints which are wanted.
|
---|
20 | * 5. the entry points are verified. (elf$)
|
---|
21 | * 6. finished.
|
---|
22 | *
|
---|
23 | * Copyright (c) 1998-2000 knut st. osmundsen (knut.stange.osmundsen@mynd.no)
|
---|
24 | *
|
---|
25 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
26 | *
|
---|
27 | */
|
---|
28 |
|
---|
29 |
|
---|
30 | /*******************************************************************************
|
---|
31 | * Defined Constants And Macros *
|
---|
32 | *******************************************************************************/
|
---|
33 | /* Disable logging when doing extracts */
|
---|
34 | #if defined(EXTRACT) || defined(RING0)
|
---|
35 | #define NOLOGGING 1
|
---|
36 | #endif
|
---|
37 |
|
---|
38 | #define fclose(a) DosClose(a)
|
---|
39 | #define SEEK_SET FILE_BEGIN
|
---|
40 | #define SEEK_END FILE_END
|
---|
41 |
|
---|
42 | #define WORD unsigned short int
|
---|
43 | #define DWORD unsigned long int
|
---|
44 |
|
---|
45 | /* "@#IBM:14.039#@ os2krnl... "*/
|
---|
46 | /* "@#IBM:8.264#@ os2krnl... "*/
|
---|
47 | #define KERNEL_ID_STRING_LENGTH 42
|
---|
48 | #define KERNEL_READ_SIZE 512
|
---|
49 |
|
---|
50 | #define INCL_BASE
|
---|
51 | #define INCL_DOS
|
---|
52 | #define INCL_NOPMAPI
|
---|
53 |
|
---|
54 | /*******************************************************************************
|
---|
55 | * Header Files *
|
---|
56 | *******************************************************************************/
|
---|
57 | #include <os2.h>
|
---|
58 |
|
---|
59 | #include <exe386.h>
|
---|
60 | #include <strat2.h>
|
---|
61 | #include <reqpkt.h>
|
---|
62 |
|
---|
63 | #include "devSegDf.h"
|
---|
64 | #undef DATA16_INIT
|
---|
65 | #define DATA16_INIT
|
---|
66 | #undef CODE16_INIT
|
---|
67 | #define CODE16_INIT
|
---|
68 | #include "os2krnl.h" /* must be included before dev1632.h! */
|
---|
69 | #include "sym.h"
|
---|
70 | #include "probkrnl.h"
|
---|
71 | #include "dev16.h"
|
---|
72 | #include "dev1632.h"
|
---|
73 | #include "vprntf16.h"
|
---|
74 | #include "log.h"
|
---|
75 | #include "options.h"
|
---|
76 | #include "errors.h"
|
---|
77 |
|
---|
78 | /*******************************************************************************
|
---|
79 | * Global Variables *
|
---|
80 | * Note: must be inited or else we'll get BSS segment *
|
---|
81 | *******************************************************************************/
|
---|
82 |
|
---|
83 |
|
---|
84 | /*
|
---|
85 | * aImportTab defines the imported and overloaded OS/2 kernel functions.
|
---|
86 | * IMPORTANT: aImportTab has two sibling arrays, one in d32init.c, aulProc, and
|
---|
87 | * the calltab.asm, which must match entry by entry.
|
---|
88 | * When adding/removing/shuffling items in aImportTab, aulProc and
|
---|
89 | * calltab.asm has to be updated immediately!
|
---|
90 | */
|
---|
91 | IMPORTKRNLSYM DATA16_GLOBAL aImportTab[NBR_OF_KRNLIMPORTS] =
|
---|
92 | {/* iFound cchName offObject usSel fType */
|
---|
93 | /* iObject achName ulAddress cProlog */
|
---|
94 | {FALSE, -1, 8, "_ldrRead", -1, -1, -1, -1, EPT_PROC32}, /* 0 */
|
---|
95 | {FALSE, -1, 8, "_ldrOpen", -1, -1, -1, -1, EPT_PROC32}, /* 1 */
|
---|
96 | {FALSE, -1, 9, "_ldrClose", -1, -1, -1, -1, EPT_PROC32}, /* 2 */
|
---|
97 | {FALSE, -1, 12, "_LDRQAppType", -1, -1, -1, -1, EPT_PROC32}, /* 3 */
|
---|
98 | {FALSE, -1, 20, "_ldrEnum32bitRelRecs", -1, -1, -1, -1, EPT_PROC32}, /* 4 */
|
---|
99 | {FALSE, -1, 10, "_IOSftOpen", -1, -1, -1, -1, EPT_PROCIMPORT32}, /* 5 */
|
---|
100 | {FALSE, -1, 11, "_IOSftClose", -1, -1, -1, -1, EPT_PROCIMPORT32}, /* 6 */
|
---|
101 | {FALSE, -1, 15, "_IOSftTransPath", -1, -1, -1, -1, EPT_PROCIMPORT32}, /* 7 */
|
---|
102 | {FALSE, -1, 12, "_IOSftReadAt", -1, -1, -1, -1, EPT_PROCIMPORT32}, /* 8 */
|
---|
103 | {FALSE, -1, 13, "_IOSftWriteAt", -1, -1, -1, -1, EPT_PROCIMPORT32}, /* 9 */
|
---|
104 | {FALSE, -1, 12, "_SftFileSize", -1, -1, -1, -1, EPT_PROCIMPORT32}, /* 10 */
|
---|
105 | {FALSE, -1, 11, "_VMAllocMem", -1, -1, -1, -1, EPT_PROCIMPORT32}, /* 11 */
|
---|
106 | {FALSE, -1, 11, "_VMGetOwner", -1, -1, -1, -1, EPT_PROCIMPORT32}, /* 12 */
|
---|
107 | {FALSE, -1, 11, "g_tkExecPgm", -1, -1, -1, -1, EPT_PROC32}, /* 13 */
|
---|
108 | {FALSE, -1, 15, "_tkStartProcess", -1, -1, -1, -1, EPT_PROC32}, /* 14 */
|
---|
109 | {FALSE, -1, 11, "f_FuStrLenZ", -1, -1, -1, -1, EPT_PROCIMPORT16}, /* 15 */
|
---|
110 | {FALSE, -1, 10, "f_FuStrLen", -1, -1, -1, -1, EPT_PROCIMPORT16}, /* 16 */
|
---|
111 | {FALSE, -1, 8, "f_FuBuff", -1, -1, -1, -1, EPT_PROCIMPORT16}, /* 17 */
|
---|
112 | {FALSE, -1, 16, "_VMObjHandleInfo", -1, -1, -1, -1, EPT_PROCIMPORT32}, /* 18 */
|
---|
113 | {FALSE, -1, 21, "_ldrASMpMTEFromHandle",-1, -1, -1, -1, EPT_PROCIMPORT32}, /* 19 */
|
---|
114 | {FALSE, -1, 12, "_ldrOpenPath", -1, -1, -1, -1, EPT_PROC32}, /* 20 */
|
---|
115 | {FALSE, -1, 12, "_LDRClearSem", -1, -1, -1, -1, EPT_PROCIMPORT32}, /* 21 */
|
---|
116 | {FALSE, -1, 14, "_ldrFindModule", -1, -1, -1, -1, EPT_PROCIMPORT32}, /* 22 */
|
---|
117 | {FALSE, -1, 17, "_KSEMRequestMutex", -1, -1, -1, -1, EPT_PROCIMPORT32}, /* 23 */
|
---|
118 | {FALSE, -1, 17, "_KSEMReleaseMutex", -1, -1, -1, -1, EPT_PROCIMPORT32}, /* 24 */
|
---|
119 | {FALSE, -1, 15, "_KSEMQueryMutex", -1, -1, -1, -1, EPT_PROCIMPORT32}, /* 25 */
|
---|
120 | {FALSE, -1, 9, "_KSEMInit", -1, -1, -1, -1, EPT_PROCIMPORT32}, /* 26 */
|
---|
121 | {FALSE, -1, 7, "_LdrSem", -1, -1, -1, -1, EPT_VARIMPORT32}, /* 27 */
|
---|
122 | {FALSE, -1, 11, "_LDRLibPath", -1, -1, -1, -1, EPT_VARIMPORT32}, /* 28 */
|
---|
123 | {FALSE, -1, 9, "_TKSuBuff", -1, -1, -1, -1, EPT_PROCIMPORT32}, /* 29 */
|
---|
124 | {FALSE, -1, 9, "_TKFuBuff", -1, -1, -1, -1, EPT_PROCIMPORT32}, /* 30 */
|
---|
125 | {FALSE, -1, 11, "_TKFuBufLen", -1, -1, -1, -1, EPT_PROCIMPORT32}, /* 31 */
|
---|
126 | {FALSE, -1, 21, "_ldrValidateMteHandle",-1, -1, -1, -1, EPT_PROCIMPORT32}, /* 32 */
|
---|
127 | {FALSE, -1, 8, "_pTCBCur", -1, -1, -1, -1, EPT_VARIMPORT16}, /* 33 */
|
---|
128 | {FALSE, -1, 9, "_pPTDACur", -1, -1, -1, -1, EPT_VARIMPORT16}, /* 34 */
|
---|
129 | {FALSE, -1, 10, "ptda_start", -1, -1, -1, -1, EPT_VARIMPORT16}, /* 35 */
|
---|
130 | {FALSE, -1, 12, "ptda_environ", -1, -1, -1, -1, EPT_VARIMPORT16}, /* 36 */
|
---|
131 | {FALSE, -1, 12, "ptda_ptdasem", -1, -1, -1, -1, EPT_VARIMPORT16}, /* 37 */
|
---|
132 | {FALSE, -1, 11, "ptda_module", -1, -1, -1, -1, EPT_VARIMPORT16}, /* 38 */
|
---|
133 | {FALSE, -1, 18, "ptda_pBeginLIBPATH", -1, -1, -1, -1, EPT_VARIMPORT16}, /* 39 */
|
---|
134 | {FALSE, -1, 16, "_ldrpFileNameBuf", -1, -1, -1, -1, EPT_VARIMPORT32}, /* 40 */
|
---|
135 | {FALSE, -1, 14, "SecPathFromSFN", -1, -1, -1, -1, EPT_PROCIMPORTNR32},/* 41 */
|
---|
136 | {FALSE, -1, 14, "_ldrSetVMflags", -1, -1, -1, -1, EPT_PROC32}, /* 42 */
|
---|
137 |
|
---|
138 | };
|
---|
139 |
|
---|
140 | /**
|
---|
141 | * szSymbolFile holds the name of the symbol file used.
|
---|
142 | *
|
---|
143 | */
|
---|
144 | char DATA16_GLOBAL szSymbolFile[60] = {0};
|
---|
145 |
|
---|
146 | /**
|
---|
147 | * iProc holds the number of the procedure which failed during verify.
|
---|
148 | */
|
---|
149 | int DATA16_GLOBAL iProc = -1; /* The procedure number which failed Verify. */
|
---|
150 |
|
---|
151 |
|
---|
152 |
|
---|
153 | /*
|
---|
154 | * privat data
|
---|
155 | */
|
---|
156 | static char * DATA16_INIT apszSym[] =
|
---|
157 | {
|
---|
158 | {"c:\\os2krnl.sym"}, /* usual for debugkernel */
|
---|
159 | {"c:\\os2\\pdpsi\\pmdf\\warp4\\os2krnlr.sym"}, /* warp 4 */
|
---|
160 | {"c:\\os2\\pdpsi\\pmdf\\warp4\\os2krnld.sym"}, /* warp 4 */
|
---|
161 | {"c:\\os2\\pdpsi\\pmdf\\warp4\\os2krnlb.sym"}, /* warp 4 */
|
---|
162 | {"c:\\os2\\pdpsi\\pmdf\\warp45_u\\os2krnlr.sym"}, /* warp 45 */
|
---|
163 | {"c:\\os2\\pdpsi\\pmdf\\warp45_u\\os2krnld.sym"}, /* warp 45 */
|
---|
164 | {"c:\\os2\\pdpsi\\pmdf\\warp45_u\\os2krnlb.sym"}, /* warp 45 */
|
---|
165 | {"c:\\os2\\pdpsi\\pmdf\\warp45_s\\os2krnlr.sym"}, /* warp 45 */
|
---|
166 | {"c:\\os2\\pdpsi\\pmdf\\warp45_s\\os2krnld.sym"}, /* warp 45 */
|
---|
167 | {"c:\\os2\\pdpsi\\pmdf\\warp45_s\\os2krnlb.sym"}, /* warp 45 */
|
---|
168 | {"c:\\os2\\system\\trace\\os2krnl.sym"}, /* warp 3 ?*/
|
---|
169 | {"c:\\os2\\system\\pmdf\\os2krnlr.sym"}, /* warp 3 ?*/
|
---|
170 | {"c:\\os2krnlr.sym"}, /* custom */
|
---|
171 | {"c:\\os2krnlh.sym"}, /* custom */
|
---|
172 | {"c:\\os2krnld.sym"}, /* custom */
|
---|
173 | NULL
|
---|
174 | };
|
---|
175 |
|
---|
176 | /* Result from GetKernelInfo/ReadOS2Krnl. */
|
---|
177 | unsigned char DATA16_INIT cObjects = 0;
|
---|
178 | POTE DATA16_INIT paKrnlOTEs = NULL;
|
---|
179 |
|
---|
180 |
|
---|
181 | /*
|
---|
182 | *
|
---|
183 | */
|
---|
184 | static struct
|
---|
185 | {
|
---|
186 | short sErr;
|
---|
187 | const char *pszMsg;
|
---|
188 | } DATA16_INIT aErrorMsgs[] =
|
---|
189 | {
|
---|
190 | {ERROR_PROB_KRNL_OPEN_FAILED, "Krnl: Failed to open kernel file."},
|
---|
191 | {ERROR_PROB_KRNL_SEEK_SIZE, "Krnl: Failed to seek to end to of file."},
|
---|
192 | {ERROR_PROB_KRNL_SEEK_FIRST, "Krnl: Failed to start of file."},
|
---|
193 | {ERROR_PROB_KRNL_READ_FIRST, "Krnl: Failed to read (first)."},
|
---|
194 | {ERROR_PROB_KRNL_READ_NEXT, "Krnl: Failed to read."},
|
---|
195 | {ERROR_PROB_KRNL_TAG_NOT_FOUND, "Krnl: Build level tag was not found."},
|
---|
196 | {ERROR_PROB_KRNL_INV_SIGANTURE, "Krnl: Invalid build level signature."},
|
---|
197 | {ERROR_PROB_KRNL_INV_BUILD_NBR, "Krnl: Invalid build level number."},
|
---|
198 | {ERROR_PROB_KRNL_BUILD_VERSION, "Krnl: Invalid build level version."},
|
---|
199 | {ERROR_PROB_KRNL_MZ_SEEK, "Krnl: Failed to seek to start of file. (MZ)"},
|
---|
200 | {ERROR_PROB_KRNL_MZ_READ, "Krnl: Failed to read MZ header."},
|
---|
201 | {ERROR_PROB_KRNL_NEOFF_INVALID, "Krnl: Invalid new-header offset in MZ header."},
|
---|
202 | {ERROR_PROB_KRNL_NEOFF_SEEK, "Krnl: Failed to seek to new-header offset."},
|
---|
203 | {ERROR_PROB_KRNL_LX_READ, "Krnl: Failed to read LX header."},
|
---|
204 | {ERROR_PROB_KRNL_LX_SIGNATURE, "Krnl: Invalid LX header signature."},
|
---|
205 | {ERROR_PROB_KRNL_OBJECT_CNT, "Krnl: Object count don't match the running kernel."},
|
---|
206 | {ERROR_PROB_KRNL_OBJECT_CNR_10, "Krnl: Less than 10 objects - not a valid kernel file!"},
|
---|
207 | {ERROR_PROB_KRNL_OTE_SEEK, "Krnl: Failed to seek to OTEs."},
|
---|
208 | {ERROR_PROB_KRNL_OTE_READ, "Krnl: Failed to read OTEs."},
|
---|
209 | {ERROR_PROB_KRNL_OTE_SIZE_MIS, "Krnl: Size of a OTE didn't match the running kernel."},
|
---|
210 |
|
---|
211 | /*
|
---|
212 | * ProbeSymFile error messages + some extra ones.
|
---|
213 | */
|
---|
214 | {ERROR_PROB_SYM_FILE_NOT_FOUND, "Sym: Symbol file was not found."},
|
---|
215 | {ERROR_PROB_SYM_READERROR, "Sym: Read failed."},
|
---|
216 | {ERROR_PROB_SYM_INVALID_MOD_NAME, "Sym: Invalid module name (not OS2KRNL)."},
|
---|
217 | {ERROR_PROB_SYM_SEGS_NE_OBJS, "Sym: Number of segments don't match the object count of the kernel."},
|
---|
218 | {ERROR_PROB_SYM_SEG_DEF_SEEK, "Sym: Failed to seek to a segment definition."},
|
---|
219 | {ERROR_PROB_SYM_SEG_DEF_READ, "Sym: Failed to read a segment definition."},
|
---|
220 | {ERROR_PROB_SYM_IMPORTS_NOTFOUND, "Sym: Some of the imports wasn't found."},
|
---|
221 | {ERROR_PROB_SYM_V_PROC_NOT_FND, "Sym: Verify failed: Procedure not found."},
|
---|
222 | {ERROR_PROB_SYM_V_OBJ_OR_ADDR, "Sym: Verify failed: Invalid object or address."},
|
---|
223 | {ERROR_PROB_SYM_V_ADDRESS, "Sym: Verify failed: Invalid address."},
|
---|
224 | {ERROR_PROB_SYM_V_PROLOG, "Sym: Verify failed: Invalid prolog."},
|
---|
225 | {ERROR_PROB_SYM_V_NOT_IMPL, "Sym: Verify failed: Not implemented."},
|
---|
226 | {ERROR_PROB_SYM_V_GETOS2KRNL, "GetOs2Krnl: failed."},
|
---|
227 | {ERROR_PROB_SYM_V_NO_SWAPMTE, "GetOs2Krnl: No Swap MTE."},
|
---|
228 | {ERROR_PROB_SYM_V_OBJECTS, "GetOs2Krnl: Too many objects."},
|
---|
229 | {ERROR_PROB_SYM_V_OBJECT_TABLE, "GetOs2Krnl: No object table."},
|
---|
230 | {ERROR_PROB_SYM_V_BUILD_INFO, "GetOs2Krnl: Build info not found."},
|
---|
231 | {ERROR_PROB_SYM_V_INVALID_BUILD, "GetOs2Krnl: Unsupported build."},
|
---|
232 | {ERROR_PROB_SYM_V_VERIFY, "importTabInit: Import failed."},
|
---|
233 | {ERROR_PROB_SYM_V_IPE, "importTabInit: Internal-Processing-Error."},
|
---|
234 | {ERROR_PROB_SYM_V_HEAPINIT, "R0Init32: HeapInit Failed."},
|
---|
235 | {ERROR_PROB_SYM_V_D32_LDR_INIT, "R0Init32: ldrInit Failed."},
|
---|
236 |
|
---|
237 | {ERROR_PROB_SYMDB_KRNL_NOT_FOUND, "SymDB: Kernel was not found."}
|
---|
238 | };
|
---|
239 |
|
---|
240 | /*
|
---|
241 | * Fake data for Ring-3 testing.
|
---|
242 | */
|
---|
243 | #ifdef R3TST
|
---|
244 | USHORT DATA16_INIT usFakeVerMajor = 0;
|
---|
245 | USHORT DATA16_INIT usFakeVerMinor = 0;
|
---|
246 | #ifdef R3TST
|
---|
247 | static DATA16_INIT ach[11] = {0}; /* works around compiler/linker bug */
|
---|
248 | #endif
|
---|
249 | #endif
|
---|
250 |
|
---|
251 |
|
---|
252 | /*******************************************************************************
|
---|
253 | * Internal Functions *
|
---|
254 | *******************************************************************************/
|
---|
255 | /* File an output replacements */
|
---|
256 | HFILE fopen(const char * pszFilename, const char * pszIgnored);
|
---|
257 | int fread(void * pvBuffer, USHORT cbBlock, USHORT cBlock, HFILE hFile);
|
---|
258 | int fseek(HFILE hfile, signed long off, int iOrg);
|
---|
259 | unsigned long fsize(HFILE hFile);
|
---|
260 |
|
---|
261 | /* C-library replacements and additions. */
|
---|
262 | void kmemcpy(char *psz1, const char *psz2, int cch);
|
---|
263 | char * kstrstr(const char *psz1, const char *psz2);
|
---|
264 | int kstrcmp(const char *psz1, const char *psz2);
|
---|
265 | int kstrncmp(const char *psz1, const char *psz2, int cch);
|
---|
266 | int kstrnicmp(const char *psz1, const char *psz2, int cch);
|
---|
267 | int kstrlen(const char *psz);
|
---|
268 | char * kstrcpy(char * pszTarget, const char * pszSource);
|
---|
269 | int kargncpy(char *pszTarget, const char *pszArg, unsigned cchMaxlen);
|
---|
270 |
|
---|
271 | /* Workers */
|
---|
272 | int LookupKrnlEntry(unsigned short usBuild, unsigned short fKernel, unsigned char cObjects);
|
---|
273 | int VerifyPrologs(void);
|
---|
274 | int ProbeSymFile(const char *pszFilename);
|
---|
275 | int GetKernelInfo(void);
|
---|
276 |
|
---|
277 | /* Ouput */
|
---|
278 | void ShowResult(int rc);
|
---|
279 |
|
---|
280 | /* Others used while debugging in R3. */
|
---|
281 | int VerifyKernelVer(void);
|
---|
282 | int ReadOS2Krnl(char *pszFilename);
|
---|
283 | int ReadOS2Krnl2(HFILE hKrnl, unsigned long cbKrnl);
|
---|
284 |
|
---|
285 |
|
---|
286 |
|
---|
287 | /*******************************************************************************
|
---|
288 | * Implementation of Internal Helper Functions *
|
---|
289 | *******************************************************************************/
|
---|
290 |
|
---|
291 | /**
|
---|
292 | * Quick implementation of fopen.
|
---|
293 | * @param pszFilename name of file to open (sz)
|
---|
294 | * @param pszIgnored whatever - it is ignored
|
---|
295 | * @return Handle to file. (not pointer to a FILE stream as in C-library)
|
---|
296 | * @remark binary and readonly is assumed!
|
---|
297 | */
|
---|
298 | HFILE fopen(const char * pszFilename, const char * pszIgnored)
|
---|
299 | {
|
---|
300 | HFILE hFile = 0;
|
---|
301 | USHORT rc;
|
---|
302 | unsigned short Action = 0;
|
---|
303 |
|
---|
304 | rc = DosOpen(
|
---|
305 | (char*)pszFilename,
|
---|
306 | &hFile,
|
---|
307 | &Action,
|
---|
308 | 0,
|
---|
309 | FILE_NORMAL,
|
---|
310 | OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,
|
---|
311 | OPEN_SHARE_DENYNONE + OPEN_ACCESS_READONLY,
|
---|
312 | NULL);
|
---|
313 |
|
---|
314 | pszIgnored = pszIgnored;
|
---|
315 | return hFile;
|
---|
316 | }
|
---|
317 |
|
---|
318 |
|
---|
319 | /**
|
---|
320 | * fread emulation
|
---|
321 | * @returns Number of blocks read.
|
---|
322 | * @param pvBuffer Buffer to read into
|
---|
323 | * @param cbBlock Blocksize
|
---|
324 | * @param cBlock Block count
|
---|
325 | * @param hFile Handle to file (HFILE)
|
---|
326 | */
|
---|
327 | int fread(void * pvBuffer, USHORT cbBlock, USHORT cBlock, HFILE hFile)
|
---|
328 | {
|
---|
329 | USHORT ulRead;
|
---|
330 | USHORT rc;
|
---|
331 |
|
---|
332 | rc = DosRead(hFile, pvBuffer, (USHORT)(cbBlock*cBlock), &ulRead);
|
---|
333 | if (rc == 0)
|
---|
334 | rc = (USHORT)cBlock;
|
---|
335 | else
|
---|
336 | rc = 0;
|
---|
337 |
|
---|
338 | return rc;
|
---|
339 | }
|
---|
340 |
|
---|
341 |
|
---|
342 | /**
|
---|
343 | * fseek emultation
|
---|
344 | * @returns Same as DosChgFilePtr
|
---|
345 | * @param hFile Filehandle
|
---|
346 | * @param off offset into file from origin
|
---|
347 | * @param org origin
|
---|
348 | */
|
---|
349 | int fseek(HFILE hFile, signed long off, int iOrg)
|
---|
350 | {
|
---|
351 | ULONG ul;
|
---|
352 | return (int)DosChgFilePtr(hFile, off, iOrg, &ul);
|
---|
353 | }
|
---|
354 |
|
---|
355 |
|
---|
356 | /**
|
---|
357 | * Get filesize in bytes.
|
---|
358 | * @returns Filesize.
|
---|
359 | * @param hFile Filehandle
|
---|
360 | * @remark This function sets the file position to end of file.
|
---|
361 | */
|
---|
362 | unsigned long fsize(HFILE hFile)
|
---|
363 | {
|
---|
364 | USHORT rc;
|
---|
365 | unsigned long cb;
|
---|
366 |
|
---|
367 | rc = DosChgFilePtr(hFile, 0, FILE_END, &cb);
|
---|
368 |
|
---|
369 | return cb;
|
---|
370 | }
|
---|
371 |
|
---|
372 |
|
---|
373 | /**
|
---|
374 | * kmemcpy - memory copy - slow!
|
---|
375 | * @param psz1 target
|
---|
376 | * @param psz2 source
|
---|
377 | * @param cch length
|
---|
378 | */
|
---|
379 | void kmemcpy(char *psz1, const char *psz2, int cch)
|
---|
380 | {
|
---|
381 | while (cch-- != 0)
|
---|
382 | *psz1++ = *psz2++;
|
---|
383 | }
|
---|
384 |
|
---|
385 |
|
---|
386 | /**
|
---|
387 | * Finds psz2 in psz2.
|
---|
388 | * @returns Pointer to occurence of psz2 in psz1.
|
---|
389 | * @param psz1 String to be search.
|
---|
390 | * @param psz2 Substring to search for.
|
---|
391 | * @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
|
---|
392 | */
|
---|
393 | char *kstrstr(const char *psz1, const char *psz2)
|
---|
394 | {
|
---|
395 | while (*psz1 != '\0')
|
---|
396 | {
|
---|
397 | register int i = 0;
|
---|
398 | while (psz2[i] != '\0' && psz1[i] == psz2[i])
|
---|
399 | i++;
|
---|
400 |
|
---|
401 | /* found it? */
|
---|
402 | if (psz2[i] == '\0')
|
---|
403 | return (char*)psz1;
|
---|
404 | if (psz1[i] == '\0' )
|
---|
405 | break;
|
---|
406 | psz1++;
|
---|
407 | }
|
---|
408 |
|
---|
409 | return NULL;
|
---|
410 | }
|
---|
411 |
|
---|
412 |
|
---|
413 | #if 0 /* not in use */
|
---|
414 | /**
|
---|
415 | * kstrcmp - String compare
|
---|
416 | * @returns 0 - equal else !0
|
---|
417 | * @param psz1 String 1
|
---|
418 | * @param psz2 String 2
|
---|
419 | */
|
---|
420 | int kstrcmp(const char *psz1, const char *psz2);
|
---|
421 | {
|
---|
422 | while (*psz1 == *psz2 && *psz1 != '\0' && *psz2 != '\0')
|
---|
423 | {
|
---|
424 | psz1++;
|
---|
425 | psz2++;
|
---|
426 | }
|
---|
427 | return *psz1 - *psz2;
|
---|
428 | }
|
---|
429 | #endif
|
---|
430 |
|
---|
431 |
|
---|
432 | /**
|
---|
433 | * kstrncmp - String 'n' compare.
|
---|
434 | * @returns 0 - equal else !0
|
---|
435 | * @param p1 String 1
|
---|
436 | * @param p2 String 2
|
---|
437 | * @param len length
|
---|
438 | */
|
---|
439 | int kstrncmp(register const char *psz1, register const char *psz2, int cch)
|
---|
440 | {
|
---|
441 | int i = 0;
|
---|
442 | while (i < cch && *psz1 == *psz2 && *psz1 != '\0' && *psz2 != '\0')
|
---|
443 | {
|
---|
444 | psz1++;
|
---|
445 | psz2++;
|
---|
446 | i++;
|
---|
447 | }
|
---|
448 |
|
---|
449 | return i - cch;
|
---|
450 | }
|
---|
451 |
|
---|
452 |
|
---|
453 | #if 0 /* not in use */
|
---|
454 | /**
|
---|
455 | * kstrnicmp - String 'n' compare, case-insensitive.
|
---|
456 | * @returns 0 - equal else !0
|
---|
457 | * @param p1 String 1
|
---|
458 | * @param p2 String 2
|
---|
459 | * @param len length
|
---|
460 | */
|
---|
461 | int kstrnicmp(const char *psz1, const char *psz2, int cch)
|
---|
462 | {
|
---|
463 | register char ch1, ch2;
|
---|
464 |
|
---|
465 | do
|
---|
466 | {
|
---|
467 | ch1 = *psz1++;
|
---|
468 | if (ch1 >= 'A' && ch1 <= 'Z')
|
---|
469 | ch1 += 'a' - 'A'; /* to lower case */
|
---|
470 | ch2 = *psz2++;
|
---|
471 | if (ch2 >= 'A' && ch2 <= 'Z')
|
---|
472 | ch2 += 'a' - 'A'; /* to lower case */
|
---|
473 | } while (--cch > 0 && ch1 == ch2 && ch1 != '\0' && ch2 != '\0');
|
---|
474 |
|
---|
475 | return ch1 - ch2;
|
---|
476 | }
|
---|
477 | #endif
|
---|
478 |
|
---|
479 |
|
---|
480 | /**
|
---|
481 | * kstrlen - String length.
|
---|
482 | * @returns Length of the string.
|
---|
483 | * @param psz Pointer to string.
|
---|
484 | * @status completely implemented and tested.
|
---|
485 | * @author knut st. osmundsen
|
---|
486 | */
|
---|
487 | int kstrlen(register const char * psz)
|
---|
488 | {
|
---|
489 | register int cch = 0;
|
---|
490 | while (*psz++ != '\0')
|
---|
491 | cch++;
|
---|
492 | return cch;
|
---|
493 | }
|
---|
494 |
|
---|
495 |
|
---|
496 | /**
|
---|
497 | * String copy (strcpy).
|
---|
498 | * @returns Pointer to target string.
|
---|
499 | * @param pszTarget Target string.
|
---|
500 | * @param pszSource Source string.
|
---|
501 | * @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
|
---|
502 | */
|
---|
503 | char * kstrcpy(char * pszTarget, register const char * pszSource)
|
---|
504 | {
|
---|
505 | register char *psz = pszTarget;
|
---|
506 |
|
---|
507 | while (*pszSource != '\0')
|
---|
508 | *psz++ = *pszSource++;
|
---|
509 | *psz = '\0';
|
---|
510 | return pszTarget;
|
---|
511 | }
|
---|
512 |
|
---|
513 |
|
---|
514 |
|
---|
515 |
|
---|
516 | /**
|
---|
517 | * Copy an argument to a buffer. Ie. "-K[=|:]c:\os2krnl ....". Supports quotes
|
---|
518 | * @returns Number of chars of pszArg that has been processed.
|
---|
519 | * @param pszTarget - pointer to target buffer.
|
---|
520 | * @param pszArg - pointer to source argument string.
|
---|
521 | * @param cchMaxlen - maximum chars to copy.
|
---|
522 | */
|
---|
523 | int kargncpy(char * pszTarget, const char * pszArg, unsigned cchMaxlen)
|
---|
524 | {
|
---|
525 | int i = 0;
|
---|
526 | int fQuote = FALSE;
|
---|
527 |
|
---|
528 | /* skip option word/letter */
|
---|
529 | while (*pszArg != '\0' && *pszArg != ' ' && *pszArg != ':' &&
|
---|
530 | *pszArg != '=' && *pszArg != '-' && *pszArg != '/')
|
---|
531 | {
|
---|
532 | pszArg++;
|
---|
533 | i++;
|
---|
534 | }
|
---|
535 |
|
---|
536 | if (*pszArg == ' ' || *pszArg == '-' || *pszArg == '/' || *pszArg == '\0')
|
---|
537 | return 0;
|
---|
538 |
|
---|
539 |
|
---|
540 | do
|
---|
541 | {
|
---|
542 | pszArg++;
|
---|
543 | i++;
|
---|
544 | } while (*pszArg != '\0' && *pszArg == ' ');
|
---|
545 |
|
---|
546 | /* copy maxlen or less */
|
---|
547 | /* check for quotes */
|
---|
548 | if (*pszArg == '"')
|
---|
549 | {
|
---|
550 | fQuote = TRUE;
|
---|
551 | pszArg++;
|
---|
552 | i++;
|
---|
553 | }
|
---|
554 | /* copy loop */
|
---|
555 | while (cchMaxlen > 1 && (fQuote ? *pszArg != '"' : *pszArg != ' ') && *pszArg != '\0')
|
---|
556 | {
|
---|
557 | *pszTarget++ = *pszArg++;
|
---|
558 | i++;
|
---|
559 | cchMaxlen--;
|
---|
560 | }
|
---|
561 |
|
---|
562 | /* terminate pszTarget */
|
---|
563 | pszTarget = '\0';
|
---|
564 |
|
---|
565 | return i;
|
---|
566 | }
|
---|
567 |
|
---|
568 |
|
---|
569 | /**
|
---|
570 | * Get the message text for an error message.
|
---|
571 | * @returns Pointer to error text. NULL if not found.
|
---|
572 | * @param sErr Error code id.
|
---|
573 | * @status completely implemented.
|
---|
574 | * @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
|
---|
575 | */
|
---|
576 | const char * GetErrorMsg(short sErr)
|
---|
577 | {
|
---|
578 | int i;
|
---|
579 | for (i = 0; i < sizeof(aErrorMsgs) / sizeof(aErrorMsgs[0]); i++)
|
---|
580 | {
|
---|
581 | if (aErrorMsgs[i].sErr == sErr)
|
---|
582 | return aErrorMsgs[i].pszMsg;
|
---|
583 | }
|
---|
584 | return NULL;
|
---|
585 | }
|
---|
586 |
|
---|
587 |
|
---|
588 |
|
---|
589 | /*******************************************************************************
|
---|
590 | * Implementation Of The Important Functions *
|
---|
591 | *******************************************************************************/
|
---|
592 | /**
|
---|
593 | * Checks if this kernel is within the kernel symbol database.
|
---|
594 | * If an entry for the kernel is found, the data is copied from the
|
---|
595 | * database entry to aImportTab.
|
---|
596 | * @returns NO_ERROR on succes (0)
|
---|
597 | * 1 if not found.
|
---|
598 | * Error code on error.
|
---|
599 | * @param usBuild Build level.
|
---|
600 | * @param fKernel Kernel (type) flags. (KF_* from options.h)
|
---|
601 | * @param cObjects Count of object in the running kernel.
|
---|
602 | * @sketch Loop thru the table.
|
---|
603 | * @status completely implemented.
|
---|
604 | * @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
|
---|
605 | */
|
---|
606 | int LookupKrnlEntry(unsigned short usBuild, unsigned short fKernel, unsigned char cObjects)
|
---|
607 | {
|
---|
608 | int i;
|
---|
609 |
|
---|
610 | /*
|
---|
611 | * Loop tru the DB entries until a NULL pointer is found.
|
---|
612 | */
|
---|
613 | for (i = 0; aKrnlSymDB[i].usBuild != 0; i++)
|
---|
614 | {
|
---|
615 | if ( aKrnlSymDB[i].usBuild == usBuild
|
---|
616 | && aKrnlSymDB[i].fKernel == fKernel
|
---|
617 | && aKrnlSymDB[i].cObjects == cObjects)
|
---|
618 | { /* found matching entry! */
|
---|
619 | int j;
|
---|
620 | int rc;
|
---|
621 | register PKRNLDBENTRY pEntry = &aKrnlSymDB[i];
|
---|
622 |
|
---|
623 | dprintf(("LookUpKrnlEntry - found entry for this kernel!\n"));
|
---|
624 |
|
---|
625 | /*
|
---|
626 | * Copy symbol data from the DB to aImportTab.
|
---|
627 | */
|
---|
628 | for (j = 0; j < NBR_OF_KRNLIMPORTS; j++)
|
---|
629 | {
|
---|
630 | aImportTab[j].offObject = pEntry->aSyms[j].offObject;
|
---|
631 | aImportTab[j].iObject = pEntry->aSyms[j].iObject;
|
---|
632 | aImportTab[j].ulAddress = paKrnlOTEs[pEntry->aSyms[j].iObject].ote_base
|
---|
633 | + pEntry->aSyms[j].offObject;
|
---|
634 | aImportTab[j].usSel = paKrnlOTEs[pEntry->aSyms[j].iObject].ote_sel;
|
---|
635 | aImportTab[j].fFound = (char)((aImportTab[j].offObject != 0xFFFFFFFFUL) ? 1 : 0);
|
---|
636 | dprintf((" %-3d addr=0x%08lx off=0x%08lx %s\n",
|
---|
637 | j, aImportTab[j].ulAddress, aImportTab[j].offObject,
|
---|
638 | aImportTab[j].achName));
|
---|
639 | }
|
---|
640 |
|
---|
641 | /* Verify prologs*/
|
---|
642 | rc = VerifyPrologs();
|
---|
643 |
|
---|
644 | /* set sym name on success or complain on error */
|
---|
645 | if (rc == 0)
|
---|
646 | kstrcpy(szSymbolFile, "Win32k Symbol Database");
|
---|
647 | else
|
---|
648 | {
|
---|
649 | printf16("Warning: The Win32k Symbol Database entry found.\n"
|
---|
650 | " But, VerifyPrologs() returned rc=0x%x and iProc=%d\n", rc, iProc);
|
---|
651 | DosSleep(3000);
|
---|
652 | }
|
---|
653 |
|
---|
654 | return rc;
|
---|
655 | }
|
---|
656 | }
|
---|
657 |
|
---|
658 | /* not found */
|
---|
659 | return ERROR_PROB_SYMDB_KRNL_NOT_FOUND;
|
---|
660 | }
|
---|
661 |
|
---|
662 |
|
---|
663 | /**
|
---|
664 | * Verifies the that the addresses in aImportTab are valid.
|
---|
665 | * This is done at Ring-0 of course.
|
---|
666 | * @returns NO_ERROR (ie. 0) on success. iProc = -1
|
---|
667 | * The appropriate OS/2 or Win32k return code on success. iProc
|
---|
668 | * is set to the failing procedure (if appliable).
|
---|
669 | */
|
---|
670 | int VerifyPrologs(void)
|
---|
671 | {
|
---|
672 | #if !defined(EXTRACT)
|
---|
673 | APIRET rc;
|
---|
674 | HFILE hDev0 = 0;
|
---|
675 | USHORT usAction = 0;
|
---|
676 |
|
---|
677 | /* Set the failing procedure number to -1. */
|
---|
678 | iProc = -1;
|
---|
679 |
|
---|
680 | /* Open the elf device driver. */
|
---|
681 | rc = DosOpen("\\dev\\elf$", &hDev0, &usAction, 0UL, FILE_NORMAL,
|
---|
682 | OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,
|
---|
683 | OPEN_SHARE_DENYNONE | OPEN_ACCESS_READONLY,
|
---|
684 | 0UL);
|
---|
685 | if (rc == NO_ERROR)
|
---|
686 | {
|
---|
687 | D16VERIFYIMPORTTABDATA Data = {0};
|
---|
688 |
|
---|
689 | /* Issue the VerifyImportTab IOCtl call. */
|
---|
690 | rc = DosDevIOCtl(&Data, "", D16_IOCTL_VERIFYIMPORTTAB, D16_IOCTL_CAT, hDev0);
|
---|
691 | DosClose(hDev0);
|
---|
692 | if (rc == NO_ERROR)
|
---|
693 | {
|
---|
694 | if (Data.usRc != NO_ERROR)
|
---|
695 | {
|
---|
696 | /* set the appropriate return values. */
|
---|
697 | rc = (Data.usRc & ERROR_D32_ERROR_MASK) + ERROR_PROB_SYM_D32_FIRST;
|
---|
698 | if (Data.usRc & ERROR_D32_PROC_FLAG)
|
---|
699 | iProc = (Data.usRc & ERROR_D32_PROC_MASK) >> ERROR_D32_PROC_SHIFT;
|
---|
700 | }/* else success */
|
---|
701 | }
|
---|
702 | else
|
---|
703 | {
|
---|
704 | dprintf(("DosDevIOCtl failed with rc=%d\n", rc));
|
---|
705 | DosSleep(3000);
|
---|
706 | }
|
---|
707 | }
|
---|
708 | else
|
---|
709 | {
|
---|
710 | dprintf(("DosOpen Failed with rc=%d\n", rc));
|
---|
711 | DosSleep(3000);
|
---|
712 | }
|
---|
713 |
|
---|
714 | return rc;
|
---|
715 | #else
|
---|
716 | return 0;
|
---|
717 | #endif
|
---|
718 | }
|
---|
719 |
|
---|
720 |
|
---|
721 | /**
|
---|
722 | * Check a symbol file. Searches for the wanted entry-point addresses.
|
---|
723 | * @returns 0 on success - something else on failiure.
|
---|
724 | * @param pszFilename Name of file to probe.
|
---|
725 | * @precond Must be called after kernel-file is found and processed.
|
---|
726 | * @remark Error codes starts at -50.
|
---|
727 | */
|
---|
728 | int ProbeSymFile(const char * pszFilename)
|
---|
729 | {
|
---|
730 | HFILE hSym; /* Filehandle */
|
---|
731 | int cLeftToFind; /* Symbols left to find */
|
---|
732 | unsigned long iSeg; /* Outer search loop: Segment number */
|
---|
733 | unsigned iSym; /* Middle search loop: Symbol number */
|
---|
734 | unsigned i; /* Inner search loop: ProcTab index */
|
---|
735 | int rc;
|
---|
736 |
|
---|
737 | MAPDEF MapDef; /* Mapfile header */
|
---|
738 | SEGDEF SegDef; /* Segment header */
|
---|
739 | SYMDEF32 SymDef32; /* Symbol definition 32-bit */
|
---|
740 | SYMDEF16 SymDef16; /* Symbol definition 16-bit */
|
---|
741 | char achBuffer[256]; /* Name buffer */
|
---|
742 | unsigned long offSegment; /* Segment definition offset */
|
---|
743 | unsigned long offSymPtr; /* Symbol pointer(offset) offset */
|
---|
744 | unsigned short offSym; /* Symbol definition offset */
|
---|
745 |
|
---|
746 |
|
---|
747 | /*
|
---|
748 | * Open the symbol file
|
---|
749 | */
|
---|
750 | hSym = fopen(pszFilename, "rb");
|
---|
751 | if (hSym==0)
|
---|
752 | {
|
---|
753 | dprintf(("Error opening file %s\n", pszFilename));
|
---|
754 | return ERROR_PROB_SYM_FILE_NOT_FOUND;
|
---|
755 | }
|
---|
756 | dprintf(("\nSuccessfully opened symbolfile: %s\n", pszFilename));
|
---|
757 |
|
---|
758 |
|
---|
759 | /*
|
---|
760 | * (Open were successfully.)
|
---|
761 | * Now read header and display it.
|
---|
762 | */
|
---|
763 | rc = fread(&MapDef, sizeof(MAPDEF), 1, hSym);
|
---|
764 | if (!rc)
|
---|
765 | { /* oops! read failed, close file and fail. */
|
---|
766 | fclose(hSym);
|
---|
767 | return ERROR_PROB_SYM_READERROR;
|
---|
768 | }
|
---|
769 | achBuffer[0] = MapDef.achModName[0];
|
---|
770 | fread(&achBuffer[1], 1, MapDef.cbModName, hSym);
|
---|
771 | achBuffer[MapDef.cbModName] = '\0';
|
---|
772 | dprintf(("*Module name: %s\n", achBuffer));
|
---|
773 | dprintf(("*Segments: %d\n*MaxSymbolLength: %d\n", MapDef.cSegs, MapDef.cbMaxSym));
|
---|
774 | dprintf(("*ppNextMap: 0x%x\n", MapDef.ppNextMap ));
|
---|
775 |
|
---|
776 |
|
---|
777 | /*
|
---|
778 | * Verify that the modulename of the symbol file is OS2KRNL.
|
---|
779 | */
|
---|
780 | if (MapDef.cbModName == 7 && kstrncmp(achBuffer, "OS2KRNL", 7) != 0)
|
---|
781 | { /* modulename was not OS2KRNL, fail. */
|
---|
782 | dprintf(("Modulename verify failed\n"));
|
---|
783 | fclose(hSym);
|
---|
784 | return ERROR_PROB_SYM_INVALID_MOD_NAME;
|
---|
785 | }
|
---|
786 |
|
---|
787 |
|
---|
788 | /*
|
---|
789 | * Verify that the number of segments is equal to the number objects in OS2KRNL.
|
---|
790 | */
|
---|
791 | #ifndef EXTRACT
|
---|
792 | if (MapDef.cSegs != cObjects)
|
---|
793 | { /* incorrect count of segments. */
|
---|
794 | dprintf(("Segment No. verify failed\n"));
|
---|
795 | fclose(hSym);
|
---|
796 | return ERROR_PROB_SYM_SEGS_NE_OBJS;
|
---|
797 | }
|
---|
798 | #endif /* !EXTRACT */
|
---|
799 |
|
---|
800 |
|
---|
801 | /*
|
---|
802 | * Reset ProcTab
|
---|
803 | */
|
---|
804 | for (i = 0; i < NBR_OF_KRNLIMPORTS; i++)
|
---|
805 | {
|
---|
806 | aImportTab[i].fFound = 0;
|
---|
807 | #ifdef DEBUG
|
---|
808 | aImportTab[i].offObject = 0;
|
---|
809 | aImportTab[i].ulAddress = 0;
|
---|
810 | aImportTab[i].usSel = 0;
|
---|
811 | #endif
|
---|
812 | }
|
---|
813 |
|
---|
814 |
|
---|
815 | /*
|
---|
816 | * Fileoffset of the first segment.
|
---|
817 | * And set cLeftToFind.
|
---|
818 | */
|
---|
819 | offSegment = SEGDEFOFFSET(MapDef);
|
---|
820 | cLeftToFind = NBR_OF_KRNLIMPORTS;
|
---|
821 |
|
---|
822 | /*
|
---|
823 | * Search thru the entire file, segment by segment.
|
---|
824 | *
|
---|
825 | * ASSUME: last segment is the only 32-bit code segment.
|
---|
826 | *
|
---|
827 | */
|
---|
828 | for (iSeg = 0; iSeg < MapDef.cSegs; iSeg++, offSegment = NEXTSEGDEFOFFSET(SegDef))
|
---|
829 | {
|
---|
830 | int fSegEPTBitType; /* Type of segment, 16 or 32 bit, expressed in EPT_XXBIT flags */
|
---|
831 | int fCode; /* Set if this is a code segment, else clear. */
|
---|
832 |
|
---|
833 | /*
|
---|
834 | * Read the segment definition.
|
---|
835 | */
|
---|
836 | if (fseek(hSym, offSegment, SEEK_SET))
|
---|
837 | { /* Failed to seek to the segment definition, fail! */
|
---|
838 | fclose(hSym);
|
---|
839 | return ERROR_PROB_SYM_SEG_DEF_SEEK;
|
---|
840 | }
|
---|
841 | rc = fread(&SegDef, sizeof(SEGDEF), 1, hSym);
|
---|
842 | if (!rc)
|
---|
843 | { /* Failed to read the segment definition, fail! */
|
---|
844 | fclose(hSym);
|
---|
845 | return ERROR_PROB_SYM_SEG_DEF_READ;
|
---|
846 | }
|
---|
847 |
|
---|
848 | /*
|
---|
849 | * Some debugging info.
|
---|
850 | */
|
---|
851 | achBuffer[0] = SegDef.achSegName[0];
|
---|
852 | fread(&achBuffer[1], 1, SegDef.cbSegName, hSym);
|
---|
853 | achBuffer[SegDef.cbSegName] = '\0';
|
---|
854 | dprintf(("Segment %.2li Flags=0x%02x cSymbols=0x%04x Name=%s\n",
|
---|
855 | iSeg, SegDef.bFlags, SegDef.cSymbols, &achBuffer[0]));
|
---|
856 |
|
---|
857 | /*
|
---|
858 | * Determin segment bit type.
|
---|
859 | */
|
---|
860 | fSegEPTBitType = SEG32BitSegment(SegDef) ? EPT_32BIT : EPT_16BIT;
|
---|
861 | fCode = kstrstr(achBuffer, "CODE") != NULL;
|
---|
862 |
|
---|
863 | /*
|
---|
864 | * Search thru all the symbols in this segment
|
---|
865 | * while we look for the requested symbols in aImportTab.
|
---|
866 | */
|
---|
867 | for (iSym = 0; iSym < SegDef.cSymbols && cLeftToFind; iSym++)
|
---|
868 | {
|
---|
869 | IMPORTKRNLSYM * pImport;
|
---|
870 | unsigned cchName;
|
---|
871 |
|
---|
872 | /*
|
---|
873 | * Fileoffset of the current symbol.
|
---|
874 | * Set filepointer to that position.
|
---|
875 | * Read word (which is the offset of the symbol).
|
---|
876 | */
|
---|
877 | offSymPtr = SYMDEFOFFSET(offSegment, SegDef, iSym);
|
---|
878 | rc = fseek(hSym, offSymPtr, SEEK_SET);
|
---|
879 | if (rc)
|
---|
880 | { /* Symboloffset seek failed, try read next symbol. */
|
---|
881 | dprintf(("Warning: Seek failed (offSymPtr=%d, rc=%d)\n", offSymPtr, rc));
|
---|
882 | continue;
|
---|
883 | }
|
---|
884 | rc = fread(&offSym, sizeof(unsigned short int), 1, hSym);
|
---|
885 | if (!rc)
|
---|
886 | { /* Symboloffset read failed, try read next symbol. */
|
---|
887 | dprintf(("Warning: read failed (offSymPtr=%d, rc=%d)\n", offSymPtr, rc));
|
---|
888 | continue;
|
---|
889 | }
|
---|
890 | rc = fseek(hSym, offSym + offSegment, SEEK_SET);
|
---|
891 | if (rc)
|
---|
892 | { /* Symbol Seek failed, try read next symbol. */
|
---|
893 | dprintf(("Warning: Seek failed (offSym=%d, rc=%d)\n", offSym, rc));
|
---|
894 | continue;
|
---|
895 | }
|
---|
896 |
|
---|
897 |
|
---|
898 | /*
|
---|
899 | * Read symbol and symbolname.
|
---|
900 | */
|
---|
901 | if (SegDef.bFlags & 0x01)
|
---|
902 | rc = fread(&SymDef32, sizeof(SYMDEF32), 1, hSym);
|
---|
903 | else
|
---|
904 | rc = fread(&SymDef16, sizeof(SYMDEF16), 1, hSym);
|
---|
905 | if (!rc)
|
---|
906 | { /* Symbol read failed, try read next symbol */
|
---|
907 | dprintf(("Warning: Read(1) failed (offSym=%d, rc=%d)\n", offSym, rc));
|
---|
908 | continue;
|
---|
909 | }
|
---|
910 | achBuffer[0] = (SegDef.bFlags & 0x01) ? SymDef32.achSymName[0] : SymDef16.achSymName[0];
|
---|
911 | cchName = (SegDef.bFlags & 0x01) ? SymDef32.cbSymName : SymDef16.cbSymName;
|
---|
912 | rc = fread(&achBuffer[1], 1, cchName, hSym);
|
---|
913 | if (!rc)
|
---|
914 | { /* Symbol read failed, try read next symbol */
|
---|
915 | dprintf(("Warning: Read(2) failed (offSym=%d, rc=%d)\n", offSym, rc));
|
---|
916 | continue;
|
---|
917 | }
|
---|
918 | achBuffer[cchName] = '\0';
|
---|
919 |
|
---|
920 |
|
---|
921 | /*
|
---|
922 | * Search proctable.
|
---|
923 | */
|
---|
924 | for (i = 0, pImport = &aImportTab[0]; i < NBR_OF_KRNLIMPORTS; i++, pImport++)
|
---|
925 | {
|
---|
926 | if (!pImport->fFound /* Not allready found */
|
---|
927 | && (pImport->fType & EPT_VARIMPORT ? !fCode : fCode) /* Don't look for code in a data segment */
|
---|
928 | && pImport->cchName == cchName /* Equal name length */
|
---|
929 | && kstrncmp(pImport->achName, achBuffer, cchName) == 0 /* Equal name */
|
---|
930 | )
|
---|
931 | { /* Symbol was found */
|
---|
932 | pImport->offObject = (SegDef.bFlags & 0x01 ? SymDef32.wSymVal : SymDef16.wSymVal);
|
---|
933 | pImport->ulAddress = pImport->offObject + paKrnlOTEs[iSeg].ote_base;
|
---|
934 | pImport->iObject = (unsigned char)iSeg;
|
---|
935 | pImport->usSel = paKrnlOTEs[iSeg].ote_sel;
|
---|
936 | dprintf(("debug: base=%lx, size=%lx iSeg=%d\n", paKrnlOTEs[iSeg].ote_base, paKrnlOTEs[iSeg].ote_size, iSeg));
|
---|
937 |
|
---|
938 | /* Paranoia test! */
|
---|
939 | #ifndef EXTRACT
|
---|
940 | if (pImport->offObject < paKrnlOTEs[iSeg].ote_size)
|
---|
941 | {
|
---|
942 | pImport->fFound = TRUE;
|
---|
943 | cLeftToFind--;
|
---|
944 | dprintf(("Found: %s at off 0x%lx addr 0x%lx, sel=0x%x\n",
|
---|
945 | pImport->achName, pImport->offObject,
|
---|
946 | pImport->ulAddress, pImport->usSel));
|
---|
947 | }
|
---|
948 | else/* test failed, continue on next symbol*/
|
---|
949 | dprintf(("Error: Paranoia test failed for %s\n", pImport->achName));;
|
---|
950 | #else
|
---|
951 | pImport->fFound = TRUE;
|
---|
952 | cLeftToFind--;
|
---|
953 | #endif /* !EXTRACT */
|
---|
954 | break;
|
---|
955 | }
|
---|
956 |
|
---|
957 | } /* aImportTab for-loop */
|
---|
958 |
|
---|
959 | } /* Symbol for-loop */
|
---|
960 |
|
---|
961 | } /* Segment for-loop */
|
---|
962 |
|
---|
963 | /*
|
---|
964 | * Close symbol file.
|
---|
965 | */
|
---|
966 | fclose(hSym);
|
---|
967 |
|
---|
968 | /*
|
---|
969 | * If not all procedures were found fail.
|
---|
970 | */
|
---|
971 | for (i = 0; i < NBR_OF_KRNLIMPORTS; i++)
|
---|
972 | if (!aImportTab[i].fFound && !(aImportTab[i].fType & EPT_NOT_REQ))
|
---|
973 | return ERROR_PROB_SYM_IMPORTS_NOTFOUND;
|
---|
974 |
|
---|
975 | /*
|
---|
976 | * Verify function prologs and return.
|
---|
977 | */
|
---|
978 | return VerifyPrologs();
|
---|
979 | }
|
---|
980 |
|
---|
981 |
|
---|
982 | /**
|
---|
983 | * Get kernelinformation (OTEs (object table entries), build, type, debug...)
|
---|
984 | * @returns 0 on success.
|
---|
985 | * options.ulBuild, fchType, fDebug, cObjects and paKrnlOTEs is set on successful return.
|
---|
986 | * Not 0 on error.
|
---|
987 | */
|
---|
988 | int GetKernelInfo(void)
|
---|
989 | {
|
---|
990 | #if !defined(EXTRACT) /* This IOCtl is not available after inittime! */
|
---|
991 | static KRNLINFO DATA16_INIT KrnlInfo = {0};
|
---|
992 | APIRET rc;
|
---|
993 | HFILE hDev0 = 0;
|
---|
994 | USHORT usAction = 0;
|
---|
995 |
|
---|
996 | /*
|
---|
997 | * Issue an IOCtl to elf$ to query kernel information.
|
---|
998 | */
|
---|
999 | rc = DosOpen("\\dev\\elf$", &hDev0, &usAction, 0UL, FILE_NORMAL,
|
---|
1000 | OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,
|
---|
1001 | OPEN_SHARE_DENYNONE | OPEN_ACCESS_READONLY,
|
---|
1002 | 0UL);
|
---|
1003 | if (rc == NO_ERROR)
|
---|
1004 | {
|
---|
1005 | rc = DosDevIOCtl(&KrnlInfo, "", D16_IOCTL_GETKRNLINFO, D16_IOCTL_CAT, hDev0);
|
---|
1006 | if (rc == NO_ERROR)
|
---|
1007 | {
|
---|
1008 | #ifdef DEBUG
|
---|
1009 | unsigned i;
|
---|
1010 | #endif
|
---|
1011 |
|
---|
1012 | /*
|
---|
1013 | * Set the exported parameters
|
---|
1014 | */
|
---|
1015 | options.ulBuild = KrnlInfo.ulBuild;
|
---|
1016 | options.fKernel = KrnlInfo.fKernel;
|
---|
1017 | cObjects = KrnlInfo.cObjects;
|
---|
1018 | paKrnlOTEs = &KrnlInfo.aObjects[0];
|
---|
1019 |
|
---|
1020 | /*
|
---|
1021 | * If debugging probkrnl dump kernel OTEs.
|
---|
1022 | */
|
---|
1023 | #ifdef DEBUG
|
---|
1024 | dprintf(("debug: kernel OTE:\n"));
|
---|
1025 | for (i = 0; i < cObjects; i++)
|
---|
1026 | dprintf(("debug: no.%2d base=%lx size=%lx sel=%x\n",
|
---|
1027 | i,
|
---|
1028 | paKrnlOTEs[i].ote_base,
|
---|
1029 | paKrnlOTEs[i].ote_size,
|
---|
1030 | paKrnlOTEs[i].ote_sel));
|
---|
1031 | #endif
|
---|
1032 | }
|
---|
1033 | DosClose(hDev0);
|
---|
1034 | }
|
---|
1035 |
|
---|
1036 | if (rc != NO_ERROR)
|
---|
1037 | printf16("Failed to get kernel OTEs. rc=%d\n", rc);
|
---|
1038 |
|
---|
1039 | return rc;
|
---|
1040 |
|
---|
1041 | #else
|
---|
1042 | return 0;
|
---|
1043 | #endif
|
---|
1044 | }
|
---|
1045 |
|
---|
1046 |
|
---|
1047 | /**
|
---|
1048 | * Shows result of kernelprobing if not quiet or on error.
|
---|
1049 | * @param rc Return code.
|
---|
1050 | */
|
---|
1051 | void ShowResult(int rc)
|
---|
1052 | {
|
---|
1053 | int i;
|
---|
1054 |
|
---|
1055 | /*
|
---|
1056 | * Complain even if quiet on error
|
---|
1057 | */
|
---|
1058 | if (!options.fQuiet || rc != NO_ERROR)
|
---|
1059 | {
|
---|
1060 | printf16("Win32k - Odin32 support driver.\n");
|
---|
1061 |
|
---|
1062 | /*
|
---|
1063 | * kernel stuff
|
---|
1064 | */
|
---|
1065 | if (rc == NO_ERROR || rc > ERROR_PROB_KRNL_LAST)
|
---|
1066 | printf16(" Build: %ld - v%d.%d\n",
|
---|
1067 | options.ulBuild, options.usVerMajor, options.usVerMinor);
|
---|
1068 | else if (rc >= ERROR_PROB_KRNL_FIRST)
|
---|
1069 | printf16(" Kernel probing failed with rc=%d.\n", rc);
|
---|
1070 | else
|
---|
1071 | printf16(" Failed before probing kernel.\n");
|
---|
1072 |
|
---|
1073 | /*
|
---|
1074 | * symbol-file
|
---|
1075 | */
|
---|
1076 | if (rc == NO_ERROR || (rc > ERROR_PROB_SYM_LAST && szSymbolFile[0] != '\0'))
|
---|
1077 | printf16(" Found symbolfile: %s\n", (NPSZ)szSymbolFile);
|
---|
1078 | else if (rc >= ERROR_PROB_SYM_FIRST)
|
---|
1079 | printf16(" Failed to find symbolfile!\n");
|
---|
1080 | else
|
---|
1081 | printf16(" Failed before searching for symbolfile.\n");
|
---|
1082 |
|
---|
1083 | /*
|
---|
1084 | * function listing
|
---|
1085 | */
|
---|
1086 | if (options.fLogging)/* || rc != NO_ERROR)*/
|
---|
1087 | {
|
---|
1088 | for (i = 0; i < NBR_OF_KRNLIMPORTS; i++)
|
---|
1089 | {
|
---|
1090 | printf16(" %-21s at ", aImportTab[i].achName);
|
---|
1091 | if (aImportTab[i].fFound)
|
---|
1092 | printf16("0x%08lx%s", aImportTab[i].ulAddress, (i % 2) == 0 ? "" : "\n");
|
---|
1093 | else
|
---|
1094 | printf16("not found!%s", (i % 2) == 0 ? "" : "\n");
|
---|
1095 | }
|
---|
1096 | if (i % 2) printf16("\n");
|
---|
1097 | }
|
---|
1098 |
|
---|
1099 | /*
|
---|
1100 | * Display error code.
|
---|
1101 | */
|
---|
1102 | if (rc != NO_ERROR)
|
---|
1103 | {
|
---|
1104 | const char *psz = GetErrorMsg(rc);
|
---|
1105 | printf16("ProbeKernel failed with rc=%d. iProc=%x\n", rc, iProc);
|
---|
1106 | if (psz) printf16("%s\n", psz);
|
---|
1107 | }
|
---|
1108 | }
|
---|
1109 | }
|
---|
1110 |
|
---|
1111 |
|
---|
1112 | /**
|
---|
1113 | * "main" function.
|
---|
1114 | * Note that the option -Noloader causes nothing to be done.
|
---|
1115 | * @returns 0 on success, something else on error.
|
---|
1116 | * @param pReqPack Pointer to init request packet
|
---|
1117 | * @remark
|
---|
1118 | */
|
---|
1119 | int ProbeKernel(PRPINITIN pReqPack)
|
---|
1120 | {
|
---|
1121 | int rc;
|
---|
1122 | int i;
|
---|
1123 | int n;
|
---|
1124 | SEL selGIS;
|
---|
1125 | SEL selLIS;
|
---|
1126 | PGINFOSEG pGIS;
|
---|
1127 | PLINFOSEG pLIS;
|
---|
1128 | USHORT usBootDrive;
|
---|
1129 |
|
---|
1130 | /*----------------*/
|
---|
1131 | /* parse InitArgs */
|
---|
1132 | /*----------------*/
|
---|
1133 | if (pReqPack != NULL && pReqPack->InitArgs != NULL)
|
---|
1134 | {
|
---|
1135 | n = kstrlen(pReqPack->InitArgs);
|
---|
1136 | for (i = 0; i < n; i++)
|
---|
1137 | {
|
---|
1138 | if ((pReqPack->InitArgs[i] == '/' || pReqPack->InitArgs[i] == '-') && (i+1) < n)
|
---|
1139 | {
|
---|
1140 | i++;
|
---|
1141 | switch (pReqPack->InitArgs[i])
|
---|
1142 | {
|
---|
1143 | case 'n':
|
---|
1144 | case 'N': /* NoLoader */
|
---|
1145 | options.fNoLoader = TRUE;
|
---|
1146 | return 0;
|
---|
1147 |
|
---|
1148 | case 'q':
|
---|
1149 | case 'Q': /* Quiet */
|
---|
1150 | options.fQuiet = TRUE;
|
---|
1151 | break;
|
---|
1152 |
|
---|
1153 | case 's':
|
---|
1154 | case 'S': /* Symbol file */
|
---|
1155 | i++;
|
---|
1156 | if ( pReqPack->InitArgs[i] != 'c' && pReqPack->InitArgs[i] != 'C'
|
---|
1157 | && pReqPack->InitArgs[i] != 'm' && pReqPack->InitArgs[i] != 'M'
|
---|
1158 | ) /* -script and -smp is ignored */
|
---|
1159 | i += kargncpy(szSymbolFile, &pReqPack->InitArgs[i], sizeof(szSymbolFile));
|
---|
1160 | break;
|
---|
1161 |
|
---|
1162 | case 'v':
|
---|
1163 | case 'V': /* Verbose */
|
---|
1164 | options.fQuiet = FALSE;
|
---|
1165 | break;
|
---|
1166 | }
|
---|
1167 | }
|
---|
1168 | }
|
---|
1169 | }
|
---|
1170 |
|
---|
1171 | /*---------------------*/
|
---|
1172 | /* determin boot drive */
|
---|
1173 | /*---------------------*/
|
---|
1174 | rc = DosGetInfoSeg(&selGIS, &selLIS);
|
---|
1175 | if (rc != NO_ERROR)
|
---|
1176 | return rc;
|
---|
1177 |
|
---|
1178 | pLIS = MAKEPLINFOSEG(selLIS);
|
---|
1179 | pGIS = MAKEPGINFOSEG(selGIS);
|
---|
1180 | usBootDrive = pGIS->bootdrive;
|
---|
1181 | #ifndef R3TST
|
---|
1182 | options.usVerMajor = pGIS->uchMajorVersion;
|
---|
1183 | options.usVerMinor = pGIS->uchMinorVersion;
|
---|
1184 | #else
|
---|
1185 | if (usFakeVerMajor == 0)
|
---|
1186 | {
|
---|
1187 | usFakeVerMajor = pGIS->uchMajorVersion;
|
---|
1188 | usFakeVerMinor = pGIS->uchMinorVersion;
|
---|
1189 | }
|
---|
1190 | options.usVerMajor = usFakeVerMajor;
|
---|
1191 | options.usVerMinor = usFakeVerMinor;
|
---|
1192 | #endif
|
---|
1193 | dprintf(("BootDrive: %d\n", usBootDrive));
|
---|
1194 |
|
---|
1195 | /* set driveletter in constants strings */
|
---|
1196 | usBootDrive = (char)usBootDrive + (char)'a' - 1;
|
---|
1197 | for (i = 0; apszSym[i] != NULL; i++)
|
---|
1198 | apszSym[i][0] = (char)usBootDrive;
|
---|
1199 |
|
---|
1200 | /*-----------------*/
|
---|
1201 | /* get kernel info */
|
---|
1202 | /*-----------------*/
|
---|
1203 | rc = GetKernelInfo();
|
---|
1204 |
|
---|
1205 | /*--------------*/
|
---|
1206 | /* read symfile */
|
---|
1207 | /*--------------*/
|
---|
1208 | if (!rc)
|
---|
1209 | {
|
---|
1210 | rc = 1;
|
---|
1211 | if (szSymbolFile[0] != '\0')
|
---|
1212 | {
|
---|
1213 | rc = ProbeSymFile(szSymbolFile);
|
---|
1214 | if (rc)
|
---|
1215 | {
|
---|
1216 | printf16("Warning: Invalid symbol file specified. rc=%x iProc=%d\n"
|
---|
1217 | " Tries defaults.\n", rc, iProc);
|
---|
1218 | szSymbolFile[0] = '\0';
|
---|
1219 | DosSleep(3000);
|
---|
1220 | }
|
---|
1221 | }
|
---|
1222 | if (rc != NO_ERROR) /* if user sym failed or don't exists. */
|
---|
1223 | {
|
---|
1224 | /*
|
---|
1225 | * Check database - only if not a debug kernel!
|
---|
1226 | * You usually have a .sym-file when using a debug kernel.
|
---|
1227 | * (This is because I am unable to distinguish between half and
|
---|
1228 | * all strict kernels...)
|
---|
1229 | */
|
---|
1230 | if ((options.fKernel & KF_DEBUG) ||
|
---|
1231 | (rc = LookupKrnlEntry((unsigned short)options.ulBuild,
|
---|
1232 | (unsigned short)options.fKernel,
|
---|
1233 | cObjects)
|
---|
1234 | ) != NO_ERROR
|
---|
1235 | )
|
---|
1236 | {
|
---|
1237 | #if 1 /* ndef R3TST */
|
---|
1238 | APIRET rc2;
|
---|
1239 | /* search on disk */
|
---|
1240 | i = 0;
|
---|
1241 | while (apszSym[i] != NULL
|
---|
1242 | && (rc2 = ProbeSymFile(apszSym[i])) != NO_ERROR
|
---|
1243 | )
|
---|
1244 | {
|
---|
1245 | i++;
|
---|
1246 | if (rc2 >= ERROR_PROB_SYM_D32_FIRST)
|
---|
1247 | rc = rc2;
|
---|
1248 | }
|
---|
1249 | if (rc == NO_ERROR)
|
---|
1250 | kstrcpy(szSymbolFile, apszSym[i]);
|
---|
1251 | else if (rc == 1 || rc2 == NO_ERROR)
|
---|
1252 | rc = rc2;
|
---|
1253 | #endif
|
---|
1254 | }
|
---|
1255 | }
|
---|
1256 | }
|
---|
1257 |
|
---|
1258 | /* Show the result and set return-value */
|
---|
1259 | dprintf(("rc=%d(0x%x); i=%d; iProc=%d\n", rc, rc, i, iProc));
|
---|
1260 | ShowResult(rc);
|
---|
1261 |
|
---|
1262 | return rc;
|
---|
1263 | }
|
---|
1264 |
|
---|