-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathExplorer.pas
299 lines (277 loc) · 7.79 KB
/
Explorer.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
unit Explorer;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics,
Controls, Forms, Dialogs, StdCtrls, Menus, ExtCtrls, ComCtrls;
type
DefKind = (UNDEFINE, DEFINE_AS_CODE, DEFINE_AS_STRING);
TFExplorer=class(TForm)
pc1: TPageControl;
tsCode: TTabSheet;
tsData: TTabSheet;
lbCode: TListBox;
lbData: TListBox;
tsString: TTabSheet;
rgStringViewStyle: TRadioGroup;
tsText: TTabSheet;
lbText: TListBox;
pm1: TPopupMenu;
miCopy2Clipboard: TMenuItem;
Panel2: TPanel;
rgDataViewStyle: TRadioGroup;
lbString: TMemo;
Panel3: TPanel;
btnDefCode: TButton;
btnUndefCode: TButton;
Panel1: TPanel;
btnDefString: TButton;
btnUndefString: TButton;
procedure btnDefCodeClick(Sender : TObject);
procedure btnUndefCodeClick(Sender : TObject);
procedure rgStringViewStyleClick(Sender : TObject);
procedure miCopy2ClipboardClick(Sender : TObject);
procedure FormKeyDown(Sender : TObject; var Key:Word; Shift:TShiftState);
procedure FormShow(Sender : TObject);
procedure rgDataViewStyleClick(Sender : TObject);
procedure btnDefStringClick(Sender : TObject);
private
{ Private declarations }
Adr:Integer; // Starting address
public
{ Public declarations }
DefineAs:DefKind; //1- Define as Code, 2 - Undefine
WAlign:Integer; //Alignment for WideString visualization
Procedure ShowCode(fromAdr:Integer; maxBytes:Integer);
Procedure ShowData(fromAdr:Integer; maxBytes:Integer);
Procedure ShowString(fromAdr:Integer; maxbytes:Integer);
end;
Var
FExplorer:TFExplorer;
implementation
{$R *.DFM}
Uses Disasm,Misc,Def_disasm,Main;
Type
PReal = ^Real;
Procedure TFExplorer.ShowCode (fromAdr:Integer; maxBytes:Integer);
var
_pos:Integer;
DisInfo:TDisInfo;
curAdr:Integer;
disLine:AnsiString;
n,instrLen:Integer;
Begin
lbCode.Clear;
_pos := Adr2Pos(fromAdr);
if _pos = -1 then Exit;
Adr := fromAdr;
curAdr := Adr;
n:=0;
while n < maxBytes do
begin
instrLen := frmDisasm.Disassemble(Code + _pos, curAdr, @DisInfo, @disLine);
if instrLen=0 then
begin
instrLen := 1;
lbCode.Items.Add(Val2Str(curAdr,8) + ' ???');
end
else lbCode.Items.Add(Val2Str(curAdr,8) + ' ' + disLine);
if n + instrLen > maxBytes then break;
if _pos + instrLen >= CodeSize then break;
Inc(_pos,instrLen);
Inc(curAdr,instrLen);
Inc(n,instrLen);
end;
end;
Procedure TFExplorer.ShowData (fromAdr:Integer; maxBytes:Integer);
var
b:Char;
n, k, m, _pos:Integer;
singleVal:Single;
doubleVal:Double;
extendedVal:Extended;
realVal:Real;
compVal:Comp;
line1, line2:AnsiString;
curAdr:Integer;
Begin
lbData.Clear;
_pos := Adr2Pos(fromAdr);
if _pos = -1 Then Exit;
Adr := fromAdr;
curAdr := Adr;
Case rgDataViewStyle.ItemIndex of
0: // Hex (default)
begin
k:=0;
for n := 0 to maxBytes-1 do
begin
if _pos > ImageSize then break;
if k=0 then
begin
line1 := Val2Str(curAdr,8) + ' ';
line2 := ' ';
End;
line1 :=line1 + ' ' + Val2Str(Ord(Image[_pos]),2);
b := Image[_pos];
if b < ' ' then b := ' ';
line2 :=line2 + b;
Inc(k);
if k = 16 then
begin
lbData.Items.Add(line1 + line2);
Inc(curAdr,16);
k := 0;
End;
Inc(_pos);
End;
if (k > 0) and (k < 16) then
begin
for m := k To 15 do line1 := line1 + ' ';
lbData.Items.Add(line1 + line2);
End;
End;
//Single = float
1:
begin
singleVal := PSingle(Image + _pos)^;
line1 := Val2Str(curAdr,8) + ' ' + FloatToStr(singleVal);
lbData.Items.Add(line1);
end;
//Double = doulbe
2:
begin
doubleVal := PDouble(Image + _pos)^;
line1 := Val2Str(curAdr,8) + ' ' + FloatToStr(doubleVal);
lbData.Items.Add(line1);
end;
//Extended = long double
3:
begin
try
extendedVal := PExtended(Image + _pos)^;
line1 := Val2Str(curAdr,8) + ' ' + FloatToStr(extendedVal);
Except
line1 := 'Impossible!';
End;
lbData.Items.Add(line1);
end;
//Real = double
4:
begin
realVal := PReal(Image + _pos)^;
line1 := Val2Str(curAdr,8) + ' ' + FloatToStr(realVal);
lbData.Items.Add(line1);
end;
//Comp = Comp
5:
begin
compVal := PComp(Image + _pos)^;
line1 := Val2Str(curAdr,8) + ' ' + FloatToStr(compVal);
lbData.Items.Add(line1);
end;
end;
lbData.Update;
end;
Procedure TFExplorer.ShowString (fromAdr:Integer; maxbytes:Integer);
var
len, size, _pos:Integer;
str:AnsiString;
wStr:WideString;
Begin
lbString.Clear;
_pos := Adr2Pos(fromAdr);
if _pos = -1 then Exit;
Case rgStringViewStyle.ItemIndex of
0: //PAnsiChar
begin
len := StrLen(Image + _pos);
if len < 0 then len := 0;
if len > maxBytes then len := maxBytes;
str := TransformString(Image + _pos, len);
end;
1: //PWideChar
begin
len := lstrlenW(PWideChar(Image) + _pos);
if len < 0 then len := 0;
if len > maxBytes then len := maxBytes;
wStr := WideString(PWideChar(Image + _pos));
size := WideCharToMultiByte(CP_ACP, 0, PWideChar(wStr), len, Nil, 0, Nil, Nil);
if size<>0 then
begin
SetLength(str,size);
WideCharToMultiByte(CP_ACP, 0, PWideChar(wStr), len, PAnsiChar(str), size, Nil, Nil);
End;
end;
2: //ShortString
begin
len := PByte(Image + _pos)^;
//if len < 0 len = 0;
if len > maxBytes then len := maxBytes;
str := TransformString(Image + _pos + 1, len);
end;
3: //AnsiString
begin
len := PLongInt(Image + _pos)^;
if len < 0 then len := 0;
if len > maxBytes then len := maxBytes;
str := TransformString(Image + _pos + 4, len);
end;
4: //WideString
begin
len := PLongInt(Image + _pos + WAlign)^;
if len < 0 then len := 0;
if len > maxBytes then len := maxBytes;
wStr := WideString(PWideChar(Image + _pos + WAlign + 4));
size := WideCharToMultiByte(CP_ACP, 0, PWideChar(wStr), len, Nil, 0, Nil, Nil);
if size<>0 then
begin
SetLength(str,size);
WideCharToMultiByte(CP_ACP, 0, PWideChar(wStr), len, PAnsiChar(str), size, Nil, Nil);
end;
end;
end;
lbString.Lines.Add(str);
end;
procedure TFExplorer.btnDefCodeClick(Sender : TObject);
begin
DefineAs:=DEFINE_AS_CODE;
ModalResult:=mrOk;
end;
procedure TFExplorer.btnUndefCodeClick(Sender : TObject);
begin
DefineAs:=UNDEFINE;
ModalResult:=mrCancel;
end;
procedure TFExplorer.btnDefStringClick(Sender : TObject);
begin
DefineAs:=DEFINE_AS_STRING;
ModalResult:=mrOk;
end;
procedure TFExplorer.rgStringViewStyleClick(Sender : TObject);
begin
ShowString(Adr,1024);
end;
procedure TFExplorer.miCopy2ClipboardClick(Sender : TObject);
var
items:TStrings;
begin
if pc1.ActivePage = tsCode then items := lbCode.Items
Else if pc1.ActivePage = tsData then items := lbData.Items
Else If pc1.ActivePage = tsString then items := lbString.Lines
Else If pc1.ActivePage = tsText then items := lbText.Items
Else items:=Nil;
Copy2Clipboard(items, 0, false);
end;
procedure TFExplorer.FormKeyDown(Sender : TObject; var Key:Word; Shift:TShiftState);
begin
if Key=VK_ESCAPE then ModalResult:=mrCancel;
end;
procedure TFExplorer.FormShow(Sender : TObject);
begin
DefineAs:=UNDEFINE;
end;
procedure TFExplorer.rgDataViewStyleClick(Sender : TObject);
begin
ShowData(Adr,1024);
end;
end.