我在nmap脚本中调试了一行代码,得到的结果如下:
local target_info = '\x02\x00\x1a\x00W\x00I\x00N\x00S\x00E\x00R\x00V\x00E\x00R\x002\x000\x001\x002\x00\x01\x00\x1e\x00W\x00I\x00N\x00-\x00V\x00B\x00N\x00G\x00O\x007\x00T\x00N\x008\x00N\x00S\x00\x04\x00&\x00w\x00i\x00n\x00s\x00e\x00r\x00v\x00e\x00r\x002\x000\x001\x00
我试图使用ASCII编码将文本转换为二进制,然后将二进制代码解码回文本,作为更大项目的概念证明。下面的代码运行良好,并完成了它应该做的事情:
bytes = []
input_data = "Hello"
for b in input_data:
new_byte = bin(int.from_bytes(b.encode('ascii'), 'big'))
bytes.append(new_byte)
for x in bytes:
print(x)
for byte in bytes:
byte_int
我正在制作一个脚本来获取Valve的服务器信息(在线播放器、地图等)--当我请求提供信息时,我得到的数据包如下:
'\xff\xff\xff\xffI\x11Stargate Central CAP SBEP\x00sb_wuwgalaxy_fix\x00garrysmod\x00Spacebuild\x00\xa0\x0f\n\x0c\x00dw\x00\x0114.09.08\x00\xb1\x87i\x06\xb4g\x17.\x15@\x01gm:spacebuild3\x00\xa0\x0f\x00\x00\x00\x00\x00\x00'
这也许能帮你看看我在做什么
我有两个结构,它们的大小和内容应该是相同的:
from ctypes import *
class struct_1(Structure):
_fields_ = (
('field1', c_int16),
('field2', c_int16)
)
class struct_2(Structure):
# having _pack_ doesn't appear to do anything as it yields the same result
_pack_ = 1
_
我希望将字节字符串的第一个字节连接到字符串的末尾:
a = b'\x14\xf6'
a += a[0]
我得到一个错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can't concat bytes to int
当我输入bytes(a[0])时,我得到:
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
我遇到了以下问题。我已经用C编写了一些双类型数据到二进制文件中,现在我想使用Python读取它们。当我使用python函数时
with open("test.dat","rb") as dfile:
data = dfile.read()
它给了我
b'\x00\x00\x00\x00\x00\x00\xf8?\x00\x00\x00\x00\x00\x00\x04@\x00\x00\x00\x00\x00\x00\n@\x00\x00\x00\x00\x00\x00\x11@‘
所以我试着用data.decode()解码,然后它给了我解