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

📄 w2k_lib.c

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

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

BYTE WINAPI w2kRandomByte (PDWORD pdData,
                           PDWORD pdAddress)
    {
    BYTE bRandom = 0;

    __asm
        {
                push    ebx
                mov     eax, pdData
                mov     edx, pdAddress
                mov     ebx, [eax]
                mov     ecx, [edx]
        }
    __asm
        {
                rol     ebx, 1
                test    bl, 10101110b
                setpo   ah
                xor     bl, ah
                shl     ecx, 1
                sets    ah
                or      cl, ah
                test    cl, 00001000b
                setpo   ah
                xor     cl, ah
                rol     ecx, 11
                bt      ebx, ecx
                rcr     al, 1
                ror     ecx, 11
        }
    __asm
        {
                rol     ebx, 1
                test    bl, 10101110b
                setpo   ah
                xor     bl, ah
                shl     ecx, 1
                sets    ah
                or      cl, ah
                test    cl, 00001000b
                setpo   ah
                xor     cl, ah
                rol     ecx, 11
                bt      ebx, ecx
                rcr     al, 1
                ror     ecx, 11
        }
    __asm
        {
                rol     ebx, 1
                test    bl, 10101110b
                setpo   ah
                xor     bl, ah
                shl     ecx, 1
                sets    ah
                or      cl, ah
                test    cl, 00001000b
                setpo   ah
                xor     cl, ah
                rol     ecx, 11
                bt      ebx, ecx
                rcr     al, 1
                ror     ecx, 11
        }
    __asm
        {
                rol     ebx, 1
                test    bl, 10101110b
                setpo   ah
                xor     bl, ah
                shl     ecx, 1
                sets    ah
                or      cl, ah
                test    cl, 00001000b
                setpo   ah
                xor     cl, ah
                rol     ecx, 11
                bt      ebx, ecx
                rcr     al, 1
                ror     ecx, 11
        }
    __asm
        {
                rol     ebx, 1
                test    bl, 10101110b
                setpo   ah
                xor     bl, ah
                shl     ecx, 1
                sets    ah
                or      cl, ah
                test    cl, 00001000b
                setpo   ah
                xor     cl, ah
                rol     ecx, 11
                bt      ebx, ecx
                rcr     al, 1
                ror     ecx, 11
        }
    __asm
        {
                rol     ebx, 1
                test    bl, 10101110b
                setpo   ah
                xor     bl, ah
                shl     ecx, 1
                sets    ah
                or      cl, ah
                test    cl, 00001000b
                setpo   ah
                xor     cl, ah
                rol     ecx, 11
                bt      ebx, ecx
                rcr     al, 1
                ror     ecx, 11
        }
    __asm
        {
                rol     ebx, 1
                test    bl, 10101110b
                setpo   ah
                xor     bl, ah
                shl     ecx, 1
                sets    ah
                or      cl, ah
                test    cl, 00001000b
                setpo   ah
                xor     cl, ah
                rol     ecx, 11
                bt      ebx, ecx
                rcr     al, 1
                ror     ecx, 11
        }
    __asm
        {
                rol     ebx, 1
                test    bl, 10101110b
                setpo   ah
                xor     bl, ah
                shl     ecx, 1
                sets    ah
                or      cl, ah
                test    cl, 00001000b
                setpo   ah
                xor     cl, ah
                rol     ecx, 11
                bt      ebx, ecx
                rcr     al, 1
                ror     ecx, 11
        }
    __asm
        {
                mov     bRandom, al
                mov     eax, pdData
                mov     edx, pdAddress
                mov     [eax], ebx
                mov     [edx], ecx
                pop     ebx
        }
    return bRandom;
    }

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

WORD WINAPI w2kRandomWord (PDWORD pdData,
                           PDWORD pdAddress)
    {
    WORD wRandom = 0;

    wRandom  = (((WORD) w2kRandomByte (pdData, pdAddress))     );
    wRandom |= (((WORD) w2kRandomByte (pdData, pdAddress)) << 8);
    return wRandom;
    }

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

DWORD WINAPI w2kRandomDword (PDWORD pdData,
                             PDWORD pdAddress)
    {
    DWORD dRandom = 0;

    dRandom  = (((DWORD) w2kRandomWord (pdData, pdAddress))      );
    dRandom |= (((DWORD) w2kRandomWord (pdData, pdAddress)) << 16);
    return dRandom;
    }

// =================================================================
// ENVIRONMENT MANAGEMENT
// =================================================================

PWORD WINAPI w2kEnvironmentString (PWORD pwStrings,
                                   PWORD pwName)
    {
    DWORD i, j, k;
    PWORD pwValue = NULL;

    if ((pwStrings != NULL) && (pwName != NULL))
        {
        for (i = 0; pwStrings [i]; i += (lstrlen (pwStrings+i) + 1))
            {
            if (pwStrings [j=i] == '=') j++;

            while (pwStrings [j] && (pwStrings [j] != '=')) j++;

            if (pwStrings [j] == '=')
                {
                for (k = 0; (i+k < j) && pwName [k]; k++)
                    {
                    if (LCASE (pwStrings [i+k]) !=
                        LCASE (pwName    [  k])) break;
                    }
                if ((i+k == j) && (!pwName [k]))
                    {
                    pwValue = pwStrings+j+1;
                    break;
                    }
                }
            }
        }
    return pwValue;
    }

// =================================================================
// PATH MANAGEMENT
// =================================================================

DWORD WINAPI w2kPathNormalize (PWORD pwPath)
    {
    DWORD i, j;
    DWORD dData = 0;

    if (pwPath != NULL)
        {
        i = j = 0;

        while (pwPath [i])
            {
            if (pwPath [i++] != '"')
                {
                pwPath [j++] = pwPath [i-1];
                }
            else
                {
                while (pwPath [i] && (pwPath [i++] != '"'))
                    {
                    pwPath [j++] = pwPath [i-1];
                    }
                }
            }
        while (j && (pwPath [j-1] == ' ')) j--;
        for (i = 0; (i < j) && (pwPath [i] == ' '); i++);

        dData = j-i;

        if (i)
            {
            for (j = 0; j < dData; j++)
                {
                pwPath [j] = pwPath [i+j];
                }
            }
        pwPath [dData++] = 0;
        }
    return dData;
    }

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

PWORD WINAPI w2kPathEvaluate (PWORD  pwPath,
                              PDWORD pdData)
    {
    PWORD pwStrings, pwValue;
    DWORD i, j, n;
    DWORD dData   = 0;
    PWORD pwPath1 = NULL;

    if (w2kPathNormalize (pwPath) &&
        ((pwStrings = GetEnvironmentStrings ()) != NULL))
        {
        i = n = 0;

        while (pwPath [i])
            {
            while (pwPath [i] && (pwPath [i] != '%')) n++, i++;

            if (pwPath [i] == '%')
                {
                j = ++i;

                while (pwPath [j] && (pwPath [j] != '%')) j++;

                if ((pwPath [j] == '%') && (i < j))
                    {
                    pwPath [j] = 0;

                    pwValue = w2kEnvironmentString (pwStrings,
                                                    pwPath+i);
                    pwPath [j] = '%';
                    }
                else
                    {
                    pwValue = NULL;
                    }
                if (pwValue != NULL)
                    {
                    n += lstrlen (pwValue);
                    i  = j + 1;
                    }
                else
                    {
                    n += (1 + j - i);
                    i  = j;
                    }
                }
            }
        if ((pwPath1 = w2kMemoryCreate (++n * WORD_)) != NULL)
            {
            i = 0;

            while (pwPath [i])
                {
                while (pwPath [i] && (pwPath [i] != '%'))
                    {
                    pwPath1 [dData++] = pwPath [i++];
                    }
                if (pwPath [i] == '%')
                    {
                    j = ++i;

                    while (pwPath [j] && (pwPath [j] != '%')) j++;

                    if ((pwPath [j] == '%') && (i < j))
                        {
                        pwPath [j] = 0;

                        pwValue = w2kEnvironmentString (pwStrings,
                                                        pwPath+i);
                        pwPath [j] = '%';
                        }
                    else
                        {
                        pwValue = NULL;
                        }
                    if (pwValue != NULL)
                        {
                        i = j + 1;

                        for (j = 0; pwValue [j]; dData++, j++)
                            {
                            pwPath1 [dData] = pwValue [j];
                            }
                        }
                    else
                        {
                        for (--i; i < j; dData++, i++)
                            {
                            pwPath1 [dData] = pwPath [i];
                            }
                        }
                    }
                }
            pwPath1 [dData++] = 0;
            }
        FreeEnvironmentStrings (pwStrings);
        }
    if (pdData != NULL) *pdData = dData;
    return pwPath1;
    };

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

DWORD WINAPI w2kPathRoot (PWORD pwPath)
    {
    DWORD dRoot = 0;

    if ((pwPath != NULL) && pwPath [0])
        {
        if (pwPath [0] == '\\')
            {
            if (pwPath [1] == '\\')
                {
                for (dRoot = 2;
                     pwPath [dRoot] && (pwPath [dRoot] != '\\');
                     dRoot++);
                }
            }
        else
            {
            if (pwPath [1] == ':') dRoot = 2;
            }
        }
    return dRoot;
    }

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

DWORD WINAPI w2kPathName (PWORD  pwPath,
                          PDWORD pdExtension)
    {
    DWORD dRoot, dEnd;
    DWORD dExtension = 0;
    DWORD dName      = 0;

    if (pwPath != NULL)
        {
        dRoot = w2kPathRoot (pwPath);
        dEnd  = dRoot + lstrlen (pwPath + dRoot);

        for (dName = dEnd;
             (dName > dRoot) && (pwPath [dName-1] != '\\')
                             && (pwPath [dName-1] != ':' );
             dName--);

        for (dExtension = dEnd;
             (dExtension > dName) && (pwPath [dExtension-1] != '.');
             dExtension--);

        dExtension = (dExtension == dName ? dEnd : dExtension - 1);
        }
    if (pdExtension != NULL) *pdExtension = dExtension;
    return dName;
    }

// =================================================================
// FILE MANAGEMENT
// =================================================================

DWORD WINAPI w2kFilePath (HINSTANCE hInstance,
         

⌨️ 快捷键说明

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