为什么 gdb 和 python 中的十六进制地址加法不一样

Why hex address addition are not the same in gdb and python

我正在使用 gdb 和 python(3.9) pwntools 在 kali 上进行缓冲区溢出练习。 我正在使用 32 位 ELF,所以我的上下文是这样设置的: context(arch="i386", os="linux")

我正处于必须计算地址函数之间的偏移量的步骤,python 中的结果快把我逼疯了。

在 gdb 中:p 0xf7e280e0 + 0xefdc8000 = 0xe7bf00e0

在我的python脚本中:0xf7e280e0 + 0xefdc8000 = 0x1e7bf00e0

你能帮我理解为什么结果不一样吗?

谢谢:)

Can you help me to understand why the result is not the same?

Python 执行任意精度的算术运算。如果将两个 32 位数字相加,结果可能会溢出并产生一个不适合 32 位的数字。

Is there any way to force this?

假设“强制这个”是指:强制 Python 计算一个 32 位数字,当然:您只需要屏蔽掉不需要的位即可:

result = result & 0xFFFFFFFF