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

📄 test.c

📁 汇编语言编的TOOLHELPasm.rar程序,初学者可能会用到哦^_^TOOLHELPasm.rar
💻 C
📖 第 1 页 / 共 4 页
字号:
    SetCursor(hCursor);

    return 0L;
}



/*  DoStackTrace
 *      Does a stack trace for the current module in the lower box
 */

LONG DoStackTrace(
    HWND hwnd)
{
    STACKTRACEENTRY StackTrace;
    MODULEENTRY ModuleEntry;
    HCURSOR hCursor;
    HANDLE hTask;
    WORD wCS;
    HANDLE hModule;

    /* Turn on the hourglass */
    hCursor = SetCursor(LoadCursor(NULL, IDC_WAIT));
    ShowCursor(TRUE);

    /* Get the task handle from the list box */
    SendMessage(hwndList, LB_GETTEXT,
        (WORD)SendMessage(hwndList, LB_GETCURSEL, 0, 0L),
        (LONG)(LPSTR)szText);
    sscanf(szText, "%*6c%x", &hTask);

    /* Clear list box */
    SendMessage(hwndListLocal, WM_SETREDRAW, FALSE, 0L);
    SendMessage(hwndListLocal, LB_RESETCONTENT, 0, 0L);

    /* Do the stack trace */
    StackTrace.dwSize = sizeof (STACKTRACEENTRY);
    wCS = 0;
    hModule = NULL;
    if (StackTraceFirst(&StackTrace, hTask))
        do
        {
            /* Get the module name */
            ModuleEntry.dwSize = sizeof (MODULEENTRY);
            if (!ModuleFindHandle(&ModuleEntry, StackTrace.hModule))
                ModuleEntry.szModule[0] = '\0';

            /* Put some fun garbage in the text buffer */
            sprintf(szText, "BP=%04X CS:IP=%04X:%04X (Mod=%s Seg=%u)", 
                StackTrace.wBP, StackTrace.wCS, StackTrace.wIP,
                ModuleEntry.szModule, StackTrace.wSegment);

            /* Set the last wCS in case we're using a near frame */
            if (StackTrace.wCS)
            {
                wCS = StackTrace.wCS;
                hModule = StackTrace.hModule;
            }

            /* Put the string in the list box */
            SendMessage(hwndListLocal, LB_ADDSTRING, 0, (LONG)(LPSTR)szText);
        }
        while (StackTraceNext(&StackTrace));

    /* OK to redraw list box now */
    SendMessage(hwndListLocal, WM_SETREDRAW, TRUE, 0L);
    InvalidateRect(hwndListLocal, NULL, TRUE);

    /* Done with hourglass */
    ShowCursor(FALSE);
    SetCursor(hCursor);

    return 0L;
}


/*  DoUserInfo
 *      Displays the data from a call to UserInfo()
 */

LONG DoUserInfo(
    HWND hwnd)
{
    USERHEAPINFO User;

    wListStatus = LIST_USER;

    /* Clear list box */
    SendMessage(hwndList, WM_SETREDRAW, FALSE, 0L);
    SendMessage(hwndList, LB_RESETCONTENT, 0, 0L);

    /* Get the user information */
    User.dwSize = sizeof (USERHEAPINFO);
    UserHeapInfo(&User);

    /* Display the User information */
    wsprintf(szText, "hSegment = %04X", User.hSegment);
    SendMessage(hwndList, LB_ADDSTRING, 0, (LONG)(LPSTR)szText);
    wsprintf(szText, "wHeapFree = %u", User.wHeapFree);
    SendMessage(hwndList, LB_ADDSTRING, 0, (LONG)(LPSTR)szText);
    wsprintf(szText, "wMaxHeapSize = %u", User.wMaxHeapSize);
    SendMessage(hwndList, LB_ADDSTRING, 0, (LONG)(LPSTR)szText);
    wsprintf(szText, "User Free = %u%%", User.wPercentFree);
    SendMessage(hwndList, LB_ADDSTRING, 0, (LONG)(LPSTR)szText);

    /* OK to redraw list box now.  Also draw its title */
    SendMessage(hwndList, WM_SETREDRAW, TRUE, 0L);
    InvalidateRect(hwndList, NULL, TRUE);
    SetWindowText(hwndListStatic, "User Information");
    InvalidateRect(hwndListStatic, NULL, TRUE);

    return 0L;
}


/*  DoGDIInfo
 *      Displays the data from a call to UserInfo()
 */

LONG DoGDIInfo(
    HWND hwnd)
{
    GDIHEAPINFO GDI;

    wListStatus = LIST_GDI;

    /* Clear list box */
    SendMessage(hwndList, WM_SETREDRAW, FALSE, 0L);
    SendMessage(hwndList, LB_RESETCONTENT, 0, 0L);

    /* Get the GDI information */
    GDI.dwSize = sizeof (GDIHEAPINFO);
    GDIHeapInfo(&GDI);

    /* Display the GDI information */
    wsprintf(szText, "hSegment = %04X", GDI.hSegment);
    SendMessage(hwndList, LB_ADDSTRING, 0, (LONG)(LPSTR)szText);
    wsprintf(szText, "wHeapFree = %u", GDI.wHeapFree);
    SendMessage(hwndList, LB_ADDSTRING, 0, (LONG)(LPSTR)szText);
    wsprintf(szText, "wMaxHeapSize = %u", GDI.wMaxHeapSize);
    SendMessage(hwndList, LB_ADDSTRING, 0, (LONG)(LPSTR)szText);
    wsprintf(szText, "GDI Free = %u%%", GDI.wPercentFree);
    SendMessage(hwndList, LB_ADDSTRING, 0, (LONG)(LPSTR)szText);

    /* OK to redraw list box now.  Also draw its title */
    SendMessage(hwndList, WM_SETREDRAW, TRUE, 0L);
    InvalidateRect(hwndList, NULL, TRUE);
    SetWindowText(hwndListStatic, "GDI Information");
    InvalidateRect(hwndListStatic, NULL, TRUE);

    return 0L;
}


/*  DoMemManInfo
 *      Displays the data from a call to UserInfo()
 */

LONG DoMemManInfo(
    HWND hwnd)
{
    MEMMANINFO MemMan;

    wListStatus = LIST_MEMMAN;

    /* Clear list box */
    SendMessage(hwndList, WM_SETREDRAW, FALSE, 0L);
    SendMessage(hwndList, LB_RESETCONTENT, 0, 0L);

    /* Get the Memory manager information */
    MemMan.dwSize = sizeof (MEMMANINFO);
    MemManInfo(&MemMan);

    /* Display the MemMan information */
    wsprintf(szText, "Largest Free Block = %08lXh", MemMan.dwLargestFreeBlock);
    SendMessage(hwndList, LB_ADDSTRING, 0, (LONG)(LPSTR)szText);
    wsprintf(szText, "Max Pages Available = %08lXh", MemMan.dwMaxPagesAvailable);
    SendMessage(hwndList, LB_ADDSTRING, 0, (LONG)(LPSTR)szText);
    wsprintf(szText, "Max Pages Lockable = %08lXh", MemMan.dwMaxPagesLockable);
    SendMessage(hwndList, LB_ADDSTRING, 0, (LONG)(LPSTR)szText);
    wsprintf(szText, "Total Linear Space = %08lXh", MemMan.dwTotalLinearSpace);
    SendMessage(hwndList, LB_ADDSTRING, 0, (LONG)(LPSTR)szText);
    wsprintf(szText, "Total Unlocked Pages = %08lXh", MemMan.dwTotalUnlockedPages);
    SendMessage(hwndList, LB_ADDSTRING, 0, (LONG)(LPSTR)szText);
    wsprintf(szText, "Free Pages = %08lXh", MemMan.dwFreePages);
    SendMessage(hwndList, LB_ADDSTRING, 0, (LONG)(LPSTR)szText);
    wsprintf(szText, "Total Pages = %08lXh", MemMan.dwTotalPages);
    SendMessage(hwndList, LB_ADDSTRING, 0, (LONG)(LPSTR)szText);
    wsprintf(szText, "Free Linear Space = %08lXh", MemMan.dwFreeLinearSpace);
    SendMessage(hwndList, LB_ADDSTRING, 0, (LONG)(LPSTR)szText);
    wsprintf(szText, "Swap File Pages = %08lXh", MemMan.dwSwapFilePages);
    SendMessage(hwndList, LB_ADDSTRING, 0, (LONG)(LPSTR)szText);
    wsprintf(szText, "Page Size = %04Xh", MemMan.wPageSize);
    SendMessage(hwndList, LB_ADDSTRING, 0, (LONG)(LPSTR)szText);

    /* OK to redraw list box now.  Also draw its title */
    SendMessage(hwndList, WM_SETREDRAW, TRUE, 0L);
    InvalidateRect(hwndList, NULL, TRUE);
    SetWindowText(hwndListStatic, "Memory Manager Information");
    InvalidateRect(hwndListStatic, NULL, TRUE);

    return 0L;
}

/*  DoGlobalEntryModuleTest
 *      Tests the GlobalEntryModule API for correctness.
 */

LONG DoGlobalEntryModuleTest(
    HWND hwnd)
{
    GLOBALENTRY Global;
    HANDLE hModule;

    /* Get an interesting module handle */
    hModule = GetModuleHandle("USER");

    /* Find out about the segment */
    Global.dwSize = sizeof (GLOBALENTRY);
    if (!GlobalEntryModule(&Global, hModule, 14))
        MessageBox(hwnd, "Error returned!", "GlobalEntryModule Test",
            MB_OK | MB_ICONEXCLAMATION);
    else
    {
        wsprintf(szText, "USER Code Seg 14 has handle %04X", Global.hBlock);
        MessageBox(hwnd, szText, "GlobalEntryModule Test",
            MB_OK | MB_ICONINFORMATION);
    }
}


/*  ReadMemoryTest
 *      Opens a popup window and allows the user to scroll through the
 *      contents of the memory block.
 */

LONG ReadMemoryTest(
    HWND hwnd,
    HANDLE hBlock)
{
    HWND hwndPopup;
    GLOBALENTRY Global;

    /* Make a popup window to handle the data */
    Global.dwSize = sizeof (GLOBALENTRY);
    GlobalEntryHandle(&Global, hBlock);
    wsprintf(szText,"Handle = %4Xh  Length = %8lXh",
        hBlock, Global.dwBlockSize);
    hwndPopup = CreateWindow(
        szMemName,
        szText,
        WS_POPUP | WS_CAPTION |
        WS_SYSMENU | WS_THICKFRAME | WS_MAXIMIZEBOX | WS_VSCROLL,
        xScreen / 2 - 45 * xChar,
        yScreen / 8,
        90 * xChar,
        2 * yScreen / 3,
        hwnd,
        NULL,
        hInst,
        (LPSTR)MAKELONG(hBlock, 0));
 
    /* Display the window */
    ShowWindow(hwndPopup, SW_SHOWNORMAL);
    UpdateWindow(hwndPopup);

    return 0L;
}


/*  TimerCountTest
 *      Tests the timer count function.
 */

LONG TimerCountTest(
    HWND hwnd)
{
    TIMERINFO TimerInfo;

    /* Get the tick count */
    TimerInfo.dwSize = sizeof (TIMERINFO);
    if (!TimerCount(&TimerInfo))
    {
        MessageBox(hwnd, "Error calling TimerCount()", "Timer Count Test",
            MB_OK);
        return 0L;
    }

    /* Display it */
    wsprintf(szText, "Milliseconds since Windows started = %ld\r\n"
        "Milliseconds in this VM = %ld",
        TimerInfo.dwmsSinceStart, TimerInfo.dwmsThisVM);
    MessageBox(hwnd, szText, "Timer Count Test", MB_OK | MB_ICONINFORMATION);

    /* Return success */
    return 0L;
}


/*  MyNotifyHandler
 *      Notification message callback
 */

BOOL FAR PASCAL MyNotifyHandler(
    WORD wID,
    DWORD dwData)
{
    /* See if we should process this notification */
    if (!wNotifyState)
        return FALSE;

    /* Filter out task switch notifications if necessary */
    if (wFilterState && (wID == NFY_TASKIN || wID == NFY_TASKOUT))
        return FALSE;

    /* Put the information in a message */
    PostMessage(hwndMain, WM_USER, wID, dwData);

    /* Only return that we handled debug strings and RIPs */
    if (wID == NFY_RIP || wID == NFY_DEBUGSTR)
        return TRUE;
    else
        return FALSE;
}


/*  MyCFaultHandler
 *      This routine is used to prove that C routines can be used to
 *      make fault handlers.  As can be seen here, the parameters are
 *      actually pointing into the stack frame.  Two important notes:
 *          1) This function MUST be declared as _cdecl so that the
 *              parameters are not popped off the stack!
 *          2) This function may change these values with the understanding
 *              that they are actually passed "by value" implying that
 *              any changes are for real.
 *      As defined in MyFaultHandler (TEST2.ASM), 0 nukes app, 1 restarts
 *      the instruction, 2 chains on.
 */

WORD _cdecl MyCFaultHandler(
    WORD wES,
    WORD wDS,
    WORD wDI,
    WORD wSI,
    WORD wBP,
    WORD wSP,
    WORD wBX,
    WORD wDX,
    WORD wCX,
    WORD wOldAX,
    WORD wOldBP,
    WORD wRetIP,
    WORD wRetCS,
    WORD wRealAX,
    WORD wNumber,
    WORD wHandle,
    WORD wIP,
    WORD wCS,
    WORD wFlags)
{
    FARPROC lpfnDlg;
    int nResult;
    static WORD wReentry;

    /* See if we're already here.  If so, tell routine to chain on */
    if (wReentry)
        return 2;
    wReentry = 1;

    /* If this was a CtlAltSysRq interrupt, just restart the instr. */
    if (wNumber == INT_CTLALTSYSRQ)
    {
        wsprintf(szText, "THTest:  CtlAltSysRq at %04X:%04X\r\n", wCS, wIP);
        OutputDebugString(szText);
        wReentry = 0;
        return 1;
    }

    /* Set the static variables */
    wsCS = wCS;
    wsIP = wIP;
    wsFault = wNumber;
    wsFaultTask = GetCurrentTask();

    /* Use the dialog box to determine what to do with the fault */
    lpfnDlg = MakeProcInstance((FARPROC)FaultDialogProc, hInst);
    nResult = DialogBox(hInst, MAKEINTRESOURCE(IDD_FAULT), hwndMain, lpfnDlg);
    FreeProcInstance(lpfnDlg);

    /* We're getting out now, so undo reentry flag */
    wReentry = 0;

    return (WORD)nResult;
}


/*  FaultDialogProc
 *      Handles the Fault dialog box
 *      It returns 0 to nuke the app, 1 to restart the instruction,
 *      2 to chain on
 */

BOOL FAR PASCAL FaultDialogProc(
    HWND hDlg,
    WORD wMessage,
    WORD wParam,
    DWORD dwParam)
{
    switch (wMessage)
    {
    case WM_INITDIALOG:
        wsprintf(szText, "%d", wsFault);
        SetDlgItemText(hDlg, IDC_FAULTNUM, szText);
        wsprintf(szText, "%04X:%04X", wsCS, wsIP);
        SetDlgItemText(hDlg, IDC_CSIP, szText);
        wsprintf(szText, "%04X", wsFaultTask);
        SetDlgItemText(hDlg, IDC_HFAULT, szText);
        wsprintf(szText, "%04X", wsProgramTask);
        SetDlgItemText(hDlg, IDC_HPROGRAM, szText);
        return TRUE;

    case WM_COMMAND:
        switch (wParam)
        {
        case IDC_KILL:
            EndDialog(hDlg, 0);
            return TRUE;

        case IDC_RESTART:
            EndDialog(hDlg, 1);
            return TRUE;

        case IDC_CHAIN:
            EndDialog(hDlg, 2);
            return TRUE;

        default:
            return FALSE;
        }

    default:
        return FALSE;
    }
}

⌨️ 快捷键说明

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