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

📄 w32start.h

📁 Undocumented WIndows 2000 Secrets 完整简体中文版!!NT架构windows(20000、xp)Kernel Hacking必备!!附cd iso与完整附录!
💻 H
📖 第 1 页 / 共 3 页
字号:
                    }
                else break;
                }
            LocalFree (pbBuffer);
            }
        LocalFree (pwBuffer);
        }
    return n;
    }

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

DWORD WINAPI veprintfW (PWORD pwFormat,
                        PVOID pArguments)
    {
    ConsoleOpen ();
    return vfprintfW (ghStdError, pwFormat, pArguments);
    }

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

DWORD WINAPI vprintfW (PWORD pwFormat,
                       PVOID pArguments)
    {
    ConsoleOpen ();
    return vfprintfW (ghStdOutput, pwFormat, pArguments);
    }

// =================================================================
// printf() ROUTINES (UNICODE)
// =================================================================

DWORD WINAPI sprintfW (PWORD pwBuffer,
                       PWORD pwFormat,
                       ...)
    {
    return vsprintfW (pwBuffer, pwFormat, (&pwFormat)+1);
    }

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

INT WINAPI mprintfW (HWND  hWnd,
                     UINT  uiType,
                     PWORD pwCaption,
                     PWORD pwFormat,
                     ...)
    {
    return vmprintfW (hWnd, uiType, pwCaption, pwFormat,
                      (&pwFormat)+1);
    }

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

DWORD WINAPI fprintfW (HANDLE hFile,
                       PWORD  pwFormat,
                       ...)
    {
    return vfprintfW (hFile, pwFormat, (&pwFormat)+1);
    }

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

DWORD WINAPI eprintfW (PWORD pwFormat,
                       ...)
    {
    return veprintfW (pwFormat, (&pwFormat)+1);
    }

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

DWORD WINAPI printfW (PWORD pwFormat,
                      ...)
    {
    return vprintfW (pwFormat, (&pwFormat)+1);
    }

// =================================================================
// vprintf() ROUTINES (ANSI)
// =================================================================

DWORD WINAPI vsprintfA (PBYTE pbBuffer,
                        PBYTE pbFormat,
                        PVOID pArguments)
    {
    PWORD pwBuffer, pwFormat;
    DWORD n = 0;

    if ((pwFormat = ConvertAnsiToUnicode (pbFormat, NULL))
        != NULL)
        {
        n = FormatMultiW (NULL, 0, pwFormat, pArguments,
                          gwFill, FALSE);

        if (pbBuffer != NULL)
            {
            if ((pwBuffer = ALLOC_UNICODE (n+1))
                != NULL)
                {
                FormatMultiW (pwBuffer, 0, pwFormat, pArguments,
                              gwFill, FALSE);

                ConvertUnicodeToAnsi (pwBuffer, pbBuffer);
                LocalFree (pwBuffer);
                }
            else
                {
                pbBuffer [n = 0] = 0;
                }
            }
        LocalFree (pwFormat);
        }
    return n;
    }

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

INT WINAPI vmprintfA (HWND  hWnd,
                      UINT  uiType,
                      PBYTE pbCaption,
                      PBYTE pbFormat,
                      PVOID pArguments)
    {
    PWORD pwFormat;
    PWORD pwBuffer;
    PBYTE pbBuffer;
    DWORD dBuffer;
    INT   iId = IDABORT;

    if ((pwFormat = ConvertAnsiToUnicode (pbFormat, NULL))
        != NULL)
        {
        dBuffer = FormatMultiW (NULL, 0, pwFormat, pArguments,
                                gwFill, FALSE);

        if ((pwBuffer = ALLOC_UNICODE (dBuffer+1))
            != NULL)
            {
            FormatMultiW (pwBuffer, 0, pwFormat, pArguments,
                          gwFill, FALSE);

            if ((pbBuffer = ConvertUnicodeToAnsi (pwBuffer, NULL))
                != NULL)
                {
                iId = MessageBoxA (hWnd, pbBuffer,
                                   (pbCaption != NULL
                                    ? pbCaption
                                    : SA(MAIN_CAPTION)),
                                   uiType);

                LocalFree (pbBuffer);
                }
            LocalFree (pwBuffer);
            }
        LocalFree (pwFormat);
        }
    return iId;
    }

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

DWORD WINAPI vfprintfA (HANDLE hFile,
                        PBYTE  pbFormat,
                        PVOID  pArguments)
    {
    PWORD pwFormat;
    PWORD pwBuffer;
    PBYTE pbBuffer;
    DWORD dBuffer, n1, n2;
    DWORD n = 0;

    if ((pwFormat = ConvertAnsiToUnicode (pbFormat, NULL))
        != NULL)
        {
        dBuffer = FormatMultiW (NULL, 0, pwFormat, pArguments,
                                gwFill, FALSE);

        if ((pwBuffer = ALLOC_UNICODE (dBuffer+1))
            != NULL)
            {
            FormatMultiW (pwBuffer, 0, pwFormat, pArguments,
                          gwFill, FALSE);

            if ((pbBuffer = ConvertUnicodeToAnsi (pwBuffer, NULL))
                != NULL)
                {
                while (dBuffer > n)
                    {
                    n1 = min (dBuffer-n, WRITE_FILE_BLOCK);
                    n2 = 0;

                    if (WriteFile (hFile, pbBuffer+n, n1, &n2, NULL)
                        && n2)
                        {
                        n += n2;
                        }
                    else break;
                    }
                LocalFree (pbBuffer);
                }
            LocalFree (pwBuffer);
            }
        LocalFree (pwFormat);
        }
    return n;
    }

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

DWORD WINAPI veprintfA (PBYTE pbFormat,
                        PVOID pArguments)
    {
    ConsoleOpen ();
    return vfprintfA (ghStdError, pbFormat, pArguments);
    }

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

DWORD WINAPI vprintfA (PBYTE pbFormat,
                       PVOID pArguments)
    {
    ConsoleOpen ();
    return vfprintfA (ghStdOutput, pbFormat, pArguments);
    }

// =================================================================
// printf() ROUTINES (ANSI)
// =================================================================

DWORD WINAPI sprintfA (PBYTE pbBuffer,
                       PBYTE pbFormat,
                       ...)
    {
    return vsprintfA (pbBuffer, pbFormat, (&pbFormat)+1);
    }

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

INT WINAPI mprintfA (HWND  hWnd,
                     UINT  uiType,
                     PBYTE pbCaption,
                     PBYTE pbFormat,
                     ...)
    {
    return vmprintfA (hWnd, uiType, pbCaption,
                      pbFormat, (&pbFormat)+1);
    }

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

DWORD WINAPI fprintfA (HANDLE hFile,
                       PBYTE  pbFormat,
                       ...)
    {
    return vfprintfA (hFile, pbFormat, (&pbFormat)+1);
    }

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

DWORD WINAPI eprintfA (PBYTE pbFormat,
                       ...)
    {
    return veprintfA (pbFormat, (&pbFormat)+1);
    }

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

DWORD WINAPI printfA (PBYTE pbFormat,
                      ...)
    {
    return vprintfA (pbFormat, (&pbFormat)+1);
    }

// =================================================================
// PROTOTYPES
// =================================================================

#ifdef _CONSOLE

DWORD Main (DWORD argc, PTBYTE *argv, PTBYTE *argp);

#else

#pragma warning (disable: 4028)

int WINAPI WinMain (HINSTANCE hInstance,
                    PWIN_CMD  pwc,
                    PTBYTE    ptCmdLine,
                    int       iShowCmd);

#pragma warning (default: 4028)

#endif

// =================================================================
// COMMAND PARSER
// =================================================================

PWIN_CMD W32Command (void)
    {
    PTBYTE   ptRaw;
    DWORD    dCount, dRaw, dCooked;
    PWIN_CMD pwc = NULL;

    if ((ptRaw = GetCommandLine ()) != NULL)
        {
        for (dCount = dRaw = dCooked = 0; ptRaw [dRaw];
             dCount++)
            {
            while (ptRaw [dRaw] == ' ') dRaw++;

            if (!ptRaw [dRaw]) break;

            while ( ptRaw [dRaw] &&
                   (ptRaw [dRaw] != ' '))
                {
                if (ptRaw [dRaw++] != '"')
                    {
                    dCooked++;
                    }
                else
                    {
                    while ( ptRaw [dRaw  ] &&
                           (ptRaw [dRaw++] != '"'))
                        {
                        dCooked++;
                        }
                    }
                }
            dCooked++;
            }
        dRaw++;

        if ((pwc = LocalAlloc (LMEM_FIXED,
                               WIN_CMD_                       +
                               (dCount * 2 * sizeof (PTBYTE)) +
                               (dRaw       * sizeof ( TBYTE)) +
                               (dCooked    * sizeof ( TBYTE))))
            != NULL)
            {
            pwc->argc     =             dCount;
            pwc->argv     = (PTBYTE *)  pwc->abData;
            pwc->argp     =             pwc->argv  + dCount;
            pwc->ptRaw    = (PTBYTE  ) (pwc->argp  + dCount);
            pwc->ptCooked =             pwc->ptRaw + dRaw;
            pwc->ptTail   =             NULL;

            CopyMemory (pwc->ptRaw, ptRaw, dRaw * sizeof ( TBYTE));

            for (dCount = dRaw = dCooked = 0; pwc->ptRaw [dRaw];
                 dCount++)
                {
                while (pwc->ptRaw [dRaw] == ' ') dRaw++;

                if (!pwc->ptRaw [dRaw]) break;

                pwc->argp [dCount] = pwc->ptRaw    + dRaw;
                pwc->argv [dCount] = pwc->ptCooked + dCooked;

                while ( pwc->ptRaw [dRaw] &&
                       (pwc->ptRaw [dRaw] != ' '))
                    {
                    if (pwc->ptRaw [dRaw++] != '"')
                        {
                        pwc->ptCooked [dCooked++] =
                        pwc->ptRaw    [dRaw-1];
                        }
                    else
                        {
                        while ( pwc->ptRaw [dRaw  ] &&
                               (pwc->ptRaw [dRaw++] != '"'))
                            {
                            pwc->ptCooked [dCooked++] =
                            pwc->ptRaw    [dRaw-1];
                            }
                        }
                    }
                pwc->ptCooked [dCooked++] = 0;
                }
            pwc->ptTail = (pwc->argc > 1 ? pwc->argp [1]
                                         : pwc->ptRaw + dRaw);
            }
        }
    return pwc;
    }

// =================================================================
// STARTUP CODE
// =================================================================

void W32Start (void)
    {

#ifdef _CONSOLE

    CONSOLE_SCREEN_BUFFER_INFO csbi;
    DWORD                      dCodePage;

#else

    STARTUPINFO                si;
    INT                        iShowCmd;

#endif

    PWIN_CMD                   pwc;
    DWORD                      dStatus = 0;

    if ((pwc = W32Command ()) != NULL)
        {
        giNetwork = GetSystemMetrics (SM_NETWORK);
        giDebug   = GetSystemMetrics (SM_DEBUG  );

#ifdef _CONSOLE
// -----------------------------------------------------------------

        if (ConsoleOpen ())
            {
            dCodePage = GetConsoleOutputCP ();
            SetConsoleOutputCP (GetACP ());
            GetConsoleScreenBufferInfo (ghStdOutput, &csbi);
            gdLine = csbi.dwSize.X;

            dStatus = Main (pwc->argc, pwc->argv, pwc->argp);

            SetConsoleOutputCP (dCodePage);
            }
#else
// -----------------------------------------------------------------

        GetStartupInfo (&si);

        iShowCmd = (si.dwFlags & STARTF_USESHOWWINDOW
                    ? (INT) si.wShowWindow
                    : SW_SHOWDEFAULT);

        dStatus = WinMain (GetModuleHandle (NULL),
                           pwc, pwc->ptTail,  iShowCmd);

#endif
// -----------------------------------------------------------------

        ConsoleClose ();
        LocalFree (pwc);
        }
    ExitProcess (dStatus);
    return;
    }

// =================================================================
// LINKER CONTROL
// =================================================================

#pragma comment (linker, "/entry:\"W32Start\"")

////////////////////////////////////////////////////////////////////
#endif // #ifndef _RC_PASS_
////////////////////////////////////////////////////////////////////

#endif // #ifndef _W32START_H_

// =================================================================
// END OF FILE
// =================================================================

⌨️ 快捷键说明

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