* Base64-encode a string as UTF-16LE, which is the encoding required by * PowerShell's -EncodedCommand parameter.
(text: string)
| 667 | * PowerShell's -EncodedCommand parameter. |
| 668 | */ |
| 669 | function toUtf16LeBase64(text: string): string { |
| 670 | if (typeof Buffer !== 'undefined') { |
| 671 | return Buffer.from(text, 'utf16le').toString('base64') |
| 672 | } |
| 673 | // Fallback for non-Node environments |
| 674 | const bytes: number[] = [] |
| 675 | for (let i = 0; i < text.length; i++) { |
| 676 | const code = text.charCodeAt(i) |
| 677 | bytes.push(code & 0xff, (code >> 8) & 0xff) |
| 678 | } |
| 679 | return btoa(bytes.map(b => String.fromCharCode(b)).join('')) |
| 680 | } |
| 681 | |
| 682 | /** |
| 683 | * Build the full PowerShell script that parses a command. |
no test coverage detected