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

📄 dumpwnd.c

📁 CC386 is a general-purpose 32-bit C compiler. It is not an optimizing compiler but given that the co
💻 C
📖 第 1 页 / 共 2 页
字号:
                }
                curscol = 0;
                // FALL THROUGH
            case VK_DOWN:
                modifying = FALSE;
                strcpy(cursmod, "   ");
                curpos = 0;
                if (cursrow + 1 >= lines)
                    SendMessage(hwnd, WM_VSCROLL, SB_LINEDOWN, 0);
                else
                {
                    cursrow++;
                    InvalidateRect(hwnd, 0, 0);
                }
                break;
            case VK_RETURN:
                if (modifying)
                {
                    MEMORY_BASIC_INFORMATION mbi;
                    DWORD dwOldProtect;
                    unsigned v = 0;
                    int address = DumpAddress + cursrow * chars + curscol;
                    sscanf(cursmod, "%x", &v);
                    GetClientRect(hwnd, &r);
                    lines = r.bottom / 16;
                    chars = (r.right - 10 * 8) / 8 / 4;
                    // so it will work on the code page if protected...
                    VirtualQueryEx(DebugProcess.hProcess, (LPVOID)address, &mbi,
                        sizeof(mbi));
                    VirtualProtectEx(DebugProcess.hProcess, mbi.BaseAddress,
                        mbi.RegionSize, PAGE_EXECUTE_READWRITE, &mbi.Protect);
                    if (!WriteProcessMemory(DebugProcess.hProcess, (LPVOID)
                        address, (LPVOID) &v, 1, 0))
                        ExtendedMessageBox("Memory Error", MB_SETFOREGROUND |
                            MB_SYSTEMMODAL, 
                            "Could not write process memory with new value");
                    VirtualProtectEx(DebugProcess.hProcess, mbi.BaseAddress,
                        mbi.RegionSize, mbi.Protect, &dwOldProtect);
                    FlushInstructionCache(DebugProcess.hProcess, (LPVOID)
                        address, 1);
                    modifying = FALSE;
                    curpos = 0;
                    strcpy(cursmod, "   ");
                    InvalidateRect(hwnd, 0, 0);
                }
                break;
            case VK_ESCAPE:
                modifying = FALSE;
                curpos = 0;
                strcpy(cursmod, "   ");
                InvalidateRect(hwnd, 0, 0);
                break;
            case VK_NEXT:
                SendMessage(hwnd, WM_VSCROLL, SB_PAGEDOWN, 0);
                break;
            case VK_PRIOR:
                SendMessage(hwnd, WM_VSCROLL, SB_PAGEUP, 0);
                break;
            }
            break;
        case WM_CHAR:
            if (isxdigit(wParam))
            {
                modifying = TRUE;
                cursmod[curpos] = toupper(wParam);
                if (curpos == 0)
                    curpos++;
                InvalidateRect(hwnd, 0, 0);
            }
            break;
        case WM_VSCROLL:
            GetClientRect(hwnd, &r);
            lines = r.bottom / 16;
            chars = (r.right - 10 * 8) / 8 / 4;
            switch (LOWORD(wParam))
            {
            case SB_BOTTOM:
                DumpAddress =  - (lines *chars);
                break;
            case SB_TOP:
                DumpAddress = 0;
                break;
            case SB_ENDSCROLL:
                return 0;
            case SB_LINEDOWN:
                DumpAddress += chars;
                break;
            case SB_LINEUP:
                DumpAddress -= chars;
                break;
            case SB_PAGEDOWN:
                DumpAddress += chars *(lines - 1);
                break;
            case SB_PAGEUP:
                DumpAddress -= chars *(lines - 1);
                break;
            case SB_THUMBPOSITION:
                DumpAddress = oldDumpAddress + (HIWORD(wParam) - 32000) *16;
                oldDumpAddress = DumpAddress;
                break;
            case SB_THUMBTRACK:
                DumpAddress = oldDumpAddress + (HIWORD(wParam) - 32000) *16;
                break;
                //					return DefMDIChildProc(hwnd,iMessage,wParam,lParam) ;
            }
            InvalidateRect(hwnd, 0, 0);
            SetScrollPos(hwnd, SB_VERT, 32000, TRUE);
            return 0;
    }
    return DefWindowProc(hwnd, iMessage, wParam, lParam);
}

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

LRESULT CALLBACK EditHook(HWND hwnd, UINT iMessage, WPARAM wParam, LPARAM
    lParam)
{
    switch (iMessage)
    {
        case WM_KEYDOWN:
            switch (wParam)
            {
            case VK_RETURN:
                if (GetKeyState(VK_SHIFT) &0x80000000)
                    return SendMessage(hwndBlank, iMessage, wParam, lParam);
                else
                    return SendMessage(hwndDump, WM_COMMAND, IDC_RETURN, 0);
            case VK_LEFT:
            case VK_RIGHT:
            case VK_UP:
            case VK_DOWN:
                if (GetKeyState(VK_SHIFT) &0x80000000)
                    return SendMessage(hwndBlank, iMessage, wParam, lParam);
                break;
            case VK_NEXT:
            case VK_PRIOR:
                return SendMessage(hwndBlank, iMessage, wParam, lParam);
            }
            break;
        case WM_KEYUP:
        case WM_CHAR:
            if (wParam == VK_RETURN)
                return 0;
            if (wParam == VK_TAB)
                return 0;
            break;
    }
    return CallWindowProc(oldproc, hwnd, iMessage, wParam, lParam);
}

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

LRESULT CALLBACK _export DumpProc(HWND hwnd, UINT iMessage, WPARAM wParam,
    LPARAM lParam)
{
    static HWND hwndStatic;
    static int charwidth;
    char buf[256];
    int i, lines, chars;
    HDC dc;
    TEXTMETRIC metric;
    DEBUG_EVENT *xc;
    HFONT oldFont;
    LOGBRUSH brushstr;
    RECT r;
    switch (iMessage)
    {
        case WM_MDIACTIVATE:
            SendMessage(hwndCtrl, LCF_SETACTIVE, 0, lParam == (LPARAM)hwnd);
            if (lParam == (LPARAM)hwnd)
            {
                SendMessage(hwndSourceTab, WM_SETACTIVETAB, 0, (LPARAM)hwnd);
                SetFocus(hwndBlank);
            }
            return TRUE;
        case WM_SETFOCUS:
            break;
        case WM_SYSCOMMAND:
            if (wParam == SC_CLOSE)
                SendMessage(hwnd, WM_CLOSE, 0, 0);
            break;
        case WM_COMMAND:
            switch (LOWORD(wParam))
            {
            case IDM_GOTO:
                DumpAddress = lParam;
                oldDumpAddress = DumpAddress;
                InvalidateRect(hwndBlank, 0, 0);
                break;
            case IDC_RETURN:
                SendMessage(hwndEdit, WM_GETTEXT, 256, (LPARAM)buf);
                DumpAddress = GetDumpAddress(buf);
                oldDumpAddress = DumpAddress;
                InvalidateRect(hwndBlank, 0, 0);
                break;
            default:
                return DefMDIChildProc(hwnd, iMessage, wParam, lParam);
            }
            break;
        case WM_CTLCOLORSTATIC:
            SetBkColor((HDC)wParam, GetSysColor(COLOR_INACTIVEBORDER));
            return hbrBackground;
        case WM_PAINT:
            break;
        case WM_KILLFOCUS:
            break;
        case WM_LBUTTONDOWN:
            break;
        case WM_RESTACK:
            InvalidateRect(hwndBlank, 0, 0);
            break;
        case WM_CREATE:
            hwndDump = hwnd;
            modifying = 0;
            cursrow = curscol = curpos = 0;
            strcpy(cursmod, "   ");
            DumpFont = CreateFontIndirect(&fontdata);
            staticFont = CreateFontIndirect(&Normalfontdata);
            GetClientRect(hwnd, &r);
            hwndCtrl = CreateControlWindow(DID_MEMWND, hwnd, &r, (int)(
                (LPMDICREATESTRUCT)(*(int*)lParam))->lParam, szMemTitle);
            SendMessage(hwndCtrl, LCF_ADJUSTRECT, 0, (LPARAM) &r);
            hwndStatic = CreateWindow("STATIC", "Address:", WS_CHILD +
                WS_CLIPSIBLINGS + WS_VISIBLE, r.left + 20, r.top + 2, 48, 20,
                hwndCtrl, 0, hInstance, 0);
            SendMessage(hwndStatic, WM_SETFONT, (LPARAM)staticFont, 1);
            hwndEdit = CreateWindow("EDIT", "", WS_CHILD + WS_CLIPSIBLINGS +
                WS_BORDER + WS_VISIBLE, r.left + 70, r.top, 200, 20, hwndCtrl,
                0, hInstance, 0);
            SendMessage(hwndEdit, WM_SETFONT, (LPARAM)DumpFont, 1);
            oldproc = (WNDPROC)SetWindowLong(hwndEdit, GWL_WNDPROC, (int)
                EditHook);
            hwndBlank = CreateWindow(szDumpBlankClassName, 0, WS_CHILD +
                WS_VSCROLL + WS_CLIPSIBLINGS + WS_BORDER + WS_VISIBLE, r.left,
                r.top + 24, r.right - r.left, r.bottom - r.top - 24, hwndCtrl,
                0, hInstance, 0);
            //         SetFocus(hwndEdit) ;            
            break;

        case WM_CLOSE:
            dmgrHideWindow(DID_MEMWND, TRUE);
            return 0;
        case WM_DESTROY:
            dmgrRemoveClient((CCW_params*)GetWindowLong(hwndCtrl, 0));
            DestroyWindow(hwndBlank);
            hwndDump = 0;
            DeleteObject(DumpFont);
            break;
        case WM_SIZE:
            r.left = r.top = 0;
            r.right = LOWORD(lParam);
            r.bottom = HIWORD(lParam);
            MoveWindow(hwndCtrl, 0, 0, r.right, r.bottom, TRUE);
            SendMessage(hwndCtrl, LCF_ADJUSTRECT, 0, (LPARAM) &r);
            MoveWindow(hwndStatic, r.left + 20, r.top + 2, 48, 20, TRUE);
            MoveWindow(hwndEdit, r.left + 70, r.top, 200, 20, TRUE);
            MoveWindow(hwndBlank, r.left, r.top + 24, r.right - r.left,
                r.bottom - r.top - 24, TRUE);
            break;
        case WM_INITMENUPOPUP:
            return 0;
        default:
            break;
    }
    return DefMDIChildProc(hwnd, iMessage, wParam, lParam);
}

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

void RegisterDumpWindow(void)
{
    WNDCLASS wc;
    memset(&wc, 0, sizeof(wc));
    wc.style = CS_HREDRAW + CS_VREDRAW;
    wc.lpfnWndProc = &DumpProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInstance;
    wc.hIcon = LoadIcon(0, IDI_APPLICATION);
    wc.hCursor = LoadCursor(0, IDC_ARROW);
    hbrBackground = wc.hbrBackground = CreateSolidBrush(GetSysColor
        (COLOR_INACTIVEBORDER));
    wc.lpszMenuName = 0;
    wc.lpszClassName = szDumpClassName;
    RegisterClass(&wc);

    wc.hbrBackground = GetStockObject(WHITE_BRUSH);
    wc.lpfnWndProc = &DumpBlankProc;
    wc.lpszClassName = szDumpBlankClassName;
    RegisterClass(&wc);
}

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

HWND CreateDumpWindow(void)
{
    MDICREATESTRUCT mc;
    HWND rv;
    RECT r;
    if (hwndDump)
    {
        SendMessage(hwndDump, WM_SETFOCUS, 0, 0);
        return hwndDump;
    }
    GetClientRect(hwndClient, &r);
    mc.szClass = szDumpClassName;
    mc.szTitle = szMemTitle;
    mc.hOwner = hInstance;
    mc.x = CW_USEDEFAULT;
    mc.y = CW_USEDEFAULT;
    mc.cx = 80 * 8;
    mc.cy = 19 * 8+40;
    mc.style = WS_CHILD | WS_CLIPSIBLINGS | WS_DLGFRAME;
    mc.lParam = (LPARAM)0;
    rv = (HWND)SendMessage(hwndClient, WM_MDICREATE, 0, (LPARAM) &mc);
    return rv;
}

⌨️ 快捷键说明

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