如何获取结构数据的十六进制转储
....
finalize(char *hdrs, sendip_data *headers[], int index,
sendip_data *data, sendip_data *pack)
{
........
出于调试目的,我需要 data
和 pack
结构的十六进制转储,它们的类型为 sendip_data
,这是一个非常复杂的结构。实际上它们包含一些二进制信息,所以我不确定我的项目的输出是否正确。因此,出于调试目的,我想将数据写入文件,以便可以按如下方式使用 hexdump -
$hexdump -C file.txt
另外,因为这是 an/w 数据包的运行时生成,所以我也不确定 data 的长度
和 pack
结构,我认为 fread / fwrite
需要......所以请给我一些建议。
....
finalize(char *hdrs, sendip_data *headers[], int index,
sendip_data *data, sendip_data *pack)
{
........
For debugging purposes I want a hex dump of the data
and pack
structures, which are of type sendip_data
, a really complex structure. Actually they contain some binary information so I am not sure whether output of my project is correct or not. So for debugging purposes, I want to write the data into a file so that I can use hexdump as follows -
$hexdump -C file.txt
Also as this is a run time generation of a n/w packet so I am also not sure about the length of data
and pack
structure which I think fread / fwrite
will require ..So please suggest me something.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以下代码将为您提供代码中任意内存的十六进制转储。
您向
hexDump
传递描述、内存地址、长度以及每行所需的字节数。它将输出十六进制转储(包括字符数据)以供检查。当您使用包含的
main
运行它时,输出为:The following code will give you a hex dump of arbitrary memory from within your code.
You pass into
hexDump
a description, memory address, length, and how many bytes you want on each line.It will output a hex dump (including character data) for examination. When you run it with the included
main
, the output is:适用于 Android 的十六进制转储也应该适用于其他平台。
LOGD()
与DLOG()
相同,起到printf()
的作用,因为printf()
确实在 Android 中不起作用。对于 Android 以外的平台,您可以#define DLOG printf
。dlog.h:
dump.cpp:
使用示例:
输出:
更新:
请参阅 dump.cpp 和 re_dump.h 在 re_dump.h com/18446744073709551615/reDroid/tree/master/jni" rel="noreferrer">reDroid (github),它包含一个递归转储,用于检查指针是否有效。
A hex dump for Android, should be suitable for other platforms as well.
LOGD()
, same asDLOG()
, plays the role ofprintf()
becauseprintf()
does not work in Android. For platforms other than Android, you may#define DLOG printf
.dlog.h:
dump.cpp:
Usage example:
Output:
UPDATE:
see dump.cpp and re_dump.h in reDroid (github), it includes a recursive dump that checks if a pointer is valid.