Repository navigation
Expand file tree
/
Copy pathBreak.cpp
More file actions
137 lines (131 loc) · 5.43 KB
/
Copy pathBreak.cpp
File metadata and controls
137 lines (131 loc) · 5.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
//---------------------------------------------------------------------------
#include <vcl.h>
#include <string.h>
#pragma hdrstop
#include "Break.h"
#include "Xbdm.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TBreakForm *BreakForm;
// Breakpoint sizes for the size box (1 Byte, 2 Bytes, 4 Bytes).
static const DWORD BreakSizes[3] = { 1, 2, 4 };
// Pointer-chain grid columns.
enum { colBase = 1, colOffset = 2, colValue = 3, colLink = 4 };
//---------------------------------------------------------------------------
__fastcall TBreakForm::TBreakForm(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
static unsigned int HexToInt(const UnicodeString &s)
{
return (unsigned int)(L"0x" + s).ToInt();
}
//---------------------------------------------------------------------------
// One big-endian dword from the console (0 when the read fails), as a host value.
unsigned int TBreakForm::ReadDword(unsigned int addr)
{
unsigned int v;
if (pDmGetMemory((const void *)addr, 4, &v, NULL) < 0)
v = 0;
Swap32(&v);
return v;
}
//---------------------------------------------------------------------------
void __fastcall TBreakForm::FormCreate(TObject *Sender)
{
ChainGrid->Cells[colBase][0] = L"Base";
ChainGrid->Cells[colOffset][0] = L"Offset";
ChainGrid->Cells[colValue][0] = L"Value";
ChainGrid->Cells[colLink][0] = L"Link Value";
for (unsigned char i = 1; i < 100; i++)
ChainGrid->Cells[0][i] = UnicodeString().sprintf(L"%02u", i);
}
//---------------------------------------------------------------------------
// Frame a Link Value in red when it differs from the row's Value.
void __fastcall TBreakForm::ChainGridDrawCell(TObject *Sender, int ACol, int ARow, TRect &Rect,
TGridDrawState State)
{
if (ARow != 0 && ACol == colLink)
{
if (ChainGrid->Cells[colLink][ARow] != ChainGrid->Cells[colValue][ARow])
{
ChainGrid->Canvas->Brush->Color = clRed;
ChainGrid->Canvas->FrameRect(Rect);
}
}
}
//---------------------------------------------------------------------------
// Set: clear any breakpoint at the address, then set one of the chosen type and size.
void __fastcall TBreakForm::SetButtonClick(TObject *Sender)
{
void *addr = (void *)HexToInt(BreakAddressEdit->Text);
const DWORD type = (DWORD)BreakTypeCombo->ItemIndex;
pDmSetDataBreakpoint(addr, DMBREAK_NONE, BreakSizes[BreakSizeCombo->ItemIndex]);
pDmSetDataBreakpoint(addr, type, BreakSizes[BreakSizeCombo->ItemIndex]);
}
//---------------------------------------------------------------------------
// Read: show the type of the breakpoint at the address.
void __fastcall TBreakForm::ReadTypeButtonClick(TObject *Sender)
{
DWORD type = 0;
pDmIsBreakpoint((void *)HexToInt(BreakAddressEdit->Text), &type);
CurrentTypeCombo->ItemIndex = (int)type;
}
//---------------------------------------------------------------------------
// Calc: CalcResultEdit = CalcBaseEdit + CalcOffsetEdit (hex, 32-bit).
void __fastcall TBreakForm::CalcButtonClick(TObject *Sender)
{
const unsigned int sum = HexToInt(CalcBaseEdit->Text) + HexToInt(CalcOffsetEdit->Text);
CalcResultEdit->Text = UnicodeString().sprintf(L"%08X", sum);
}
//---------------------------------------------------------------------------
// Double to Hex: the 64 bits of the value, high dword first.
void __fastcall TBreakForm::DoubleToHexButtonClick(TObject *Sender)
{
const double d = DoubleHexEdit->Text.ToDouble();
unsigned int dw[2]; // dw[0] low, dw[1] high
memcpy(dw, &d, sizeof dw);
DoubleHexEdit->Text = UnicodeString().sprintf(L"%08X%08X", dw[1], dw[0]);
}
//---------------------------------------------------------------------------
// Hex to Double: characters 1-8 are the high dword, 9-16 the low dword.
void __fastcall TBreakForm::HexToDoubleButtonClick(TObject *Sender)
{
unsigned int dw[2];
dw[1] = HexToInt(DoubleHexEdit->Text.SubString(1, 8));
dw[0] = HexToInt(DoubleHexEdit->Text.SubString(9, 8));
double d;
memcpy(&d, dw, sizeof d);
DoubleHexEdit->Text = UnicodeString(d);
}
//---------------------------------------------------------------------------
// Read the pointer chain. The last row with a Base is the start of the chain:
// Value[r] = [Base[r] + Offset[r]] for every row r up to the last one (an empty Base becomes "0");
// Link[last] = Value[last], and going up, Link[r] = [Link[r+1] + Offset[r]].
// DrawCell then frames each Link that differs from its row's Value.
void __fastcall TBreakForm::ReadChainButtonClick(TObject *Sender)
{
// The original starts at row 100, one past the last row (RowCount is 100), which always reads empty.
int last;
for (last = ChainGrid->RowCount - 1; last > 0; last--)
if (ChainGrid->Cells[colBase][last] != L"")
break;
if (last == 0)
return;
for (int r = last; r > 0; r--)
{
if (ChainGrid->Cells[colBase][r] == L"")
ChainGrid->Cells[colBase][r] = L"0";
const unsigned int addr = HexToInt(ChainGrid->Cells[colBase][r]) + HexToInt(ChainGrid->Cells[colOffset][r]);
ChainGrid->Cells[colValue][r] = UnicodeString().sprintf(L"%08X", ReadDword(addr));
}
ChainGrid->Cells[colLink][last] = ChainGrid->Cells[colValue][last];
for (int r = last - 1; r > 0; r--)
{
const unsigned int addr = HexToInt(ChainGrid->Cells[colLink][r + 1]) + HexToInt(ChainGrid->Cells[colOffset][r]);
ChainGrid->Cells[colLink][r] = UnicodeString().sprintf(L"%08X", ReadDword(addr));
}
}
//---------------------------------------------------------------------------