-
Notifications
You must be signed in to change notification settings - Fork 225
/
TabStrings.cpp
249 lines (233 loc) · 8.68 KB
/
TabStrings.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
extern WideString __fastcall UnicodeEncode(String Str, int CodePage);
//---------------------------------------------------------------------------
void __fastcall TFMain_11011981::ShowStrings(int idx)
{
int n, itemidx, wid, maxwid = 0;
PInfoRec recN;
String line, line1, str;
TCanvas* canvas = lbStrings->Canvas;
lbStrings->Clear();
lbStrings->Items->BeginUpdate();
for (n = 0; n < CodeSize; n++)
{
recN = GetInfoRec(Pos2Adr(n));
if (recN && !IsFlagSet(cfRTTI, n))
{
if (recN->kind == ikResString && recN->rsInfo->value != "")
{
//line = " " + Val2Str8(Pos2Adr(n)) + " <ResString> " + recN->rsInfo->value;
line = Val2Str8(Pos2Adr(n)) + " <ResString> " + recN->rsInfo->value;
if (recN->rsInfo->value.Length() <= MAXLEN)
line1 = line;
else
{
line1 = line.SubString(1, MAXLEN) + "..."; //line1[1] ^= 1;
}
lbStrings->Items->Add(line1);
wid = canvas->TextWidth(line1); if (wid > maxwid) maxwid = wid;
continue;
}
if (recN->HasName())
{
switch (recN->kind)
{
case ikString:
str = "<ShortString>";
break;
case ikLString:
str = "<AnsiString>";
break;
case ikWString:
str = "<WideString>";
break;
case ikCString:
str = "<PAnsiChar>";
break;
case ikWCString:
str = "<PWideChar>";
break;
case ikUString:
str = "<UString>";
break;
default:
str = "";
break;
}
if (str != "")
{
//bool truncate = false;
//line = " " + Val2Str8(Pos2Adr(n)) + " " + str + " " + recN->GetName();
line = Val2Str8(Pos2Adr(n)) + " " + str + " " + recN->GetName();
if (recN->GetNameLength() <= MAXLEN)
line1 = line;
else
{
line1 = line.SubString(1, MAXLEN) + "...";
//truncate = true;
}
WideString ws = UnicodeEncode(line1, CodePage);
//if (truncate) line1[1] ^= 1;
lbStrings->Items->Add(ws);
wid = canvas->TextWidth(line1); if (wid > maxwid) maxwid = wid;
}
}
}
}
lbStrings->ItemIndex = idx;
lbStrings->ScrollWidth = maxwid + 2;
lbStrings->ItemHeight = lbStrings->Canvas->TextHeight("T");
lbStrings->Items->EndUpdate();
}
//---------------------------------------------------------------------------
void __fastcall TFMain_11011981::lbStringsClick(TObject *Sender)
{
StringsSearchFrom = lbStrings->ItemIndex;
WhereSearch = SEARCH_STRINGS;
if (lbStrings->ItemIndex >= 0)
{
DWORD adr;
String line = lbStrings->Items->Strings[lbStrings->ItemIndex];
//sscanf(line.c_str() + 1, "%lX", &adr);
sscanf(line.c_str(), "%lX", &adr);
ShowStringXrefs(adr, -1);
}
}
//---------------------------------------------------------------------------
void __fastcall TFMain_11011981::lbStringsDblClick(TObject *Sender)
{
DWORD adr;
String line = lbStrings->Items->Strings[lbStrings->ItemIndex];
//sscanf(line.c_str() + 1, "%lX", &adr);
sscanf(line.c_str(), "%lX", &adr);
if (IsValidImageAdr(adr))
{
PInfoRec recN = GetInfoRec(adr);
if (recN->kind == ikResString)
{
FStringInfo_11011981->Caption = "ResString context";
FStringInfo_11011981->memStringInfo->Clear();
FStringInfo_11011981->memStringInfo->Lines->Add(recN->rsInfo->value);
FStringInfo_11011981->ShowModal();
}
else
{
FStringInfo_11011981->Caption = "String context";
FStringInfo_11011981->memStringInfo->Clear();
WideString ws = UnicodeEncode(recN->GetName(), CodePage);
FStringInfo_11011981->memStringInfo->Lines->Add(UnicodeEncode(recN->GetName(), CodePage));
FStringInfo_11011981->ShowModal();
}
}
}
//---------------------------------------------------------------------------
/*
void __fastcall TFMain_11011981::lbStringsDrawItem(TWinControl *Control,
int Index, TRect &Rect, TOwnerDrawState State)
{
int flags;
TColor _color;
TListBox *lb;
TCanvas *canvas;
String text, str;
lb = (TListBox*)Control;
canvas = lb->Canvas;
SaveCanvas(canvas);
if (Index < lb->Count)
{
flags = Control->DrawTextBiDiModeFlags(DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX);
if (!Control->UseRightToLeftAlignment())
Rect.Left += 2;
else
Rect.Right -= 2;
canvas->FillRect(Rect);
text = lb->Items->Strings[Index];
//lb->ItemHeight = canvas->TextHeight(text);
str = text.SubString(2, text.Length() - 1);
//Long strings
if (text[1] & 1)
_color = TColor(0xBBBBBB); //LightGray
else
_color = TColor(0);//Black
Rect.Right = Rect.Left;
DrawOneItem(str, canvas, Rect, _color, flags);
}
RestoreCanvas(canvas);
}
*/
//---------------------------------------------------------------------------
void __fastcall TFMain_11011981::miSearchStringClick(TObject *Sender)
{
WhereSearch = SEARCH_STRINGS;
FindDlg_11011981->cbText->Clear();
for (int n = 0; n < StringsSearchList->Count; n++)
FindDlg_11011981->cbText->AddItem(StringsSearchList->Strings[n], 0);
if (FindDlg_11011981->ShowModal() == mrOk && FindDlg_11011981->cbText->Text != "")
{
if (lbStrings->ItemIndex < 0)
StringsSearchFrom = 0;
else
StringsSearchFrom = lbStrings->ItemIndex;
StringsSearchText = FindDlg_11011981->cbText->Text;
if (StringsSearchList->IndexOf(StringsSearchText) == -1) StringsSearchList->Add(StringsSearchText);
FindText(StringsSearchText);
DWORD adr;
String line = lbStrings->Items->Strings[lbStrings->ItemIndex];
//sscanf(line.c_str() + 1, "%lX", &adr);
sscanf(line.c_str(), "%lX", &adr);
ShowStringXrefs(adr, -1);
}
}
//---------------------------------------------------------------------------
void __fastcall TFMain_11011981::lbStringsMouseMove(
TObject *Sender, TShiftState Shift, int X, int Y)
{
if (lbStrings->CanFocus()) ActiveControl = lbStrings;
}
//---------------------------------------------------------------------------
void __fastcall TFMain_11011981::ShowSXrefsClick(TObject *Sender)
{
if (lbSXrefs->Visible)
{
ShowSXrefs->BevelOuter = bvRaised;
lbSXrefs->Visible = false;
}
else
{
ShowSXrefs->BevelOuter = bvLowered;
lbSXrefs->Visible = true;
}
}
//---------------------------------------------------------------------------
void __fastcall TFMain_11011981::ShowStringXrefs(DWORD Adr, int selIdx)
{
lbSXrefs->Clear();
PInfoRec recN = GetInfoRec(Adr);
if (recN && recN->xrefs)
{
int wid, maxwid = 0;
TCanvas *canvas = lbSXrefs->Canvas;
DWORD pAdr = 0;
char f = 2;
lbSXrefs->Items->BeginUpdate();
for (int m = 0; m < recN->xrefs->Count; m++)
{
PXrefRec recX = (PXrefRec)recN->xrefs->Items[m];
String line = " " + Val2Str8(recX->adr + recX->offset) + " " + recX->type;
wid = canvas->TextWidth(line); if (wid > maxwid) maxwid = wid;
PUnitRec recU = GetUnit(recX->adr);
if (recU && recU->kb) line[1] ^= 1;
if (pAdr != recX->adr) f ^= 2; line[1] ^= f;
pAdr = recX->adr;
lbSXrefs->Items->Add(line);
}
lbSXrefs->Items->EndUpdate();
lbSXrefs->ScrollWidth = maxwid + 2;
lbSXrefs->ItemIndex = selIdx;
}
}
//---------------------------------------------------------------------------
void __fastcall TFMain_11011981::pmStringsPopup(TObject *Sender)
{
if (lbStrings->ItemIndex < 0) return;
}
//---------------------------------------------------------------------------