forked from dim-s/soulengine
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathExeMod.pas
More file actions
393 lines (337 loc) · 9.5 KB
/
ExeMod.pas
File metadata and controls
393 lines (337 loc) · 9.5 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
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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
unit ExeMod;
{
}
interface
uses
Windows, SysUtils, Classes, Forms, ShellAPI,
Dialogs, TypInfo, ZendTypes, ZLib, ZLibConst;
type
TExeStream = class(TObject)
private
SS: TStringStream;
FName: WideString;
_MainExeName: WideString;
FFileName: WideString;
function GetACount: Integer;
procedure SetFileName(const Value: WideString);
procedure Add2String(DemarcStr, String2Add: WideString);
public
constructor Create(FileName: WideString);
destructor Destroy;
procedure ReadData;
procedure AddStringToExe(Alias, Source: WideString);
procedure AddComponentToExe(Alias: WideString; OBJ: TComponent);
procedure AddStreamToExe(Alias: WideString; Stream: TStream);
procedure AddFileToExe(Alias, FileName: WideString);
procedure GetDemarcName(DNumber: Integer; var DName: WideString);
procedure AddFromStream(AName: WideString; AStream: TStream);
procedure AddFromFile(AName, AFileName: WideString);
procedure AddFromStrings(AName: WideString; AStrings: TStrings);
procedure AddFromString(AName, S: WideString);
procedure AttachToExe(ExeName: WideString);
procedure ExtractFromExe(DemarcStr: WideString; var ExtractedStr: WideString);
procedure String2File(FileName: zend_ustr);
function IndexOf(Name: WideString): Integer;
procedure SaveAsExe(FileName: WideString);
property FileName: WideString read FFileName write SetFileName;
function ExtractToString(AName: WideString): WideString; overload;
procedure ExtractToStrings(Alias: WideString; List: TStrings);
procedure ExtractToString(const Alias: WideString;
var Source: WideString); overload;
procedure ExtractToList(Alias: WideString; List: TStrings);
property AliasCount: Integer read GetACount;
procedure EraseAlias(Alias: WideString);
procedure ExtractToFile(Alias, FileName: WideString);
procedure ExtractToStream(Alias: WideString; Stream: TMemoryStream);
procedure Save;
end;
function File2String(FileName: zend_ustr): zend_ustr;
function Stream2String(b: TStream): zend_ustr; overload;
procedure Stream2String(b: TStream; var a: zend_ustr); overload;
procedure String2Stream(a: zend_ustr; b: TMemoryStream);
function WinDrv: char;
function getcnt: integer;
procedure String2File2(String2BeSaved, FileName: zend_ustr);
implementation
{ TExeStream }
var
EsCount: integer = 0;
function getcnt: integer;
begin
Result := EsCount;
end;
function WinDrv: char;
var
WinDir: WideString;
n: Integer;
begin
SetLength(WinDir, 256);
n := GetWindowsDirectory(PChar(WinDir), 256);
SetLength(WinDir, n);
Result := WinDir[1];
end;
procedure TExeStream.AddComponentToExe(Alias: WideString; OBJ: TComponent);
begin
ShowMessage('AddComponentToExe:' + Alias);
end;
procedure TExeStream.AddFileToExe(Alias, FileName: WideString);
begin
ShowMessage('AddFileToExe:' + Alias + '::' + FileName);
end;
procedure TExeStream.AddFromFile(AName, AFileName: WideString);
begin
ShowMessage('AddFromFile:' + AName + '::' + AFileName);
end;
procedure TExeStream.AddFromStream(AName: WideString; AStream: TStream);
begin
ShowMessage('AddFromStream:' + AName);
end;
procedure TExeStream.AddFromString(AName, S: WideString);
begin
ShowMessage('AddFromString:' + AName + '::' + S);
end;
procedure TExeStream.AddFromStrings(AName: WideString; AStrings: TStrings);
begin
ShowMessage('AddFromStrings:' + AName);
end;
procedure TExeStream.AddStreamToExe(Alias: WideString; Stream: TStream);
begin
ShowMessage('AddStreamToExe:' + Alias);
end;
constructor TExeStream.Create(FileName: WideString);
begin
inherited Create;
FName := FileName;
_MainExeName := FName;
inc(EsCount);
SS := TStringStream.Create;
SS.LoadFromFile(FileName);
end;
procedure TExeStream.String2File(FileName: zend_ustr);
begin
SetCurrentDir(ExtractFilePath(_MainExeName));
SS.SaveToFile(String(FileName));
end;
procedure TExeStream.Add2String(DemarcStr, String2Add: WideString);
var
DemarcStr2: string;
begin
DemarcStr2 := string(DemarcStr).ToUpper;
SS.Position := SS.Size;
SS.WriteString(WideString('SO!#' + DemarcStr2 + chr(182)) + String2Add +
WideString('EO!#' + DemarcStr2));
end;
procedure TExeStream.AddStringToExe(Alias, Source: WideString);
begin
Add2String(Alias, Source);
end;
procedure TExeStream.SaveAsExe(FileName: WideString);
begin
SS.SaveToFile(FileName);
end;
procedure TExeStream.AttachToExe(ExeName: WideString);
begin
ShowMessage('AttachToExe:' + ExeName);
end;
destructor TExeStream.Destroy;
begin
_MainExeName := '';
Dec(EsCount);
SS.Destroy;
inherited Destroy;
end;
procedure TExeStream.EraseAlias(Alias: WideString);
begin
ShowMessage('EraseAlias:' + Alias);
end;
procedure TExeStream
. ExtractFromExe(DemarcStr: WideString; var ExtractedStr: WideString);
var
d, e: Integer;
Exe, DemarcStr2: string;
rl: Integer;
begin
DemarcStr2 := string(DemarcStr).ToUpper;
Exe := SS.DataString;
rl := Pos('SO!#' + DemarcStr2 + chr(182), Exe);
if rl > 0 then
begin
d := rl + Length('SO!#' + DemarcStr2 + chr(182));
e := Pos('EO!#' + DemarcStr2, Exe);
ExtractedStr := Copy(Exe, d, e - d);
end;
end;
procedure TExeStream.ExtractToFile(Alias, FileName: WideString);
begin
ShowMessage('ExtractToFile:' + Alias + '::' + FileName);
end;
procedure TExeStream.ExtractToList(Alias: WideString; List: TStrings);
Var
S: WideString;
begin
ExtractFromExe(Alias, S);
List.Text := S;
Finalize(S);
end;
procedure TExeStream.ExtractToStream(Alias: WideString; Stream: TMemoryStream);
begin
ShowMessage('ExtractToStream:' + Alias);
end;
procedure TExeStream.Save;
begin
SaveAsExe(FName);
end;
procedure TExeStream.ExtractToString(const Alias: WideString;
var Source: WideString);
begin
ExtractFromExe(Alias, Source);
// ShowMessage('ExtractToString:' + Alias + '::' + Source);
end;
function TExeStream.ExtractToString(AName: WideString): WideString;
begin
Self.ExtractToString(AName, Result);
// ShowMessage('ExtractToString:' + AName);
end;
procedure TExeStream.ExtractToStrings(Alias: WideString; List: TStrings);
begin
ExtractToList(Alias, List);
end;
function TExeStream.GetACount: Integer;
var
Count, X: Integer;
Exe: string;
begin
Exe := SS.DataString;
Count := 0;
For X := 1 to Length(Exe) - 10 do
begin
If (Exe[X] = 'S') and (Exe[X + 1] = 'O') and (Exe[X + 2] = '!') and
(Exe[X + 3] = '#') then
begin
Inc(Count);
end;
end;
Result := Count;
end;
function PeekExeByte(Byte2Get: Integer): byte;
Begin
If Byte2Get < 1 then
Exit;
Result := byte(pointer(Hinstance + Byte2Get - 1)^);
End;
function PeekExeWord(Word2Get: Integer): word;
Begin
If Word2Get < 1 then
Exit;
Result := word(pointer(Hinstance + Word2Get - 1)^);
End;
procedure PeekExeString(StartByte, Count: Integer; var ReturnedStr: WideString);
var
X: Integer;
Begin
If StartByte < 1 then
Exit;
For X := StartByte to StartByte + Count - 1 do
begin
ReturnedStr := ReturnedStr + (Char(pointer(Hinstance + X - 1)^));
end;
End;
procedure TExeStream.GetDemarcName(DNumber: Integer; var DName: WideString);
var
Count, X, Y: Integer;
Exe: string;
begin
Count := 0;
Exe := SS.DataString;
For X := 1 to Length(Exe) - 10 do
begin
If (Exe[X] = 'S') and (Exe[X + 1] = 'O') and (Exe[X + 2] = '!') and
(Exe[X + 3] = '#') then
begin
Inc(Count);
If Count = DNumber then
begin
Y := X + 4;
While Exe[Y] <> chr(182) do
begin
DName := DName + Exe[Y];
Inc(Y);
end;
end;
end;
end;
end;
function TExeStream.IndexOf(Name: WideString): Integer;
Var
Len: Integer;
S: WideString;
begin
Len := AliasCount;
Name := string(Name).ToUpper;
for Result := 0 to Len - 1 do
begin
GetDemarcName(Result, S);
if string(S).ToUpper = Name then
Exit;
end;
Result := -1;
end;
procedure TExeStream.ReadData;
begin
ShowMessage('ReadData:');
end;
procedure TExeStream.SetFileName(const Value: WideString);
begin
ShowMessage('SetFileName:' + Value);
end;
procedure String2File2(String2BeSaved, FileName: zend_ustr);
var
MyStream: TMemoryStream;
begin
if String2BeSaved = '' then
Exit;
SetCurrentDir(ExtractFilePath(String(Filename)));
MyStream := TMemoryStream.Create;
try
MyStream.WriteBuffer(pointer(String2BeSaved)^, Length(String2BeSaved));
MyStream.SaveToFile(String(FileName));
finally
MyStream.Destroy;
end;
end;
procedure String2Stream(a: zend_ustr; b: TMemoryStream);
begin
b.Position := 0;
b.WriteBuffer(pointer(a)^, Length(a));
b.Position := 0;
end;
procedure Stream2String(b: TStream; var a: zend_ustr); overload;
begin
b.Position := 0;
SetLength(a, b.Size);
b.ReadBuffer(pointer(a)^, b.Size);
b.Position := 0;
end;
function Stream2String(b: TStream): zend_ustr; overload;
begin
Stream2String(b, Result);
end;
function File2String(FileName: zend_ustr): zend_ustr;
var
MyStream: TMemoryStream;
begin
MyStream := TMemoryStream.Create;
try
MyStream.LoadFromFile(String(FileName));
MyStream.Position := 0;
SetLength(Result, MyStream.Size);
MyStream.ReadBuffer(pointer(Result)^, MyStream.Size);
finally
MyStream.Destroy;
end;
end;
initialization
begin
SetCurrentDir(ExtractFilePath(ParamStr(0)));
end;
end.