如何解决在python中将奇怪的十六进制值解码为字符串
我有一个奇怪的十六进制值,它应该是一个映射字符串。
当 0
应该是 000000070000000b
时,我尝试删除不必要的 7b
但由于某种原因我仍然得到奇怪的字符
示例:(我只能显示 json 的一部分,因为它有私人信息)
我需要得到的:
{"BotBehavior": {"type": 2,"score": 304,"score_timestamp": 1623730836453,"score_metadata": {"scoreCount": "0"
我有什么:
000000070000000b426f744265686176696f720000014500000004000000020000000400000130000000080000017a0de653e5000000f8000000060000000a73636f7265436f756e74
我尝试过类似的东西:(请不要判断代码只是为了测试我的想法XD)
def get_decoded_char(char):
index = 0
for byte in char:
if byte == '0':
index += 1
else:
return char[index:]
def get_decoded_string(string):
string_index = 0
decoded_string = ""
while string_index <= len(string):
if string[string_index] == '0':
encoded_char = get_decoded_char(string[string_index: string_index + 8]) + get_decoded_char(
string[string_index + 8: string_index + 16])
decoded_string += bytearray.fromhex(encoded_char).decode()
string_index += 16
else:
encoded_char = string[string_index: string_index + 2]
decoded_string += bytearray.fromhex(encoded_char).decode()
string_index += 2
return decoded_string
感谢您的帮助!
编辑:
我使用了命令:sstabledump -d -t <my_file> > dump.json
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。