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