[9471] | 1 | /* $Id: extract.c,v 1.7 2002-12-06 02:55:58 bird Exp $
|
---|
[4217] | 2 | *
|
---|
| 3 | * Description: SymDB entry generator.
|
---|
| 4 | * Builds SymDB entry from one or more symbol files.
|
---|
| 5 | *
|
---|
[4972] | 6 | * Copyright (c) 2000-2001 knut st. osmundsen (knut.stange.osmundsen@mynd.no)
|
---|
[4217] | 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
|
---|
[5103] | 28 | #define INCL_OS2KRNL_LDR
|
---|
[4217] | 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
|
---|
[5103] | 43 | #include "os2Krnl.h" /* must be included before dev1632.h! */
|
---|
[4217] | 44 | #include "probkrnl.h"
|
---|
| 45 | #include "dev1632.h"
|
---|
| 46 | #include "vprntf16.h"
|
---|
| 47 |
|
---|
| 48 |
|
---|
| 49 | /*******************************************************************************
|
---|
| 50 | * Global Variables *
|
---|
| 51 | *******************************************************************************/
|
---|
| 52 | /* Result from GetKernelInfo/ReadOS2Krnl. */
|
---|
| 53 | extern unsigned char cObjects;
|
---|
| 54 | extern POTE paKrnlOTEs;
|
---|
| 55 |
|
---|
| 56 | /* dummy replacement for SymDB.c */
|
---|
| 57 | KRNLDBENTRY DATA16_INIT aKrnlSymDB[] = {{0}};
|
---|
| 58 |
|
---|
| 59 | /*******************************************************************************
|
---|
| 60 | * Internal Functions *
|
---|
| 61 | *******************************************************************************/
|
---|
| 62 | int processFile(const char *pszFilename);
|
---|
| 63 |
|
---|
| 64 | /*******************************************************************************
|
---|
| 65 | * External Functions *
|
---|
| 66 | *******************************************************************************/
|
---|
| 67 | /* Workers */
|
---|
| 68 | extern int ProbeSymFile(const char *pszFilename);
|
---|
| 69 |
|
---|
| 70 | /* C-library replacements and additions. */
|
---|
| 71 | extern void kmemcpy(char *psz1, const char *psz2, int cch);
|
---|
| 72 | extern char * kstrstr(const char *psz1, const char *psz2);
|
---|
| 73 | extern int kstrcmp(const char *psz1, const char *psz2);
|
---|
| 74 | extern int kstrncmp(const char *psz1, const char *psz2, int cch);
|
---|
| 75 | extern int kstrnicmp(const char *psz1, const char *psz2, int cch);
|
---|
| 76 | extern int kstrlen(const char *psz);
|
---|
| 77 | extern char * kstrcpy(char * pszTarget, const char * pszSource);
|
---|
| 78 | extern 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:
|
---|
[4972] | 85 | * nnnn[n]tm[r].SYM
|
---|
[4217] | 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+
|
---|
[4972] | 89 | * r - revision letter. Currently only 'A' is supported.
|
---|
[4217] | 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.
|
---|
[4787] | 93 | * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
|
---|
[4217] | 94 | * @remark Currently only retail kernels are processed. See note below.
|
---|
| 95 | */
|
---|
| 96 | static int processFile(const char *pszFilename)
|
---|
| 97 | {
|
---|
| 98 | APIRET rc;
|
---|
| 99 | int cch;
|
---|
[4972] | 100 | int cchNum;
|
---|
[4217] | 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 |
|
---|
[4307] | 110 | /* Progress information */
|
---|
| 111 | DosWrite(2, (char*)pszFilename, cch, &rc);
|
---|
| 112 | DosWrite(2, "\r\n", 2, &rc);
|
---|
| 113 |
|
---|
[4217] | 114 | /* Filename check */
|
---|
[4972] | 115 | cchNum = psz[0] > '2' ? 4 : 5; /* build number length. */
|
---|
| 116 | if (cch < 10 || cch > 12
|
---|
[4217] | 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')
|
---|
[4972] | 121 | || !(cchNum == 4 || (psz[4] >= '0' && psz[4] <= '9'))
|
---|
[9471] | 122 | || !(psz[cchNum] == 'A' || psz[cchNum] == 'H' || psz[cchNum] == 'R' || psz[cchNum] == 'B')
|
---|
[4972] | 123 | || !(psz[cchNum+1] == 'S' || psz[cchNum+1] == 'U' || psz[cchNum+1] == '4')
|
---|
| 124 | /* || !(cch != 12 || psz[cchNum+2] == 'A') */
|
---|
[4217] | 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 | */
|
---|
[4972] | 149 | if (psz[cchNum] != 'R')
|
---|
[4217] | 150 | printf16("#ifdef ALLKERNELS\n");
|
---|
| 151 |
|
---|
| 152 | printf16(" { /* %s */\n"
|
---|
| 153 | " %.*s, ",
|
---|
| 154 | psz,
|
---|
[4972] | 155 | cchNum, &psz[0] /* build number */
|
---|
[4217] | 156 | );
|
---|
| 157 |
|
---|
[4972] | 158 | switch (psz[cchNum + 1])
|
---|
[4217] | 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 | }
|
---|
[4972] | 164 | switch (psz[cchNum])
|
---|
[4217] | 165 | {
|
---|
| 166 | case 'A': printf16(" | KF_ALLSTRICT"); break;
|
---|
| 167 | case 'H': printf16(" | KF_HALFSTRICT"); break;
|
---|
[9471] | 168 | case 'B': printf16(" | KF_HALFSTRICT"); break;
|
---|
[4217] | 169 | }
|
---|
[6004] | 170 | if (psz[cchNum + 2] >= 'A' && psz[cchNum + 2] <= 'Z')
|
---|
[5103] | 171 | printf16(" | KF_REV_%c", psz[cchNum + 2]);
|
---|
[4972] | 172 |
|
---|
[4217] | 173 | printf16(", %d,\n"
|
---|
| 174 | " {\n",
|
---|
| 175 | aImportTab[0].iObject + 1); /* ASSUMES that DOSCODE32 is the last object. */
|
---|
| 176 |
|
---|
| 177 | for (i = 0; i < NBR_OF_KRNLIMPORTS; i++)
|
---|
| 178 | {
|
---|
| 179 | char *psz = aImportTab[i].achName;
|
---|
| 180 | printf16(" {%-2d, 0x%08lx}, /* %s */\n",
|
---|
[5103] | 181 | aImportTab[i].fFound ? aImportTab[i].iObject : 0,
|
---|
[4217] | 182 | aImportTab[i].fFound ? aImportTab[i].offObject : 0xFFFFFFFFUL,
|
---|
| 183 | (char *)&aImportTab[i].achName[0]
|
---|
| 184 | );
|
---|
| 185 | }
|
---|
| 186 | printf16(" }\n"
|
---|
| 187 | " },\n");
|
---|
| 188 |
|
---|
| 189 | /** @remark
|
---|
| 190 | * Currently information for retail kernels are usable, but we'll
|
---|
| 191 | * generate it for the debug kernels too, but this information
|
---|
| 192 | * is enclaved within an "#ifdef ALLKERNELS ... #endif".
|
---|
| 193 | */
|
---|
[4972] | 194 | if (psz[cchNum] != 'R')
|
---|
[4217] | 195 | printf16("#endif\n");
|
---|
| 196 | }
|
---|
| 197 | else
|
---|
| 198 | printf16("ProbeSymFile failed with rc=%d\n", rc);
|
---|
| 199 |
|
---|
| 200 | return rc;
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 |
|
---|
| 204 | /**
|
---|
| 205 | * Extract program.
|
---|
| 206 | *
|
---|
| 207 | * This is some initial trial-and-error for creating an "database" of
|
---|
| 208 | * kernel entrypoints.
|
---|
| 209 | *
|
---|
| 210 | * Output to stderr the structs generated for the passed in *.sym file.
|
---|
| 211 | *
|
---|
| 212 | */
|
---|
| 213 | int main(int argc, char **argv)
|
---|
| 214 | {
|
---|
| 215 | APIRET rc;
|
---|
| 216 | const char * psz;
|
---|
[5103] | 217 | int i;
|
---|
[4217] | 218 |
|
---|
| 219 | /*
|
---|
| 220 | * Set paKrnlOTEs to point to an zeroed array of OTEs.
|
---|
| 221 | */
|
---|
| 222 | static KRNLINFO DATA16_INIT KrnlInfo = {0};
|
---|
| 223 | paKrnlOTEs = &KrnlInfo.aObjects[0];
|
---|
| 224 |
|
---|
[5103] | 225 | /*
|
---|
| 226 | * Check name lengths.
|
---|
| 227 | */
|
---|
| 228 | for (i = 0; i < NBR_OF_KRNLIMPORTS; i++)
|
---|
| 229 | {
|
---|
| 230 | if (kstrlen(aImportTab[i].achName) != (int)aImportTab[i].cchName)
|
---|
| 231 | {
|
---|
| 232 | printf16("internal error - bad length of entry %d - %s. %d should be %d.\n",
|
---|
| 233 | i, aImportTab[i].achName, aImportTab[i].cchName, kstrlen(aImportTab[i].achName));
|
---|
| 234 | return -1;
|
---|
| 235 | }
|
---|
| 236 | }
|
---|
| 237 |
|
---|
| 238 | /*
|
---|
| 239 | * Do work.
|
---|
| 240 | */
|
---|
[4217] | 241 | if (argc > 1)
|
---|
| 242 | {
|
---|
| 243 | /*
|
---|
| 244 | * Arguments: extract.exe <symfiles...>
|
---|
| 245 | */
|
---|
| 246 | int i;
|
---|
| 247 | for (i = 1; i < argc; i++)
|
---|
| 248 | {
|
---|
| 249 | rc = processFile(argv[i]);
|
---|
| 250 | if (rc != NO_ERROR)
|
---|
| 251 | {
|
---|
| 252 | printf16("processFile failed with rc=%d for file %s\n",
|
---|
| 253 | rc, argv[i]);
|
---|
| 254 | if (psz = GetErrorMsg(rc))
|
---|
| 255 | printf16("%s\n", psz);
|
---|
| 256 | return rc;
|
---|
| 257 | }
|
---|
| 258 | }
|
---|
| 259 | }
|
---|
| 260 | else
|
---|
| 261 | {
|
---|
| 262 | /*
|
---|
| 263 | * Arguments: extract.exe
|
---|
| 264 | *
|
---|
| 265 | * Action: Scan current directory for *.sym files.
|
---|
| 266 | *
|
---|
| 267 | */
|
---|
| 268 | USHORT usSearch = 1;
|
---|
| 269 | HDIR hDir = HDIR_CREATE;
|
---|
| 270 | FILEFINDBUF ffb;
|
---|
| 271 | int i;
|
---|
| 272 |
|
---|
[9471] | 273 | printf16("/* $Id: extract.c,v 1.7 2002-12-06 02:55:58 bird Exp $\n"
|
---|
[4217] | 274 | "*\n"
|
---|
| 275 | "* Autogenerated kernel symbol database.\n"
|
---|
| 276 | "*\n"
|
---|
[4787] | 277 | "* Copyright (c) 2000 knut st. osmundsen (knut.stange.osmundsen@mynd.no)\n"
|
---|
[4217] | 278 | "*\n"
|
---|
| 279 | "* Project Odin Software License can be found in LICENSE.TXT\n"
|
---|
| 280 | "*\n"
|
---|
| 281 | "*/\n");
|
---|
| 282 |
|
---|
| 283 | printf16("\n"
|
---|
| 284 | "#define INCL_NOPMAPI\n"
|
---|
| 285 | "#define INCL_NOBASEAPI\n"
|
---|
| 286 | "#include <os2.h>\n"
|
---|
| 287 | "#include \"DevSegDf.h\"\n"
|
---|
| 288 | "#include \"probkrnl.h\"\n"
|
---|
| 289 | "#include \"options.h\"\n"
|
---|
| 290 | "\n");
|
---|
| 291 |
|
---|
| 292 | printf16("KRNLDBENTRY DATA16_INIT aKrnlSymDB[] = \n"
|
---|
| 293 | "{\n");
|
---|
| 294 |
|
---|
| 295 | rc = DosFindFirst("*.sym", &hDir, FILE_NORMAL,
|
---|
| 296 | &ffb, sizeof(ffb),
|
---|
| 297 | &usSearch, 0UL);
|
---|
| 298 | while (rc == NO_ERROR & usSearch > 0)
|
---|
| 299 | {
|
---|
| 300 | rc = processFile(&ffb.achName[0]);
|
---|
| 301 | if (rc != NO_ERROR)
|
---|
| 302 | {
|
---|
| 303 | printf16("processFile failed with rc=%d for file %s\n",
|
---|
| 304 | rc, &ffb.achName[0]);
|
---|
| 305 | if (psz = GetErrorMsg(rc))
|
---|
| 306 | printf16("%s\n", psz);
|
---|
| 307 | return rc;
|
---|
| 308 | }
|
---|
| 309 |
|
---|
| 310 | /* next file */
|
---|
| 311 | rc = DosFindNext(hDir, &ffb, sizeof(ffb), &usSearch);
|
---|
| 312 | }
|
---|
| 313 | DosFindClose(hDir);
|
---|
| 314 |
|
---|
| 315 | printf16(" { /* Terminating entry */\n"
|
---|
| 316 | " 0,0,0,\n"
|
---|
| 317 | " {\n");
|
---|
| 318 | for (i = 0; i < NBR_OF_KRNLIMPORTS; i++)
|
---|
| 319 | printf16(" {0,0},\n");
|
---|
| 320 | printf16(" }\n"
|
---|
| 321 | " }\n"
|
---|
| 322 | "}; /* end of aKrnlSymDB[] */\n"
|
---|
| 323 | );
|
---|
| 324 | }
|
---|
| 325 |
|
---|
| 326 |
|
---|
| 327 | return rc;
|
---|
| 328 | }
|
---|
| 329 |
|
---|