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

📄 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 页
字号:
/* 
Copyright 2001-2003 Free Software Foundation, Inc.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.  

You may contact the author at:

mailto::camille@bluegrass.net

or by snail mail at:

David Lindauer
850 Washburn Ave Apt 99
Louisville, KY 40222
 **********************************************************************

DUMPWND.C is the memory view.  It has the interfaces for getting addressing
and drawing the window.

 **********************************************************************
 */
#define STRICT
#include <windows.h>
#include <commctrl.h>
#include <commdlg.h>
#include <richedit.h>
#include <stdio.h>

#include "header.h"
#include "operands.h"
#include "opcodes.h"
#include <ctype.h>
extern HWND hwndSourceTab;
extern HINSTANCE hInstance;
extern HWND hwndClient, hwndStatus, hwndFrame, hwndError;
extern PROCESS DebugProcess;
extern enum DebugState uState;
extern THREAD *StoppedThread;


HWND hwndDump;

static char szDumpClassName[] = "xccMemoryClass";
static char szDumpBlankClassName[] = "xccMemoryClass2";
static HWND hwndCtrl, hwndBlank, hwndEdit;
static HBRUSH hbrBackground;
static WNDPROC oldproc;
static int cursrow, curscol, curpos;
static char cursmod[4];
static int modifying;
static int oldDumpAddress;

static LOGFONT fontdata = 
{
    16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
        OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FIXED_PITCH |
        FF_DONTCARE, "Courier New"
};
static LOGFONT Normalfontdata = 
{
    14, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
        OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_MODERN |
        FF_DONTCARE, "Arial"
};

static HFONT DumpFont, staticFont;
static int DumpAddress;
static char *szMemTitle = "Memory Window";
int GetDumpAddress(char *buf)
{
    int addr, newaddr;
    int stars = 0;
    while (*buf == ' ')
        buf++;
    //   while (*buf == '*') buf++,stars++ ;
    #ifdef XXXXX
        if (isdigit(buf[0]))
        {
            if (buf[0] == '0' && buf[1] == 'x' || buf[1] == 'X')
                sscanf(buf + 2, "%x", &addr);
            else
                sscanf(buf, "%d", &addr);
        }
        else
    #endif 
    {
        char *types,  *syms;
        int offset = StoppedThread->regs.Eip, l;
        DEBUG_INFO *dbg;
        VARINFO *var;
        var = EvalExpr(&types, &syms, &dbg, offset, &offset, buf);
        if (var)
        {
            if (var->constant)
                addr = var->ival;
            else if (var->address < 0x1000)
            {
                char data[20];
                if (!var->explicitreg)
                    ExtendedMessageBox("Address error", MB_SETFOREGROUND |
                        MB_SYSTEMMODAL, 
                        "Address is a register.  Dumping from value.");
                ReadValue(var->address, &data, 4, StoppedThread);
                addr = *(int*)data;
            }
            else
                addr = var->address;
            FreeVarInfo(var);
        }
        else
        {
            addr = 0;
        }
        SetFocus(hwndEdit);
    }
    //   newaddr = addr ;
    //   while (stars) {
    //      if (!ReadProcessMemory(DebugProcess.hProcess,(LPVOID)newaddr,(LPVOID)&newaddr, 4, 0) )
    //         break ;
    //      stars-- ;
    //   }
    //   if (!stars)
    //      addr = newaddr ;

    return addr;
}

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

void DumpDoPaint(HWND hwnd, int focussed)
{
    int i;
    char buf[256];
    unsigned char charbuf[100];
    PAINTSTRUCT ps;
    CONTEXT context;
    HDC dc;
    HFONT oldFont;
    COLORREF oldbk, oldtxt;
    RECT rect;
    int lines;
    int chars;
    memset(charbuf, 0, sizeof(charbuf));
    GetClientRect(hwnd, &rect);
    lines = (rect.bottom - rect.top) / 16;
    chars = (rect.right - rect.left - 10 * 8) / 8 / 4;
    dc = BeginPaint(hwnd, &ps);
    SelectObject(dc, DumpFont);
    for (i = 0; i < lines; i++)
    {
        int j;
        sprintf(buf, "%08X: ", DumpAddress + i * chars);
        TextOut(dc, 0, i *16+rect.top, buf, strlen(buf));
        for (j = 0; j < chars; j++)
        {
            if (i == cursrow && j == curscol && focussed)
            {
                oldbk = GetBkColor(dc);
                oldtxt = SetTextColor(dc, oldbk);
                if (modifying)
                    SetBkColor(dc, 0xff0000);
                else
                    SetBkColor(dc, oldtxt);
            }
            if (ReadProcessMemory(DebugProcess.hProcess, (LPVOID)(DumpAddress +
                i * chars + j), (LPVOID)(charbuf + j), 1, 0))
            {
                sprintf(buf, "%02X ", charbuf[j]);
                if (i == cursrow && j == curscol)
                    if (modifying)
                        strcpy(buf, cursmod);
            }
            else
            {
                if (i == cursrow && j == curscol)
                {
                    modifying = FALSE;
                    curpos = 0;
                    strcpy(cursmod, "   ");
                }
                strcpy(buf, "?? ");
                charbuf[j] = '.';
            }
            if (i == cursrow && j == curscol && focussed && modifying)
                TextOut(dc, (10+j * 3) *8-4, i *16+rect.top, buf, 2);
            else
                TextOut(dc, (10+j * 3) *8, i *16+rect.top, buf, 2);
            if (charbuf[j] < 32 || charbuf[j] > 126)
                charbuf[j] = '.';
            if (i == cursrow && j == curscol && focussed)
            {
                SetTextColor(dc, oldtxt);
                SetBkColor(dc, oldbk);
            }
            if (i == cursrow && j == curscol && focussed && modifying)
                TextOut(dc, (12+j * 3) *8-4, i *16+rect.top, " ", 1);
            else
                TextOut(dc, (12+j * 3) *8, i *16+rect.top, " ", 1);
        }
        TextOut(dc, (10+j * 3) *8, i *16+rect.top, charbuf, strlen(charbuf));
    }

    SelectObject(dc, oldFont);

    EndPaint(hwnd, &ps);
}

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

LRESULT CALLBACK _export DumpBlankProc(HWND hwnd, UINT iMessage, WPARAM wParam,
    LPARAM lParam)
{
    RECT r;
    int lines, chars;
    static int focussed;
    switch (iMessage)
    {
        case WM_CREATE:
            SetScrollRange(hwnd, SB_VERT, 0, 64000, FALSE);
            SetScrollPos(hwnd, SB_VERT, 32000, TRUE);
            break;
        case WM_PAINT:
            DumpDoPaint(hwnd, focussed);
            return 0;
        case WM_SETFOCUS:
            //         SendMessage(hwndFrame,WM_REDRAWTOOLBAR,0,0) ;
            focussed = TRUE;
            InvalidateRect(hwnd, 0, 0);
            break;
        case WM_KILLFOCUS:
            focussed = FALSE;
            modifying = FALSE;
            strcpy(cursmod, "   ");
            InvalidateRect(hwnd, 0, 0);
            break;
        case WM_LBUTTONDOWN:
        case WM_RBUTTONDOWN:
            GetClientRect(hwnd, &r);
            lines = r.bottom / 16;
            chars = (r.right - 10 * 8) / 8 / 4;
            if (LOWORD(lParam) >= 10 *8 && LOWORD(lParam) < (10+chars) *8 * 3)
            {
                curscol = (LOWORD(lParam) - 10 * 8) / 3 / 8;
                cursrow = HIWORD(lParam) / 16;
                if (focussed)
                    InvalidateRect(hwnd, 0, 0);
            }
            SetFocus(hwnd);
            break;
        case WM_KEYDOWN:
            GetClientRect(hwnd, &r);
            lines = r.bottom / 16;
            chars = (r.right - 10 * 8) / 8 / 4;
            switch (wParam)
            {
            case VK_BACK:
                if (modifying)
                {
                    cursmod[curpos] = ' ';
                    if (curpos)
                        curpos--;
                    InvalidateRect(hwnd, 0, 0);
                }
                break;
            case VK_LEFT:
                if (modifying)
                {
                    cursmod[curpos] = ' ';
                    if (curpos)
                        curpos--;
                    InvalidateRect(hwnd, 0, 0);
                    break;
                }
                if (curscol != 0)
                {
                    curscol--;
                    InvalidateRect(hwnd, 0, 0);
                    break;
                }
                curscol = chars - 1;
                // FALL THROUGH
            case VK_UP:
                modifying = FALSE;
                strcpy(cursmod, "   ");
                curpos = 0;
                if (cursrow == 0)
                    SendMessage(hwnd, WM_VSCROLL, SB_LINEUP, 0);
                else
                {
                    cursrow--;
                    InvalidateRect(hwnd, 0, 0);
                }
                break;
            case VK_RIGHT:
                if (modifying)
                {
                    if (curpos == 0)
                        curpos++;
                    break;
                }
                if (curscol + 1 < chars)
                {
                    curscol++;
                    InvalidateRect(hwnd, 0, 0);
                    break;

⌨️ 快捷键说明

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