diff options
author | PowerShellMafia <PowerShellMafia@users.noreply.github.com> | 2015-12-18 16:33:59 -0800 |
---|---|---|
committer | PowerShellMafia <PowerShellMafia@users.noreply.github.com> | 2015-12-18 16:33:59 -0800 |
commit | 9e771d15bf19ab3c2ac196393c088ecdab6c9a73 (patch) | |
tree | 58927893ecb9289ad1de64d3a67eb58d00e4b762 /Tests/PowerSploit.tests.ps1 | |
parent | 9f78286ea7b0ec65d2aa09893a076864dd8d14e9 (diff) | |
parent | 9f183e36518176c4299eed5c68b7deac7f4e8025 (diff) | |
download | PowerSploit-9e771d15bf19ab3c2ac196393c088ecdab6c9a73.tar.gz PowerSploit-9e771d15bf19ab3c2ac196393c088ecdab6c9a73.zip |
Merge pull request #102 from PowerShellMafia/devv3.0.0
Merge 3.0 release changes
Diffstat (limited to 'Tests/PowerSploit.tests.ps1')
-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 |