📄 memwndcd.c
字号:
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Memory display window, with disassembly.
*
****************************************************************************/
#include <string.h>
#include <io.h>
#include <ctype.h>
#define INCLUDE_TOOLHELP_H
#include <windows.h>
#include "memwnd.h"
#include "segmem.h"
#include "sdkasm.h"
#include "font.h"
#include "mem.h"
#define MAX_BACKUPS 1000
#define BYTES_PER_BACKUP 100
extern WORD FontWidth;
extern WORD FontHeight;
static DWORD _Offset; // conflicts with extern in wdisasm/h/global.h
static WORD Sel;
static DWORD Limit;
static BOOL Is32Bit;
static char StatBuf[50];
static DisAsmRtns DisasmInfo;
static BOOL DisasmRegistered;
static void GotoIns( MemWndInfo *info, DWORD ins_cnt );
/*
disassembler interface routines
*/
int_16 MemWndGetDataByte() {
char buf;
ReadMem( Sel, _Offset, &buf, 1 );
_Offset++;
return( buf );
} /* GetDataByte */
int_16 MemWndGetDataWord() {
int_16 buf;
ReadMem( Sel, _Offset, (char *)&buf, sizeof( int_16 ) );
_Offset += sizeof( int_16 );
return( buf );
} /* GetDataWord */
int_16 MemWndGetNextByte() {
char buf;
ReadMem( Sel, _Offset, &buf, 1 );
return( buf );
}
long MemWndGetDataLong() {
long buf;
ReadMem( Sel, _Offset, (char *)&buf, sizeof( long ) );
_Offset += sizeof( long );
return( buf );
}
char MemWndEndOfSegment() {
return( _Offset > Limit );
}
DWORD MemWndGetOffset() {
return( _Offset );
}
/*
* ToStr - return a string of length 'length' containing 'value'
* in Hex notation
*/
char *MemWndToStr( unsigned long value, uint_16 len, DWORD addr ) {
int i;
addr = addr;
for( i = len-1; i >= 0; --i ) {
StatBuf[ i ] = MkHexDigit( value & 0xf );
value >>= 4;
}
StatBuf[ len ] = '\0';
return( StatBuf );
}
/*
* JmpLabel - return a string containing addr in segment:offset form
*/
char *MemWndJmpLabel( unsigned long addr, DWORD off ) {
unsigned len;
off = off;
len = Is32Bit?8:4;
sprintf( StatBuf, "%04X:%0*lX", Sel, len, addr );
return( StatBuf );
}
/*
* ToBrStr - return a string representing 'value' in hex form enclosed in []
*/
char *MemWndToBrStr( unsigned long value, DWORD addr ) {
unsigned len;
addr = addr;
len = Is32Bit?8:4;
sprintf( StatBuf, "[%0*lX]", len, value );
return( StatBuf );
}
/*
* ToIndex - convert value to a hex string with a + or - at the begining
*/
char *MemWndToIndex( unsigned long value, unsigned long addr ) {
char sign[2];
addr = addr;
if( (long)value < 0 ) {
sign[0] = '-';
value = -(long)value;
} else {
sign[0] = '+';
}
sign[1] = '\0';
sprintf( StatBuf, "%s%lX", sign, value );
return( StatBuf );
}
/*
* ToSegStr - convert to seg:off form
*/
char *MemWndToSegStr( DWORD value, WORD seg, DWORD addr ) {
unsigned len;
addr = addr;
len = Is32Bit?8:4;
sprintf( StatBuf, "%04X:%0*lX", seg, len, value );
return( StatBuf );
}
char *MemWndGetWtkInsName( unsigned ins )
{
ins = ins;
return( "" );
}
void MemWndDoWtk(void)
{
}
int MemWndIsWtk()
{
return( 0 );
}
void DumpMemAsm( MemWndInfo *info, int hdl ) {
char buf[80];
WORD len;
instruction ins;
_Offset = 0;
Limit = info->limit;
Is32Bit = ( info->disp_type == MEMINFO_CODE_32 );
Sel = info->sel;
while( _Offset < Limit ) {
sprintf( buf, "%08lX ", _Offset );
MiscDoCode( &ins, Is32Bit, &DisasmInfo );
MiscFormatIns( buf + 10 , &ins, 0, &DisasmInfo );
len = strlen( buf );
write( hdl, buf, len );
write( hdl, "\n", 1 );
}
} /* DumpMemAsm */
BOOL NeedScrollBar( MemWndInfo *info ) {
WORD line;
instruction ins;
BOOL is_32;
_Offset = 0;
Limit = info->limit;
Sel = info->sel;
is_32 = ( info->disp_type == MEMINFO_CODE_32 );
for( line = 0; line < info->lastline; line ++ ) {
MiscDoCode( &ins, is_32, &DisasmInfo );
}
return( _Offset < info->limit );
} /* NeedScrollBar */
static DWORD GenAsmLine( MemWndInfo *info, DWORD ins_cnt, char *buf )
{
instruction ins;
DWORD offset;
Is32Bit = ( info->disp_type == MEMINFO_CODE_32 );
Sel = info->sel;
Limit = info->limit;
GotoIns( info, ins_cnt );
offset = _Offset;
sprintf( buf, "%08lX ", _Offset );
MiscDoCode( &ins, Is32Bit, &DisasmInfo );
MiscFormatIns( buf + 10 , &ins, 0, &DisasmInfo );
return( offset );
} /* GenAsmLine */
/*
* GenBackup - Generates a backup reference.
* Is32Bit, Limit and Sel must be set before calling this routine
*/
static void GenBackup( AsmInfo *asm ) {
WORD cnt;
WORD *wptr;
instruction ins;
if( asm->usage_cnt < MAX_BACKUPS ) {
cnt = asm->increment;
wptr = (WORD *)asm->data;
_Offset = wptr[asm->usage_cnt];
while( cnt > 0 ) {
MiscDoCode( &ins, Is32Bit, &DisasmInfo );
cnt--;
}
asm->usage_cnt ++;
wptr[asm->usage_cnt] = _Offset;
}
} /* GenBackup */
/*
* GenBigBackup - Generates a backup reference for a big code item
* Is32Bit, Limit and Sel must be set before calling this routine
*/
static void GenBigBackup( AsmInfo *asm ) {
DWORD cnt;
DWORD *dwptr;
instruction ins;
if( asm->usage_cnt < MAX_BACKUPS ) {
cnt = asm->increment;
dwptr = (DWORD *)asm->data;
_Offset = dwptr[asm->usage_cnt];
while( cnt > 0 ) {
MiscDoCode( &ins, Is32Bit, &DisasmInfo );
cnt--;
}
asm->usage_cnt ++;
dwptr[asm->usage_cnt] = _Offset;
}
} /* GenBigBackup */
/*
* GetInsCnt - finds the number of instructions before the one that
* straddles offset
*/
DWORD GetInsCnt( MemWndInfo *info, DWORD offset ) {
AsmInfo *asm;
DWORD *dwptr;
DWORD old_offset;
DWORD ins_cnt;
WORD *wptr;
WORD i;
instruction ins;
Is32Bit = ( info->disp_type == MEMINFO_CODE_32 );
Sel = info->sel;
Limit = info->limit;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -