-
Notifications
You must be signed in to change notification settings - Fork 9
/
removeNoise.ps1
76 lines (56 loc) · 1.83 KB
/
removeNoise.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#
# Filename: removeNoise.py
#
# Version: 1.1.0
#
# Author: Joe Gervais (TryCatchHCF)
#
# Port to Powershell : John Aho
#
# Summary: Removes random noise that has been prepended to a cloaked file
# (see cloakify.ps1).
#
# Description:
# Read in the noise-enhanced cloaked file and reprint each line without the
# prepended noise.
#
# Example:
#
# $ ./removeNoise.ps1 2 noisyCloaked.txt cloaked.txt
param (
[Parameter(Mandatory=$false)][int]$numberOfColumnsToStrip,
[Parameter(Mandatory=$false)][string]$cloakedFile,
[Parameter(Mandatory=$false)][string]$outputFile
)
# Get directory path.
$invocation = (Get-Variable MyInvocation).Value
$directorypath = Split-Path $invocation.MyCommand.Path
Set-Location $directorypath
[void](Invoke-Expression("chcp 65001"))
if ( $numberOfColumnsToStrip -eq 0){
write-host("usage: removeNoise.ps1 <numberOfColumnsToStrip> <noisyFilename> <outputFile>")
write-host("")
return
}
if(($numberOfColumnsToStrip -gt 0) -and ( $cloakedFile.Length -gt 0 ) -and($outputFile.Length -gt 0) ){
if(Test-Path $cloakedFile){
$clFile = Get-Content $cloakedFile -Encoding UTF8
$i = 0
while($i -lt $clFile.Length ){
$j=1
ForEach ( $match in ($clFile[$i] | select-String " " -allMatches).matches )
{
$index = $match.Index
if ( $j -eq $numberOfColumnsToStrip )
{
$clFile[$i] = $clFile[$i].Substring($index+1)
}
$j++
}
$i = $i+1
}
Out-File -FilePath $outputFile -InputObject $clFile -Encoding UTF8
}else{
Write-Host "File not found"
}
}