Как исправить ошибку внедрения DLL в Cheat Engine для приложения .NETC#

Место общения программистов C#
Ответить
Anonymous
 Как исправить ошибку внедрения DLL в Cheat Engine для приложения .NET

Сообщение Anonymous »


Изображение
Я пытаюсь внедрить DLL, написанную на C/C++ в приложение .NET с помощью Cheat Engine. Однако появляется сообщение об ошибке: «Ошибка dllInject: не удалось внедрить модуль принудительной загрузки DLL: не удалось найти адрес msvcrt! _dllonexit». Я относительно новичок в программировании .NET и не уверен, нужно ли писать DLL на .NET, а не на C/C++. Как я могу решить эту проблему? Необходимо ли писать DLL в .NET, чтобы она корректно работала с приложением .NET?
Сначала я попробовал внедрить отсутствующую библиотеку msvcrt.dll, но это не решило проблему. проблема. Я ожидал, что DLL будет успешно внедрена в приложение .NET без ошибок. Вместо этого я получил сообщение об ошибке: «Ошибка dllInject: не удалось внедрить модуль принудительной загрузки DLL: не удалось найти адрес msvcrt!_dllonexit».
вот этот код dll
#include
#include

// Function pointer for managed code function
typedef void(__stdcall *ActivateClickFunction)();

// Function prototype
void InjectedMain();

// Entry point of DLL
BOOL APIENTRY DllMain(HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
// Load msvcrt.dll explicitly
{
HMODULE hMsvcrt = LoadLibraryA("msvcrt.dll");
if (hMsvcrt == NULL)
{
MessageBoxW(NULL, L"Failed to load msvcrt.dll!", L"Error", MB_OK | MB_ICONERROR);
return FALSE; // Or handle the error as appropriate
}
}

// Injected into process
MessageBoxW(NULL, L"SRhij.dll loaded successfully!", L"DLL Injector", MB_OK | MB_ICONINFORMATION);
InjectedMain();
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}

// Function to find MainWindow and invoke Activate_Click method
void InjectedMain()
{
// Find the target window by class name or other criteria
HWND mainWindowHandle = FindWindowW(L"iRemovalProWPF.MainWindow", NULL);

if (mainWindowHandle == NULL)
{
MessageBoxW(NULL, L"Failed to find MainWindow!", L"Error", MB_OK | MB_ICONERROR);
return;
}

// Get process ID of the window
DWORD processId;
GetWindowThreadProcessId(mainWindowHandle, &processId);

// Open process with necessary permissions
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processId);
if (hProcess == NULL)
{
MessageBoxW(NULL, L"Failed to open process!", L"Error", MB_OK | MB_ICONERROR);
return;
}

// Specify the path of mscoree.dll
LPCWSTR dllPath = L"mscoree.dll";

// Load .NET runtime into the target process using full path
HMODULE hDotNetModule = LoadLibraryExW(dllPath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
if (hDotNetModule == NULL)
{
DWORD error = GetLastError();
WCHAR errorMsg[256];
// Use snwprintf for buffer safety
_snwprintf(errorMsg, 256, L"Failed to load %s! Error code: %lu", dllPath, error);
errorMsg[255] = L'\0'; // Ensure null termination
MessageBoxW(NULL, errorMsg, L"Error", MB_OK | MB_ICONERROR);
CloseHandle(hProcess); // Assuming hProcess is a valid handle to the target process
return;
}

// Get the address of the managed entry point method in the target process
ActivateClickFunction activateClick = (ActivateClickFunction) GetProcAddress(hDotNetModule, "Someting_That_is+under_those_program"); // that is example
if (activateClick == NULL)
{
DWORD error = GetLastError();
WCHAR errorMsg[256];
// Use snwprintf for buffer safety
_snwprintf(errorMsg, 256, L"Failed to get address of Activate_Click method! Error code: %lu", error);
errorMsg[255] = L'\0'; // Ensure null termination
MessageBoxW(NULL, errorMsg, L"Error", MB_OK | MB_ICONERROR);
FreeLibrary(hDotNetModule);
CloseHandle(hProcess);
return;
}

// Call the managed method in the target process
activateClick();

// Cleanup
FreeLibrary(hDotNetModule);
CloseHandle(hProcess);
}



Подробнее здесь: https://stackoverflow.com/questions/786 ... pplication
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»