diff options
author | Matt Graeber <PowerShellMafia@users.noreply.github.com> | 2015-11-05 10:36:17 -0500 |
---|---|---|
committer | Matt Graeber <PowerShellMafia@users.noreply.github.com> | 2015-11-05 10:36:17 -0500 |
commit | 641eff706e9f34914235441a70333b1daab73ae9 (patch) | |
tree | 2764add1e8aa67fbdc353bca09b0baed83dc03f5 | |
parent | d1145e05402d1130a2a3f9444a6da84ef80e3f79 (diff) | |
download | PowerSploit-641eff706e9f34914235441a70333b1daab73ae9.tar.gz PowerSploit-641eff706e9f34914235441a70333b1daab73ae9.zip |
Test: Ensure all scripts are not LE Unicode encoded
-rw-r--r-- | Tests/PowerSploit.tests.ps1 | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/Tests/PowerSploit.tests.ps1 b/Tests/PowerSploit.tests.ps1 new file mode 100644 index 0000000..527face --- /dev/null +++ b/Tests/PowerSploit.tests.ps1 @@ -0,0 +1,49 @@ +Set-StrictMode -Version Latest + +$TestScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent +$ModuleRoot = Resolve-Path "$TestScriptRoot\.." + +filter Assert-NotLittleEndianUnicode { + [CmdletBinding()] + param ( + [Parameter(Mandatory = $True, + ValueFromPipelineByPropertyName = $True, + ValueFromPipeline = $True)] + [Alias('FullName')] + [String[]] + $FilePath + ) + + $LittleEndianMarker = 48111 # 0xBBEF + + Write-Verbose "Current file: $FilePath" + Write-Debug "Current file: $FilePath" + + if ([System.IO.Directory]::Exists($FilePath)) { + Write-Debug "File is a directory." + return + } + + if (-not [System.IO.File]::Exists($FilePath)) { + Write-Debug "File does not exist." + return + } + + $FileBytes = Get-Content -TotalCount 3 -Encoding Byte -Path $FilePath + + if ($FileBytes.Length -le 2) { + Write-Debug "File must be at least 2 bytes in length." + return + } + + if ([BitConverter]::ToUInt16($FileBytes, 0) -eq $LittleEndianMarker) { + Write-Debug "File contains little endian unicode marker." + throw "$_ is little-endian unicode encoded." + } +} + +Describe 'ASCII encoding of all scripts' { + It 'should not contain little-endian unicode encoded scripts or modules' { + { Get-ChildItem -Path $ModuleRoot -Recurse -Include *.ps1,*.psd1,*.psm1 | Assert-NotLittleEndianUnicode } | Should Not Throw + } +}
\ No newline at end of file |