-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAntiWebalta.pas
362 lines (312 loc) · 9.45 KB
/
AntiWebalta.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
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
{
This unit is part of Webalta Killer project (webaltakiller.ru)
Author: Georgiy Kuznetsov ([email protected])
License: LGPL
}
unit AntiWebalta;
interface
uses Classes;
procedure KillWebalta();
var
LogStrs: TStrings = nil;
implementation
uses SysUtils, StrUtils, Windows, ShlObj, ComOBJ, ActiveX, Registry, SHFolder;
procedure LogMessage(s: string);
begin
if Assigned(LogStrs) then
LogStrs.Add(s);
end;
function myDeleteFile(dirname: string):boolean;
begin
if (FileExists(dirname)) then begin
DeleteFile(PWideChar(dirname));
LogMessage('Ôàéë '+dirname+' óäàëåí');
end;
end;
function RemoveFullDir(dirname: string):boolean;
var
SR: TSearchRec;
Found: Boolean;
begin
if not DirectoryExists(dirname) then begin
Result := true;
exit;
end;
Result := true;
Found := FindFirst(dirname+'\*', faAnyFile, SR) = 0;
while Found do begin
if (SR.Attr and faDirectory) = faDirectory then begin
if (SR.Name <> '.') and (SR.Name <> '..') then begin
Result := Result and RemoveFullDir(dirname +'\'+ SR.Name);
end;
end else begin
result := Result and myDeleteFile(dirname +'\'+ SR.Name);
end;
Found := (FindNext(SR) = 0);
end;
Found := RemoveDirectory(PWideChar(dirname));
result := Result and Found;
end;
function GetSpecialFolderPath(folder : integer) : string;
const
SHGFP_TYPE_CURRENT = 0;
var
path: array [0..MAX_PATH] of char;
begin
if SUCCEEDED(SHGetFolderPath(0, folder, 0, SHGFP_TYPE_CURRENT, @path[0])) then
Result := path
else
Result := '';
end;
procedure CleanClsId(Reg: TRegistry; Key: string);
var
KeyPrefix, CurVal: string;
SLKeys: TStrings;
RegKeys: TStrings;
i: integer;
begin
LogMessage('Ïîèñê çàðàæåííûõ êëþ÷åé ðååñòðà â:'#13#10+Key);
RegKeys := TStringList.Create();
RegKeys.Add(Key);
while (RegKeys.Count > 0) do begin
reg.OpenKey(RegKeys[0],false);
if (RegKeys[0] = '') then begin
KeyPrefix := '';
end else begin
KeyPrefix := RegKeys[0]+'\';
end;
SLKeys := TStringList.Create;
reg.GetKeyNames(SLKeys);
for i := 0 to SLKeys.Count-1 do begin
RegKeys.Add(KeyPrefix+SLKeys[i]);
end;
SLKeys.Destroy;
if (Reg.GetDataType('Assembly') = rdString) then begin
CurVal := Reg.GetDataAsString('Assembly');
if (PosEx('WebAltaSearch,',CurVal) > 0) then begin
LogMessage(RegKeys[0]);
Reg.DeleteValue('Assembly');
end;
end;
reg.CloseKey();
RegKeys.Delete(0);
end;
end;
procedure FixIE();
var
Reg: TRegistry;
SL: TStringList;
ShitKey: string;
i:integer;
begin
LogMessage('Î÷èùàåì áðàóçåð IE');
Reg := TRegistry.Create();
Reg.RootKey := HKEY_CURRENT_USER;
if (Reg.OpenKey('Software\Microsoft\Internet Explorer\Main',false)) then begin
Reg.WriteString('Default_Search_URL','http://go.microsoft.com/fwlink/?LinkId=54896');
Reg.WriteString('Search Page','http://go.microsoft.com/fwlink/?LinkId=54896');
Reg.WriteString('Search Bar','http://go.microsoft.com/fwlink/?LinkId=54896');
Reg.CloseKey;
end;
if (Reg.OpenKey('Software\Microsoft\Internet Explorer\Search',false)) then begin
Reg.WriteString('SearchAssistant','http://ya.ru/');
Reg.CloseKey;
end;
SL := TStringList.Create;
if (Reg.OpenKey('Software\Microsoft\Internet Explorer\SearchScopes',false)) then begin
Reg.GetKeyNames(SL);
Reg.CloseKey;
for i := 0 to SL.Count-1 do begin
Reg.OpenKey('Software\Microsoft\Internet Explorer\SearchScopes\'+SL[i],false);
ShitKey := Reg.ReadString('URL');
Reg.CloseKey;
if (PosEx('webalta.ru',ShitKey) > 0) then break;
ShitKey := '';
end;
if (ShitKey <> '') then begin
Reg.DeleteKey('Software\Microsoft\Internet Explorer\SearchScopes\'+SL[i]);
end;
end;
SL.Destroy;
Reg.Destroy();
end;
function FixFirefoxProfile(profiledir: string):boolean;
var
SL: TStringList;
i: integer;
begin
myDeleteFile(profiledir+'\searchplugins\webalta-search.xml');
myDeleteFile(profiledir+'\extensions\{4933189D-C7F7-4C6E-834B-A29F087BFD23}.xpi');
myDeleteFile(profiledir+'\extensions\staged\{4933189D-C7F7-4C6E-834B-A29F087BFD23}.json');
myDeleteFile(profiledir+'\extensions\staged\{4933189D-C7F7-4C6E-834B-A29F087BFD23}.xpi');
SL := TStringList.Create;
if (FileExists(profiledir+'\prefs.js')) then begin
SL.LoadFromFile(profiledir+'\prefs.js');
for i := 0 to SL.Count-1 do begin
if (PosEx('http://home.webalta.ru',SL[i]) > 0) then begin
SL[i] := ReplaceStr(SL[i],'http://home.webalta.ru','about:home');
break;
end;
end;
SL.SaveToFile(profiledir+'\prefs.js');
end;
SL.Destroy();
result := true;
end;
function FixFirefox():boolean;
var
SR: TSearchRec;
Found: Boolean;
FoxDir: string;
begin
LogMessage('Î÷èùàåì áðàóçåð Firefox');
FoxDir := GetSpecialFolderPath(CSIDL_APPDATA)+'\Mozilla\Firefox\Profiles';
Found := FindFirst(FoxDir+'\*', faDirectory, SR) = 0;
while Found do begin
if (SR.Name <> '.') and (SR.Name <> '..') then begin
FixFirefoxProfile(FoxDir+'\'+SR.Name);
end;
Found := (FindNext(SR) = 0);
end;
result := true;
end;
function FixOpera():boolean;
var
SL: TStringList;
i: integer;
operadir: string;
begin
LogMessage('Î÷èùàåì áðàóçåð Opera');
operadir := GetSpecialFolderPath(CSIDL_APPDATA)+'\Opera\Opera';
myDeleteFile(operadir+'\widgets\webalta.oex');
SL := TStringList.Create;
if (FileExists(operadir+'\operaprefs.ini')) then begin
LogMessage('Èñïðàâëÿåì ôàéë operaprefs.ini');
SL.LoadFromFile(operadir+'\operaprefs.ini');
for i := 0 to SL.Count-1 do begin
if (PosEx('http://home.webalta.ru/?new',SL[i]) > 0) then begin
SL[i] := ReplaceStr(SL[i],'http://home.webalta.ru/?new','http://yandex.ru');
break;
end;
end;
SL.SaveToFile(operadir+'\operaprefs.ini');
end;
LogMessage('Èñïðàâëÿåì ôàéë search.ini');
if (FileExists(operadir+'\search.ini')) then begin
SL.LoadFromFile(operadir+'\search.ini');
for i := 0 to SL.Count-1 do begin
SL[i] := ReplaceStr(SL[i],'http://webalta.ru/srch?q=%s','http://yandex.ru/yandsearch?text=%s&lr=2');
SL[i] := ReplaceStr(SL[i],'webalta Search','Yandex');
end;
SL.SaveToFile(operadir+'\search.ini');
end;
SL.Destroy();
operadir := GetSpecialFolderPath(CSIDL_LOCAL_APPDATA)+'\Opera\Opera';
myDeleteFile(operadir+'\widgets\webalta.oex');
end;
procedure DelUninstaller();
var
s: string;
Reg: TRegistry;
begin
LogMessage('Óäàëÿåì "äåíèñòàëÿöèþ" Webalta');
s := GetSpecialFolderPath(CSIDL_LOCAL_APPDATA);
RemoveFullDir(s+'\Webalta Toolbar');
Reg := TRegistry.Create();
Reg.RootKey := HKEY_CURRENT_USER;
Reg.DeleteKey('Software\Microsoft\Windows\CurrentVersion\Uninstall\Webalta Toolbar');
Reg.Destroy();
end;
function FixLink(LinkFileName: string): boolean;
var
MyObject: IUnknown;
MySLink: IShellLink;
MyPFile: IPersistFile;
WidePath: array[0..MAX_PATH] of WideChar;
Buff: array[0..MAX_PATH] of WideChar;
begin
result := false;
if (fileexists(Linkfilename) = false) then
exit;
MyObject := CreateComObject(CLSID_ShellLink);
MyPFile := MyObject as IPersistFile;
MySLink := MyObject as IShellLink;
StringToWideChar(LinkFileName, WidePath, SizeOf(WidePath));
MyPFile.Load(WidePath, 0);
MySLink.GetArguments(Buff, MAX_PATH);
if (PosEx('webalta.ru',Buff) > 0) then begin
Buff := '';
MySLink.SetArguments(Buff);
MyPFile.Save(WidePath,false);
result := true;
end;
end;
procedure ClearLinks(dirname: string);
var
SR: TSearchRec;
Found: Boolean;
begin
if not DirectoryExists(dirname) then begin
exit;
end;
LogMessage('Ñêàíèðóåì ÿðëûêè â'#13#10+dirname);
Found := FindFirst(dirname+'\*.lnk', faNormal, SR) = 0;
while Found do begin
if FixLink(dirname+'\'+SR.Name) then
LogMessage('ßðëûê '+SR.Name+' èñöåëåí');
Found := (FindNext(SR) = 0);
end;
end;
procedure WebaltaRegScanKeys(Reg: TRegistry; Key: string; RegKeys: TStrings; ValueNames: TStrings);
var
KeyPrefix, CurVal: string;
SLKeys, SLValsNames: TStrings;
i: integer;
begin
reg.OpenKey(Key,false);
if (Key = '') then begin
KeyPrefix := ''
end else begin
KeyPrefix := Key+'\'
end;
SLKeys := TStringList.Create;
reg.GetKeyNames(SLKeys);
for i := 0 to SLKeys.Count-1 do begin
RegKeys.Add(KeyPrefix+SLKeys[i]);
end;
SLKeys.Destroy;
SLValsNames := TStringList.Create;
reg.GetValueNames(SLValsNames);
ValueNames.Clear();
for i := 0 to SLValsNames.Count-1 do begin
if (Reg.GetDataType(SLValsNames[i]) = rdString) then begin
CurVal := LowerCase(Reg.GetDataAsString(SLValsNames[i]));
if (PosEx('webalta',CurVal) > 0) then begin
ValueNames.Add(SLValsNames[i]);
end;
end;
end;
SLValsNames.Destroy;
reg.CloseKey();
end;
procedure KillWebalta;
var
reg: TRegistry;
begin
reg := TRegistry.Create();
reg.RootKey := HKEY_LOCAL_MACHINE;
CleanClsId(reg,'SOFTWARE\Classes\CLSID');
CleanClsId(reg,'SOFTWARE\Classes\Record');
reg.Destroy();
FixIE();
FixFirefox();
FixOpera();
DelUninstaller();
ClearLinks(GetSpecialFolderPath(0));
ClearLinks(GetSpecialFolderPath(CSIDL_APPDATA)+'\Microsoft\Internet Explorer\Quick Launch');
ClearLinks(GetSpecialFolderPath(CSIDL_APPDATA)+'\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar');
ClearLinks(GetSpecialFolderPath(CSIDL_COMMON_DESKTOPDIRECTORY));
ClearLinks(GetSpecialFolderPath(CSIDL_COMMON_APPDATA)+'\Microsoft\Internet Explorer\Quick Launch');
ClearLinks(GetSpecialFolderPath(CSIDL_COMMON_APPDATA)+'\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar');
end;
end.