forked from AlexanderBagel/ProcessMemoryMap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuSelectAddress.pas
More file actions
202 lines (181 loc) · 5.02 KB
/
Copy pathuSelectAddress.pas
File metadata and controls
202 lines (181 loc) · 5.02 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
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
////////////////////////////////////////////////////////////////////////////////
//
// ****************************************************************************
// * Project : ProcessMM
// * Unit Name : uSelectAddress.pas
// * Purpose : Диалог для выбора адреса
// * Author : Александр (Rouse_) Багель
// * Copyright : © Fangorn Wizards Lab 1998 - 2016, 2023.
// * Version : 1.4.30
// * Home Page : http://rouse.drkb.ru
// * Home Blog : http://alexander-bagel.blogspot.ru
// ****************************************************************************
// * Stable Release : http://rouse.drkb.ru/winapi.php#pmm2
// * Latest Source : https://github.com/AlexanderBagel/ProcessMemoryMap
// ****************************************************************************
//
unit uSelectAddress;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
Vcl.StdCtrls, uBaseForm;
type
TCaptionType = (ctDump, ctHighLight, ctQuery);
TdlgSelectAddress = class(TBaseAppForm)
Label1: TLabel;
Label2: TLabel;
edInt: TEdit;
lblHex: TLabel;
edHex: TEdit;
btnCancel: TButton;
btnOk: TButton;
edSize: TEdit;
lblSizeInt: TLabel;
lblSize: TLabel;
procedure edIntKeyPress(Sender: TObject; var Key: Char);
procedure edIntChange(Sender: TObject);
procedure edHexChange(Sender: TObject);
private
InChange: Boolean;
public
function ShowDlg(CaptionType: TCaptionType; ASelectAddress: UInt64 = 0): TModalResult;
end;
var
dlgSelectAddress: TdlgSelectAddress;
implementation
uses
uUtils;
{$R *.dfm}
function TrimZeros(const Value: string): string;
var
I: Integer;
begin
Result := '';
for I := 1 to Length(Value) do
if Value[I] <> '0' then
begin
Result := Copy(Value, I, Length(Value));
Break;
end;
if Result = '' then
Result := '0';
end;
procedure TdlgSelectAddress.edHexChange(Sender: TObject);
var
TmpValue: string;
Index: Integer;
Valid: Boolean;
CalculatedAddr, LeftVal, RightVal: Int64;
begin
if InChange then Exit;
InChange := True;
try
TmpValue := edHex.Text;
if TmpValue = '' then
begin
edHex.Text := '0';
btnOk.Enabled := True;
Exit;
end;
CalculatedAddr := 0;
TmpValue := StringReplace(TmpValue, ' ', '', [rfReplaceAll]);
Valid := HexValueToInt64(TmpValue, LeftVal);
if Valid then
CalculatedAddr := LeftVal
else
begin
// минимальный набор адресной арифметики для быстрого перехода по оффсету
Index := Pos('+', TmpValue);
if Index > 0 then
begin
Valid :=
HexValueToInt64(Copy(TmpValue, 1, Index - 1), LeftVal) and
HexValueToInt64(Copy(TmpValue, Index + 1, Length(TmpValue)), RightVal);
CalculatedAddr := LeftVal + RightVal;
end
else
begin
Index := Pos('-', TmpValue);
if Index > 0 then
begin
Valid :=
HexValueToInt64(Copy(TmpValue, 1, Index - 1), LeftVal) and
HexValueToInt64(Copy(TmpValue, Index + 1, Length(TmpValue)), RightVal);
CalculatedAddr := LeftVal - RightVal;
end;
end;
end;
if Valid then
lblHex.Font.Color := clWindowText
else
lblHex.Font.Color := clRed;
edInt.Text := IntToStr(CalculatedAddr);
finally
InChange := False;
end;
end;
procedure TdlgSelectAddress.edIntChange(Sender: TObject);
var
I: Int64;
Edit: TEdit;
begin
if InChange then Exit;
InChange := True;
try
Edit := Sender as TEdit;
if Edit.Text = '' then
Edit.Text := '0';
if not TryStrToInt64(Edit.Text, I) then
begin
ShowErrorHint(Edit.Handle);
Edit.Text := '0';
end;
if Edit = edInt then
begin
edHex.Text := TrimZeros(IntToHex(StrToInt64Def(Edit.Text, 0), 16));
lblHex.Font.Color := clWindowText;
end;
finally
InChange := False;
end;
end;
procedure TdlgSelectAddress.edIntKeyPress(Sender: TObject; var Key: Char);
begin
if not CharInSet(Key, [#8, #22, '0'..'9']) then
begin
Key := #0;
ShowErrorHint((Sender as TEdit).Handle);
end;
end;
function TdlgSelectAddress.ShowDlg(CaptionType: TCaptionType;
ASelectAddress: UInt64): TModalResult;
var
Offset: Integer;
begin
if ASelectAddress <> 0 then
begin
InChange := True;
try
edHex.Text := TrimZeros(IntToHex(ASelectAddress, 16));
edInt.Text := IntToStr(ASelectAddress);
finally
InChange := False;
end;
end;
if CaptionType = ctHighLight then
Caption := 'Process Memory Map - HighLight Address';
if CaptionType = ctDump then
begin
Caption := 'Process Memory Map - Dump Address';
lblSize.Visible := True;
lblSizeInt.Visible := True;
edSize.Visible := True;
Offset := edSize.Top - edHex.Top;
btnOk.Top := btnOk.Top + Offset;
btnCancel.Top := btnCancel.Top + Offset;
Height := Height + Offset;
end;
Result := ShowModal;
end;
end.