aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Graeber <PowerShellMafia@users.noreply.github.com>2015-11-05 10:36:17 -0500
committerMatt Graeber <PowerShellMafia@users.noreply.github.com>2015-11-05 10:36:17 -0500
commit641eff706e9f34914235441a70333b1daab73ae9 (patch)
tree2764add1e8aa67fbdc353bca09b0baed83dc03f5
parentd1145e05402d1130a2a3f9444a6da84ef80e3f79 (diff)
downloadPowerSploit-641eff706e9f34914235441a70333b1daab73ae9.tar.gz
PowerSploit-641eff706e9f34914235441a70333b1daab73ae9.zip
Test: Ensure all scripts are not LE Unicode encoded
-rw-r--r--Tests/PowerSploit.tests.ps149
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