代码之家  ›  专栏  ›  技术社区  ›  CuriousDeveloper

如何从python回显十六进制

  •  0
  • CuriousDeveloper  · 技术社区  · 7 年前

    TypeError: must be string without null bytes, not str 当我运行此代码时。我想回显十六进制代码

    #!/usr/bin/python
    
    import os
    
    test = '\x76\x06\x40\x00'
    cmd = "echo '"+test+"'"
    os.system(cmd)
    

    \x76\x06\x40\x00 而不是真实的角色。

    如果我更改了 \x00 (null)到类似于 \x0A

    2 回复  |  直到 7 年前
        1
  •  1
  •   Bhakta Raghavan    7 年前

    你为什么需要回音?您可以从python程序和|另一个命令进行打印

    $ cat x.py
    #!/usr/bin/python
    
    import os
    
    print '0x10'
    print '0x20'
    
    $ ./x.py  | wc -l
       2
    

        2
  •  0
  •   EchoMike444    7 年前

    您可以使用模块binascii( https://docs.python.org/2/library/binascii.html )

    #!/usr/bin/python
    import binascii
    test = '\x76\x06\x40\x00'
    print( "%s\n" % binascii.hexlify(test)  )
    

    具有shell调用的版本

    #!/usr/bin/python
    import binascii
    import os
    test = '\x76\x06\x40\x00'
    print( "from python:%s\n" % binascii.hexlify(test)  )
    cmd = "echo 'from shell:"+("%s\n" % binascii.hexlify(test))+"'"
    os.system(cmd)