Changeset 860 in kBuild
- Timestamp:
- Mar 30, 2007 1:48:58 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kDepIDB/kDepIDB.c
r793 r860 31 31 #include <stdio.h> 32 32 #include <stdlib.h> 33 #include <stddef.h> 33 34 #include <string.h> 34 35 #include <errno.h> … … 45 46 #define OFFSETOF(type, member) ( (int)(size_t)(void *)&( ((type *)(void *)0)->member) ) 46 47 47 /*#define DEBUG*/ 48 #define DEBUG 48 49 #ifdef DEBUG 49 # define dprintf(a)printf a50 # define dump(pb, cb, offBase)hexdump(pb,cb,offBase)50 # define dprintf(a) printf a 51 # define dump(pb, cb, offBase) hexdump(pb,cb,offBase) 51 52 #else 52 # define dprintf(a)do {} while (0)53 # define dump(pb, cb, offBase)do {} while (0)53 # define dprintf(a) do {} while (0) 54 # define dump(pb, cb, offBase) do {} while (0) 54 55 #endif 55 56 … … 238 239 } PDB70ROOT, *PPDB70ROOT; 239 240 241 /** 242 * The PDB 7.0 name stream (#1) header. 243 */ 244 typedef struct PDB70NAMES 245 { 246 /** The structure version. */ 247 uint32_t Version; 248 /** Timestamp. */ 249 uint32_t TimeStamp; 250 /** Unknown. */ 251 uint32_t Unknown1; 252 /** GUID. */ 253 uint32_t u32Guid[4]; 254 /** The size of the following name table. */ 255 uint32_t cbNames; 256 /** The name table. */ 257 char szzNames[1]; 258 } PDB70NAMES, *PPDB70NAMES; 259 260 /** The version / magic of the names structure. */ 261 #define PDB70NAMES_VERSION 20000404 240 262 241 263 … … 291 313 off *= cbPage; 292 314 memcpy(pbBuf + iPage * cbPage, (uint8_t *)pHdr + off, cbPage); 293 dump(pbBuf + iPage * cbPage, cbPage, off);315 dump(pbBuf + iPage * cbPage, iPage + 1 < cPages ? cbPage : cb % cbPage, off); 294 316 } 295 317 else … … 312 334 { 313 335 /* 314 * The tricky bit here is to find the right length. 315 * (Todo: Check if we can just use the stream size..)336 * The tricky bit here is to find the right length. Really? 337 * (Todo: Check if we can just use the stream #0 size..) 316 338 */ 317 339 PPDB70PAGE piPageMap = (uint32_t *)((uint8_t *)pHdr + pHdr->iRootPages * pHdr->cbPage); … … 319 341 if (pRoot) 320 342 { 343 #if 1 321 344 /* This stuff is probably unnecessary: */ 322 345 /* size = stream header + array of stream. */ … … 339 362 } 340 363 } 364 #else 365 /* validate? */ 366 return pRoot; 367 #endif 341 368 } 342 369 return NULL; … … 345 372 static void *Pdb70AllocAndReadStream(PPDB70HDR pHdr, PPDB70ROOT pRoot, unsigned iStream, size_t *pcbStream) 346 373 { 347 size_tcbStream = pRoot->aStreams[iStream].cbStream;348 PPDB70PAGE paiPageMap;374 const size_t cbStream = pRoot->aStreams[iStream].cbStream; 375 PPDB70PAGE paiPageMap; 349 376 if ( iStream >= pRoot->cStreams 350 377 || cbStream == ~(uint32_t)0) … … 368 395 PPDB70HDR pHdr = (PPDB70HDR)pbFile; 369 396 PPDB70ROOT pRoot; 397 PPDB70NAMES pNames; 398 size_t cbStream; 399 unsigned fDone = 0; 370 400 unsigned iStream; 371 401 int rc = 0; … … 382 412 383 413 /* 384 * Iterate the streams in the root and scan their content for 385 * dependencies. 386 */ 387 rc = 0; 388 for (iStream = 0; iStream < pRoot->cStreams && !rc; iStream++) 389 { 390 const size_t cbStream = Pdb70Align(pHdr, pRoot->aStreams[iStream].cbStream); 391 uint8_t *pbStream; 392 if ( pRoot->aStreams[iStream].cbStream == ~(uint32_t)0 393 || !pRoot->aStreams[iStream].cbStream) 394 continue; 395 dprintf(("Stream #%d: %#x bytes (%#x aligned)\n", iStream, pRoot->aStreams[iStream].cbStream, cbStream)); 396 pbStream = (uint8_t *)Pdb70AllocAndReadStream(pHdr, pRoot, iStream, NULL); 397 if (pbStream) 398 { 399 rc = ScanStream(pbStream, cbStream, "/mr/inversedeps/", sizeof("/mr/inversedeps/") - 1); 400 free(pbStream); 414 * The names we want are usually all found in the 'Names' stream, that is #1. 415 */ 416 dprintf(("Reading the names stream....\n")); 417 pNames = Pdb70AllocAndReadStream(pHdr, pRoot, 1, &cbStream); 418 if (pNames) 419 { 420 dprintf(("Names: Version=%u cbNames=%u (%#x)\n", pNames->Version, pNames->cbNames, pNames->cbNames)); 421 if ( pNames->Version == PDB70NAMES_VERSION 422 && pNames->cbNames > 32 423 && pNames->cbNames + offsetof(PDB70NAMES, szzNames) <= pRoot->aStreams[1].cbStream) 424 { 425 /* 426 * Iterate the names and add the /mr/inversedeps/ ones to the dependency list. 427 */ 428 const char *psz = &pNames->szzNames[0]; 429 size_t cb = pNames->cbNames; 430 size_t off = 0; 431 dprintf(("0x0000 #0: %6d bytes [root / toc]\n", pRoot->aStreams[0].cbStream)); 432 for (iStream = 1; cb > 0; iStream++) 433 { 434 int fAdded = 0; 435 size_t cch = strlen(psz); 436 if ( cch >= sizeof("/mr/inversedeps/") 437 && !memcmp(psz, "/mr/inversedeps/", sizeof("/mr/inversedeps/") - 1)) 438 { 439 depAdd(psz + sizeof("/mr/inversedeps/") - 1, cch - (sizeof("/mr/inversedeps/") - 1)); 440 fAdded = 1; 441 } 442 dprintf(("%#06x #%d: %6d bytes %s%s\n", off, iStream, 443 iStream < pRoot->cStreams ? pRoot->aStreams[iStream].cbStream : -1, 444 psz, fAdded ? " [dep]" : "")); 445 (void)fAdded; 446 447 /* next */ 448 if (cch >= cb) 449 { 450 dprintf(("warning! cch=%d cb=%d\n", cch, cb)); 451 cch = cb - 1; 452 } 453 cb -= cch + 1; 454 psz += cch + 1; 455 off += cch + 1; 456 } 457 rc = 0; 458 fDone = 1; 401 459 } 402 460 else 403 rc = 1; 461 dprintf(("Unknown version or bad size: Version=%u cbNames=%d cbStream=%d\n", 462 pNames->Version, pNames->cbNames, cbStream)); 463 free(pNames); 464 } 465 466 if (!fDone) 467 { 468 /* 469 * Iterate the streams in the root and scan their content for 470 * dependencies. 471 */ 472 rc = 0; 473 for (iStream = 0; iStream < pRoot->cStreams && !rc; iStream++) 474 { 475 uint8_t *pbStream; 476 if ( pRoot->aStreams[iStream].cbStream == ~(uint32_t)0 477 || !pRoot->aStreams[iStream].cbStream) 478 continue; 479 dprintf(("Stream #%d: %#x bytes (%#x aligned)\n", iStream, pRoot->aStreams[iStream].cbStream, 480 Pdb70Align(pHdr, pRoot->aStreams[iStream].cbStream))); 481 pbStream = (uint8_t *)Pdb70AllocAndReadStream(pHdr, pRoot, iStream, &cbStream); 482 if (pbStream) 483 { 484 rc = ScanStream(pbStream, cbStream, "/mr/inversedeps/", sizeof("/mr/inversedeps/") - 1); 485 free(pbStream); 486 } 487 else 488 rc = 1; 489 } 404 490 } 405 491
Note:
See TracChangeset
for help on using the changeset viewer.