65,210
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <windows.h>
const char* dllPath = "E:\\CAJ\\Osiris.dll"; // 替换为Osiris.dll的路径
BOOL InjectDll(DWORD processId, const char* dllPath)
{
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processId);
if (!hProcess)
{
std::cout << "Failed to open process." << std::endl;
return FALSE;
}
LPVOID pRemoteDllPath = VirtualAllocEx(hProcess, NULL, strlen(dllPath) + 1, MEM_COMMIT, PAGE_READWRITE);
if (!pRemoteDllPath)
{
std::cout << "Failed to allocate memory in remote process." << std::endl;
CloseHandle(hProcess);
return FALSE;
}
if (!WriteProcessMemory(hProcess, pRemoteDllPath, dllPath, strlen(dllPath) + 1, NULL))
{
std::cout << "Failed to write DLL path to remote process." << std::endl;
VirtualFreeEx(hProcess, pRemoteDllPath, 0, MEM_RELEASE);
CloseHandle(hProcess);
return FALSE;
}
HMODULE hKernel32 = GetModuleHandleA("kernel32.dll");
if (!hKernel32)
{
std::cout << "Failed to get handle to kernel32.dll." << std::endl;
VirtualFreeEx(hProcess, pRemoteDllPath, 0, MEM_RELEASE);
CloseHandle(hProcess);
return FALSE;
}
LPTHREAD_START_ROUTINE pLoadLibraryA = (LPTHREAD_START_ROUTINE)GetProcAddress(hKernel32, "LoadLibraryA");
if (!pLoadLibraryA)
{
std::cout << "Failed to get address of LoadLibraryA." << std::endl;
VirtualFreeEx(hProcess, pRemoteDllPath, 0, MEM_RELEASE);
CloseHandle(hProcess);
return FALSE;
}
HANDLE hRemoteThread = CreateRemoteThread(hProcess, NULL, 0, pLoadLibraryA, pRemoteDllPath, 0, NULL);
if (!hRemoteThread)
{
std::cout << "Failed to create remote thread." << std::endl;
VirtualFreeEx(hProcess, pRemoteDllPath, 0, MEM_RELEASE);
CloseHandle(hProcess);
return FALSE;
}
WaitForSingleObject(hRemoteThread, INFINITE);
DWORD exitCode;
GetExitCodeThread(hRemoteThread, &exitCode);
VirtualFreeEx(hProcess, pRemoteDllPath, 0, MEM_RELEASE);
CloseHandle(hRemoteThread);
CloseHandle(hProcess);
return exitCode != 0;
}
bool IsRunAsAdmin()
{
BOOL fIsRunAsAdmin = FALSE;
DWORD dwError = ERROR_SUCCESS;
PSID pAdministratorsGroup = NULL;
SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;
if (!AllocateAndInitializeSid(&NtAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID,
DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &pAdministratorsGroup))
{
dwError = GetLastError();
goto Cleanup;
}
if (!CheckTokenMembership(NULL, pAdministratorsGroup, &fIsRunAsAdmin))
{
dwError = GetLastError();
goto Cleanup;
}
Cleanup:
if (pAdministratorsGroup)
{
FreeSid(pAdministratorsGroup);
pAdministratorsGroup = NULL;
}
SetLastError(dwError);
return fIsRunAsAdmin == TRUE;
}
int main()
{
if (!IsRunAsAdmin())
{
std::cout << "Please run the program as administrator." << std::endl;
std::cin.get();
return 0;
}
DWORD processId;
HWND hwnd = FindWindowA(NULL, "Counter-Strike: Global Offensive - Direct3d 9"); // 替换为csgo.exe窗口的标题或其他标识符
if (hwnd == NULL)
{
std::cout << "Failed to find csgo.exe window." << std::endl;
std::cin.get();
return 0;
}
GetWindowThreadProcessId(hwnd, &processId);
if (InjectDll(processId, dllPath))
{
std::cout << "DLL successfully injected." << std::endl;
}
else
{
std::cout << "Failed to inject DLL." << std::endl;
}
std::cout << "Press Enter to exit." << std::endl;
std::cin.get();
return 0;
}
应该已经成功了,但就是没有效果
这段代码的作用是注入指定的 DLL 文件到指定进程中,并且需要以管理员权限运行才能生效。如果你已经按照代码要求进行了操作,但是没有效果,可能是以下原因之一:
DLL 文件路径错误:请确保代码中 dllPath 变量的值正确,并且指向了正确的 DLL 文件路径。
进程 ID 错误:请确保代码中获取到的进程 ID 是正确的,并且是目标进程。
窗口标题或标识符错误:请确保代码中指定的窗口标题或标识符是正确的,并且是目标进程的窗口。
权限不足:如果你的程序没有足够的权限来注入 DLL 文件,那么即使代码运行成功,也不会生效。你可以尝试使用管理员权限运行程序,或者将代码中的权限检查去掉。
目标进程不存在:请确保你指定的进程 ID 是正确的,并且目标进程确实存在。你可以尝试在任务管理器中查看进程列表,或者使用其他方法查找目标进程。
如果你仍然无法解决问题,请提供更多的信息,例如错误信息、程序运行日志等,以便我更好地帮助你。