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

📄 test.c

📁 汇编语言编的TOOLHELPasm.rar程序,初学者可能会用到哦^_^TOOLHELPasm.rar
💻 C
📖 第 1 页 / 共 4 页
字号:
/**************************************************************************
 *  TEST.C
 *
 *      Tests TOOLHELP.DLL
 *
 **************************************************************************/

#include <stdio.h>
#undef NULL
#include <windows.h>
#include <string.h>
#include "toolhelp.h"
#include "test.h"

/* ----- Symbols ----- */
#define LIST_WIDTH      60
#define LIST_NONE       0
#define LIST_GLOBAL     1
#define LIST_MODULE     2
#define LIST_TASK       3
#define LIST_USER       4
#define LIST_GDI        5
#define LIST_TOOLHELP   6
#define LIST_MEMMAN     7
#define LIST_CLASS      8
#define BUTTON_WIDTH    (10 * xChar)
#define BUTTON_MARGIN   xChar
#define IDM_WRITE       100
#define IDM_WRITEBP     101
#ifndef SHORT
typedef short int SHORT;
#endif

/* ----- Memory window extra values ----- */
#define MEM_BLOCK       0
#define MEM_GLOBALENTRY 2
#define MEM_LPOURBLOCK  4
#define MEM_HOURBLOCK   8

/* ----- Macros ----- */
#define MAXLINES(dwSize,yClient) \
    max((SHORT)(dwSize / 16) - ((SHORT)yClient) / yChar, 0)

/* ----- Function prototypes ----- */

    LONG FAR PASCAL WndProc(
        HWND hWnd,
        int iMessage,
        WORD wParam,
        LONG lParam);

    LONG FAR PASCAL MemWndProc(
        HWND hWnd,
        int iMessage,
        WORD wParam,
        LONG lParam);

    void PASCAL DumpMem(
        HWND hwnd,
        HDC hDC,
        SHORT nScrollPos,
        SHORT nPos);

    LONG WalkGlobalHeap(
        HWND hwnd);

    LONG WalkFreeList(
        HWND hwnd);

    LONG WalkLRUList(
        HWND hwnd);

    LONG WalkLocalHeap(
        HWND hwnd,
        HANDLE hBlock);

    LONG WalkModuleList(
        HWND hwnd);

    LONG WalkTaskList(
        HWND hwnd);

    LONG WalkClassList(
        HWND hwnd);

    LONG DoStackTrace(
        HWND hwnd);

    LONG DoUserInfo(
        HWND hwnd);

    LONG DoGDIInfo(
        HWND hwnd);

    LONG DoMemManInfo(
        HWND hwnd);

    LONG DoGlobalEntryModuleTest(
        HWND hwnd);

    LONG ReadMemoryTest(
        HWND hwnd,
        HANDLE hBlock);

    LONG TimerCountTest(
        HWND hwnd);

    BOOL FAR PASCAL MyNotifyHandler(
        WORD wID,
        DWORD dwData);

    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);

    BOOL FAR PASCAL FaultDialogProc(
        HWND hDlg,
        WORD wMessage,
        WORD wParam,
        DWORD dwParam);

/* ----- Global variables ----- */
    short xScreen;
    short yScreen;
    short xChar;
    short yChar;
    HANDLE hInst;
    HWND hwndList;
    HWND hwndListLocal;
    HWND hwndListStatic;
    WORD wListStatus = LIST_NONE;
    char szText[80];
    HWND hwndMain;
    WORD wNotifyIn;
    WORD wNotifyOut;
    WORD wNotifyState;
    WORD wFilterState;
    WORD wsCS;
    WORD wsIP;
    WORD wsFault;
    WORD wsFaultTask;
    WORD wsProgramTask;
    char szAppName[] = "THTest";
    char szMemName[] = "THMemPopup";
    extern BYTE _AHINCR;

    char *szBlockTypes[] =
    {
        "Private", "DGroup", "Data", "Code", "Task", "Resource",
        "Module", "Free", "Internal", "Sentinel", "BMaster"
    };
    char bHasData[] =
    { 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0 };
    char *szLocalFlags[] =
    { "", "Fixed", "Free", "", "Moveable" };
    char *szGDI[] =
    {
        "Unknown", "Pen", "Brush", "Font", "Palette", "Bitmap", "Region",
        "DC", "DisabledDC", "MetaDC", "Metafile", ""
    };
    char *szUser[] =
    {
        "Unknown", "Class", "Window", "String", "Menu", "Clip", "CBox",
        "Palette", "Ed", "Bwl", "OwnerDraw", "SPB", "CheckPoint", "DCE",
        "MWP", "PROP", "LBIV", "Misc", "Atoms", "LockInp", "HookList",
        "UserSeeUserDo", "HotKeyList", "PopupMenu", "HandleTab", ""
    };
    char *szNotify[] =
    {
        "Unknown", "LoadSeg", "FreeSeg", "StartTask", "ExitTask",
        "LoadDLL", "DelModule", "DebugStr", "RIP", "TaskIn",
        "TaskOut", "InChar", "OutStr", "CASRq"
    };


/*  WinMain
 */

int PASCAL WinMain(
    HANDLE hInstance,
    HANDLE hPrevInstance,
    LPSTR lpszCmdLine,
    int nCmdShow)
{
    HWND hwnd;
    MSG msg;
    WNDCLASS wndclass;
    FARPROC lpfnNotify;
    FARPROC lpfnFault;

    /* Register the interrupt handler */
    wsProgramTask = GetCurrentTask();
    lpfnFault = MakeProcInstance(MyFaultHandler, hInstance);
    if (!InterruptRegister(NULL, lpfnFault))
    {
        OutputDebugString("THTest: Interrupt hook failed!!\r\n");
        return 1;
    }

    /* Register the notification handler */
    lpfnNotify = MakeProcInstance(MyNotifyHandler, hInstance);
    if (!NotifyRegister(
        NULL, lpfnNotify, NF_TASKSWITCH | NF_RIP | NF_DEBUGSTR))
    {
        OutputDebugString("THTest: Notification hook failed!!\r\n");
        return 1;
    }

    xScreen = GetSystemMetrics(SM_CXSCREEN);
    yScreen = GetSystemMetrics(SM_CYSCREEN);
    hInst = hInstance;

    if (!hPrevInstance)
    {
        wndclass.style = 0L;
        wndclass.lpfnWndProc = WndProc;
        wndclass.cbClsExtra = 0;
        wndclass.cbWndExtra = 0;
        wndclass.hInstance = hInstance;
        wndclass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(1));
        wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
        wndclass.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
        wndclass.lpszMenuName = MAKEINTRESOURCE(ID_MENU);
        wndclass.lpszClassName = szAppName;

        if (!RegisterClass(&wndclass))
            return FALSE;

        wndclass.style = 0L;
        wndclass.lpfnWndProc = MemWndProc;
        wndclass.cbClsExtra = 0;
        wndclass.cbWndExtra = 10;
        wndclass.hInstance = hInstance;
        wndclass.hIcon = NULL;
        wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
        wndclass.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
        wndclass.lpszMenuName = NULL;
        wndclass.lpszClassName = szMemName;

        if (!RegisterClass(&wndclass))
            return FALSE;
    }

    hwnd = CreateWindow(
        szAppName,              /* Window class name */
        "TOOLHELP.DLL Test",    /* Window caption */
        WS_OVERLAPPEDWINDOW,    /* Window style */
        CW_USEDEFAULT,          /* Initial X position */
        0,                      /* Initial Y position */
        CW_USEDEFAULT,          /* Initial X size */
        0,                      /* Initial Y size */
        NULL,                   /* Parent window handle */
        NULL,                   /* Window menu handle */
        hInstance,              /* Program instance handle */
        NULL);                  /* Create parameters */

    ShowWindow(hwnd, nCmdShow);
    UpdateWindow(hwnd);

    hwndMain = hwnd;

    while (GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    /* Get rid of our Fault handler and our notification handler */
    InterruptUnRegister(NULL);
    FreeProcInstance(lpfnFault);
    NotifyUnRegister(NULL);
    FreeProcInstance(lpfnNotify);

    return msg.wParam;
}


LONG FAR PASCAL WndProc(
    HWND hwnd,
    int nMessage,
    WORD wParam,
    LONG lParam)
{
    HDC hDC;
    TEXTMETRIC tm;
    WORD wLine;
    HANDLE hTask;
    static HFONT hFont;

    switch (nMessage)
    {
    case WM_CREATE:

        /* Get static constants */
        hDC = GetDC(hwnd);
        GetTextMetrics(hDC, &tm);
        xChar = tm.tmAveCharWidth;
        yChar = tm.tmHeight + tm.tmExternalLeading;
        ReleaseDC(hwnd, hDC);

        /* Create child controls */
        hwndListStatic = CreateWindow(
            "static",
            NULL,
            WS_CHILD | WS_VISIBLE | SS_LEFT,
            xChar, 4 * yChar, 0, 0,
            hwnd, 1, hInst, NULL);
        hwndList = CreateWindow(
            "listbox",
            NULL,
            WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL | LBS_USETABSTOPS |
            LBS_NOTIFY,
            xChar, 5 * yChar + 2, 0, 0,
            hwnd, 2, hInst, NULL);
        hwndListLocal = CreateWindow(
            "listbox",
            NULL,
            WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL | LBS_USETABSTOPS |
            LBS_NOTIFY,
            xChar, 0, 0, 0,
            hwnd, 3, hInst, NULL);

        /* Put a small non-proportional font in the box */
   		hFont = GetStockObject(SYSTEM_FIXED_FONT);
        SendMessage(hwndList, WM_SETFONT, hFont, NULL);
        SendMessage(hwndListLocal, WM_SETFONT, hFont, NULL);
        break;

    case WM_SIZE:
        if (HIWORD(lParam) < 8 * yChar || LOWORD(lParam) < 10 * xChar)
        {
            ShowWindow(hwndList, SW_HIDE);
            ShowWindow(hwndListLocal, SW_HIDE);
            ShowWindow(hwndListStatic, SW_HIDE);
        }
        else
        {
            short nHeight;
            short nWidth;

            nHeight = (HIWORD(lParam) - 2 * yChar) / 2 - yChar / 2;
            nWidth = LOWORD(lParam) - 2 * xChar;
            ShowWindow(hwndList, SW_SHOWNORMAL);
            ShowWindow(hwndListStatic, SW_SHOWNORMAL);
            ShowWindow(hwndListLocal, SW_SHOWNORMAL);
            MoveWindow(hwndList, xChar, yChar, nWidth, nHeight, TRUE);
            MoveWindow(hwndListLocal, xChar, yChar + nHeight + yChar,
                nWidth, nHeight, TRUE);
            MoveWindow(hwndListStatic, 2 * xChar, 0, nWidth - 2 * xChar,
                yChar, TRUE);
            UpdateWindow(hwndList);
            UpdateWindow(hwndListLocal);
        }
        return 0L;

    case WM_USER:
        wsprintf(szText, "%-12s\t| %08lX",
            (LPSTR)szNotify[wParam], lParam);
        SendMessage(hwndListLocal, LB_ADDSTRING, 0, (LONG)(LPSTR)szText);
        return 0L;

    case WM_COMMAND:
        switch (wParam)
        {
        case 2:     /* List box notification message */
            if (HIWORD(lParam) != LBN_DBLCLK)
                return 0L;

            if (wListStatus == LIST_GLOBAL)
            {
                HANDLE hBlock;
                GLOBALENTRY Global;

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

                /* See if this block has a local heap, if not, call the
                 *  memory dump routine to test the memory functions.
                 */
                if (hBlock)
                {
                    Global.dwSize = sizeof (GLOBALENTRY);
                    GlobalEntryHandle(&Global, hBlock);
                }
                if (!hBlock)
                    return 0L;
                else if (Global.wHeapPresent)
                    return WalkLocalHeap(hwnd, hBlock);
                else
                    return ReadMemoryTest(hwnd, hBlock);
            }
            else if (wListStatus == LIST_TASK)
                return DoStackTrace(hwnd);
            else
                return 0L;

        case IDM_TEST_1:
            return WalkGlobalHeap(hwnd);

        case IDM_TEST_2:
            return WalkFreeList(hwnd);

        case IDM_TEST_3:
            return WalkLRUList(hwnd);

        case IDM_TEST_4:
            return WalkModuleList(hwnd);

        case IDM_TEST_5:
            return WalkTaskList(hwnd);

        case IDM_TEST_10:
            return WalkClassList(hwnd);

        case IDM_TEST_6:
            return DoUserInfo(hwnd);

        case IDM_TEST_7:
            return DoGDIInfo(hwnd);

        case IDM_TEST_8:
            return DoGlobalEntryModuleTest(hwnd);

        case IDM_TEST_9:
            return DoMemManInfo(hwnd);

⌨️ 快捷键说明

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