-
Notifications
You must be signed in to change notification settings - Fork 20
/
EditFieldsDlg.pas
316 lines (281 loc) · 8.21 KB
/
EditFieldsDlg.pas
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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
unit EditFieldsDlg;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics,
Controls, Forms, Dialogs, StdCtrls, ExtCtrls;
type
TFieldOp = (FD_OP_EDIT, FD_OP_ADD, FD_OP_DELETE);
TFEditFieldsDlg=class(TForm)
lbFXrefs: TListBox;
lbFields: TListBox;
Panel1: TPanel;
bAdd: TButton;
bRemove: TButton;
edtPanel: TPanel;
edtName: TLabeledEdit;
edtType: TLabeledEdit;
bApply: TButton;
bClose: TButton;
edtOffset: TLabeledEdit;
bEdit: TButton;
panel2: TPanel;
procedure FormDestroy(Sender: TObject);
procedure FormShow(Sender : TObject);
procedure lbFXrefsDblClick(Sender : TObject);
procedure lbFieldsClick(Sender : TObject);
procedure edtNameChange(Sender : TObject);
procedure edtTypeChange(Sender : TObject);
procedure bCloseClick(Sender : TObject);
procedure bApplyClick(Sender : TObject);
procedure bEditClick(Sender : TObject);
procedure bRemoveClick(Sender : TObject);
procedure bAddClick(Sender : TObject);
procedure FormCreate(Sender : TObject);
private
{ Private declarations }
Procedure ShowFields;
public
{ Public declarations }
Op:TFieldOp;
SelIndex:Integer;
FieldOffset:Integer;
VmtAdr:Integer;
fieldsList:TList;
end;
var
FEditFieldsDlg:TFEditFieldsDlg;
implementation
{$R *.DFM}
Uses Main,KnowledgeBase,Misc,Infos,Def_main,Def_info,Def_know,Scanf;
procedure TFEditFieldsDlg.FormCreate(Sender : TObject);
begin
Op := FD_OP_EDIT;
SelIndex := -1;
FieldOffset := -1;
VmtAdr := 0;
fieldsList := TList.Create;
end;
procedure TFEditFieldsDlg.FormDestroy(Sender: TObject);
begin
fieldsList.Free;
end;
Procedure TFEditFieldsDlg.ShowFields;
Var
n, fieldsNum:Integer;
fInfo:FieldInfo;
line:AnsiString;
Begin
lbFields.Enabled := true;
lbFields.Clear;
fieldsList.Clear;
fieldsNum := FMain.LoadFieldTable(VmtAdr, fieldsList);
if fieldsNum<>0 then
begin
SelIndex := -1;
for n := 0 To fieldsNum-1 do
begin
fInfo := fieldsList.Items[n];
line := Val2Str(fInfo.Offset,5) + ' ';
if fInfo.Name <> '' then line := line + fInfo.Name
else line := line + '?';
line := line + ':';
if fInfo._Type <> '' then line := line + fInfo._Type
else line := line + '?';
lbFields.Items.Add(line);
if fInfo.Offset = FieldOffset then SelIndex := n;
End;
End;
end;
procedure TFEditFieldsDlg.FormShow(Sender : TObject);
begin
Caption := GetClsName(VmtAdr) + ' fields';
edtPanel.Visible := false;
lbFields.Height := lbFXrefs.Height;
lbFXrefs.Clear;
ShowFields;
lbFields.ItemIndex := SelIndex;
bEdit.Enabled := (lbFields.Count<>0) and (lbFields.ItemIndex <> -1);
bAdd.Enabled := true;
bRemove.Enabled := (lbFields.Count<>0) and (lbFields.ItemIndex <> -1);
bClose.Enabled := true;
end;
procedure TFEditFieldsDlg.lbFXrefsDblClick(Sender : TObject);
var
//_type:Array[0..1] of Char;
adr:Integer;
item:AnsiString;
m:Integer;
_type:Array[1..2] of Char;
begin
item := lbFXrefs.Items[lbFXrefs.ItemIndex];
adr:=StrToInt(item);
//sscanf(item.c_str() + 1, "%lX%2c", &adr, type);
sscanf(PAnsiChar(item) + 1, '%lX%2c', [@adr, @_type]);
for m := Adr2Pos(adr) Downto 0 do
if IsFlagSet([cfProcStart], m) then
begin
FMain.ShowCode(Pos2Adr(m), adr, -1, -1);
break;
End;
end;
procedure TFEditFieldsDlg.lbFieldsClick(Sender : TObject);
var
line:AnsiString;
fInfo:FieldInfo;
n:Integer;
recX:PXrefRec;
begin
lbFXrefs.Clear;
if lbFields.ItemIndex = -1 then Exit;
fInfo := fieldsList.Items[lbFields.ItemIndex];
if Assigned(fInfo.xrefs) then
for n := 0 to fInfo.xrefs.Count-1 do
begin
recX := fInfo.xrefs.Items[n];
line := Val2Str(recX.adr + recX.offset,8);
if recX._type = 'c' then line := line + ' <-';
lbFXrefs.Items.Add(line);
End;
bEdit.Enabled := (lbFields.Count<>0) and (lbFields.ItemIndex <> -1);
bRemove.Enabled := (lbFields.Count<>0) and (lbFields.ItemIndex <> -1);
end;
procedure TFEditFieldsDlg.bEditClick(Sender : TObject);
Var
fInfo:FieldInfo;
begin
Op := FD_OP_EDIT;
edtPanel.Visible := true;
fInfo := fieldsList.Items[lbFields.ItemIndex];
edtOffset.Text := Val2Str(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;
end;
procedure TFEditFieldsDlg.edtNameChange(Sender : TObject);
begin
bApply.Enabled := true;
end;
procedure TFEditFieldsDlg.edtTypeChange(Sender : TObject);
begin
bApply.Enabled := true;
end;
procedure TFEditFieldsDlg.bApplyClick(Sender : TObject);
var
vmt:Boolean;
adr,n,size,offset,fromOfs,toOfs:Integer;
recN:InfoRec;
fInfo:FieldInfo;
txt:AnsiString;
itemidx,topidx:Integer;
rtti:AnsiString;
begin
recN:=GetInfoRec(VmtAdr);
edtName.Text:=Trim(edtName.Text);
edtType.Text:=Trim(edtType.Text);
edtOffset.Text:=Trim(edtOffset.Text);
Case Op of
FD_OP_EDIT:
begin
fInfo := fieldsList.Items[lbFields.ItemIndex];
fInfo.Name := edtName.text;
fInfo._Type := edtType.text;
//Delete all fields (if exists) that covered by new type
fromOfs := fInfo.Offset;
if GetTypeKind(edtType.Text, size) = ikRecord then
begin
toOfs := fromOfs + size;
for n := 0 to fieldsList.Count-1 do
begin
fInfo := fieldsList[n];
offset := fInfo.Offset;
if (offset > fromOfs) and (offset < toOfs) then
recN.vmtInfo.RemoveField(offset);
end;
end;
End;
FD_OP_ADD,
FD_OP_DELETE:
begin
sscanf(PAnsiChar(edtOffset.Text),'%lX',[@offset]);
if Op = FD_OP_ADD then
begin
fInfo := FMain.GetField(recN.Name, offset, vmt, adr,'');
if Not Assigned(fInfo) Or (Application.MessageBox('Field already exists', 'Replace?', MB_YESNO) = IDYES) then
recN.vmtInfo.AddField(0, 0, FIELD_PUBLIC, offset, -1, edtName.text, edtType.text);
if Assigned(fInfo) and (fInfo.Scope=SCOPE_TMP) then fInfo.Free;
end
else if Application.MessageBox('Delete field?', 'Confirmation', MB_YESNO) = IDYES then
recN.vmtInfo.RemoveField(offset);
End;
End;
itemidx := lbFields.ItemIndex;
topidx := lbFields.TopIndex;
ShowFields;
lbFields.ItemIndex := itemidx;
lbFields.TopIndex := topidx;
FMain.RedrawCode;
FMain.ShowClassViewer(VmtAdr);
edtPanel.Visible := false;
lbFields.Enabled := true;
bEdit.Enabled := (lbFields.Count<>0) and (lbFields.ItemIndex <> -1);
bAdd.Enabled := true;
bRemove.Enabled := (lbFields.Count<>0) and (lbFields.ItemIndex <> -1);
ProjectModified := true;
end;
procedure TFEditFieldsDlg.bCloseClick(Sender : TObject);
begin
edtPanel.Visible := false;
lbFields.Height := lbFXrefs.Height;
lbFields.Enabled := true;
bEdit.Enabled := (lbFields.Count<>0) and (lbFields.ItemIndex <> -1);
bAdd.Enabled := true;
bRemove.Enabled := (lbFields.Count<>0) and (lbFields.ItemIndex <> -1);
end;
procedure TFEditFieldsDlg.bAddClick(Sender : TObject);
begin
Op := FD_OP_ADD;
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;
end;
procedure TFEditFieldsDlg.bRemoveClick(Sender : TObject);
Var
fInfo:FieldInfo;
begin
Op := FD_OP_DELETE;
edtPanel.Visible := true;
fInfo := fieldsList.Items[lbFields.ItemIndex];
edtOffset.Text := Val2Str(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;
end;
end.