我正在尝试调试我注入另一个进程的dll。
这是我的代码:
// dllmain.cpp : Defines the entry point for the DLL application.
#include "stdafx.h"
#include <iostream>
#include <thread>
#include "jvmti/jni.h"
bool started = false;
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
std::cout << "Started?" << std::endl;
if(ul_reason_for_call == DLL_PROCESS_ATTACH)
{
std::cout << "Attached to process!" << std::endl;
if(!started)
{
started = true;
void startClient();
std::thread startThread(startClient);
}
}
else if(ul_reason_for_call == DLL_PROCESS_DETACH)
{
std::cout << "Detached from process!" << std::endl;
}
return TRUE;
}
typedef jint(CALLBACK* GetJvmsFunc)(JavaVM**, jsize, jsize*);
void startClient()
{
HMODULE javaHandle = GetModuleHandle(L"jvm.dll");
GetJvmsFunc getJvmsFunc = reinterpret_cast<GetJvmsFunc>(GetProcAddress(javaHandle, "JNI_GetCreatedJavaVMs"));
JavaVM** vmBuf = NULL;
jsize* numberOfVms = NULL;
jsize bufLen = 1;
long* numOfVms = static_cast<long*>(numberOfVms);
jint funcStatus = getJvmsFunc(vmBuf, bufLen, numberOfVms);
printf("Function status: %ld\n", funcStatus);
printf("Number of VMS: %p\n", (void*)numberOfVms);
}
现在每当我运行此代码时,我都会注入崩溃的进程。为了诊断这个,我在这个方法的第一行放了一个断点,如下所示:
现在我看不出这个代码怎么会被击中?我启动一个应立即调用startClient()
函数的线程。
我还尝试清理并重建我的项目,删除所有符号文件,清除符号缓存等等。
我目前唯一的想法是Visual Studio在调试时产生的输出。它没有明确声明它为我的DLL加载符号。这是输出:
'Incognito Premium.exe' (Win32): Loaded 'C:\Programming\VisualProjects\Incognito Premium\Incognito Premium\x64\Debug\Incognito Premium.exe'. Symbols loaded.
'Incognito Premium.exe' (Win32): Loaded 'C:\Windows\System32\ntdll.dll'. Symbols loaded.
'Incognito Premium.exe' (Win32): Loaded 'C:\Windows\System32\kernel32.dll'. Symbols loaded.
'Incognito Premium.exe' (Win32): Loaded 'C:\Windows\System32\KernelBase.dll'. Symbols loaded.
'Incognito Premium.exe' (Win32): Loaded 'C:\Windows\System32\vcruntime140d.dll'. Symbols loaded.
'Incognito Premium.exe' (Win32): Loaded 'C:\Windows\System32\ucrtbased.dll'. Symbols loaded.
'Incognito Premium.exe' (Win32): Loaded 'C:\Windows\System32\msvcp140d.dll'. Symbols loaded.
'Incognito Premium.exe' (Win32): Loaded 'C:\Windows\System32\advapi32.dll'. Symbols loaded.
'Incognito Premium.exe' (Win32): Loaded 'C:\Windows\System32\msvcrt.dll'. Symbols loaded.
'Incognito Premium.exe' (Win32): Loaded 'C:\Windows\System32\sechost.dll'. Symbols loaded.
'Incognito Premium.exe' (Win32): Loaded 'C:\Windows\System32\rpcrt4.dll'. Symbols loaded.
'Incognito Premium.exe' (Win32): Loaded 'C:\Windows\System32\cryptbase.dll'. Symbols loaded.
'Incognito Premium.exe' (Win32): Loaded 'C:\Windows\System32\bcryptprimitives.dll'. Symbols loaded.
The thread 0x20b4 has exited with code 0 (0x0).
The thread 0x21dc has exited with code 0 (0x0).
The thread 0x2098 has exited with code 0 (0x0).
是什么导致了这个问题?