gpt4 book ai didi

c++ - 如何在 Windows 上以编程方式等效地查询 proc 文件系统?

转载 作者:太空宇宙 更新时间:2023-11-04 03:36:59 25 4
gpt4 key购买 nike

我正在开发一个实现,我需要将访问的每个函数的入口点存储在 HashMap 中。为了创建有效的哈希函数,我需要知道程序已加载到内存中时的最小和最大可能的函数入口点。

以编程方式(可能在 Windows 和 Linux 上)执行此操作的理想方法是什么,以便程序可以确定已加载到内存中的最小和最大函数入口点。

我想我可能应该查询进程的加载地址并确定进程大小,但转眼间,进程大小可能包括堆栈和堆大小,这对我来说毫无意义。

我正在寻找的可能是 /proc/<processid>/maps ,所以对于 Linux 来说,问题可能是,如何以编程方式查询 proc 文件系统,以及 Windows 的等效方法是什么?

最佳答案

我不知道如何在 Windows 上访问此信息,但在 Linux 上我从 man proc 看到以下内容:

   /proc/[pid]/maps
A file containing the currently mapped memory regions and their access permissions.

The format is:

address perms offset dev inode pathname
08048000-08056000 r-xp 00000000 03:0c 64593 /usr/sbin/gpm
08056000-08058000 rw-p 0000d000 03:0c 64593 /usr/sbin/gpm
08058000-0805b000 rwxp 00000000 00:00 0
40000000-40013000 r-xp 00000000 03:0c 4165 /lib/ld-2.2.4.so
40013000-40015000 rw-p 00012000 03:0c 4165 /lib/ld-2.2.4.so
4001f000-40135000 r-xp 00000000 03:0c 45494 /lib/libc-2.2.4.so
40135000-4013e000 rw-p 00115000 03:0c 45494 /lib/libc-2.2.4.so
4013e000-40142000 rw-p 00000000 00:00 0
bffff000-c0000000 rwxp 00000000 00:00 0

where "address" is the address space in the process that it occupies, "perms" is a set of permis-
sions:

r = read
w = write
x = execute
s = shared
p = private (copy on write)

"offset" is the offset into the file/whatever, "dev" is the device (major:minor), and "inode" is the
inode on that device. 0 indicates that no inode is associated with the memory region, as the case
would be with BSS (uninitialized data).

Under Linux 2.0 there is no field giving pathname.

您打开文件,解析它(可能使用 fscanf),查找具有“x”权限的段(可能也没有“w”)。这些是可以找到函数的地址。

关于c++ - 如何在 Windows 上以编程方式等效地查询 proc 文件系统?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31249085/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com