我正在尝试为我在网络安全课程的教科书中看到的示例创建概念证明。我设置了所需的文件并尝试了它,但我只收到错误。
这是例子:
C:\> type C:\windows\system32\notepad.exe > c:\windows\system32\calc.exe:notepad.exe
这就是我所做的:
C:\> type c:\hello.exe > c:\README.txt:hello.exe
其中
hello.exe
是一个打印 hello world
的可执行文件,README.txt
是一个文本文件,其中包含一些随机文本。
我得到的错误是:
out-file: The given path's format is not supported.
当第一个参数和重定向运算符之间有空格时,并且
Get-Content : A positional parameter cannot be found that accepts argument 'C:\README.txt:hello.exe'.
没有空间时。
我尝试将
type
替换为 cat
,添加和删除运算符之间的空格,在尝试导入数据之前创建备用流以及不同的文件类型。另外,切题的问题是,我无法让 ::$DATA
处理 NTFS 文件。它只是给出了cat : Cannot find path 'C:\hello.exe::' because it does not exist.
在PowerShell中
type
,cat
或gc
都只是别名到Get-Content
,默认情况下与文本一起使用,所以显然你不能将它们用于二进制数据(在cmd中) type
也只适用于文本)。要处理二进制文件,您必须使用 -Encoding Byte
或 -AsByteStream
告诉 Get-Content
不要将文件作为文本处理
>
只是 Out-File
的别名,它不支持流。您必须使用 -Stream
中的 Set-Content
选项指定要存储的流
Get-Content -Encoding Byte "C:\windows\system32\notepad.exe" | `
Set-Content -Encoding Byte -Stream Notepad .\README.txt
Get-Item
、Get-Content
、Remove-Item
、Set-Content
、Clear-Content
、Add-Content
》都有 -Stream
在流上操作的选项。不幸的是Out-File
没有这个选项
另请参阅与备用数据流交互