Python:列表转十六进制

发布于 2024-08-15 12:49:45 字数 596 浏览 1 评论 0原文

我正在编写一个小型取证 python 应用程序,但在将列表条目转换为十六进制时遇到问题。我尝试过编码/解码方法,但出现虚假转换或奇数长度字符串类型错误。我粘贴了下面的代码,正如您所看到的,我需要十六进制的地址,这样我就可以向其中添加计数。

def location_finder(line):
count = 0
temp = line.split(' ') #3 Tokenizes first element, by first space
address = str(temp[0].split(':')) # Take's : off of first element(address)
print address, "dog"
address = address.decode("hex")
print address, "cat"
#print temp[0]
line_address = temp[0].upper()
for addy in temp:

    if addy == "ffd8":
        return (address+count)
    if addy == "ffd9":
        return (address+count)

count = count + 1

I am writing a small forensics python app and I am having trouble converting a List entry to Hex. I have tried the encode/decode methood but get bogus conversions or odd-length string Type Errors. I have pasted the code below, and as you can see I need the address in hex, so I can add the count to it.

def location_finder(line):
count = 0
temp = line.split(' ') #3 Tokenizes first element, by first space
address = str(temp[0].split(':')) # Take's : off of first element(address)
print address, "dog"
address = address.decode("hex")
print address, "cat"
#print temp[0]
line_address = temp[0].upper()
for addy in temp:

    if addy == "ffd8":
        return (address+count)
    if addy == "ffd9":
        return (address+count)

count = count + 1

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

薄凉少年不暖心 2024-08-22 12:49:45

hex 函数将整数转换为其十六进制表示形式:

>>> a = 123
>>> hex(a)
'0x7b'

The hex function converts integers to their hexadecimal representation:

>>> a = 123
>>> hex(a)
'0x7b'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文