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

📄 asmwnd.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

 **********************************************************************

ASMWND.C defines the assembly language window procedure and various
things that go with it.

 **********************************************************************

 */
#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>

#define ASM_OFFSET 35

#define LINES 512
#define LINELEN 564

extern HWND hwndSourceTab;
extern HINSTANCE hInstance;
extern HWND hwndClient, hwndStatus, hwndFrame;
extern int childxpos, childypos;
extern PROCESS DebugProcess;
extern enum DebugState uState;
extern THREAD *StoppedThread;

HWND hwndASM;
HBRUSH pcBrush, stopBrush;
static HBITMAP pcBitmap, stopBitmap;
static HWND hwndCtrl, hwndBlank;

static char **lines;
static int *addrs;
static int curline, shownLine;

static char szASMClassName[] = "xccASMClass";
static char szASMBlankClassName[] = "xccASMClass2";
static char *szASMTitle = "Assembly Window";
static int asmAddress = 0x410000, asmIP;
static DWORD threadID = 0;
static int rePosition = 0;
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 HFONT asmFont;
static int caretX, caretY;
static int charwidth;

extern long code_address;
BYTE *code_ptr;
BOOL GetCodeLine(char *s)
{
    BOOL isNewLine = TRUE;
    BYTE *oldposition = code_ptr;
    char *put;
    OPTABLE *theTable;
    s[0] = 0;
    sprintf(s, "%08x: ", (int)(code_address));
    put = TabTo(s, 11);
    code_ptr = ReadOverrides(code_ptr, VAL_386 | VAL_FLOAT);
    if (!(theTable = FindOpcode(code_ptr, VAL_386 | VAL_FLOAT)))
    {
        strcpy(put, "db");
        put = TabTo(put, TAB_ARGPOS);
        sprintf(put, "%02x",  *code_ptr++);
    }
    else
    {
        code_ptr = DispatchOperand(code_ptr, theTable, TRUE);
        FormatDissassembly(put);
    }
    code_address += code_ptr - oldposition;
}

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

char *getline(char *module, int lineno)
{
    static char line[256];
    static char oldmodule[256];
    static int oldline;
    static FILE *infile;
    char buffer[1024],  *rline;
    int l;

    line[0] = 0;
    if (infile && (lineno == 0 || strcmp(module, oldmodule) || lineno <=
        oldline))
    {
        fclose(infile);
        infile = 0;
        oldline = 0;
    }
    strcpy(oldmodule, module);
    if (lineno == 0)
        return lineno;
    if (!infile)
        infile = fopen(module, "r");
    if (!infile)
        return line;

    do
    {
        buffer[0] = 0;
        fgets(buffer, 1024, infile);
    }
    while (!feof(infile) && ++oldline < lineno);
    if (!feof(infile))
        strncpy(line, buffer, 255);
    rline = line;
    while (isspace(*rline))
        rline++;
    l = strlen(rline) - 1;
    if (rline[l] < 32)
        rline[l] = 0;
    return rline;
}

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

void CalculateDisassembly(int moving)
{
    RECT r;
    int rv = 0;
    int lineno;
    char buffer[256];
    char buf1[256];
    BYTE dbuf[32];
    int i;
    int linecount;
    GetClientRect(hwndBlank, &r);
    linecount = (r.bottom - r.top) / 16;
    code_ptr = dbuf;

    i = 0;
    code_address = asmAddress - LINES / 2;
    while (code_address < asmAddress + LINES / 2 && i < LINES)
    {
        code_ptr = dbuf;
        if (code_address >= asmAddress && !rv)
            rv = i;
        if (!ReadProcessMemory(DebugProcess.hProcess, (LPVOID)(code_address),
            dbuf, 32, 0))
        {
            addrs[i] = code_address;
            sprintf(lines[i++], "%08X: ??", code_address++);
        }
        else
        {
            DEBUG_INFO *dbg;
            char *types,  *syms;
            int offset;
            if (GetBreakpointLine(code_address, buf1, &lineno) == code_address)
            {
                addrs[i] = code_address;
                sprintf(lines[i++], "MODULE: %s LINE: %d %s", buf1, lineno,
                    getline(buf1, lineno));
            }
            if (FindSymbolByAddress(&dbg, &types, &syms, &offset, code_address,
                buffer))
            {
                addrs[i] = code_address;
                strcat(buffer, ":");
                strcpy(lines[i++], buffer);
            }
            addrs[i] = code_address;
            GetCodeLine(lines[i++]);
        }
    }
    if (!moving)
    {
        shownLine = rv - linecount / 2;
    }
    else
    {
        shownLine = rv;
        if (moving > 0)
            while (addrs[shownLine] == addrs[shownLine + 1])
                shownLine++;
        shownLine += moving;
    }
    while (shownLine && addrs[shownLine - 1] == addrs[shownLine])
        shownLine--;
    asmAddress = addrs[shownLine];
    getline("", 0);
}

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

void DoDisassembly(HDC dc, RECT *r)
{
    int i;
    COLORREF v;
    int linecnt = (r->bottom - r->top) / 16;
    for (i = 0; i < linecnt; i++)
    {
        int n;
        RECT r1;
        sscanf(lines[i + shownLine], "%x", &n);
        if (addrs[i + shownLine] == addrs[i + shownLine + 1])
        {
            v = SetTextColor(dc, 0xcc00);
        }
        TextOut(dc, ASM_OFFSET + 5, i *16+r->top, lines[i + shownLine], strlen
            (lines[i + shownLine]));
        if (addrs[i + shownLine] == addrs[i + shownLine + 1])
        {
            SetTextColor(dc, v);
        }
        if (n == asmIP && (uState == atException || uState == atBreakpoint))
        {
            r1.left = 16;
            r1.top = i * 16;
            r1.right = r1.left + 16;
            r1.bottom = r1.top + 16;
            FillRect(dc, &r1, pcBrush);
        }
        if (isBreakPoint(n))
        {
            r1.left = 0;
            r1.top = i * 16;
            r1.right = r1.left + 16;
            r1.bottom = r1.top + 16;
            FillRect(dc, &r1, stopBrush);
        }

    }
}

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

void doPaint(HWND hwnd)
{
    HDC dc;
    HPEN hpen, oldpen;
    RECT r;
    HBRUSH graybrush;
    PAINTSTRUCT paint;
    HFONT oldFont;
    int oldcolor;
    GetClientRect(hwnd, &r);
    dc = BeginPaint(hwnd, &paint);
    hpen = CreatePen(PS_SOLID, 1, 0xcccccc);
    graybrush = CreateSolidBrush(GetSysColor(COLOR_3DFACE));
    r.right = ASM_OFFSET - 3;
    MoveToEx(dc, ASM_OFFSET - 1, 0, 0);
    LineTo(dc, ASM_OFFSET - 1, r.bottom);
    FillRect(dc, &r, graybrush);
    oldpen = SelectObject(dc, hpen);
    MoveToEx(dc, ASM_OFFSET - 2, 0, 0);
    LineTo(dc, ASM_OFFSET - 2, r.bottom);
    SelectObject(dc, oldpen);
    DeleteObject(hpen);

    if (DebugProcess.hProcess)
    {
        oldFont = SelectObject(dc, asmFont);
        oldcolor = SetTextColor(dc, 0xff0000);
        DoDisassembly(dc, &r);
        SetTextColor(dc, oldcolor);
        SelectObject(dc, oldFont);
    }
    EndPaint(hwnd, &paint);
}

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

LRESULT CALLBACK _export ASMBlankProc(HWND hwnd, UINT iMessage, WPARAM wParam,
    LPARAM lParam)
{
    static int offset;
    RECT r;
    int xlines;
    switch (iMessage)
    {
        case WM_CREATE:
            SetScrollRange(hwnd, SB_VERT, 0, 64000, FALSE);
            SetScrollPos(hwnd, SB_VERT, 32000, TRUE);
            break;
        case WM_PAINT:
            doPaint(hwnd);
            return 0;
        case WM_SETFOCUS:

⌨️ 快捷键说明

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