如何确定'malloc'符号是来自源还是来自编译器?
How to determine if a 'malloc' symbol came from the source or from the compiler?
使用 Dll 注入,我能够从msvcrt.dll
挂住malloc
符号,并打印从注入的过程中malloc
的所有调用的日志。问题是在日志中,我可以找到对目标 exe 中没有的malloc
调用,请参阅进一步的示例。
我相信有一种方法可以解决这个问题,基于我在钩子过程中发现的malloc
调用的返回地址。下面是使用 tcc 编译的目标 PE 的日志文件:
0 malloc(18) memory allocated at: 10229112 the return adress is 74ab770a.
1 malloc(4096) memory allocated at: 10232824 the return adress is 74ab770a.
2 malloc(15) memory allocated at: 10229144 the return adress is 401022.
3 malloc(15) memory allocated at: 10229168 the return adress is 401041.
4 malloc(15) memory allocated at: 10229192 the return adress is 401060.
在 exe 文件中,只有最后三个调用存在,很明显另一个来自完全不同的 PE。
打印日志时,如何检测来自exe
文件的哪些调用以及来自不同 PE 的哪些调用?感谢您的任何帮助。
当我们从 DLL 挂钩函数时,假设msvcrt!malloc
调用可以来自不同的 PE 模块。 我们可以从带有GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS
标志的 returnAddress 调用GetModuleHandleExW
获取调用模块的基址。 如果我们需要检测调用是否来自 EXE,我们可以将此地址与 EXE 的基址进行比较,我们可以通过GetModuleHandleW
代码可能看起来像
HMODULE hmod;
if (GetModuleHandleEx(
GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS|
GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, (PCWSTR)_ReturnAddress(), &hmod))
{
static HMODULE hmodEXE = 0;
if (!hmodEXE)
{
hmodEXE = GetModuleHandleW(0);
}
DbgPrint("%p: call %sfrom exen", _ReturnAddress(), hmodEXE == hmod ? "" : "not ");
}
else
{
DbgPrint("%p: call not from any PEn", _ReturnAddress());
}
相关文章:
- 是否有任何 2 补充平台/编译器,其中有符号移位不做通常的事情?
- C++ 如何禁用具有不同符号变量比较的特定行的编译器警告?
- Android Cmake编译器正在生成带有额外前缀和符号后缀的.out文件
- 如何确定'malloc'符号是来自源还是来自编译器?
- Clang编译器/链接器找不到x86_64架构的符号NSMenuItem
- 编译器链接器外部符号mhook_sethook
- 来自 clang/llvm 编译器的重复符号错误
- C++编译器或预处理器是否可以将符号转换为大写
- 什么是 ?和 @ 符号演示此编译器错误?- Visual Studio 2013 Compiler.
- 编译器错误:从int*到无符号int*的转换无效[-fpermission]
- 现代编译器是否优化了for循环中使用的无符号int
- boost::bind 似乎使用不同的编译器生成不同的符号
- Visual C++编译器为不明确的符号提供了错误的行引用
- types.h中的内容——编译器在哪里定义int、带符号int和其他值的宽度
- C++ 在 Win DLL 到 Linux SO 转换中将 LPBYTE 更改为无符号字符*后编译器错误
- 如何防止编译器/链接器去除特定符号
- C++编译器 - 生成的符号类型
- 在 Scala 2.9.3 编译器的擦除阶段之后获取具体类型的符号
- 有符号整数溢出为负数:这是一个编译器错误,还是我误解了优化
- 玩具编译器符号表