Skip to content

Commit

Permalink
Fix hidden app link ignored path rules
Browse files Browse the repository at this point in the history
- I had the regex patterns in the $ignorePaths variable being escaped twice which made it not correctly detect the pattern.
- Renamed the program files restrictive paths variable to be more descriptive. Also moved the placement of wildcards into declaration of the variable list so it's easier to see how it will be matched.
- Renamed variable for paths to only search specific binary to be better to understand. Also moved placement of patterns into variable declaration
- Added $ignorePathsRegex variable to also allow unescaped regex patterns to be used
- Added Epic Games folder to list of paths to be more restrictive to avoid searching huge game directories
  • Loading branch information
ThioJoe committed Aug 29, 2024
1 parent e5e9f7a commit 8aadf03
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions Super_God_Mode.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ param(
# -debugSearchOnlyProtocolList
# -uniqueOutputFolder

$VERSION = "1.2.1"
$VERSION = "1.2.2"



Expand Down Expand Up @@ -3472,23 +3472,31 @@ function Search-HiddenLinks {



# If it the path contains "\Program Files" or "\Program Files (x86)", then use the path until the next backslash, otherwise match to the last backslash
$moreRestrictivePaths = @("Common Files", "WindowsApps", "Adobe", "Microsoft Office")
# These are regex path patterns that will be ignored while searching within the program files directory
$ignorePaths = @('\steamapps\' )
# If the path starts with something in this list, then it will only search the specific file, not the whole directory
$dontSearchFolders = @($env:WINDIR)
# Wildcard Patterns & Applies within Program Files or Program Files x86 only: Will ensure the direct parent directory of the exe is searched, not the whole Publisher name directory for example
$moreRestrictiveProgramFilesPaths = @("*\Common Files\*", "*\WindowsApps\*", "*\Adobe\*", "*\Microsoft Office\*", "*\Epic Games\*")

# Wildcard Patterns: If the path starts with something in this list, then it will only search the specific file, not the whole directory. Not regex but uses wildcards, and a * will be added to the end
$foldersToOnlySearchBinary = @("$env:WINDIR\*", "*\SteamLibrary\*")
# Regex Patterns: These are literal regex path patterns that will be ignored while searching within the program files directory. Will be escaped later, and not case sensitive.
$ignorePaths = @("\steamapps\")
# Regex Pattern: Same as $ignorePaths but you must escape it yourself, but allows for more complex patterns
$ignorePathsRegex = @()

# Prepare variables if necessary - Regex escape ignorePaths
$ignorePaths = $ignorePaths | ForEach-Object { [regex]::Escape($_) }
# Combine with $ignorePathsRegex which must be already escaped
$ignorePaths = $($ignorePaths ; $ignorePathsRegex)

# Determine the program's install directory based on the target.
# If it the path contains "\Program Files" or "\Program Files (x86)", then use the path until the next backslash, otherwise match to the last backslash
if ($target -match '^(.*\\[Pp]rogram [Ff]iles( \(x86\))?\\[^\\]+)') {
$installDir = $Matches[1]
$Matches = $null
$containsRestrictivePath = $false
foreach ($exception in $moreRestrictivePaths) {
if (($installDir -like "*\$exception\*") -or ($($installDir + "\") -like "*\$exception\*")) {
# Exceptions for more restrictive paths for 'Program Files' paths. If the install directory is in one of these paths, then use the immediate parent directory of the executable
foreach ($exception in $moreRestrictiveProgramFilesPaths) {
# Matches using wildcards already in each variable item. Explicitly case insensitive even though it already would be by default
if (($installDir -ilike "$exception") -or ($($installDir + "\") -ilike "$exception")) {
$containsRestrictivePath = $true
break
}
Expand All @@ -3502,8 +3510,8 @@ function Search-HiddenLinks {
}

# If the install directory is in a list of exclusions, only search that specific file, not the whole directory
foreach ($excludedFolder in $dontSearchFolders) {
if ($installDir -like "$excludedFolder*") {
foreach ($excludedFolder in $foldersToOnlySearchBinary) {
if (($installDir -ilike "$excludedFolder") -or (($installDir + "\") -ilike "$excludedFolder")) {
$installDir = $null
break
}
Expand Down Expand Up @@ -3561,8 +3569,9 @@ function Search-HiddenLinks {
$currentCheckingFile = $_
$currentCheckingFile.Length -lt $maxFileSize -and
$currentCheckingFile.Extension -notin $ignoredExtensions -and
$currentCheckingFile.Length -gt 0 -and
($ignorePaths | ForEach-Object { $currentCheckingFile.FullName -notmatch [regex]::Escape($_) }) -notcontains $false
$currentCheckingFile.Length -gt 0 -and
# Check if the file is in an ignored path. The $_ variable is each regex pattern within $ignorePaths, and is already escaped earlier. Case insensitive
($ignorePaths | ForEach-Object { $currentCheckingFile.FullName -inotmatch $_ }) -notcontains $false
}
$program.FilesToSearch = $files
Write-Verbose "Got $($files.Count) files in $folder for $($program.Protocols)"
Expand Down

0 comments on commit 8aadf03

Please sign in to comment.