mirror of
https://github.com/wietze/Invoke-ArgFuscator
synced 2026-06-08 18:17:29 +00:00
43 lines
1.7 KiB
PowerShell
Executable File
43 lines
1.7 KiB
PowerShell
Executable File
using module "..\Types\Modifier.psm1"
|
|
using module "..\Types\Token.psm1"
|
|
using module "..\Types\Argument.psm1"
|
|
|
|
class CharacterInsertion : Modifier {
|
|
[float]$Probability;
|
|
[string[]]$Characters;
|
|
[int]$Offset;
|
|
|
|
CharacterInsertion([Token[]]$InputCommandTokens, [string[]]$AppliesTo, [Argument[]]$Arguments, [float]$Probability, [string[]]$Characters, [int]$Offset) : base($InputCommandTokens, $AppliesTo, $Arguments, $Probability) {
|
|
$this.Characters = $Characters;
|
|
$this.Offset = $Offset;
|
|
}
|
|
|
|
[void]GenerateOutput() {
|
|
foreach ($Token in $this.InputCommandTokens) {
|
|
if ($this.AppliesTo.Contains($Token.Type)) {
|
|
$NewTokenContent = [System.Collections.ArrayList]@();
|
|
$Token.TokenContent | Select-Object -First $this.Offset | ForEach-Object { $NewTokenContent.Add($_) }
|
|
|
|
$j = $this.Offset;
|
|
foreach ($Char in ($Token.TokenContent | Select-Object -Skip $this.Offset)) {
|
|
$NewTokenContent.Add($Char);
|
|
if(($j -eq ($Token.TokenContent.Length - 1)) -and ([Modifier]::ValueChars -contains $Char)){
|
|
continue;
|
|
}
|
|
$i = 0;
|
|
if ([Modifier]::CoinFlip($this.Probability)) {
|
|
do {
|
|
$chosen = [Modifier]::ChooseRandom($this.Characters)
|
|
$NewTokenContent.Add($chosen);
|
|
$i++;
|
|
} while ([Modifier]::CoinFlip($this.Probability * [Math]::Pow(0.9, $i)));
|
|
}
|
|
$j += 1
|
|
}
|
|
|
|
$Token.TokenContent = ($NewTokenContent -join "").ToCharArray();
|
|
}
|
|
}
|
|
}
|
|
}
|