静态链接库:如何确定代码是否位于可执行文件的连续区域?

Statically linked libraries: How to find out if code is in a contiguous area in the executable?

我读过 this 所以回答

When you statically link a file into an executable, the contents of that file are included at link time. In other words, the contents of the file are physically inserted into the executable that you will run.

我想知道,在一般情况下,这段代码是否位于连续区域。我从 another 那里了解到,所以答案可能并非总是如此:

This assumption is probably true in simple cases, but in no way is guaranteed.

假设我有一个剥离的二进制文件,没有源代码。但是我知道可执行文件是使用某个静态链接库构建的。

如果要分析可执行文件,可以使用反编译和代码查看工具。这里的人可能会更好地帮助你:https://reverseengineering.stackexchange.com/

至于为什么,这可能是一种优化,主要是针对可执行文件的大小,移动该区域或将其拆分为大小合适的孔。另一个主要原因是防止跳转到库攻击。基本上,对内存执行保护可防止攻击者将任意代码写入数据缓冲区并执行。作为回应,破解者有时会从库代码中串起攻击,因此库位置是随机的。这不是你想要做的,对吧?