你将如何访问不知道名称的C结构的成员? [英] How would you access a C structure's members without knowing the name?

查看:98
本文介绍了你将如何访问不知道名称的C结构的成员?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我处理,我试图做一些逆向工程的一个未公开的API - 不要担心,这是没有恶意,只是想实现创造性地使用案例。

I'm dealing with an undocumented API that I'm trying to do a bit of reverse engineering on - don't worry this isn't malicious, just trying to fulfill a use case in a creative way.

我有一个指向C结构。有没有办法对我来说,通过检查这个结构有多少成员内存确定?他们的价值观?

I've got a pointer to a C structure. Is there a way for me to determine by examining the memory how many members this structure has? Their values?

我怀疑实际的成员名称都无法使用,但也许他们是谁?

I suspect the actual member names aren't available, but maybe they are?

推荐答案

根据您可能能够确定结构的结束位置的内存布局,并通过了解结构做什么上了一个台阶,你也许可以猜测成员(注意对齐)。但是,这是毫无知道名称,除非code带有调试符号运气。在这种情况下很容易。打破地方使用结构,其中并在调试检验。

Depending on the memory layout you may be able to determine where the structure ends and by knowing what the structure does on a higher level you may be able to guess about the members (beware of alignment). But there is no luck about knowing the names unless the code comes with debug symbols. In that case it's easy. Break somewhere where the structure is used and inspect it in the debugger.

编辑:

假设你没发现什么成员结构包含的,你也知道,你的编译器使用相同的定位,那么你可以在你的code定义结构的传真和使用的一个指针结构,指向的地址真正的结构。然后你就可以轻松地访问所有的元素在你的code。


Assume that you did find out what members the struct contained and you also know that your compiler uses the same alignment then you can define a facsimile of the structure in your code and use a pointer to your structure to point to the address of the real structure. Then you can access all elements easily in your code.

这篇关于你将如何访问不知道名称的C结构的成员?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆