📄 dm_edit.c
字号:
// Set flag.
found = TRUE;
}
else if (forward)
{
// Get address.
PUINT16 vaMem16P = vaMemP;
// Point to next word.
vaMem16P++;
// Update pointer.
vaMemP = vaMem16P;
}
else
{
// Get address.
PUINT16 vaMem16P = vaMemP;
// Point to next word.
vaMem16P--;
// Update pointer.
vaMemP = vaMem16P;
}
}
break;
case 32: // 32-bits
// Check if this is a valid address
if (!VirtualToPhysical(vaMemP, (PUINT32)&paMem))
{
// Check for long word.
if ((UINT32)*((PUINT32)vaMemP) == searchValue)
{
// Set flag.
found = TRUE;
}
else if (forward)
{
// Get address.
PUINT32 vaMem32P = vaMemP;
// Point to next long word.
vaMem32P++;
// Update pointer.
vaMemP = vaMem32P;
}
else
{
// Get address.
PUINT32 vaMem32P = vaMemP;
// Point to next long word.
vaMem32P--;
// Update pointer.
vaMemP = vaMem32P;
}
}
break;
}
// Return address of next location.
*virtMemP = (UINT32)((PUINT32)(vaMemP));
return (found);
}
/*
*******************************************************************************
*
* FUNCTION: searchMemory
*
* DESCRIPTION: Search memory for the specified pattern
*
* INPUT PARAMETERS: BOOL forward - TRUE = forward, FALSE - backward
*
* RETURNS: void
*
* GLOBAL EFFECTS: none
*
* ASSUMPTIONS: none
*
* CALLS: none
*
* CALLED BY: DM_SearchMemory
*
* PROTOTYPE: static void searchMemory(BOOL forward);
*
*******************************************************************************
*/
static void searchMemory(BOOL forward)
{
UINT32 vaMem;
PUINT32 vaMemP = &vaMem;
UINT32 step = 1;
UINT32 x;
BOOL found;
// Determine direction of search.
if (forward)
{
printf("Searching: 0x%x to 0x%x for 0x%x bytes in %d-bits\r\n",
(UINT32)searchAddrP, ((UINT32)searchAddrP + searchLength),
searchValue, memoryWidth);
}
else
{
printf("Searching: 0x%x to 0x%x for 0x%x bytes in %d-bits\r\n",
((UINT32)searchAddrP - searchLength), (UINT32)searchAddrP,
searchValue, memoryWidth);
}
// Get starting address of search region.
vaMem = (UINT32)searchAddrP;
// Determine bitness.
switch (memoryWidth)
{
case 8:
step = sizeof(CHAR);
break;
case 16:
step = sizeof(UINT16);
break;
case 32:
step = sizeof(UINT32);
break;
}
if (forward)
{
// Forward search the whole region.
for (x = 0; x < searchLength; x += step)
{
if ((found = findValue(forward, vaMemP)) == TRUE)
{
// Update search address.
searchAddrP = (PUINT32)vaMem;
// Update view memory pointer.
viewAddrP = (PUINT32)vaMem;
// Dump memory.
memoryDump();
break;
}
}
}
else
{
// Reverse search the whole region.
for (x = searchLength; x > 0; x -= step)
{
if ((found = findValue(forward, vaMemP)) == TRUE)
{
// Update search address.
searchAddrP = (PUINT32)vaMem;
// Update view memory pointer.
viewAddrP = (PUINT32)vaMem;
// Dump memory.
memoryDump();
break;
}
}
}
// Check result.
if (!found)
{
printf("Search pattern not found!\r\n");
}
}
/*
*******************************************************************************
*
* FUNCTION: memoryDump
*
* DESCRIPTION: creates formatted output to containing
* the contents of memory.
*
* INPUT PARAMETERS: none
*
* RETURNS: void
*
* GLOBAL EFFECTS: none
*
* ASSUMPTIONS: none
*
* CALLS: getMemValue
*
* CALLED BY: DM_ViewMemory, DM_HigherMemory, DM_LowerMemory, DM_WriteMemory
*
* PROTOTYPE: static void memoryDump(void);
*
*******************************************************************************
*/
static void memoryDump(void)
{
union {
UCHAR ascii[16];
UCHAR bytes[16];
UINT16 words[8];
UINT32 dwords[4];
} buf;
UCHAR buffer[17];
UINT32 i,j, count = 16;
// Determine display count.
switch (memoryWidth)
{
case 8:
count = 8;
break;
case 16:
case 32:
count = 16;
break;
}
for (i = 0; i < dumpLength/count; i++)
{
switch (memoryWidth)
{
case 8: // 8-bits.
buf.bytes[0] = (UINT8)getMemValue();
buf.bytes[1] = (UINT8)getMemValue();
buf.bytes[2] = (UINT8)getMemValue();
buf.bytes[3] = (UINT8)getMemValue();
buf.bytes[4] = (UINT8)getMemValue();
buf.bytes[5] = (UINT8)getMemValue();
buf.bytes[6] = (UINT8)getMemValue();
buf.bytes[7] = (UINT8)getMemValue();
for (j = 0; j < count; j++)
{
if (buf.ascii[j] < 0x20 || buf.ascii[j] > 0x7f)
{
buffer[j] = '.';
}
else
{
buffer[j] = buf.ascii[j];
}
}
buffer[count] = 0;
printf("%08X: %02X %02X %02X %02X %02X %02X %02X %02X %s\r\n",
(UINT32)(viewAddrP-2),
buf.bytes[0], buf.bytes[1], buf.bytes[2], buf.bytes[3],
buf.bytes[4], buf.bytes[5], buf.bytes[6], buf.bytes[7],
buffer);
break;
case 16: // 16-bits.
buf.words[0] = (UINT16)getMemValue();
buf.words[1] = (UINT16)getMemValue();
buf.words[2] = (UINT16)getMemValue();
buf.words[3] = (UINT16)getMemValue();
buf.words[4] = (UINT16)getMemValue();
buf.words[5] = (UINT16)getMemValue();
buf.words[6] = (UINT16)getMemValue();
buf.words[7] = (UINT16)getMemValue();
for (j = 0; j < 16; j++)
{
if (buf.ascii[j] < 0x20 || buf.ascii[j] > 0x7f)
{
buffer[j] = '.';
}
else
{
buffer[j] = buf.ascii[j];
}
}
buffer[16] = 0;
printf("%08X: %04X %04X %04X %04X %04X %04X %04X %04X %s\r\n",
(UINT32)(viewAddrP-4),
buf.words[0], buf.words[1], buf.words[2],
buf.words[3], buf.words[4], buf.words[5],
buf.words[6], buf.words[7], buffer);
break;
case 32: // 32-bits.
buf.dwords[0] = getMemValue();
buf.dwords[1] = getMemValue();
buf.dwords[2] = getMemValue();
buf.dwords[3] = getMemValue();
for (j = 0; j < count; j++)
{
if (buf.ascii[j] < 0x20 || buf.ascii[j] > 0x7f)
{
buffer[j] = '.';
}
else
{
buffer[j] = buf.ascii[j];
}
}
buffer[count] = 0;
printf("%08X: %08X %08X %08X %08X %s\r\n",
(UINT32)(viewAddrP-4),
buf.dwords[0], buf.dwords[1], buf.dwords[2],
buf.dwords[3], buffer);
break;
}
// Check if user wishes to abort dump.
if (DM_KeyPressed())
{
break;
}
}
}
/*
*******************************************************************************
*
* FUNCTION: getMemValue
*
* DESCRIPTION: Accepts an address and returns the contents of the address.
* A check is made as to whether the address is valid and
* returns a constant of "0xBAD00ADD" if invalid.
*
* INPUT PARAMETERS: None.
* RETURNS: UINT32 - the contents of the address
*
* GLOBAL EFFECTS: Increments viewAddrP
*
* ASSUMPTIONS: None
*
* CALLS: VirtualToPhysical
*
* CALLED BY: memoryDump
*
* PROTOTYPE: static UINT32 getMemValue(void);
*
*******************************************************************************
*/
static UINT32 getMemValue(void)
{
UINT32 paMem;
UINT32 value;
BOOL readFlag = TRUE;
// Check if this is a valid address
if (VirtualToPhysical((PVOID)viewAddrP, (PUINT32)&paMem))
{
readFlag = FALSE;
value = 0xBAD00ADD;
}
switch (memoryWidth)
{
case 8: // 8-bits.
{
// Get address.
PUINT8 vaMem8P = (PUINT8)viewAddrP;
if (readFlag)
{
// Get value.
value = *vaMem8P;
}
// Point to next byte.
vaMem8P++;
// Update pointer.
viewAddrP = (PUINT32)vaMem8P;
break;
}
case 16: // 16-bits.
{
// Get address.
PUINT16 vaMem16P = (PUINT16)viewAddrP;
if (readFlag)
{
// Get value.
value = *vaMem16P;
}
// Point to next word.
vaMem16P++;
// Update pointer.
viewAddrP = (PUINT32)vaMem16P;
break;
}
case 32: // 32-bits.
if (readFlag)
{
value = *viewAddrP;
}
viewAddrP++;
break;
}
return (value);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -