简体   繁体   English

在Lua Dissector中将HEX转换为ASCII

[英]Converting HEX to ASCII in Lua Dissector

I'm trying to take HEX bytes and display them as their ASCII values. 我正在尝试获取十六进制字节并将其显示为ASCII值。 If someone could point me reasonably firmly in the right direction I'd be obliged. 如果有人可以合理地坚定地指出正确的方向,我就有义务。 Tried any number of uint-type commands, and working with buffer(x, 2) as an argument. 尝试了任意数量的uint型命令,并使用buffer(x,2)作为参数。

I'm not sure what you mean by hex bytes , but the relevant functions are: 我不确定十六进制字节是什么意思,但是相关的功能是:

For a single character in hexadecimal, you can use string.byte as mentioned by lhf. 对于十六进制的单个字符,可以使用string.byte提到的string.byte。 For longer sequences, you can create a loop in Lua, but that is not very efficient since it involves a lot of copying. 对于更长的序列,您可以在Lua中创建一个循环,但这并不是很有效,因为它涉及大量复制。

Since Wireshark 1.11.3 there is a Struct.fromhex function that converts a string of hexadecimal characters to the binary equivalent. 从Wireshark 1.11.3开始,提供了Struct.fromhex函数,该函数将十六进制字符的字符串转换为等效的二进制值。

Example: 例:

-- From hex to bytes (with no separators)
assert(Struct.fromhex("5753") == "WS")
-- From hex to bytes (using a single space as separator)
assert(Struct.fromhex("57 53", " ") == "WS")

Similarly, there is a Struct.tohex function that converts from bytes to hex. 同样,有一个Struct.tohex函数,可以将字节转换为十六进制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM