-
-
Notifications
You must be signed in to change notification settings - Fork 100
/
Copy pathMSEdgeRedirect.au3
681 lines (601 loc) · 23.1 KB
/
MSEdgeRedirect.au3
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
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=Assets\MSEdgeRedirect.ico
#AutoIt3Wrapper_Outfile=MSEdgeRedirect_x86.exe
#AutoIt3Wrapper_Outfile_x64=MSEdgeRedirect.exe
#AutoIt3Wrapper_Compile_Both=y
#AutoIt3Wrapper_UseX64=y
#AutoIt3Wrapper_Res_Comment=https://www.msedgeredirect.com
#AutoIt3Wrapper_Res_CompanyName=Robert Maehl Software
#AutoIt3Wrapper_Res_Description=MSEdgeRedirect
#AutoIt3Wrapper_Res_Fileversion=0.7.5.3
#AutoIt3Wrapper_Res_ProductName=MSEdgeRedirect App & Service
#AutoIt3Wrapper_Res_ProductVersion=0.7.5.3
#AutoIt3Wrapper_Res_LegalCopyright=Robert Maehl, using LGPL 3 License
#AutoIt3Wrapper_Res_Language=1033
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#AutoIt3Wrapper_Res_Compatibility=Win8,Win81,Win10
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 -v1 -v2 -v3
#AutoIt3Wrapper_Run_Au3Stripper=y
#Au3Stripper_Parameters=/so
#AutoIt3Wrapper_Res_Icon_Add=Assets\MSEdgeRedirect.ico
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <Date.au3>
#include <Misc.au3>
#include <Array.au3>
#include <WinAPIHObj.au3>
#include <WinAPIProc.au3>
#include <WinAPIShPath.au3>
#include <EditConstants.au3>
#include <TrayConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include "Includes\_Logging.au3"
#include "Includes\_Theming.au3"
#include "Includes\_Security.au3"
#include "Includes\_Settings.au3"
#include "Includes\_Translation.au3"
#include "Includes\_URLModifications.au3"
#include "Includes\Base64.au3"
#include "Includes\ResourcesEx.au3"
Opt("TrayMenuMode", 3)
Opt("TrayAutoPause", 0)
Opt("GUICloseOnESC", 0)
#include "MSEdgeRedirect_Wrapper.au3"
SetupAppdata()
ProcessCMDLine()
Func ActiveMode(ByRef $aCMDLine)
Local $sCMDLine = ""
Local $sParent = _WinAPI_GetProcessName(_WinAPI_GetParentProcess())
$aCMDLine = FixTreeIntegrity($aCMDLine)
CheckEdgeIntegrity($aCMDLine[1])
$aCMDLine[1] = StringReplace($aCMDLine[1], "msedge.exe", "msedge_IFEO.exe")
Select
Case $aCMDLine[0] = 1 ; No Parameters
ContinueCase
Case $aCMDLine[0] = 2 And UBound($aCMDLine) < 2
ReDim $aCMDLine[3]
$aCMDLine[2] = ""
ContinueCase
Case $aCMDLine[0] = 2 And FileExists($aCMDLine[2])
ContinueCase
Case $aCMDLine[0] = 2 And $aCMDLine[2] = "--uninstall" ; Uninstalling Edge
ContinueCase
Case $aCMDLine[0] = 2 And $aCMDLine[2] = "--suspend-background-mode" ; Uninstalling Edge
ContinueCase
Case $aCMDLine[0] = 2 And $aCMDLine[2] = "--from-installer" ; Installing Edge
ContinueCase
Case $aCMDLine[0] = 2 And $aCMDLine[2] = "--inprivate" ; In Private Browsing, No Parameters
ContinueCase
Case _ArraySearch($aCMDLine, "--winrt-background-task-event", 2, 0, 0, 1) > 0 ; #94 & #95, Apps
ContinueCase
Case _ArraySearch($aCMDLine, "--web-widget-jumplist-launch", 2, 0, 0, 1) > 0 ; #123, EdgeBar
ContinueCase
Case _ArraySearch($aCMDLine, "--notification-launch-id", 2, 0, 0, 1) > 0 ; #225, Web App Notifications
ContinueCase
Case _ArraySearch($aCMDLine, "--app-id", 2, 0, 0, 1) > 0 And Not _GetSettingValue("NoApps")
ContinueCase
Case _ArraySearch($aCMDLine, "--remote-debugging-port=", 2, 0, 0, 1) > 0 ; #271, Debugging Apps
ContinueCase
Case _ArraySearch($aCMDLine, "--profile-directory=", 2, 0, 0, 1) > 0 ; #68, Multiple Profiles
ContinueCase
Case $sParent = "MSEdgeRedirect.exe"
$sCMDLine = _ArrayToString($aCMDLine, " ", 2, -1)
_SafeRun($aCMDLine[1], $sCMDLine)
Case $sParent = "BrowserSelect.exe" ; TODO: DOUBLE CHECK $aCMDLine[2]
ContinueCase
Case $sParent = "BrowserSelector.exe"
ContinueCase
Case $sParent = "Hurl.exe"
ContinueCase
Case $aCMDLine[0] = 2 And $aCMDLine[2] = "--continue-active-setup"
_SafeRun($aCMDLine[1], $aCMDLine[2])
Case _ArraySearch($aCMDLine, "localhost:", 2, 0, 0, 1) > 0 ; Improve on #162
ContinueCase
Case _ArraySearch($aCMDLine, "localhost/", 2, 0, 0, 1) > 0 ; Improve on #162
ContinueCase
Case _ArraySearch($aCMDLine, @ComputerName & ":", 2, 0, 0, 1) > 0 ; Improve on #162
ContinueCase
Case _ArraySearch($aCMDLine, @ComputerName & "/", 2, 0, 0, 1) > 0 ; Improve on #162
ContinueCase
Case _ArraySearch($aCMDLine, "127.0.0.1", 2, 0, 0, 1) > 0 ; #162
$sCMDLine = _ArrayToString($aCMDLine, " ", 2, -1)
FileWrite($hLogs[$URIFailures], _NowCalc() & " - Skipped Localhost URL: " & $sCMDLine & @CRLF)
Case Else
$sCMDLine = _ArrayToString($aCMDLine, " ", 2, -1)
_DecodeAndRun($aCMDLine[1], $sCMDLine)
EndSelect
EndFunc
Func CheckEdgeIntegrity($sLocation)
If StringInStr($sLocation, "ie_to_edge_stub") Then
;;;
ElseIf $sLocation = "" Then
Exit
Else
Select
Case Not FileExists(StringReplace($sLocation, "\msedge.exe", "\msedge_IFEO.exe"))
If WinExists(_Translate($aMUI[1], "Admin File Copy Required")) Then Exit ; #202
If MsgBox($MB_YESNO + $MB_ICONINFORMATION + $MB_TOPMOST, _
_Translate($aMUI[1], "Admin Rights Required"), _
_Translate($aMUI[1], "The IFEO junctions for MSEdgeRedirect are missing and need to be created. Create Now?"), _
0) = $IDYES Then ShellExecuteWait(@ScriptFullPath, "/repair", @ScriptDir, "RunAs")
If @error Then MsgBox($MB_ICONERROR+$MB_OK, _
"Copy Failed", _
"Unable to create the IFEO junction without Admin Rights!")
Case Else
;;;
EndSelect
EndIf
EndFunc
Func FixTreeIntegrity($aCMDLine)
Local $iParent = _WinAPI_GetParentProcess()
Switch _WinAPI_GetProcessName($iParent)
Case "MSEdge.exe"
FileWrite($hLogs[$AppGeneral], _NowCalc() & " - " & "Caught MSEdge Parent Process, Launched by " & _WinAPI_GetProcessName(_WinAPI_GetParentProcess($iParent)) & ", Grabbing Parameters." & @CRLF)
Local $aAdjust
; Enable "SeDebugPrivilege" privilege for obtain full access rights to another processes
Local $hToken = _WinAPI_OpenProcessToken(BitOR($TOKEN_ADJUST_PRIVILEGES, $TOKEN_QUERY))
_WinAPI_AdjustTokenPrivileges($hToken, $SE_DEBUG_NAME, $SE_PRIVILEGE_ENABLED, $aAdjust)
Redim $aCMDLine[2]
$aCMDLine[0] = 0
$aCMDLine[1] = _WinAPI_GetProcessFileName($iParent)
_ArrayConcatenate($aCMDLine, StringSplit(_WinAPI_GetProcessCommandLine($iParent), " ", $STR_NOCOUNT))
$aCMDLine[0] = UBound($aCMDLine) - 1
ProcessClose($iParent)
_WinAPI_CloseHandle($hToken)
Case Else
;;;
EndSwitch
Return $aCMDLine
EndFunc
Func ProcessCMDLine()
Local $aPIDs
Local $bHide = _GetSettingValue("NoTray")
Local $hFile = @ScriptDir & ".\Setup.ini"
Local $bForce = False
Local $iParams = $CmdLine[0]
Local $sCMDLine = _ArrayToString($CmdLine, " ", 1)
Local $bSilent = False
Local $aInstall[3]
Local $bPortable = False
$aInstall = _IsInstalled()
If DriveGetType(@ScriptDir) = "Removable" Then $bPortable = True
If $iParams > 0 Then
$CMDLine = RepairCMDLine($CMDLine)
If _ArraySearch($aEdges, $CMDLine[1]) > 0 Or StringInStr($CMDLine[1], "ie_to_edge_stub.exe") Then ; Image File Execution Options Mode
ActiveMode($CMDLine)
If Not _GetSettingValue("NoUpdates") And Random(1, 10, 1) = 1 Then RunUpdateCheck()
Exit
EndIf
Do
Switch $CmdLine[1]
Case "/?", "/help"
MsgBox(0, "Help and Flags", _
"MSEdgeRedirect" & @CRLF & _
@CRLF & _
@TAB & "/admin " & @TAB & "Attempts to run MSEdgeRedirect as admin" & @CRLF & _
@TAB & "/change " & @TAB & "Reruns Installer" & @CRLF & _
@TAB & "/hide " & @TAB & "Hides the tray icon" & @CRLF & _
@TAB & "/force " & @TAB & "Skips Safety Checks" & @CRLF & _
@TAB & "/kill " & @TAB & "Kills other MSEdgeRedirect processes" & @CRLF & _
@TAB & "/portable " & @TAB & "Runs MSEdgeRedirect in portable mode" & @CRLF & _
@TAB & "/repair " & @TAB & "Repairs IFEO directory junctions" & @CRLF & _
@TAB & "/settings " & @TAB & "Opens Settings Menu" & @CRLF & _
@TAB & "/si " & @TAB & "Runs a Silent Install" & @CRLF & _
@TAB & "/update " & @TAB & "Downloads the latest RELEASE (default) or DEV build" & @CRLF & _
@TAB & "/uninstall" & @TAB & "Uninstalls MSEdgeRedirect" & @CRLF & _
@CRLF & _
@CRLF)
Exit 0
Case "/admin"
If Not $bIsAdmin Then
ShellExecute(@ScriptFullPath, $sCMDLine, @ScriptDir, "RunAs")
Exit
Else
_ArrayDelete($CmdLine, 1)
EndIf
Case "/change"
RunSetup(True, $bSilent, 1)
Exit
Case "/ContinueActive"
If Not $bIsAdmin Then
MsgBox($MB_ICONERROR+$MB_OK, _
"Admin Required", _
"Unable to install Active Mode without Admin Rights!")
FileWrite($hLogs[$AppFailures], _NowCalc() & " - " & "Active Mode UAC Elevation Attempt Failed!" & @CRLF)
Exit
Else
RunSetup($aInstall[0], False, -2)
EndIf
Case "/ContinueEurope", "/SetEurope"
If Not $bIsAdmin Then
MsgBox($MB_ICONERROR+$MB_OK, _
"Admin Required", _
"Unable to Setup Europe Mode without Admin Rights!")
FileWrite($hLogs[$AppFailures], _NowCalc() & " - " & "Europe Mode UAC Elevation Attempt Failed!" & @CRLF)
Exit
Else
RunSetup($aInstall[0], False, -5)
EndIf
Case "/f", "/force"
$bForce = True
_ArrayDelete($CmdLine, 1)
Case "/h", "/hide"
$bHide = True
_ArrayDelete($CmdLine, 1)
Case "/kill"
$aPIDs = ProcessList(@ScriptName)
For $iLoop = 1 To $aPIDs[0][0] Step 1
If $aPIDs[$iLoop][1] <> @AutoItPID Then ProcessClose($aPIDs[$iLoop][1])
Next
Exit
Case "/p", "/portable"
$bPortable = True
_GetSettingValue("SetPortable")
_ArrayDelete($CmdLine, 1)
Case "/repair"
RunRepair()
Exit
Case "/settings"
If $bIsPriv Then
If Not $bIsAdmin Then
ShellExecute(@ScriptFullPath, "/settings", @ScriptDir, "RunAs")
Exit
EndIf
Else
$aPIDs = ProcessList(@ScriptName)
For $iLoop = 1 To $aPIDs[0][0] Step 1
If $aPIDs[$iLoop][1] <> @AutoItPID Then ProcessClose($aPIDs[$iLoop][1])
Next
EndIf
RunSetup(True, False, 2)
If Not $bIsPriv Then ShellExecute(@ScriptFullPath)
Exit
Case "/si", "/silentinstall"
$bSilent = True
Select
Case UBound($CmdLine) = 2
_ArrayDelete($CmdLine, 1)
Case UBound($CmdLine) > 2 And FileExists($CmdLine[2])
$hFile = $CmdLine[2]
_ArrayDelete($CmdLine, "1-2")
Case StringLeft($CmdLine[2], 1) = "/"
_ArrayDelete($CmdLine, 1)
Case Else
MsgBox(0, _
"Invalid", _
'Invalid file - "' & $CmdLine[2] & @CRLF)
Exit 87 ; ERROR_INVALID_PARAMETER
EndSelect
#cs
Case "/u", "/update"
Select
Case UBound($CmdLine) = 2
InetGet("https://fcofix.org/MSEdgeRedirect/releases/latest/download/MSEdgeRedirect.exe", @ScriptDir & "\MSEdgeRedirect_Latest.exe")
_ArrayDelete($CmdLine, 1)
Case UBound($CmdLine) > 2 And $CmdLine[2] = "dev"
InetGet("https://nightly.link/rcmaehl/MSEdgeRedirect/workflows/mser/main/mser.zip", @ScriptDir & "\MSEdgeRedirect_dev.zip")
_ArrayDelete($CmdLine, "1-2")
Case UBound($CmdLine) > 2 And $CmdLine[2] = "release"
InetGet("https://fcofix.org/MSEdgeRedirect/releases/latest/download/MSEdgeRedirect.exe", @ScriptDir & "\MSEdgeRedirect_Latest.exe")
_ArrayDelete($CmdLine, "1-2")
Case StringLeft($CmdLine[2], 1) = "/"
InetGet("https://fcofix.org/MSEdgeRedirect/releases/latest/download/MSEdgeRedirect.exe", @ScriptDir & "\MSEdgeRedirect_Latest.exe")
_ArrayDelete($CmdLine, 1)
Case Else
MsgBox(0, _
"Invalid", _
'Invalid release type - "' & $CmdLine[2] & "." & @CRLF)
Exit 87 ; ERROR_INVALID_PARAMETER
EndSelect
#ce
Case "/uninstall"
RunRemoval()
Exit
Case "/wingetinstall"
$bSilent = True
$hFile = "WINGET"
_ArrayDelete($CmdLine, 1)
Case "--MSEdgeRedirect"
FileWrite($hLogs[$PEBIAT], _NowCalc() & " - " & "Recursion Prevention Check Failed. " & @CRLF & _
"Commandline: " & _ArrayToString($CmdLine) & @CRLF & _
"Parent: " & _WinAPI_GetProcessName(_WinAPI_GetParentProcess()) & @CRLF)
_ArrayDelete($CmdLine, 1)
Case Else
FileWrite($hLogs[$PEBIAT], _NowCalc() & " - " & "Unexpected Commandline: " & _ArrayToString($CmdLine) & @CRLF)
If @Compiled Then ; support for running non-compiled script - mLipok
MsgBox(0, _
"Invalid", _
'Invalid parameter - "' & $CmdLine[1] & '".' & @CRLF)
Exit 87 ; ERROR_INVALID_PARAMETER
EndIf
EndSwitch
Until UBound($CmdLine) <= 1
Else
;;;
EndIf
If $hFile = "WINGET" Then
;;;
ElseIf Not $bForce Then
RunArchCheck($bSilent)
Else
;;;
EndIf
If Not $bPortable Then
Select
Case Not $aInstall[0] ; Not Installed
RunSetup(False, $bSilent, 0, $hFile)
Case _VersionCompare($sVersion, $aInstall[2]) ; Installed, Out of Date
Select
Case StringInStr($aInstall[1], "HKCU") ; Installed, Service Mode
RunSetup($aInstall[0], $bSilent, 0, $hFile)
Case StringInStr($aInstall[1], "HKLM") And Not $bIsAdmin And @Compiled; Installed, Active Mode, Not Admin
ShellExecute(@ScriptFullPath, $sCMDLine, @ScriptDir, "RunAs")
If @error Then
If Not $bSilent Then MsgBox($MB_ICONWARNING+$MB_OK, _
"Existing Active Mode Install", _
"Unable to update an existing Active Mode install without Admin Rights! The installer will continue however.")
ContinueCase
Else
Exit
EndIf
Case StringInStr($aInstall[1], "HKLM") ; Installed, Active Mode
RunSetup($aInstall[0], $bSilent, 0, $hFile)
EndSelect
Case StringInStr($aInstall[1], "HKCU") ; Installed, Up to Date, Service Mode
If @ScriptDir <> @LocalAppDataDir & "\MSEdgeRedirect" Then
RunSetup($aInstall[0], $bSilent, 0, $hFile)
;ShellExecute(@LocalAppDataDir & "\MSEdgeRedirect\MSEdgeRedirect.exe", "", @LocalAppDataDir & "\MSEdgeRedirect\")
Else
$aPIDs = ProcessList(@ScriptName)
For $iLoop = 1 To $aPIDs[0][0] Step 1
If $aPIDs[$iLoop][1] <> @AutoItPID Then
$bHide = False
ProcessClose($aPIDs[$iLoop][1])
EndIf
Next
EndIf
Case StringInStr($aInstall[1], "HKLM") And Not $bIsAdmin ; Installed, Up to Date, Active Mode, Not Admin
ShellExecute(@ScriptFullPath, $sCMDLine, @ScriptDir, "RunAs")
If @error Then
If Not $bSilent Then MsgBox($MB_ICONWARNING+$MB_OK, _
"Existing Active Mode Install", _
"Unable to update an existing Active Mode install without Admin Rights! The installer will continue however.")
ContinueCase
Else
Exit
EndIf
Case Else
RunSetup(True, $bSilent, 0, $hFile)
EndSelect
EndIf
RunHTTPCheck()
ReactiveMode($bHide)
EndFunc
Func ReactiveMode($bHide = False)
Local $aAdjust
Local $hMsg
; Enable "SeDebugPrivilege" privilege for obtain full access rights to another processes
Local $hToken = _WinAPI_OpenProcessToken(BitOR($TOKEN_ADJUST_PRIVILEGES, $TOKEN_QUERY))
_WinAPI_AdjustTokenPrivileges($hToken, $SE_DEBUG_NAME, $SE_PRIVILEGE_ENABLED, $aAdjust)
TrayCreateItem($sVersion)
TrayItemSetState(-1, $TRAY_DISABLE)
TrayCreateItem("")
Local $hSettings = TrayCreateItem("Settings")
Local $hDonate = TrayCreateItem("Donate")
TrayCreateItem("")
Local $hUpdate = TrayCreateItem("Check for Updates")
Local $hExit = TrayCreateItem("Exit")
If $bHide Then TraySetState($TRAY_ICONSTATE_HIDE)
Local $sRegex
Local $iSIHost = ProcessExists("sihost.exe")
Local $aProcessList
Local $sCommandline
If _GetSettingValue("NoApps") Then
$sRegex = "(?i).*(microsoft\-edge|app\-id).*"
Else
$sRegex = "(?i).*(microsoft\-edge).*"
EndIf
While True
$hMsg = TrayGetMsg()
$aProcessList = _WinAPI_EnumChildProcess($iSIHost)
If @error Then
$aProcessList = ProcessList("msedge.exe")
For $iLoop = 1 To $aProcessList[0][0] - 1
$sCommandline = _WinAPI_GetProcessCommandLine($aProcessList[$iLoop][1])
If StringRegExp($sCommandline, $sRegex) Then
ProcessClose($aProcessList[$iLoop][1])
_DecodeAndRun(Default, $sCommandline)
EndIf
Next
Else
ProcessClose($aProcessList[1][0])
$sCommandline = _WinAPI_GetProcessCommandLine($aProcessList[1][0])
If StringRegExp($sCommandline, $sRegex) Then
_DecodeAndRun(Default, $sCommandline)
EndIf
EndIf
Switch $hMsg
Case $hSettings
ShellExecute(@ScriptFullPath, "/settings", @ScriptDir)
Case $hExit
ExitLoop
Case $hDonate
ShellExecute("https://paypal.me/rhsky")
Case $hUpdate
RunUpdateCheck(True)
Case Else
EndSwitch
WEnd
_WinAPI_AdjustTokenPrivileges($hToken, $aAdjust, 0, $aAdjust)
_WinAPI_CloseHandle($hToken)
For $iLoop = 0 To UBound($hLogs) - 1
FileClose($hLogs[$iLoop])
Next
Exit
EndFunc
Func RepairCMDLine($aCMDLine)
Local $sCMDLine
Local $sDelim = _ArraySafeDelim($aCMDLine)
$sCMDLine = _ArrayToString($aCMDLine, $sDelim)
Select
Case StringInStr($sCMDLine, "Program" & $sDelim & "Files" & $sDelim & "(x86)")
$sCMDLine = StringReplace($sCMDLine, "Program" & $sDelim & "Files" & $sDelim & "(x86)", "Program Files (x86)")
Case StringInStr($sCMDLine, $sDelim & "--" & $sDelim)
$sCMDLine = StringReplace($sCMDLine, "--" & $sDelim, "")
Case Else
;;;
EndSelect
$aCMDLine = StringSplit($sCMDLine, $sDelim, $STR_ENTIRESPLIT+$STR_NOCOUNT)
$aCMDLine[0] = UBound($aCMDLine) - 1
Return $aCMDLine
EndFunc
Func RunArchCheck($bSilent = False)
If @Compiled And $bIsWOW64 Then
If Not $bSilent Then
MsgBox($MB_ICONERROR+$MB_OK, _
"Wrong Version", _
"The 64-bit Version of MSEdgeRedirect must be used with 64-bit Windows!")
EndIf
FileWrite($hLogs[$AppFailures], _NowCalc() & " - " & "32 Bit Version on 64 Bit System. EXITING!" & @CRLF)
For $iLoop = 0 To UBound($hLogs) - 1
FileClose($hLogs[$iLoop])
Next
Exit 216 ; ERROR_EXE_MACHINE_TYPE_MISMATCH
EndIf
EndFunc
Func RunHTTPCheck($bSilent = False)
Local $aDefaults[3]
Local Enum $hHTTP, $hHTTPS, $hMSEdge
$aDefaults[$hHTTP] = RegRead("HKCU\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice", "ProgId")
If @error Then Return
$aDefaults[$hHTTPS] = RegRead("HKCU\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\https\UserChoice", "ProgId")
If @error Then Return
$aDefaults[$hMSEdge] = RegRead("HKCU\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\microsoft-edge\UserChoice", "ProgId")
If @error Then Return
If StringInStr($aDefaults[$hMSEdge], "MSEdge") Then
If $aDefaults[$hHTTP] = $aDefaults[$hMSEdge] Or $aDefaults[$hHTTPS] = $aDefaults[$hMSEdge] Then
If Not $bSilent Then
MsgBox($MB_ICONERROR+$MB_OK, _
"Edge Set As Default", _
"You must set a different Default Browser to use MSEdgeRedirect!")
EndIf
FileWrite($hLogs[$AppFailures], _NowCalc() & " - " & "Found same MS Edge for both default browser and microsoft-edge handling, EXITING!" & @CRLF)
For $iLoop = 0 To UBound($hLogs) - 1
FileClose($hLogs[$iLoop])
Next
Exit 4315 ; ERROR_MEDIA_INCOMPATIBLE
EndIf
EndIf
EndFunc
Func _DecodeAndRun($sEdge = $aEdges[1], $sCMDLine = "")
Local $sURL = ""
Local $aCMDLine
Select
Case StringRegExp($sCMDLine, "--default-search-provider=\? --out-pipe-name=MSEdgeDefault[a-z0-9]+")
FileWrite($hLogs[$AppSecurity], _NowCalc() & " - Passed Through MS-Settings Call: " & $sCMDLine & @CRLF)
_SafeRun($sEdge, $sCMDLine)
Case StringInStr($sCMDLine, "--default-search-provider=?")
FileWrite($hLogs[$URIFailures], _NowCalc() & " - Blocked Invalid MS-Settings Call: " & $sCMDLine & @CRLF)
Case StringInStr($sCMDLine, "profiles_settings")
FileWrite($hLogs[$URIFailures], _NowCalc() & " - Skipped Profile Settings URL: " & $sCMDLine & @CRLF)
Case StringInStr($sCMDLine, ".pdf")
If _GetSettingValue("NoPDFs") Then
$sCMDLine = StringReplace($sCMDLine, "--single-argument ", "")
Switch _GetSettingValue("PDFApp")
Case "Default", False
If RunPDFCheck() And _IsSafePDF($sCMDLine) Then ShellExecute('"' & $sCMDLine & '"')
Case Else
ShellExecute(_GetSettingValue("PDFApp"), '"' & $sCMDLine & '"')
EndSwitch
Else
$sCMDLine = StringReplace($sCMDLine, "--single-argument ", "")
_SafeRun($sEdge, $sCMDLine)
If Not _IsPriviledgedInstall() Then Sleep(1000)
EndIf
Case StringInStr($sCMDLine, "--app-id")
Select
Case StringInStr($sCMDLine, "--app-fallback-url=") And _GetSettingValue("NoApps"); Windows Store "Apps"
$sCMDLine = StringRegExpReplace($sCMDLine, "(?i)(.*)(--app-fallback-url=)", "")
$sCMDLine = StringRegExpReplace($sCMDLine, "(?i)(?= --)(.*)", "")
If _IsSafeURL($sCMDLine) Then
ShellExecute($sCMDLine)
Else
FileWrite($hLogs[$URIFailures], _NowCalc() & " - Invalid App URL: " & $sCMDLine & @CRLF)
EndIf
Case StringInStr($sCMDLine, "--ip-aumid=") ; Edge "Apps"
If _IsSafeApp($sCMDLine) Then
_SafeRun($sEdge, $sCMDLine)
Else
FileWrite($hLogs[$URIFailures], _NowCalc() & " - Invalid App URL: " & $sCMDLine & @CRLF)
EndIf
Case Else
FileWrite($hLogs[$URIFailures], _NowCalc() & " - Invalid App URL: " & $sCMDLine & @CRLF)
EndSelect
Case StringInStr($sCMDLine, "ux=copilot")
If _GetSettingValue("NoPilot") Then
ShellExecute("ms-settings:")
Else
_SafeRun($sEdge, $sCMDLine)
EndIf
Case StringInStr($sCMDLine, "bing.com/chat") Or StringInStr($sCMDLine, "bing.com%2Fchat") ; Fix BingAI
If _GetSettingValue("NoChat") Then
ContinueCase
Else
_SafeRun($sEdge, $sCMDLine)
EndIf
Case StringInStr($sCMDLine, "bing.com/spotlight?spotlightid") ; Fix Windows Spotlight
$sCMDLine = StringRegExpReplace($sCMDLine, "(?i)spotlight\?spotlightid=[^&]+&", "search?")
ContinueCase
Case StringInStr($sCMDLine, "&url=") ; Fix Windows 11 Widgets
ContinueCase
Case StringInStr($sCMDLine, "microsoft-edge:")
$aCMDLine = _CMDLineDecode($sCMDLine)
For $iLoop = 0 To Ubound($aCMDLine) - 1 Step 1
If $aCMDLine[$iLoop][0] = "url" Then
$sURL = $aCMDLine[$iLoop][1]
ExitLoop
EndIf
Next
If $sURL = "" Then
FileWrite($hLogs[$URIFailures], _NowCalc() & " - Command Line Missing Needed Parameters: " & $sCMDLine & @CRLF)
Else
FileWrite($hLogs[$AppGeneral], _NowCalc() & " - Caught Valid URI Call:" & @CRLF & _ArrayToString($aCMDLine, ": ") & @CRLF)
If _IsSafeURL($sURL) Then
$sURL = _ModifyURL($sURL)
ShellExecute($sURL)
Else
FileWrite($hLogs[$URIFailures], _NowCalc() & " - Invalid URL: " & $sCMDLine & @CRLF)
EndIf
EndIf
Case StringLeft($sCMDLine, 2) = "--"
If _GetSettingValue("RunUnsafe") Then
_SafeRun($sEdge, $sCMDLine)
Else
FileWrite($hLogs[$AppSecurity], _NowCalc() & " - " & "Blocked Unsafe Flag: " & $sCMDLine & @CRLF)
EndIf
Case Else
$sCMDLine = StringRegExpReplace($sCMDLine, "(?i)(.*) microsoft-edge:[\/]*", "") ; Legacy Installs
$sCMDLine = StringReplace($sCMDLine, "?url=", "")
If StringInStr($sCMDLine, "%2F") Then $sCMDLine = _WinAPI_UrlUnescape($sCMDLine)
FileWrite($hLogs[$AppGeneral], _NowCalc() & " - Caught Other Edge Call:" & @CRLF & $sCMDLine & @CRLF)
If _IsSafeURL($sCMDLine) Then
$sCMDLine = _ModifyURL($sCMDLine)
ShellExecute($sCMDLine)
Else
FileWrite($hLogs[$URIFailures], _NowCalc() & " - Invalid URL: " & $sCMDLine & @CRLF)
EndIf
EndSelect
EndFunc
Func _GetDefaultBrowser()
Local $sProg
Local Static $sBrowser
If $sBrowser <> "" Then
;;;
Else
$sProg = RegRead("HKCU\SOFTWARE\Microsoft\Windows\Shell\Associations\UrlAssociations\https\UserChoice", "ProgID")
$sBrowser = RegRead("HKCR\" & $sProg & "\shell\open\command", "")
$sBrowser = StringReplace($sBrowser, "%1", "")
EndIf
Return $sBrowser
EndFunc