VirtualBox

Changeset 860 in kBuild


Ignore:
Timestamp:
Mar 30, 2007 1:48:58 AM (18 years ago)
Author:
bird
Message:

PDB70 fixes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kDepIDB/kDepIDB.c

    r793 r860  
    3131#include <stdio.h>
    3232#include <stdlib.h>
     33#include <stddef.h>
    3334#include <string.h>
    3435#include <errno.h>
     
    4546#define OFFSETOF(type, member)  ( (int)(size_t)(void *)&( ((type *)(void *)0)->member) )
    4647
    47 /*#define DEBUG*/
     48#define DEBUG
    4849#ifdef DEBUG
    49 #define dprintf(a)              printf a
    50 #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)
    5152#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)
    5455#endif
    5556
     
    238239} PDB70ROOT, *PPDB70ROOT;
    239240
     241/**
     242 * The PDB 7.0 name stream (#1) header.
     243 */
     244typedef 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
    240262
    241263
     
    291313                off *= cbPage;
    292314                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);
    294316            }
    295317            else
     
    312334{
    313335    /*
    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..)
    316338     */
    317339    PPDB70PAGE piPageMap = (uint32_t *)((uint8_t *)pHdr + pHdr->iRootPages * pHdr->cbPage);
     
    319341    if (pRoot)
    320342    {
     343#if 1
    321344        /* This stuff is probably unnecessary: */
    322345        /* size = stream header + array of stream. */
     
    339362            }
    340363        }
     364#else
     365        /* validate? */
     366        return pRoot;
     367#endif
    341368    }
    342369    return NULL;
     
    345372static void *Pdb70AllocAndReadStream(PPDB70HDR pHdr, PPDB70ROOT pRoot, unsigned iStream, size_t *pcbStream)
    346373{
    347     size_t      cbStream = pRoot->aStreams[iStream].cbStream;
    348     PPDB70PAGE  paiPageMap;
     374    const size_t    cbStream = pRoot->aStreams[iStream].cbStream;
     375    PPDB70PAGE      paiPageMap;
    349376    if (    iStream >= pRoot->cStreams
    350377        ||  cbStream == ~(uint32_t)0)
     
    368395    PPDB70HDR   pHdr = (PPDB70HDR)pbFile;
    369396    PPDB70ROOT  pRoot;
     397    PPDB70NAMES pNames;
     398    size_t      cbStream;
     399    unsigned    fDone = 0;
    370400    unsigned    iStream;
    371401    int         rc = 0;
     
    382412
    383413    /*
    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;
    401459        }
    402460        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        }
    404490    }
    405491
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette