【问题标题】:What does [byte[]]$bytes = 0..65535|%{0} mean in powershell ?[byte[]]$bytes = 0..65535|%{0} 在 powershell 中是什么意思?
【发布时间】:2017-11-09 03:13:40
【问题描述】:

我想在python中添加一些powershell代码,但是当我使用format函数时遇到'%{0}',然后无法编译python。所以我想知道改变我的代码的意思

【问题讨论】:

    标签: python format shellcode


    【解决方案1】:

    双点.. 是一个范围构造函数。 0..65535 将返回一个从 0 到 65535 的整数数组。管道后的百分号 |% 是管道后 foreach-object 的简写。

    在这种情况下,你的 powershell 函数

    [byte[]]$bytes = 0..65535|%{0}
    

    创建一个名为bytes、类型为byte 的数组,其值有65536 个零。

    如果您尝试使用字符串 format 函数从 Python 调用它,那么您需要通过加倍来转义大括号。例如,如果你想使用 Python 来调整变量名,你会使用:

    # in Python:
    powershell_cmd = '[byte[]]${} = 0..65535|%{{0}}'.format('bytes')
    

    【讨论】:

    • 感谢您的回答,我将 powershellcode 更改为 [byte[]]$bt=0..65535|%{{0}},但 powershellcode 的含义似乎与以前不同并得到错误的结果
    猜你喜欢
    • 2015-03-20
    • 2018-09-10
    • 2020-04-02
    • 2020-01-07
    • 2016-06-03
    • 2014-11-06
    • 2018-09-25
    • 2017-10-29
    • 2011-05-25
    相关资源
    最近更新 更多