Allow padding of strings by setting a MinLength when converting to bytes

lx-work
Pat Hartl 2023-12-01 18:32:43 -06:00
parent 7568688c97
commit b38f2b6cef
1 changed files with 8 additions and 0 deletions

View File

@ -20,6 +20,9 @@ namespace LANCommander.PowerShell.Cmdlets
[Parameter] [Parameter]
public int MaxLength { get; set; } = 0; public int MaxLength { get; set; } = 0;
[Parameter]
public int MinLength { get; set; } = 0;
protected override void ProcessRecord() protected override void ProcessRecord()
{ {
byte[] output; byte[] output;
@ -27,6 +30,11 @@ namespace LANCommander.PowerShell.Cmdlets
if (MaxLength > 0 && Input.Length > MaxLength) if (MaxLength > 0 && Input.Length > MaxLength)
Input = Input.Substring(0, MaxLength); Input = Input.Substring(0, MaxLength);
if (MinLength > 0 && MinLength < MaxLength)
Input = Input.PadRight(MinLength, '\0');
else if (MinLength > 0)
Input = Input.PadRight(MaxLength, '\0');
if (Utf16 && BigEndian) if (Utf16 && BigEndian)
output = System.Text.Encoding.BigEndianUnicode.GetBytes(Input); output = System.Text.Encoding.BigEndianUnicode.GetBytes(Input);
else if (Utf16) else if (Utf16)