有人可以帮我解决以下问题吗?我没有在这篇文章中包含我的代码的某些部分(错误处理等),以使其尽可能清晰。
当我迭代缓冲区中的各个项目并将其打印出来时,所有模块名称都会输出,其中第一个是:
C:\Program Files\WindowsApps\Microsoft.WindowsNotepad_11.2309.28.0_x64__8wekyb3d8bbwe\Notepad\Notepad.exe
但是,当我检查相应元素中是否包含字符串
Notepad.exe
时,结果为 false。当然,对于所有其他模块(DLL),这个 if
语句的结果应该是 false(毕竟,Kernel32.dll
不包含字符串 "Notepad.exe"
),但是对于这个模块,输出应该是 true。
有谁知道为什么它没有按预期工作?
注意
array_modules
有模块的地址。
FILE* file_pointer;
HMODULE array_modules[1024];
DWORD number_bytes;
WCHAR BUFFER[1024]; //Unicode characters
int i;
BOOL APIENTRY DllMain(HMODULE Base_DLL_Address, DWORD Reason_CALL, LPVOID Reserved)
{
switch (Reason_CALL)
{
case DLL_PROCESS_ATTACH:
fopen_s(&file_pointer, "C:\\Users\\Jonas\\Documents\\test333.txt", "r+");
int Handle_Process = GetCurrentProcess();
char* ImageBase = NULL;
if (EnumProcessModules(Handle_Process, array_modules, sizeof(array_modules), &number_bytes) != 0) {
for (i = 0; i < (number_bytes / sizeof(HMODULE)); i++) {
DWORD Module_LEN_string = GetModuleFileNameEx(Handle_Process, array_modules[i], BUFFER, sizeof(BUFFER));
fprintf(file_pointer, "%ls\n", BUFFER);
fprintf(file_pointer, "%p\n", array_modules[i]);
if (wcsstr(BUFFER, "Notepad.exe") != NULL) {
ImageBase = array_modules[i];
fprintf(file_pointer, "s\n", ImageBase);
}
else
fprintf(file_pointer, "%s\n", "FAILED");
}
}
fclose(file_pointer);
您应该使用以
L
前缀开头的宽字符文字:wcsstr(BUFFER, L"Notepad.exe")
。
GetCurrentProcess
的返回值类型应该是HANDLE
而不是int
。
HMOUDLE(array_modules)
类型的值不能分配给char(ImageBase)
类型的实体。您需要转换类型。