forked from crypto2011/IDR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EditFieldsDlg.cpp
284 lines (261 loc) · 8.98 KB
/
EditFieldsDlg.cpp
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
//----------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Misc.h"
#include "EditFieldsDlg.h"
#include "Main.h"
//----------------------------------------------------------------------------
#pragma resource "*.dfm"
extern bool ProjectModified;
extern DWORD CurProcAdr;
extern DWORD CodeBase;
extern DWORD *Flags;
extern PInfoRec *Infos;
TFEditFieldsDlg_11011981 *FEditFieldsDlg_11011981;
//----------------------------------------------------------------------------
__fastcall TFEditFieldsDlg_11011981::TFEditFieldsDlg_11011981(TComponent *Owner)
: TForm(Owner)
{
Op = FD_OP_EDIT;
SelIndex = -1;
FieldOffset = -1;
VmtAdr = 0;
fieldsList = new TList;
}
//----------------------------------------------------------------------------
__fastcall TFEditFieldsDlg_11011981::~TFEditFieldsDlg_11011981()
{
if (fieldsList) delete fieldsList;
}
//----------------------------------------------------------------------------
void __fastcall TFEditFieldsDlg_11011981::ShowFields()
{
lbFields->Enabled = true;
lbFields->Clear();
fieldsList->Clear();
int fieldsNum = FMain_11011981->LoadFieldTable(VmtAdr, fieldsList);
if (fieldsNum)
{
SelIndex = -1;
for (int n = 0; n < fieldsNum; n++)
{
PFIELDINFO fInfo = (PFIELDINFO)fieldsList->Items[n];
String line = Val2Str5(fInfo->Offset) + " ";
if (fInfo->Name != "")
line += fInfo->Name;
else
line += "?";
line += ":";
if (fInfo->Type != "")
line += fInfo->Type;
else
line += "?";
lbFields->Items->Add(line);
if (fInfo->Offset == FieldOffset)
SelIndex = n;
}
}
}
//----------------------------------------------------------------------------
void __fastcall TFEditFieldsDlg_11011981::FormShow(TObject *Sender)
{
Caption = GetClsName(VmtAdr) + " fields";
edtPanel->Visible = false;
lbFields->Height = lbFXrefs->Height;
lbFXrefs->Clear();
ShowFields();
lbFields->ItemIndex = SelIndex;
bEdit->Enabled = (lbFields->Count && lbFields->ItemIndex != -1);
bAdd->Enabled = true;
bRemove->Enabled = (lbFields->Count && lbFields->ItemIndex != -1);
bClose->Enabled = true;
}
//---------------------------------------------------------------------------
void __fastcall TFEditFieldsDlg_11011981::lbFXrefsDblClick(TObject *Sender)
{
char type[2];
DWORD adr;
String item = lbFXrefs->Items->Strings[lbFXrefs->ItemIndex];
sscanf(item.c_str() + 1, "%lX%2c", &adr, type);
for (int m = Adr2Pos(adr); m >= 0; m--)
{
if (IsFlagSet(cfProcStart, m))
{
FMain_11011981->ShowCode(Pos2Adr(m), adr, -1, -1);
break;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TFEditFieldsDlg_11011981::lbFieldsClick(TObject *Sender)
{
lbFXrefs->Clear();
if (lbFields->ItemIndex == -1) return;
String line;
PFIELDINFO fInfo = (PFIELDINFO)fieldsList->Items[lbFields->ItemIndex];
if (fInfo->xrefs)
{
for (int n = 0; n < fInfo->xrefs->Count; n++)
{
PXrefRec recX = (PXrefRec)fInfo->xrefs->Items[n];
line = Val2Str8(recX->adr + recX->offset);
if (recX->type == 'c') line += " <-";
lbFXrefs->Items->Add(line);
}
}
bEdit->Enabled = (lbFields->Count && lbFields->ItemIndex != -1);
bRemove->Enabled = (lbFields->Count && lbFields->ItemIndex != -1);
}
//---------------------------------------------------------------------------
void __fastcall TFEditFieldsDlg_11011981::bEditClick(TObject *Sender)
{
Op = FD_OP_EDIT;
lbFields->Height = lbFXrefs->Height - edtPanel->Height;
edtPanel->Visible = true;
PFIELDINFO fInfo = (PFIELDINFO)fieldsList->Items[lbFields->ItemIndex];
edtOffset->Text = Val2Str0(fInfo->Offset);
edtOffset->Enabled = false;
edtName->Text = fInfo->Name;
edtName->Enabled = true;
edtType->Text = fInfo->Type;
edtType->Enabled = true;
edtName->SetFocus();
lbFields->Enabled = false;
bApply->Enabled = false;
bClose->Enabled = true;
bEdit->Enabled = false;
bAdd->Enabled = false;
bRemove->Enabled = false;
}
//---------------------------------------------------------------------------
void __fastcall TFEditFieldsDlg_11011981::edtNameChange(TObject *Sender)
{
bApply->Enabled = true;
}
//---------------------------------------------------------------------------
void __fastcall TFEditFieldsDlg_11011981::edtTypeChange(TObject *Sender)
{
bApply->Enabled = true;
}
//---------------------------------------------------------------------------
void __fastcall TFEditFieldsDlg_11011981::bApplyClick(TObject *Sender)
{
bool vmt, ok = false;
DWORD adr;
int n, size, offset, fromOfs, toOfs;
PInfoRec recN;
PFIELDINFO fInfo;
String rtti;
recN = GetInfoRec(VmtAdr);
switch (Op)
{
case FD_OP_EDIT:
fInfo = (PFIELDINFO)fieldsList->Items[lbFields->ItemIndex];
fInfo->Name = Trim(edtName->Text);
fInfo->Type = Trim(edtType->Text);
//Delete all fields (if exists) that covered by new type
fromOfs = fInfo->Offset;
if (GetTypeKind(edtType->Text, &size) == ikRecord)
{
toOfs = fromOfs + size;
for (n = 0; n < fieldsList->Count; n++)
{
fInfo = (PFIELDINFO)fieldsList->Items[n];
offset = fInfo->Offset;
if (offset > fromOfs && offset < toOfs)
{
recN->vmtInfo->RemoveField(offset);
}
}
}
break;
case FD_OP_ADD:
case FD_OP_DELETE:
sscanf(edtOffset->Text.Trim().c_str(), "%lX", &offset);
if (Op == FD_OP_ADD)
{
fInfo = FMain_11011981->GetField(recN->GetName(), offset, &vmt, &adr, "");
if (!fInfo || Application->MessageBox("Field already exists", "Replace?", MB_YESNO) == IDYES)
recN->vmtInfo->AddField(0, 0, FIELD_PUBLIC, offset, -1, Trim(edtName->Text), Trim(edtType->Text));
if (fInfo && fInfo->Scope == SCOPE_TMP)
delete fInfo;
}
if (Op == FD_OP_DELETE)
{
if (Application->MessageBox("Delete field?", "Confirmation", MB_YESNO) == IDYES)
recN->vmtInfo->RemoveField(offset);
}
break;
}
int itemidx = lbFields->ItemIndex;
int topidx = lbFields->TopIndex;
ShowFields();
lbFields->ItemIndex = itemidx;
lbFields->TopIndex = topidx;
FMain_11011981->RedrawCode();
FMain_11011981->ShowClassViewer(VmtAdr);
edtPanel->Visible = false;
lbFields->Height = lbFXrefs->Height;
lbFields->Enabled = true;
bEdit->Enabled = (lbFields->Count && lbFields->ItemIndex != -1);
bAdd->Enabled = true;
bRemove->Enabled = (lbFields->Count && lbFields->ItemIndex != -1);
ProjectModified = true;
}
//---------------------------------------------------------------------------
void __fastcall TFEditFieldsDlg_11011981::bCloseClick(
TObject *Sender)
{
edtPanel->Visible = false;
lbFields->Height = lbFXrefs->Height;
lbFields->Enabled = true;
bEdit->Enabled = (lbFields->Count && lbFields->ItemIndex != -1);
bAdd->Enabled = true;
bRemove->Enabled = (lbFields->Count && lbFields->ItemIndex != -1);
}
//---------------------------------------------------------------------------
void __fastcall TFEditFieldsDlg_11011981::bAddClick(TObject *Sender)
{
Op = FD_OP_ADD;
lbFields->Height = lbFXrefs->Height - edtPanel->Height;
edtPanel->Visible = true;
edtOffset->Text = "";
edtOffset->Enabled = true;
edtName->Text = "";
edtName->Enabled = true;
edtType->Text = "";
edtType->Enabled = true;
edtOffset->SetFocus();
lbFields->Enabled = false;
bApply->Enabled = false;
bClose->Enabled = true;
bEdit->Enabled = false;
bAdd->Enabled = false;
bRemove->Enabled = false;
}
//---------------------------------------------------------------------------
void __fastcall TFEditFieldsDlg_11011981::bRemoveClick(TObject *Sender)
{
Op = FD_OP_DELETE;
lbFields->Height = lbFXrefs->Height - edtPanel->Height;
edtPanel->Visible = true;
PFIELDINFO fInfo = (PFIELDINFO)fieldsList->Items[lbFields->ItemIndex];
edtOffset->Text = Val2Str0(fInfo->Offset);
edtOffset->Enabled = false;
edtName->Text = fInfo->Name;
edtName->Enabled = false;
edtType->Text = fInfo->Type;
edtType->Enabled = false;
lbFields->Enabled = false;
bApply->Enabled = true;
bClose->Enabled = true;
bEdit->Enabled = false;
bAdd->Enabled = false;
bRemove->Enabled = false;
}
//---------------------------------------------------------------------------
void __fastcall TFEditFieldsDlg_11011981::FormCreate(TObject *Sender)
{
ScaleForm(this);
}
//---------------------------------------------------------------------------