gpt4 book ai didi

c++ - 编写自定义 GetModuleHandle 函数的原因是什么?

转载 作者:可可西里 更新时间:2023-11-01 11:16:49 24 4
gpt4 key购买 nike

我在研究 ZeuS 恶意软件时遇到了 source code :

HMODULE _getKernel32Handle(void)
{
#if defined _WIN64
return NULL; //FIXME
#else
__asm
{
cld //clear the direction flag for the loop

mov edx, fs:[0x30] //get a pointer to the PEB
mov edx, [edx + 0x0C] //get PEB-> Ldr
mov edx, [edx + 0x14] //get the first module from the InMemoryOrder module list

next_mod:
mov esi, [edx + 0x28] //get pointer to modules name (unicode string)
mov ecx, 24 //the length we want to check
xor edi, edi //clear edi which will store the hash of the module name

loop_modname:
xor eax, eax //clear eax
lodsb //read in the next byte of the name
cmp al, 'a' //some versions of Windows use lower case module names
jl not_lowercase
sub al, 0x20 //if so normalise to uppercase

not_lowercase:
ror edi, 13 //rotate right our hash value
add edi, eax //add the next byte of the name to the hash
loop loop_modname //loop until we have read enough

cmp edi, 0x6A4ABC5B //compare the hash with that of KERNEL32.DLL
mov eax, [edx + 0x10] //get this modules base address
mov edx, [edx] //get the next module
jne next_mod //if it doesn't match, process the next module
};
#endif
}

逻辑如下:

  1. 读取 fs 段寄存器(32 位 Windows 将 TEB 存储在那里)
  2. 获取指向PEB的指针>
  3. 获取指向 PEB_LDR_DATA 的指针(包含有关进程已加载模块的信息)
  4. 遍历 InMemoryOrder 列表
  5. 使用自定义自制哈希函数将模块名称与 "kernel32.dll" 进行比较

为什么 GetModuleHandle 的使用在那里不合适?

最佳答案

代码片段正在尝试获取 kernel32.dll 的模块句柄(即基地址),可能是因为它还没有此模块的句柄。 GetModuleHandlekernel32.dll 导出。当您不知道其地址时,您无法调用函数。

关于c++ - 编写自定义 GetModuleHandle 函数的原因是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37027248/

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