确定内存中函数/存根/命名空间的大小

发布于 2024-08-16 03:01:26 字数 497 浏览 13 评论 0原文

我在名为 stub 的命名空间中有几个函数。 我必须确定命名空间的确切起始地址和结束地址,至少是内存中命名空间的大小(将这些函数复制到另一个进程中)。 这在 Visual C++ 2008 中可以完美运行

void stub_end() { }

通过在命名空间末尾添加 a 并使用

size_t size = reinterpret_cast<ULONG_PTR>(stub_end) - reinterpret_cast<ULONG_PTR>(stub_start);

来确定存根的大小,

。这是有效的,因为 Visual C++ 保留了 .cpp 文件中的函数顺序,但在 Visual C++ 2010 中似乎不再是这种情况了。

如何使用 pragma 指令、编译器/链接器工具或类似工具找出函数或整个命名空间/存根的大小?

I have a couple of functions in a namespace called stub.
I have to determine the exact start address of the namespace and the end address, of at least the size of the namespace in memory (to copy these functions into another process).
While this worked perfectly in Visual C++ 2008 by adding a

void stub_end() { }

at the end of the namespace and using

size_t size = reinterpret_cast<ULONG_PTR>(stub_end) - reinterpret_cast<ULONG_PTR>(stub_start);

to determine the size of the stub.

This worked because Visual C++ preserved the function order as it is in the .cpp file, however that does not seem to be the case in Visual C++ 2010 anymore.

How can I find out the size of the functions or the whole namespace/stub by using pragma directives, compiler/linker facilities or similar?

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

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

发布评论

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

评论(3

月野兔 2024-08-23 03:01:26

随着这些天安全性的新推动(堆随机化、布局随机化等),我认为这会困难得多。您最终可能不得不单独复制每个函数。

With the new push in security these days (heap randomization, layout randomization, etc..) I think this is going to be much more difficult. You may end up having to just copy each function individually.

夢归不見 2024-08-23 03:01:26

您可以尝试使用 VC++ 等效的 GCC 属性 ((section ("name"))) http://www.delorie.com/gnu/docs/gcc/gcc_62.html 然后使用你的技术,或者你可以放置每个函数都在不同的源文件中。

You can try and place each function in a different section, using the VC++ equivalent GCC's attribute ((section ("name"))) http://www.delorie.com/gnu/docs/gcc/gcc_62.html and then use your technique, or you could place each function in a different source file.

情愿 2024-08-23 03:01:26

C++ 语言不保证查找命名空间的地址或大小。也就是说,冒险尝试汇编语言和链接器指令。

许多汇编语言都有用于将代码放置在特定地址的操作码或助记符。这允许设置标签来指示存储区域的开始。一些链接器具有用于获取段起始地址和大小的变量。这些将是用户定义的逻辑地址。

总之,使用汇编和链接器工具来定义命名空间的开始和长度或可选的段结束的公共符号。在您的 C++ 程序中,以 extern 方式访问这些标签。

The C++ language provides no guarantees for finding addresses or sizes of namespaces. That said, venture into assembly language and linker instructions.

Many assembly languages have an opcode or mnemonic for placing code at specific addresses. This allows a label to be set up to indicate the start of a memory area. Some linkers have variables for obtaining segment starting addresses and sizes. These would be user defined logical addresses.

In summary, use your assembly and linker tools to define public symbols for the namespace start and length or optionally the end of the segment. In your C++ program, access these labels as extern.

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