Skip to content

Commit

Permalink
Merge pull request #314 from rcmaehl/0.8.0.0-dev
Browse files Browse the repository at this point in the history
0.7.5.0
  • Loading branch information
rcmaehl authored Sep 27, 2023
2 parents d937df5 + 3c043d7 commit e4971af
Show file tree
Hide file tree
Showing 5 changed files with 191 additions and 135 deletions.
5 changes: 3 additions & 2 deletions Includes/_Logging.au3
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
#include <Date.au3>
#include <FileConstants.au3>

Global $hLogs[5] = _
Global $hLogs[6] = _
[FileOpen(@LocalAppDataDir & "\MSEdgeRedirect\logs\AppFailures.log", $FO_APPEND), _
FileOpen(@LocalAppDataDir & "\MSEdgeRedirect\logs\AppGeneral.log", $FO_APPEND), _
FileOpen(@LocalAppDataDir & "\MSEdgeRedirect\logs\AppSecurity.log", $FO_APPEND), _
FileOpen(@LocalAppDataDir & "\MSEdgeRedirect\logs\Install.log", $FO_APPEND), _
FileOpen(@LocalAppDataDir & "\MSEdgeRedirect\logs\PEBIAT.log", $FO_APPEND), _
FileOpen(@LocalAppDataDir & "\MSEdgeRedirect\logs\URIFailures.log", $FO_APPEND)]

Global Enum $AppFailures, $AppGeneral, $AppSecurity, $PEBIAT, $URIFailures
Global Enum $AppFailures, $AppGeneral, $AppSecurity, $Install, $PEBIAT, $URIFailures

Func _Log($hLog, $sMsg)

Expand Down
89 changes: 48 additions & 41 deletions Includes/_Settings.au3
Original file line number Diff line number Diff line change
Expand Up @@ -53,50 +53,57 @@ Func _GetSettingValue($sSetting)
Local $vReturn = Null
Local Static $bPortable

If $sSetting = "SetPortable" Then $bPortable = True

Select
Switch $sSetting
Case "PerUser"
$vReturn = Number(RegRead("HKLM\SOFTWARE\Policies\Robert Maehl Software\MSEdgeRedirect", "PerUser"))
Case "RunUnsafe"
$vReturn = Number(RegRead("HKLM\SOFTWARE\Policies\Robert Maehl Software\MSEdgeRedirect", "RunUnsafe"))
Case "SetPortable"
$bPortable = True
Case Else
Select

Case RegRead("HKLM\SOFTWARE\Policies\Robert Maehl Software\MSEdgeRedirect", $sSetting)
Switch @extended
Case $REG_SZ Or $REG_EXPAND_SZ
$vReturn = RegRead("HKLM\SOFTWARE\Policies\Robert Maehl Software\MSEdgeRedirect", $sSetting)
Case $REG_DWORD Or $REG_QWORD
$vReturn = Number(RegRead("HKLM\SOFTWARE\Policies\Robert Maehl Software\MSEdgeRedirect", $sSetting))
Case Else
FileWrite($hLogs[$AppFailures], _NowCalc() & " - Invalid Registry Key Type: " & $sSetting & @CRLF)
EndSwitch

Case RegRead("HKLM\SOFTWARE\Robert Maehl Software\MSEdgeRedirect", $sSetting) And Not $bPortable
Switch @extended
Case $REG_SZ Or $REG_EXPAND_SZ
$vReturn = RegRead("HKLM\SOFTWARE\Robert Maehl Software\MSEdgeRedirect", $sSetting)
Case $REG_DWORD Or $REG_QWORD
$vReturn = Number(RegRead("HKLM\SOFTWARE\Robert Maehl Software\MSEdgeRedirect", $sSetting))
Case Else
FileWrite($hLogs[$AppFailures], _NowCalc() & " - Invalid Registry Key Type: " & $sSetting & @CRLF)
EndSwitch

Case RegRead("HKCU\SOFTWARE\Robert Maehl Software\MSEdgeRedirect", $sSetting) And Not $bPortable
Switch @extended
Case $REG_SZ Or $REG_EXPAND_SZ
$vReturn = RegRead("HKCU\SOFTWARE\Robert Maehl Software\MSEdgeRedirect", $sSetting)
Case $REG_DWORD Or $REG_QWORD
$vReturn = Number(RegRead("HKCU\SOFTWARE\Robert Maehl Software\MSEdgeRedirect", $sSetting))
Case Else
FileWrite($hLogs[$AppFailures], _NowCalc() & " - Invalid Registry Key Type: " & $sSetting & @CRLF)
EndSwitch

Case Not IniRead(@LocalAppDataDir & "\MSEdgeRedirect\Settings.ini", "Settings", $sSetting, Null) = Null And Not $bPortable
$vReturn = _Bool(IniRead(@LocalAppDataDir & "\MSEdgeRedirect\Settings.ini", "Settings", $sSetting, False))

Case Not IniRead(@ScriptDir & "\MSEdgeRedirect\Settings.ini", "Settings", $sSetting, Null) = Null
$vReturn = _Bool(IniRead(@ScriptDir & "\MSEdgeRedirect\Settings.ini", "Settings", $sSetting, False))

Case RegRead("HKLM\SOFTWARE\Policies\Robert Maehl Software\MSEdgeRedirect", $sSetting)
Switch @extended
Case $REG_SZ Or $REG_EXPAND_SZ
$vReturn = RegRead("HKLM\SOFTWARE\Policies\Robert Maehl Software\MSEdgeRedirect", $sSetting)
Case $REG_DWORD Or $REG_QWORD
$vReturn = Number(RegRead("HKLM\SOFTWARE\Policies\Robert Maehl Software\MSEdgeRedirect", $sSetting))
Case Else
FileWrite($hLogs[$AppFailures], _NowCalc() & " - Invalid Registry Key Type: " & $sSetting & @CRLF)
EndSwitch

Case RegRead("HKLM\SOFTWARE\Robert Maehl Software\MSEdgeRedirect", $sSetting) And Not $bPortable
Switch @extended
Case $REG_SZ Or $REG_EXPAND_SZ
$vReturn = RegRead("HKLM\SOFTWARE\Robert Maehl Software\MSEdgeRedirect", $sSetting)
Case $REG_DWORD Or $REG_QWORD
$vReturn = Number(RegRead("HKLM\SOFTWARE\Robert Maehl Software\MSEdgeRedirect", $sSetting))
Case Else
FileWrite($hLogs[$AppFailures], _NowCalc() & " - Invalid Registry Key Type: " & $sSetting & @CRLF)
EndSwitch

Case RegRead("HKCU\SOFTWARE\Robert Maehl Software\MSEdgeRedirect", $sSetting) And Not $bPortable
Switch @extended
Case $REG_SZ Or $REG_EXPAND_SZ
$vReturn = RegRead("HKCU\SOFTWARE\Robert Maehl Software\MSEdgeRedirect", $sSetting)
Case $REG_DWORD Or $REG_QWORD
$vReturn = Number(RegRead("HKCU\SOFTWARE\Robert Maehl Software\MSEdgeRedirect", $sSetting))
Case Else
FileWrite($hLogs[$AppFailures], _NowCalc() & " - Invalid Registry Key Type: " & $sSetting & @CRLF)
EndSwitch

Case Not IniRead(@LocalAppDataDir & "\MSEdgeRedirect\Settings.ini", "Settings", $sSetting, Null) = Null And Not $bPortable
$vReturn = _Bool(IniRead(@LocalAppDataDir & "\MSEdgeRedirect\Settings.ini", "Settings", $sSetting, False))
$vReturn = False

Case Not IniRead(@ScriptDir & "\MSEdgeRedirect\Settings.ini", "Settings", $sSetting, Null) = Null
$vReturn = _Bool(IniRead(@ScriptDir & "\MSEdgeRedirect\Settings.ini", "Settings", $sSetting, False))

Case Else
$vReturn = False

EndSelect
EndSelect
EndSwitch

Return $vReturn

Expand Down
42 changes: 32 additions & 10 deletions Includes/_URLModifications.au3
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Func _ChangeNewsProvider($sURL)
"autos(\/enthusiasts)?" & _
"|comics" & _
"|companies" & _
"|health(\/other)" & _
"|medical" & _
"|news(\/crime|\/other|\/politics|\/us)?" & _
"|newsscienceandtechnology" & _
Expand Down Expand Up @@ -126,6 +127,9 @@ Func _ChangeSearchEngine($sURL)
Case "Google"
$sURL = "https://www.google.com/search?q=" & $sURL

Case "Lemmy"
$sURL = "https://search-lemmy.com/results?query=" & $sURL

Case "Sogou"
$sURL = "https://www.sogou.com/web?query=" & $sURL

Expand Down Expand Up @@ -288,28 +292,46 @@ Func _ModifyURL($sURL)

EndFunc

Func _RedirectCMDDecode($sCMDLine)
Func _CMDLineDecode($sCMDLine)

Local $aTemp
Local $aUrlMeta
Local $aCMDLine_1D
Local $aCMDLine_2D[0][0]

$sCMDLine = StringReplace($sCMDLine, "--single-argument ", "Method=Undefined&")
$sCMDLine = StringReplace($sCMDLine, "--edge-redirect", "Method")
If StringInStr($sCMDLine, "://") Then ; #211
$sCMDLine = StringReplace($sCMDLine, "&", "%26")
$sCMDLine = StringReplace($sCMDLine, "/", "%2F")
$sCMDLine = StringReplace($sCMDLine, "=", "%3D")
$sCMDLine = StringReplace($sCMDLine, "URL%3D", "URL=")
$sCMDLine = StringReplace($sCMDLine, "Method%3D", "Method=")

If StringInStr($sCMDLine, "?url=") Or StringInStr($sCMDLine, "&url=") Then
$sCMDLine = StringRegExpReplace($sCMDLine, "(?i)microsoft-edge:\??[\/]*", "&")
Else
$sCMDLine = StringRegExpReplace($sCMDLine, "(?i)microsoft-edge:\??[\/]*", "&url=")
EndIf
$sCMDLine = StringReplace($sCMDLine, "microsoft-edge:?", "&")
$sCMDLine = StringRegExpReplace($sCMDLine, "(?i)microsoft-edge:[\/]*", "&url=")
If StringInStr($sCMDLine, "?url=") Then $sCMDLine = StringReplace($sCMDLine, "?url", "url")

$sCMDLine = StringReplace($sCMDLine, "&&", "&")

;TODO: Add url=<url> somehow if "url=" doesn't exist. Method=<whatver> screws this up.

$aCMDLine_1D = StringSplit($sCMDLine, "&", $STR_NOCOUNT)
Redim $aCMDLine_2D[UBound($aCMDLine_1D)][2]
For $iLoop = 0 To UBound($aCMDLine_1D) - 1 Step 1
$aTemp = StringSplit($aCMDLine_1D[$iLoop], "=")
$aCMDLine_2D[$iLoop][0] = $aTemp[1]
If $aTemp[0] >= 2 Then $aCMDLine_2D[$iLoop][1] = $aTemp[2]
If $aTemp[0] >= 2 Then
Switch $aTemp[1]
Case "hubappsubpath"
$aTemp[2] = _WinAPI_UrlUnescape($aTemp[2])
Case "upn"
$aTemp[2] = _WinAPI_UrlUnescape($aTemp[2])
Case "url"
If StringInStr($aTemp[2], "%2F") Then $aTemp[2] = _WinAPI_UrlUnescape($aTemp[2])
If $aTemp[0] >= 3 Then $aTemp[2] = _ArrayToString($aTemp, "=", 2)
Case Else
;;;
EndSwitch
$aCMDLine_2D[$iLoop][1] = $aTemp[2]
EndIf
Next

Return $aCMDLine_2D
Expand Down
94 changes: 45 additions & 49 deletions MSEdgeRedirect.au3
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#AutoIt3Wrapper_Res_Comment=https://www.msedgeredirect.com
#AutoIt3Wrapper_Res_CompanyName=Robert Maehl Software
#AutoIt3Wrapper_Res_Description=MSEdgeRedirect
#AutoIt3Wrapper_Res_Fileversion=0.7.4.0
#AutoIt3Wrapper_Res_Fileversion=0.7.5.0
#AutoIt3Wrapper_Res_ProductName=MSEdgeRedirect App & Service
#AutoIt3Wrapper_Res_ProductVersion=0.7.4.0
#AutoIt3Wrapper_Res_ProductVersion=0.7.5.0
#AutoIt3Wrapper_Res_LegalCopyright=Robert Maehl, using LGPL 3 License
#AutoIt3Wrapper_Res_Language=1033
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
Expand Down Expand Up @@ -142,29 +142,34 @@ Func FixTreeIntegrity($aCMDLine)

Local $iParent = _WinAPI_GetParentProcess()

If _WinAPI_GetProcessName($iParent) = "MSEdge.exe" Then
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)
FileWrite($hLogs[$AppGeneral], _NowCalc() & " - " & "Caught MSEdge Parent Process, Launched by " & _WinAPI_GetProcessName(_WinAPI_GetParentProcess($iParent)) & ", Grabbing Parameters." & @CRLF)

Local $aAdjust
Local $aAdjust

; Enable "SeDebugPrivilege" privilege for obtain full access rights to another processes
Local $hToken = _WinAPI_OpenProcessToken(BitOR($TOKEN_ADJUST_PRIVILEGES, $TOKEN_QUERY))
; 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)
_WinAPI_AdjustTokenPrivileges($hToken, $SE_DEBUG_NAME, $SE_PRIVILEGE_ENABLED, $aAdjust)

Redim $aCMDLine[2]
$aCMDLine[0] = 0
$aCMDLine[1] = _WinAPI_GetProcessFileName($iParent)
Redim $aCMDLine[2]
$aCMDLine[0] = 0
$aCMDLine[1] = _WinAPI_GetProcessFileName($iParent)

_ArrayConcatenate($aCMDLine, StringSplit(_WinAPI_GetProcessCommandLine($iParent), " ", $STR_NOCOUNT))
_ArrayConcatenate($aCMDLine, StringSplit(_WinAPI_GetProcessCommandLine($iParent), " ", $STR_NOCOUNT))

$aCMDLine[0] = UBound($aCMDLine) - 1
$aCMDLine[0] = UBound($aCMDLine) - 1

ProcessClose($iParent)
ProcessClose($iParent)

EndIf
Case "MSEdgeRedirect.exe"

_SafeRun(StringReplace($aEdges[1], "msedge.exe", "msedge_IFEO.exe"), $aCMDLine[3])

EndSwitch
Return $aCMDLine

EndFunc
Expand All @@ -176,6 +181,7 @@ 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
Expand All @@ -189,7 +195,6 @@ Func ProcessCMDLine()
$CMDLine = RepairCMDLine($CMDLine)

If _ArraySearch($aEdges, $CMDLine[1]) > 0 Then ; Image File Execution Options Mode
RunHTTPCheck()
ActiveMode($CMDLine)
If Not _GetSettingValue("NoUpdates") And Random(1, 10, 1) = 1 Then RunUpdateCheck()
Exit
Expand All @@ -204,6 +209,7 @@ Func ProcessCMDLine()
@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 & _
Expand All @@ -224,6 +230,9 @@ Func ProcessCMDLine()
Case "/change"
RunSetup(True, $bSilent, 1)
Exit
Case "/f", "/force"
$bForce = True
_ArrayDelete($CmdLine, 1)
Case "/h", "/hide"
$bHide = True
_ArrayDelete($CmdLine, 1)
Expand Down Expand Up @@ -316,9 +325,10 @@ Func ProcessCMDLine()

If $hFile = "WINGET" Then
;;;
Else
ElseIf Not $bForce Then
RunArchCheck($bSilent)
RunHTTPCheck($bSilent)
Else
;;;
EndIf

If Not $bPortable Then
Expand Down Expand Up @@ -371,6 +381,7 @@ Func ProcessCMDLine()
RunSetup(True, $bSilent, 0, $hFile)
EndSelect
EndIf
RunHTTPCheck()
ReactiveMode($bHide)

EndFunc
Expand Down Expand Up @@ -540,7 +551,7 @@ Func _DecodeAndRun($sEdge = $aEdges[1], $sCMDLine = "")
$sCMDLine = StringReplace($sCMDLine, "--single-argument ", "")
Switch _GetSettingValue("PDFApp")
Case "Default"
If RunPDFCheck() And _IsSafePDF($sCMDLine) Then ShellExecute($sCMDLine)
If RunPDFCheck() And _IsSafePDF($sCMDLine) Then ShellExecute('"' & $sCMDLine & '"')
Case Else
ShellExecute(_GetSettingValue("PDFApp"), '"' & $sCMDLine & '"')
EndSwitch
Expand Down Expand Up @@ -568,49 +579,34 @@ Func _DecodeAndRun($sEdge = $aEdges[1], $sCMDLine = "")
Case Else
FileWrite($hLogs[$URIFailures], _NowCalc() & " - Invalid App URL: " & $sCMDLine & @CRLF)
EndSelect
Case StringInStr($sCMDLine, "bing.com/chat") ; Fix BingAI
If _GetSettingValue("NoPDFs") Then _SafeRun($sEdge, $sCMDLine)
Case StringInStr($sCMDLine, "&url=") ; Fix Windows 11 Widgets
ContinueCase
Case StringInStr($sCMDLine, "--edge-redirect")
$aCMDLine = _RedirectCMDDecode($sCMDLine)

For $iLoop = 0 To Ubound($aCMDLine) - 1 Step 1
If $aCMDLine[$iLoop][0] = "url" Then
$sURL = $aCMDLine[$iLoop][1]
If StringInStr($sURL, "%2F") Then $sURL = _WinAPI_UrlUnescape($sURL)
ExitLoop
EndIf
Next

If $sURL = "" Then
FileWrite($hLogs[$URIFailures], _NowCalc() & " - Command Line Missing Needed Parameters: " & $sCMDLine & @CRLF)
Case StringInStr($sCMDLine, "bing.com/chat") Or StringInStr($sCMDLine, "bing.com%2Fchat") ; Fix BingAI
If _GetSettingValue("NoChat") Then
;;;
Else
FileWrite($hLogs[$AppGeneral], _NowCalc() & " - Caught 'Edge-Redirect' Call:" & @CRLF & _ArrayToString($aCMDLine, ": ") & @CRLF)
If _IsSafeURL($sURL) Then
$sURL = _ModifyURL($sURL)
ShellExecute($sURL)
Else
FileWrite($hLogs[$URIFailures], _NowCalc() & " - Invalid URL: " & $sCMDLine & @CRLF)
EndIf
_SafeRun($sEdge, $sCMDLine)
EndIf
Case StringInStr($sCMDLine, "ux=copilot")
If _GetSettingValue("NoPilot") Then
ShellExecute("ms-settings:")
Else
_SafeRun($sEdge, $sCMDLine)
EndIf
Case StringInStr($sCMDLine, "&url=") ; Fix Windows 11 Widgets
ContinueCase
Case StringInStr($sCMDLine, "microsoft-edge:")
If Not StringInStr($sCMDLine, "url=") Then $sCMDLine = StringRegExpReplace($sCMDLine, "microsoft-edge:[\/]*", "microsoft-edge:?url=")

$aCMDLine = _RedirectCMDDecode($sCMDLine)
$aCMDLine = _CMDLineDecode($sCMDLine)

For $iLoop = 0 To Ubound($aCMDLine) - 1 Step 1
If $aCMDLine[$iLoop][0] = "url" Then
$sURL = $aCMDLine[$iLoop][1]
If StringInStr($sURL, "%2F") Then $sURL = _WinAPI_UrlUnescape($sURL)
$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 'Microsoft-Edge' Call:" & @CRLF & _ArrayToString($aCMDLine, ": ") & @CRLF)
FileWrite($hLogs[$AppGeneral], _NowCalc() & " - Caught Valid URI Call:" & @CRLF & _ArrayToString($aCMDLine, ": ") & @CRLF)
If _IsSafeURL($sURL) Then
$sURL = _ModifyURL($sURL)
ShellExecute($sURL)
Expand Down
Loading

0 comments on commit e4971af

Please sign in to comment.