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

📄 w2k_img.c

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

// __________________________________________________________
//
//                         w2k_img.c
//            SBS Windows 2000 Image Library V1.01
//                08-27-2000 Sven B. Schreiber
//                       sbs@orgon.com
// __________________________________________________________

#define  _W2K_IMG_DLL_
#include "w2k_img.h"

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

/*

This software is provided "as is" and any express or implied
warranties, including, but not limited to, the implied warranties of
merchantibility 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-09-2000 V1.00 Original version (SBS).

08-27-2000 V1.01 Upgrade (SBS).

    Added imgAnsiMatch(), imgTimeDay(), imgSymbolTable(),
    imgSymbolCompare(), imgSymbolSort(), and the complete
    imgTable*() function set. Revised the symbol file finder
    algorithm. Optimized OMAP address lookup. Added detection
    of calling conventions.

*/

// =================================================================
// GLOBAL VARIABLES
// =================================================================

HINSTANCE ghInstance = NULL;

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

BYTE gabSymbolPath1 [] =  "_NT_SYMBOL_PATH";
BYTE gabSymbolPath2 [] =  "_NT_ALT_SYMBOL_PATH";
BYTE gabSymbols     [] =  "Symbols\\";
BYTE gabKernel      [] =  "ntoskrnl.exe";
BYTE gabDbg         [] =  ".dbg";
BYTE gabPdb         [] =  ".pdb";
BYTE gabNull        [] =  "";

WORD gawSymbolPath1 [] = L"_NT_SYMBOL_PATH";
WORD gawSymbolPath2 [] = L"_NT_ALT_SYMBOL_PATH";
WORD gawSymbols     [] = L"Symbols\\";
WORD gawKernel      [] = L"ntoskrnl.exe";
WORD gawDbg         [] = L".dbg";
WORD gawPdb         [] = L".pdb";
WORD gawNull        [] = L"";

// =================================================================
// LOWER-CASE CHARACTER TABLE
// =================================================================

BYTE LCase [] =
    {
      0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15,
     16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
     32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
     48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
     64, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111,
    112,113,114,115,116,117,118,119,120,121,122, 91, 92, 93, 94, 95,
     96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111,
    112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,
    128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
    144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,255,
    160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
    176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,
    224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,
    240,241,242,243,244,245,246,215,248,249,250,251,252,253,222,223,
    224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,
    240,241,242,243,244,245,246,247,248,249,250,251,252,253,222,255
    };

// =================================================================
// OUTPUT FUNCTIONS
// =================================================================

INT WINAPI imgBoxA (HWND  hWnd,
                    UINT  uiType,
                    PBYTE pbCaption,
                    PBYTE pbFormat,
                    ...)
    {
    BYTE abBuffer [1024];

    wvsprintf (abBuffer, pbFormat, (PVOID) (&pbFormat+1));
    return MessageBoxA (hWnd, abBuffer, pbCaption, uiType);
    }

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

INT WINAPI imgBoxW (HWND  hWnd,
                    UINT  uiType,
                    PWORD pwCaption,
                    PWORD pwFormat,
                    ...)
    {
    WORD awBuffer [1024];

    wvsprintfW (awBuffer, pwFormat, (PVOID) (&pwFormat+1));
    return MessageBoxW (hWnd, awBuffer, pwCaption, uiType);
    }

// =================================================================
// MEMORY MANAGEMENT
// =================================================================

PVOID WINAPI imgMemoryCreate (DWORD dBytes)
    {
    return LocalAlloc (LMEM_FIXED, max (dBytes, 1));
    }

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

PVOID WINAPI imgMemoryResize (PVOID pData,
                              DWORD dBytes)
    {
    DWORD dBytes1, dBytes2;
    PVOID pData1 = NULL;

    if (pData != NULL)
        {
        if (dBytes1 = LocalSize (pData))
            {
            if ((dBytes2 = max (dBytes, 1)) != dBytes1)
                {
                if ((pData1 = LocalReAlloc (pData, dBytes2,
                                            LMEM_MOVEABLE))
                    == NULL)
                    {
                    LocalFree (pData);
                    }
                }
            else
                {
                pData1 = pData;
                }
            }
        else
            {
            LocalFree (pData);
            }
        }
    return pData1;
    }

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

PVOID WINAPI imgMemoryDestroy (PVOID pData)
    {
    if (pData != NULL)
        {
        LocalFree (pData);
        }
    return NULL;
    }

// =================================================================
// STRING PATTERN MATCHER
// =================================================================

BOOL WINAPI imgAnsiMatchA (PBYTE pbFilter,
                           PBYTE pbData,
                           BOOL  fIgnoreCase)
    {
    DWORD i = 0;
    DWORD j = 0;

    if (pbData   == NULL) return FALSE;
    if (pbFilter == NULL) return TRUE;

    while (pbFilter [i] && pbData [j])
        {
        if (pbFilter [i] != '?')
            {
            if (pbFilter [i] == '*')
                {
                i++;

                if ((pbFilter [i] != '*') &&
                    (pbFilter [i] != '?'))
                    {
                    if (pbFilter [i])
                        {
                        while (pbData [j]
                               &&
                               (!imgAnsiMatchA (pbFilter + i,
                                                pbData   + j,
                                                fIgnoreCase)))
                            {
                            j++;
                            }
                        }
                    return pbData [j] != 0;
                    }
                }
            if (fIgnoreCase
                ? LCASEA (pbFilter [i]) != LCASEA (pbData [j])
                :         pbFilter [i]  !=         pbData [j] )
                {
                return FALSE;
                }
            }
        i++;
        j++;
        }
    if (pbFilter [i] == '*') i++;
    return !(pbFilter [i] || pbData [j]);
    }

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

BOOL WINAPI imgAnsiMatchW (PWORD pwFilter,
                           PBYTE pbData,
                           BOOL  fIgnoreCase)
    {
    DWORD i = 0;
    DWORD j = 0;

    if (pbData   == NULL) return FALSE;
    if (pwFilter == NULL) return TRUE;

    while (pwFilter [i] && pbData [j])
        {
        if (pwFilter [i] != '?')
            {
            if (pwFilter [i] == '*')
                {
                i++;

                if ((pwFilter [i] != '*') &&
                    (pwFilter [i] != '?'))
                    {
                    if (pwFilter [i])
                        {
                        while (pbData [j]
                               &&
                               (!imgAnsiMatchW (pwFilter + i,
                                                pbData   + j,
                                                fIgnoreCase)))
                            {
                            j++;
                            }
                        }
                    return pbData [j] != 0;
                    }
                }
            if (fIgnoreCase
                ? LCASEW (pwFilter [i]) != LCASEA (pbData [j])
                :         pwFilter [i]  !=         pbData [j] )
                {
                return FALSE;
                }
            }
        i++;
        j++;
        }
    if (pwFilter [i] == '*') i++;
    return !(pwFilter [i] || pbData [j]);
    }

// =================================================================
// DATE/TIME CONVERSION
// =================================================================

DWORD adDaysPerMonth [] = {31,28,31,30,31,30,31,31,30,31,30,31};

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

IMG_TIME WINAPI imgTimeNow (BOOL fLocal)
    {
    SYSTEMTIME st;
    IMG_TIME   it;

    if (fLocal) GetLocalTime  (&st);
    else        GetSystemTime (&st);

    it.wYear      = (WORD) st.wYear;
    it.bMonth     = (BYTE) st.wMonth;
    it.bDay       = (BYTE) st.wDay;
    it.bHour      = (BYTE) st.wHour;
    it.bMinute    = (BYTE) st.wMinute;
    it.bSecond    = (BYTE) st.wSecond;
    it.bDayOfWeek =
        (BYTE) (((((imgTimePack (it) / 60) / 60) / 24) + 4) % 7);

    return it;
    }

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

DWORD WINAPI imgTimePack (IMG_TIME it)
    {
    DWORD dYear, dMonth, dDay, i;
    DWORD dTime = 0;

    if (it.wYear >= 1970)
        {
        dMonth = (it.bMonth ? it.bMonth-1 : 0);

        dYear  = (DWORD) it.wYear - 1600 + (dMonth / 12);
        dMonth = dMonth % 12;
        dDay   = (dYear / 400) * DAYS_PER_400_YEARS;

        for (i = 0; i < dMonth; i++)
            {
            dDay += adDaysPerMonth [i];
            }
        if ((dMonth > 1) && (!(dYear % 4)) &&
            ((dYear % 100) || (!(dYear % 400))))
            {
            dDay += 1;
            }
        if (it.bDay)
            {
            dDay += it.bDay - 1;
            }
        if (dYear = dYear % 400)
            {
            dDay += ((dYear / 100) * (DAYS_PER_100_YEARS-1)) + 1;

            if (dYear = dYear % 100)
                {
                dDay += ((dYear / 4) * DAYS_PER_4_YEARS) - 1;

                if (dYear = dYear % 4)
                    {
                    dDay += (dYear * DAYS_PER_YEAR) + 1;
                    }
                }
            }
        dDay -= DAYS_1600_TO_1970;

        dTime  = (dDay               * 60 * 60 * 24) +
                 ((DWORD) it.bHour   * 60 * 60     ) +
                 ((DWORD) it.bMinute * 60          ) +
                 ((DWORD) it.bSecond               );
        }
    return dTime;
    }

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

IMG_TIME WINAPI imgTimeUnpack (DWORD dTime)
    {
    IMG_TIME it;

    DWORD dDaySince1600, dDayIn100Years, dDayIn4Years;
    DWORD d400Years, d100In400Years, d4In100Years, d1In4Years;
    DWORD dDay, dMonth, dYear, dDaysPerMonth;
    BOOL  fLeap;

    it.bSecond    = (BYTE) ((dTime        ) % 60);
    it.bMinute    = (BYTE) ((dTime /    60) % 60);
    it.bHour      = (BYTE) ((dTime /  3600) % 24);
    dDaySince1600 =         (dTime / 86400) + DAYS_1600_TO_1970;

    dDayIn100Years = dDaySince1600 % DAYS_PER_400_YEARS;
    d400Years      = dDaySince1600 / DAYS_PER_400_YEARS;
    d100In400Years = 0;

    while (dDayIn100Years >= DAYS_PER_100_YEARS)
        {
        dDayIn100Years -= (DAYS_PER_100_YEARS-1);
        d100In400Years++;
        }
    dDayIn4Years = dDayIn100Years % DAYS_PER_4_YEARS;
    d4In100Years = dDayIn100Years / DAYS_PER_4_YEARS;

    if (dDayIn4Years)
        {
        dDay       = (dDayIn4Years-1) % DAYS_PER_YEAR;
        d1In4Years = (dDayIn4Years-1) / DAYS_PER_YEAR;
        if (!d1In4Years) dDay++;
        }
    else
        {
        dDay       = 0;
        d1In4Years = 0;
        }
    fLeap = (d1In4Years ? FALSE
                        : (d4In100Years ? TRUE
                                        : !d100In400Years));

    for (dMonth = 0; dMonth < 12; dMonth++)
        {
        dDaysPerMonth = adDaysPerMonth [dMonth];
        if ((dMonth == 2) && fLeap) dDaysPerMonth++;
        if (dDay < dDaysPerMonth) break;
        dDay -= dDaysPerMonth;
        }
    dYear = (d1In4Years          ) +
            (d4In100Years   *   4) +
            (d100In400Years * 100) +
            (d400Years      * 400) + 1600;

    it.bDay       = (BYTE) (dDay + 1);
    it.bMonth     = (BYTE) (dMonth + 1);
    it.wYear      = (WORD) dYear;
    it.bDayOfWeek = (BYTE) ((dDaySince1600 + 6) % 7);
    return it;
    }

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

PBYTE WINAPI imgTimeDayA (IMG_TIME it)
    {
    PBYTE pbDay = NULL;

    switch (it.bDayOfWeek % 7)
        {
        case 0: pbDay = "Sunday";    break;
        case 1: pbDay = "Monday";    break;
        case 2: pbDay = "Tuesday";   break;
        case 3: pbDay = "Wednesday"; break;
        case 4: pbDay = "Thursday";  break;
        case 5: pbDay = "Friday";    break;

⌨️ 快捷键说明

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