⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 w2k_cv.c

📁 Undocumented Windows 2000 Secrets简体中文版.+源码光盘
💻 C
📖 第 1 页 / 共 2 页
字号:

// __________________________________________________________
//
//                         w2k_cv.c
//         SBS Windows 2000 CodeView Decompiler V1.00
//                08-27-2000 Sven B. Schreiber
//                       sbs@orgon.com
// __________________________________________________________

#include "w2k_cv.h"

// =================================================================
// DISCLAIMER
// =================================================================

/*

This software is provided "as is" and any express or implied
warranties, including, but not limited to, the implied warranties of
merchantability and fitness for a particular purpose are disclaimed.
In no event shall the author Sven B. Schreiber be liable for any
direct, indirect, incidental, special, exemplary, or consequential
damages (including, but not limited to, procurement of substitute
goods or services; loss of use, data, or profits; or business
interruption) however caused and on any theory of liability,
whether in contract, strict liability, or tort (including negligence
or otherwise) arising in any way out of the use of this software,
even if advised of the possibility of such damage.

*/

// =================================================================
// REVISION HISTORY
// =================================================================

/*

08-27-2000 V1.00 Original version (SBS).

*/

// =================================================================
// GLOBAL STRINGS
// =================================================================

TBYTE atArguments   [] =
 T("{ [+-hedcpPfmstx] <module> }");

TBYTE atMoreInfo    [] =
 T("\r\n")
 T("       +   enable subsequent options\r\n")
 T("       -   disable subsequent options\r\n")
 T("       h   display PE section headers\r\n")
 T("       e   display exported symbols\r\n")
 T("       d   display debug directories\r\n")
 T("       c   display CodeView data\r\n")
 T("       p   display public symbols\r\n")
 T("       P   display public symbols (extended information)\r\n")
 T("       f   display frame pointer omission (FPO) data\r\n")
 T("       m   display miscellaneous data\r\n")
 T("       s   display OMAP source table\r\n")
 T("       t   display OMAP target table\r\n")
 T("       x   display all of the above\r\n");

// -----------------------------------------------------------------

TBYTE atSeparator   [] =
 T("----------------------------------------")
 T("---------------------------------------\r\n");

TBYTE atSections    [] =
 T("\r\n%lu PE file section%s\r\n\r\n")
 T("     #  Name     Source   Target   Size     Raw Size\r\n")
 T("\0\0s\0\r\nNo PE file sections\r\n");

TBYTE atExports     [] =
 T("\r\n%lu exported symbol%s\r\n\r\n")
 T("     #  Symbol\r\n")
 T("\0\0s\0\r\nNo exported symbols\r\n");

TBYTE atDirectories [] =
 T("\r\n%lu debug director%s\r\n\r\n")
 T("     #  Address  Size     Type     Description\r\n")
 T("\0y\0ies\0\r\nNo debug directories\r\n");

TBYTE atSegments    [] =
 T("\r\n%lu CodeView NB09 segment%s (%hu logical)\r\n\r\n")
 T("     # Frame Offset   Size     Flags\r\n")
 T("\0\0s\0\r\nNo NB09 segments\r\n");

TBYTE atCodeView09  [] =
 T("\r\n%lu CodeView NB09 directory entr%s\r\n\r\n")
 T("     #  Offset   Size     Type Index Name\r\n")
 T("\0y\0ies\0\r\nNo CodeView NB09 directory entries\r\n");

TBYTE atCodeView10  [] =
 T("\r\n%lu CodeView NB10 byte%s\r\n\r\n")
 T("     #  Member     Value\r\n")
 T("\0\0s\0");

TBYTE atCodeViewXX  [] =
 T("\r\n%lu CodeView byte%s (%hc%hc%hc%hc)\r\n\r\n")
 T("Offset  ")
 T(" | 00 01 02 03 04 05 06 07 : 08 09 0A 0B 0C 0D 0E 0F")
 T(" | 0123456789ABCDEF\r\n")
 T("\0\0s\0\r\nNo CodeView data\r\n");

TBYTE atSymbols     [] =
 T("\r\n%lu symbol%s (%hc%hc%hc%hc)\r\n\r\n")
 T("     #  Section  Address  Symbol\r\n")
 T("\0\0s\0\r\nNo symbols\r\n");

TBYTE atSymbolsEx   [] =
 T("\r\n%lu symbol%s (%hc%hc%hc%hc)\r\n\r\n")
 T("     #  Section  Raw      Source   Target   Address  ")
 T("  Offset    Stack X Symbol\r\n")
 T("\0\0s\0\r\nNo symbols\r\n");

TBYTE atFpoEntries   [] =
 T("\r\n%lu FPO entr%s\r\n\r\n")
 T("     #  Address  Size     Locals   Args\r\n")
 T("\0y\0ies\0\r\nNo FPO entries\r\n");

TBYTE atMiscEntries  [] =
 T("\r\n%lu miscellaneous entr%s\r\n\r\n")
 T("     #  Type     Size     Data\r\n")
 T("\0y\0ies\0\r\nNo miscellaneous entries\r\n");

TBYTE atOmapFromSrc  [] =
 T("\r\n%lu OMAP source entr%s\r\n\r\n")
 T("     #  Source   Target\r\n")
 T("\0y\0ies\0\r\nNo OMAP source entries\r\n");

TBYTE atOmapToSrc    [] =
 T("\r\n%lu OMAP target entr%s\r\n\r\n")
 T("     #  Target   Source\r\n")
 T("\0y\0ies\0\r\nNo OMAP target entries\r\n");

// =================================================================
// PRIMITIVE DISPLAY ROUTINES
// =================================================================

VOID DisplaySeparator (VOID)
    {
    printf  (atSeparator);
    return;
    }

// -----------------------------------------------------------------

VOID DisplayTop (PTBYTE ptFormat,
                 DWORD  dCount,
                 PTBYTE ptSuffix,
                 ...)
    {
    PVOID  pArguments = &dCount;
    PTBYTE ptText     = ptFormat;

    ptText += lstrlen (ptText) + 1;

    if (dCount != 1)
        {
        ptText += lstrlen (ptText) + 1;
        }
    if (dCount == -1)
        {
        ptText += lstrlen (ptText) + 1;
        printf (ptText);
        }
    else
        {
        ((PTBYTE *) pArguments) [1] = ptText;
        vprintf (ptFormat, pArguments);

        DisplaySeparator ();
        }
    return;
    }

// -----------------------------------------------------------------

VOID WINAPI DisplayTime (PTBYTE ptFormat,
                         DWORD  dTime)
    {
    TBYTE    atTime [] = T("mm-dd-yyyy HH:MM:SS");
    IMG_TIME it        = imgTimeUnpack (dTime);

    sprintf (atTime, T("%02lu-%02lu-%04lu %02lu:%02lu:%02lu"),
            (DWORD) it.bMonth,
            (DWORD) it.bDay,
            (DWORD) it.wYear,
            (DWORD) it.bHour,
            (DWORD) it.bMinute,
            (DWORD) it.bSecond);

    printf (ptFormat, atTime);
    return;
    }

// -----------------------------------------------------------------

VOID WINAPI DisplayOmfName (POMF_NAME pon)
    {
    DWORD i;

    for (i = 0; i < pon->bLength; i++)
        {
        printf (T("%hc"),
                pon->abName [i]);
        }
    return;
    }

// -----------------------------------------------------------------

VOID WINAPI DisplaySectionName (PIMG_INFO pii,
                                DWORD     dSection)
    {
    DWORD                 i, j;
    PIMAGE_SECTION_HEADER pish = pii->pSections + (dSection-1);

    for (i = j = 0; i < IMAGE_SIZEOF_SHORT_NAME; i++)
        {
        printf (T("%hc"),
                (pish->Name [j] ? pish->Name [j++] : ' '));
        }
    return;
    }

// =================================================================
// COMPLEX DISPLAY ROUTINES
// =================================================================

VOID WINAPI DisplaySections (PIMG_INFO pii)
    {
    DWORD i;

    if (pii->dSections)
        {
        DisplayTop (atSections, pii->dSections, NULL);

        for (i = 0; i < pii->dSections; i++)
            {
            printf (T("%6lu: "), i+1);

            DisplaySectionName (pii, i+1);

            printf (T(" %08lX %08lX %08lX %08lX\r\n"),
                    pii->pSections [i].PointerToRawData,
                    pii->pSections [i].VirtualAddress,
                    pii->pSections [i].Misc.VirtualSize,
                    pii->pSections [i].SizeOfRawData);
            }
        }
    else
        {
        DisplayTop (atSections, -1, NULL);
        }
    DisplaySeparator ();
    return;
    }

// -----------------------------------------------------------------

VOID WINAPI DisplayExports (PIMG_INFO pii)
    {
    DWORD i, j;

    if (pii->dExports)
        {
        DisplayTop (atExports, pii->dExports, NULL);

        for (i = j = 0; i < pii->dExports; i++)
            {
            printf (T("%6lu: %hs\r\n"),
                    i+1,
                    pii->pbExports + j);

            j += (lstrlenA (pii->pbExports + j) + 1);
            }
        }
    else
        {
        DisplayTop (atExports, -1, NULL);
        }
    DisplaySeparator ();
    return;
    }

// -----------------------------------------------------------------

VOID WINAPI DisplayDirectories (PIMG_INFO pii)
    {
    DWORD i;

    if (pii->dDirectories)
        {
        DisplayTop (atDirectories, pii->dDirectories, NULL);

        for (i = 0; i < pii->dDirectories; i++)
            {
            printf (T("%6lu: %08lX %08lX %08lX %s\r\n"),
                    i+1,
                    pii->pDirectories [i].PointerToRawData,
                    pii->pDirectories [i].SizeOfData,
                    pii->pDirectories [i].Type,
                    imgInfoType (pii, i));
            }
        }
    else
        {
        DisplayTop (atDirectories, -1, NULL);
        }
    DisplaySeparator ();
    return;
    }

// -----------------------------------------------------------------

VOID WINAPI DisplayNB09Segments (PIMG_INFO pii,
                                 PCV_NB09  pc09)
    {
    PCV_SEGMAP pcs;
    DWORD      dCount, i;

    if ((pcs = imgCvSegments (pc09, &dCount)) != NULL)
        {
        DisplayTop (atSegments, dCount, NULL, pcs->wLogical);

        for (i = 0; i < dCount; i++)
            {
            printf (T("%6lu: %04hX %08lX %08lX %04hX\r\n"),
                    i+1,
                    pcs->Descriptors [i].wFrame,
                    pcs->Descriptors [i].dOffset,
                    pcs->Descriptors [i].dSize,
                    pcs->Descriptors [i].wFlags);
            }
        }
    else
        {
        DisplayTop (atSegments, -1, NULL);
        }
    DisplaySeparator ();
    return;
    }


// -----------------------------------------------------------------

VOID WINAPI DisplayNB09Data (PIMG_INFO pii,
                             PCV_NB09  pc09,
                             DWORD     dSize)
    {
    DWORD      i, j;
    PCV_MODULE pcm;

    if (pc09->Directory.dEntries)
        {
        DisplayTop (atCodeView09, pc09->Directory.dEntries, NULL);

        for (i = j = 0; i < pc09->Directory.dEntries; i++)
            {
            printf (T("%6lu: %08lX %08lX %04hX %04hX "),
                    i+1,
                    pc09->Entries [i].lSubSectionOffset,
                    pc09->Entries [i].dSubSectionSize,
                    pc09->Entries [i].wSubSectionType,
                    pc09->Entries [i].wModuleIndex);

            if ((pc09->Entries [i].wSubSectionType == sstModule) &&
                ((pcm = imgCvModule (pc09, j++, NULL)) != NULL))
                {
                printf (T(" "));
                DisplayOmfName (CV_MODULE_NAME (pcm));
                }
            printf (T("\r\n"));
            }
        DisplaySeparator ();
        DisplayNB09Segments (pii, pc09);
        }
    else
        {
        DisplayTop (atCodeView09, -1, NULL);
        DisplaySeparator ();
        }
    return;
    }

// -----------------------------------------------------------------

VOID WINAPI DisplayNB10Data (PIMG_INFO pii,
                             PCV_NB10  pc10,
                             DWORD     dSize)
    {
    DisplayTop (atCodeView10, dSize, NULL);

    DisplayTime (T("     1: Signature  %s\r\n"),
                 pc10->dSignature);

    printf      (T("     2: Age        %08lX\r\n"),
                 pc10->dAge);

    printf      (T("     3: PDB name   %hs\r\n"),
                 pc10->abPdbName);

    DisplaySeparator ();
    return;
    }

// -----------------------------------------------------------------

VOID WINAPI DisplayNBXXData (PIMG_INFO  pii,
                             PCV_HEADER pch,
                             DWORD      dSize)
    {
    DWORD i, j, k, n;

    DisplayTop (atCodeViewXX, dSize, NULL,
                pch->Signature.abText [0],
                pch->Signature.abText [1],
                pch->Signature.abText [2],
                pch->Signature.abText [3]);

    n = (((dSize - 1) / 16) + 1) * 16;

    for (i = 0; i < n; i += 16)
        {
        printf (T("%08lX | "), i);

        for (j = i; j < i + 16; j++)
            {
            if ((j & 0xF) == 8)
                {
                printf (T(": "));
                }
            if (j < dSize)
                {
                k = ((PBYTE) pch) [j];
                printf (T("%02lX "), k);
                }
            else
                {
                printf (T("   "));
                }
            }
        printf (T("| "));

        for (j = i; j < i + 16; j++)
            {
            if (j < dSize)
                {
                k = ((PBYTE) pch) [j];

                if ((k >= 0x20) && (k != 0x7F))
                    {
                    printf (T("%c"), k);
                    }
                else
                    {
                    printf (T("."));
                    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -