73 lines
1.8 KiB
PowerShell
73 lines
1.8 KiB
PowerShell
param(
|
|
[Parameter(ValueFromPipeline = $true)]
|
|
[string[]]$Text,
|
|
[string]$InputPath,
|
|
[string]$OutputPath,
|
|
[string]$MappingPath,
|
|
[switch]$Replace,
|
|
[Alias('IncludeOneCharNames')]
|
|
[switch]$AggressiveShortNames
|
|
)
|
|
|
|
Set-StrictMode -Version 2.0
|
|
|
|
$ScriptDirectory = if ([string]::IsNullOrWhiteSpace($PSScriptRoot)) {
|
|
Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
}
|
|
else {
|
|
$PSScriptRoot
|
|
}
|
|
|
|
if ([string]::IsNullOrWhiteSpace($MappingPath)) {
|
|
$MappingPath = Join-Path $ScriptDirectory 'OPSFile.txt'
|
|
}
|
|
|
|
$pipelineText = @($input)
|
|
$sourceText = $null
|
|
|
|
if ($Text -and $Text.Count -gt 0) {
|
|
$sourceText = ($Text -join [Environment]::NewLine)
|
|
}
|
|
elseif ($pipelineText.Count -gt 0) {
|
|
$sourceText = ($pipelineText -join [Environment]::NewLine)
|
|
}
|
|
elseif ([string]::IsNullOrWhiteSpace($InputPath)) {
|
|
try {
|
|
$clipText = Get-Clipboard -Raw -ErrorAction Stop
|
|
if (-not [string]::IsNullOrWhiteSpace($clipText)) {
|
|
$sourceText = $clipText
|
|
}
|
|
}
|
|
catch {
|
|
$sourceText = $null
|
|
}
|
|
}
|
|
|
|
$decoderPath = Join-Path $ScriptDirectory 'ObfuscatedExceptionDecoder.ps1'
|
|
$mode = if ($Replace) { 'Replace' } else { 'Annotate' }
|
|
$decoderParams = @{
|
|
NoGui = $true
|
|
MappingPath = $MappingPath
|
|
Mode = $mode
|
|
}
|
|
|
|
if ($AggressiveShortNames) {
|
|
$decoderParams['AggressiveShortNames'] = $true
|
|
}
|
|
|
|
if (-not [string]::IsNullOrWhiteSpace($InputPath)) {
|
|
$decoderParams['InputPath'] = $InputPath
|
|
}
|
|
else {
|
|
if ([string]::IsNullOrWhiteSpace($sourceText)) {
|
|
throw 'No input text. Pass -Text, pipe text, use -InputPath, or put the log in clipboard.'
|
|
}
|
|
$decoderParams['Text'] = $sourceText
|
|
}
|
|
|
|
if (-not [string]::IsNullOrWhiteSpace($OutputPath)) {
|
|
$decoderParams['OutputPath'] = $OutputPath
|
|
}
|
|
|
|
& $decoderPath @decoderParams
|