Skip to content

Commit

Permalink
Converted a scriptblock to function
Browse files Browse the repository at this point in the history
  • Loading branch information
HotCakeX committed Dec 7, 2023
1 parent a7da37c commit 6d71b73
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -878,8 +878,8 @@ CiTool --update-policy "$((Get-Location).Path)\$PolicyID.cip" -json; Remove-Item
}

if ($UpdateBasePolicy) {
# First get the Microsoft recommended driver block rules
Invoke-Command -ScriptBlock $GetBlockRulesSCRIPTBLOCK | Out-Null
# First get the Microsoft recommended block rules
Get-BlockRulesMeta | Out-Null

switch ($NewBasePolicyType) {
'AllowMicrosoft_Plus_Block_Rules' {
Expand Down
4 changes: 2 additions & 2 deletions WDACConfig/WDACConfig Module Files/Core/Edit-WDACConfig.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -750,8 +750,8 @@ CiTool --update-policy "$((Get-Location).Path)\$PolicyID.cip" -json; Remove-Item
}

if ($UpdateBasePolicy) {
# First get the Microsoft recommended driver block rules
Invoke-Command -ScriptBlock $GetBlockRulesSCRIPTBLOCK | Out-Null
# First get the Microsoft recommended block rules
Get-BlockRulesMeta | Out-Null

switch ($NewBasePolicyType) {
'AllowMicrosoft_Plus_Block_Rules' {
Expand Down
6 changes: 3 additions & 3 deletions WDACConfig/WDACConfig Module Files/Core/New-WDACConfig.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ function New-WDACConfig {

param([System.Boolean]$NoCIP)
# Get the latest Microsoft recommended block rules
Invoke-Command -ScriptBlock $GetBlockRulesSCRIPTBLOCK | Out-Null
Get-BlockRulesMeta | Out-Null
Copy-Item -Path 'C:\Windows\schemas\CodeIntegrity\ExamplePolicies\AllowMicrosoft.xml' -Destination 'AllowMicrosoft.xml'
Merge-CIPolicy -PolicyPaths .\AllowMicrosoft.xml, 'Microsoft recommended block rules.xml' -OutputFilePath .\AllowMicrosoftPlusBlockRules.xml | Out-Null
[System.String]$PolicyID = Set-CIPolicyIdInfo -FilePath .\AllowMicrosoftPlusBlockRules.xml -PolicyName "Allow Microsoft Plus Block Rules - $(Get-Date -Format 'MM-dd-yyyy')" -ResetPolicyID
Expand Down Expand Up @@ -185,7 +185,7 @@ function New-WDACConfig {

[System.Management.Automation.ScriptBlock]$MakeDefaultWindowsWithBlockRulesSCRIPTBLOCK = {
param([System.Boolean]$NoCIP)
Invoke-Command -ScriptBlock $GetBlockRulesSCRIPTBLOCK | Out-Null
Get-BlockRulesMeta | Out-Null
Copy-Item -Path 'C:\Windows\schemas\CodeIntegrity\ExamplePolicies\DefaultWindows_Enforced.xml' -Destination 'DefaultWindows_Enforced.xml'

[System.Boolean]$global:MergeSignToolPolicy = $false
Expand Down Expand Up @@ -551,7 +551,7 @@ function New-WDACConfig {
# Deploy the latest block rules
{ $GetBlockRules -and $Deploy } { & $DeployLatestBlockRulesSCRIPTBLOCK; break }
# Get the latest block rules
$GetBlockRules { & $GetBlockRulesSCRIPTBLOCK; break }
$GetBlockRules { Get-BlockRulesMeta ; break }
# Deploy the latest driver block rules
{ $GetDriverBlockRules -and $Deploy } { & $DeployLatestDriverBlockRulesSCRIPTBLOCK; break }
# Get the latest driver block rules
Expand Down
15 changes: 10 additions & 5 deletions WDACConfig/WDACConfig Module Files/Resources/Resources.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -396,22 +396,27 @@ $RuleRefsContent
return $EmptyPolicy
}


# Gets the latest Microsoft Recommended block rules, removes its allow all rules and sets HVCI to strict
[System.Management.Automation.ScriptBlock]$GetBlockRulesSCRIPTBLOCK = {
Function Get-BlockRulesMeta {
<#
.SYNOPSIS
Gets the latest Microsoft Recommended block rules, removes its allow all rules and sets HVCI to strict
.INPUTS
System.Void
.OUTPUTS
PSCustomObject
#>
[System.String]$Rules = (Invoke-WebRequest -Uri $MSFTRecommendeBlockRulesURL -ProgressAction SilentlyContinue).Content -replace "(?s).*``````xml(.*)``````.*", '$1' -replace '<Allow\sID="ID_ALLOW_A_[12]".*/>|<FileRuleRef\sRuleID="ID_ALLOW_A_[12]".*/>', ''
$Rules | Out-File '.\Microsoft recommended block rules TEMP.xml'
# Removing empty lines from policy file
Get-Content -Path '.\Microsoft recommended block rules TEMP.xml' | Where-Object -FilterScript { $_.trim() -ne '' } | Out-File -FilePath '.\Microsoft recommended block rules.xml'
Remove-Item -Path '.\Microsoft recommended block rules TEMP.xml' -Force
Set-RuleOption -FilePath '.\Microsoft recommended block rules.xml' -Option 3 -Delete
Set-HVCIOptions -Strict -FilePath '.\Microsoft recommended block rules.xml'
[PSCustomObject]@{
return [PSCustomObject]@{
PolicyFile = 'Microsoft recommended block rules.xml'
}
}


function Confirm-CertCN {
<#
.SYNOPSIS
Expand Down

0 comments on commit 6d71b73

Please sign in to comment.