powershell - 将字符串值传递给 Powershell 函数
问题描述
这可能是一个非常简单的问题,但我对 Powershell 完全陌生,还无法解决这个问题。
我想使用 Daniel BohannonInvoke-Obfuscation
来混淆用于机器学习目的的大量 Powershell 脚本。混淆脚本文件的首选用法如下:
Invoke-Obfuscation -ScriptPath .\my_script.ps1 -Command 'String\2' -Quiet
但这不会像预期的那样混淆脚本,并且可能是该工具的问题。但我发现直接调用子函数是有效的。要混淆脚本文字,我可以执行以下操作(假设我站在工具的根文件夹中):
Import-Module ./Invoke-Obfuscation.ps1
Import-Module ./Invoke-Obfuscation.psd1
Import-Module ./Out-CompressedCommand.ps1
Import-Module ./Out-EncodedAsciiCommand.ps1
Import-Module ./Out-EncodedBXORCommand.ps1
Import-Module ./Out-EncodedBinaryCommand.ps1
Import-Module ./Out-EncodedHexCommand.ps1
Import-Module ./Out-EncodedOctalCommand.ps1
Import-Module ./Out-EncodedSpecialCharOnlyCommand.ps1
Import-Module ./Out-EncodedWhitespaceCommand.ps1
Import-Module ./Out-ObfuscatedAst.ps1
Import-Module ./Out-ObfuscatedStringCommand.ps1
Import-Module ./Out-ObfuscatedTokenCommand.ps1
Import-Module ./Out-PowerShellLauncher.ps1
Import-Module ./Out-SecureStringCommand.ps1
Out-ObfuscatedStringCommand {Write-Host 'Hello World!' -ForegroundColor Green; Write-Host 'Obfuscation Rocks!' -ForegroundColor Green} 1
它按预期打印出混淆的脚本。但是,我不想使用字符串文字,而是想从脚本中读取内容,而不是执行以下操作:
$ConsoleCommand = Get-Content -Path '.\my_script.ps1' -Raw
Out-ObfuscatedStringCommand $ConsoleCommand 1
但这会导致如下错误:
Get-ChildItem : Cannot find a provider with the name [...]
如何将文件的内容传递给在 Powershell 中正确接受字符串输入的函数?
解决方案
推荐阅读
- go - GO - WaitGroups 引用中的指针或变量
- java - Surefire 在多模块 spring-boot 项目上
- excel - 在 SUMPRODUCT 中嵌套 INDEX 函数以聚合正确列中的值
- unity3d - 如何处理不同网格中的颜色
- python - 如何在粘贴一张背景图片时避免多张图片重叠?
- html5-filesystem - 是否可以使用文件系统访问 API 提示读取用户机器上的特定目录?
- html - 任何转换器可以将 css 样式表放入 html 中的样式标签中?
- java - 当属性为空时将值设置为默认值
- python - tf.keras.layers.Conv2D.trainable_variables 为空
- discord.py - 我该如何解决这个[discord.py]