-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathuMainForm.pas
244 lines (195 loc) · 5.32 KB
/
uMainForm.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
unit uMainForm;
interface
{.$DEFINE LOAD_DS}
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExeMod, EncdDecd, MD5, Utils;
function Base64_Decode(cStr: ansistring): ansistring;
function Base64_Encode(cStr: ansistring): ansistring;
type
T__mainForm = class(TForm)
procedure FormActivate(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure WMHotKey(var Msg: TMessage); message WM_HOTKEY;
procedure ReceiveMessage(var Msg: TMessage); message WM_COPYDATA;
end;
var
__mainForm: T__mainForm;
selfScript: string = '';
selfMD5Hash: string;
selfEnabled: boolean = False;
dllPHPPath: string = '';
selfModules: TStringList;
selfModulesMD5: TStringList;
selfModulesHash: string;
selfPHP5tsMD5: string;
selfPHP5tsSize: integer;
implementation
uses uMain, uPHPMod;
{$R *.dfm}
function Base64_Decode(cStr: ansistring): ansistring;
const
Base64Table =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
var
ResStr: ansistring;
DecStr: ansistring;
RecodeLine: array[1..76] of byte;
f1: word;
l: integer;
begin
Result := DecodeString(cStr);
exit;
l := length(cStr);
ResStr := '';
for f1 := 1 to l do
if cStr[f1] = '=' then
RecodeLine[f1] := 0
else
RecodeLine[f1] := pos(cStr[f1], Base64Table) - 1;
f1 := 1;
while f1 < length(cStr) do
begin
DecStr := chr(byte(RecodeLine[f1] shl 2) + RecodeLine[f1 + 1] shr 4) +
chr(byte(RecodeLine[f1 + 1] shl 4) + RecodeLine[f1 + 2] shr 2) +
chr(byte(RecodeLine[f1 + 2] shl 6) + RecodeLine[f1 + 3]);
ResStr := ResStr + DecStr;
Inc(f1, 4);
end;
Result := ResStr;
end;
function Base64_Encode(cStr: ansistring): ansistring;
begin
Result := EncodeString(cStr);
__mainForm.BringToFront;
end;
procedure T__mainForm.FormActivate(Sender: TObject);
var
f, s: string;
begin
if appShow then
exit;
appShow := True;
{$IFDEF LOAD_DS}
f := ExtractFilePath(ParamStr(0)) + 'system\include.pse';
{$ELSE}
f := ParamStr(1);
{$ENDIF}
if selfEnabled then
begin
if (xMD5(selfScript) = selfMD5Hash) then
begin
__fMain.Button1.Destroy;
__fMain.MainMenu.Destroy;
__fMain.b_Restart.Destroy;
__fMain.b_Run.Destroy;
__fMain.Memo1.Destroy;
__fMain.Width := 0;
__fMain.Height := 0;
__fMain.BorderStyle := bsNone;
phpMOD.RunCode(selfScript);
selfEnabled := True;
appShow := True;
//__fMain.Destroy;
end;
end
else if ExtractFileExt(f) = '.pse' then
begin
s := File2String(f);
phpMOD.RunCode(s);
end
else if ParamStr(1) <> '-run' then
begin
uPHPMod.SetAsMainForm(__fMain);
Application.ShowMainForm := True;
Application.MainFormOnTaskBar := True;
end
else
phpMOD.RunFile(ParamStr(2));
appShow := True;
end;
procedure T__mainForm.FormCreate(Sender: TObject);
var
f: string;
EM: TExeStream;
begin
Self.Left := -999;
{$IFDEF LOAD_DS}
f := ExtractFilePath(ParamStr(0)) + 'system\include.pse';
{$ELSE}
f := ParamStr(1);
{$ENDIF}
selfScript := '';
EM := TExeStream.Create(ParamStr(0));
progDir := ExtractFilePath(Application.ExeName);
moduleDir := progDir + 'ext\';
engineDir := progDir + 'engine\';
if DirectoryExists(progDir + 'core\') then
engineDir := progDir + 'core\';
selfScript := EM.ExtractToString('$PHPSOULENGINE\inc.php');
selfMD5Hash := EM.ExtractToString('$PHPSOULENGINE\inc.php.hash');
if (selfScript <> '') then
begin
//selfScript := myDecode(Base64_Decode(selfScript));
selfModulesHash := EM.ExtractToString('$PHPSOULENGINE\mods.hash');
if (xMD5(EM.ExtractToString('$PHPSOULENGINE\mods')) <>
selfModulesHash) then
begin
selfMD5Hash := '';
selfScript := '';
selfEnabled := True;
exit;
end;
selfModules := TStringList.Create;
selfModules.Text :=
StringReplace(EM.ExtractToString('$PHPSOULENGINE\mods'), ',',
#13, [rfReplaceAll]);
selfModulesMD5 := TStringList.Create;
selfModulesMD5.Text :=
StringReplace(EM.ExtractToString('$PHPSOULENGINE\mods_m'),
',', #13, [rfReplaceAll]);
selfPHP5tsMD5 := EM.ExtractToString('$PHPSOULENGINE\phpts.hash');
selfPHP5tsSize := StrToIntDef(EM.ExtractToString('$PHPSOULENGINE\phpts.size'), -1);
selfEnabled := True;
T__fMain.extractPHPEngine(EM);
end;
if (ExtractFileExt(f) = '.pse') and (selfScript = '') then
begin
if Pos(':', F) > 0 then
progDir := ExtractFilePath(f)
else
progDir := progDir + ExtractFilePath(f);
end
else if selfScript <> '' then
progDir := ExtractFilePath(ParamStr(0))
else if f <> '' then
progDir := ExtractFilePath(f);
end;
procedure T__mainForm.ReceiveMessage(var Msg: TMessage);
var
pcd: PCopyDataStruct;
s: ansistring;
begin
pcd := PCopyDataStruct(Msg.LParam);
s := PChar(pcd.lpData);
phpMOD.RunCode('Receiver::event(' + IntToStr(Msg.WParam) + ',''' +
AddSlashes(s) + ''');');
end;
procedure T__mainForm.WMHotKey(var Msg: TMessage);
var
idHotKey: integer;
fuModifiers: word;
uVirtKey: word;
begin
idHotkey := Msg.wParam;
fuModifiers := LOWORD(Msg.lParam);
uVirtKey := HIWORD(Msg.lParam);
phpMOD.RunCode('HotKey::event(' + IntToStr(fuModifiers) + ',' +
IntToStr(uVirtKey) + ');');
inherited;
end;
end.