注入wow.exe的X86实用程序

This commit is contained in:
尚美 2025-01-10 21:19:29 +08:00
parent 5cc6fe3451
commit 7e5b80cece
54 changed files with 483 additions and 0 deletions

228
MPQInjector/MPQInjector.cpp Normal file
View File

@ -0,0 +1,228 @@
#include <windows.h>
#include <tlhelp32.h>
#include <iostream>
#include <psapi.h>
#pragma comment(lib, "psapi.lib")
// 检查管理员权限
bool IsRunningAsAdmin() {
BOOL isAdmin = FALSE;
PSID adminGroup = NULL;
// 创建管理员组的 SID
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,
&adminGroup)) {
// 检查当前进程是否属于管理员组
if (!CheckTokenMembership(NULL, adminGroup, &isAdmin)) {
isAdmin = FALSE;
}
FreeSid(adminGroup);
}
return isAdmin == TRUE;
}
// 自动请求以管理员权限重新运行
void RelaunchAsAdmin() {
char exePath[MAX_PATH];
GetModuleFileNameA(NULL, exePath, MAX_PATH); // 获取当前程序的路径
SHELLEXECUTEINFOA sei = { sizeof(SHELLEXECUTEINFOA) };
sei.lpVerb = "runas"; // 请求管理员权限
sei.lpFile = exePath; // 当前程序路径
sei.hwnd = NULL;
sei.nShow = SW_SHOWNORMAL;
if (!ShellExecuteExA(&sei)) {
DWORD error = GetLastError();
if (error == ERROR_CANCELLED) {
std::cout << "用户取消了管理员权限请求" << std::endl;
}
else {
std::cout << "请求管理员权限失败, 错误码: " << error << std::endl;
}
}
else {
std::cout << "以管理员权限重新启动程序..." << std::endl;
}
exit(0); // 退出当前程序,等待以管理员权限运行的进程启动
}
DWORD GetProcessIdByName(const wchar_t* processName) {
DWORD processId = 0;
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (snapshot == INVALID_HANDLE_VALUE) {
std::cout << "无法创建进程快照, 错误码: " << GetLastError() << std::endl;
return 0;
}
PROCESSENTRY32W processEntry;
processEntry.dwSize = sizeof(PROCESSENTRY32W);
if (Process32FirstW(snapshot, &processEntry)) {
do {
if (_wcsicmp(processEntry.szExeFile, processName) == 0) {
processId = processEntry.th32ProcessID;
break;
}
} while (Process32NextW(snapshot, &processEntry));
}
else {
std::cout << "Process32FirstW 失败, 错误码: " << GetLastError() << std::endl;
}
CloseHandle(snapshot);
if (processId == 0) {
std::cout << "未找到目标进程: " << processName << std::endl;
}
return processId;
}
DWORD WINAPI LoadDllAndGetError(LPVOID lpParam) {
HMODULE hModule = LoadLibraryA((LPCSTR)lpParam);
if (!hModule) {
return GetLastError();
}
return 1;
}
bool InjectDLL(DWORD processId, const char* dllPath) {
std::cout << "开始注入过程..." << std::endl;
HANDLE hProcess = OpenProcess(PROCESS_CREATE_THREAD | PROCESS_VM_OPERATION |
PROCESS_VM_WRITE | PROCESS_VM_READ, FALSE, processId);
if (!hProcess) {
std::cout << "打开进程失败, 错误码: " << GetLastError() << std::endl;
return false;
}
SIZE_T pathLen = (strlen(dllPath) + 1);
LPVOID pszLibFileRemote = VirtualAllocEx(hProcess, NULL, pathLen,
MEM_COMMIT, PAGE_READWRITE);
if (!pszLibFileRemote) {
std::cout << "分配内存失败, 错误码: " << GetLastError() << std::endl;
CloseHandle(hProcess);
return false;
}
if (!WriteProcessMemory(hProcess, pszLibFileRemote, dllPath, pathLen, NULL)) {
std::cout << "写入内存失败, 错误码: " << GetLastError() << std::endl;
VirtualFreeEx(hProcess, pszLibFileRemote, 0, MEM_RELEASE);
CloseHandle(hProcess);
return false;
}
HMODULE hKernel32 = GetModuleHandleA("Kernel32");
FARPROC pfnLoadLibrary = GetProcAddress(hKernel32, "LoadLibraryA");
std::cout << "创建远程线程..." << std::endl;
HANDLE hThread = CreateRemoteThread(hProcess, NULL, 0,
(LPTHREAD_START_ROUTINE)pfnLoadLibrary, pszLibFileRemote, 0, NULL);
if (!hThread) {
std::cout << "创建线程失败, 错误码: " << GetLastError() << std::endl;
VirtualFreeEx(hProcess, pszLibFileRemote, 0, MEM_RELEASE);
CloseHandle(hProcess);
return false;
}
DWORD waitResult = WaitForSingleObject(hThread, INFINITE);
std::cout << "等待结果: " << waitResult << std::endl;
DWORD exitCode = 0;
GetExitCodeThread(hThread, &exitCode);
std::cout << "LoadLibrary返回值: 0x" << std::hex << exitCode << std::endl;
if (exitCode == 0) {
// 获取目标进程中的最后错误码
HMODULE hKernel32 = GetModuleHandleA("Kernel32");
FARPROC pfnGetLastError = GetProcAddress(hKernel32, "GetLastError");
HANDLE hErrorThread = CreateRemoteThread(hProcess, NULL, 0,
(LPTHREAD_START_ROUTINE)pfnGetLastError, NULL, 0, NULL);
if (hErrorThread) {
WaitForSingleObject(hErrorThread, INFINITE);
DWORD errorCode;
GetExitCodeThread(hErrorThread, &errorCode);
std::cout << "目标进程错误码: " << std::dec << errorCode << std::endl;
CloseHandle(hErrorThread);
}
}
VirtualFreeEx(hProcess, pszLibFileRemote, 0, MEM_RELEASE);
CloseHandle(hThread);
CloseHandle(hProcess);
return exitCode != 0;
}
int main() {
if (!IsRunningAsAdmin()) {
std::cout << "程序未以管理员权限运行,尝试重新启动..." << std::endl;
RelaunchAsAdmin();
return 0;
}
std::cout << "程序以管理员权限运行" << std::endl;
// 获取exe所在目录
char exePath[MAX_PATH];
GetModuleFileNameA(NULL, exePath, MAX_PATH);
// 获取目录部分
char* lastSlash = strrchr(exePath, '\\');
if (lastSlash) {
*lastSlash = 0;
}
std::cout << "EXE目录: " << exePath << std::endl;
char fullDllPath[MAX_PATH];
sprintf_s(fullDllPath, "%s\\MPQDumper.dll", exePath);
std::cout << "尝试加载: " << fullDllPath << std::endl;
HMODULE hDll = LoadLibraryA(fullDllPath);
if (!hDll) {
DWORD error = GetLastError();
char sysMsg[256];
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, error,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
sysMsg, sizeof(sysMsg), NULL);
std::cout << "加载失败详细信息: " << sysMsg << std::endl;
system("pause");
return 1;
}
FreeLibrary(hDll);
DWORD processId = GetProcessIdByName(L"Wow.exe");
if (!processId) {
std::cout << "未找到WoW进程" << std::endl;
system("pause");
return 1;
}
std::cout << "完整DLL路径: " << fullDllPath << std::endl;
std::cout << "进程ID: " << processId << std::endl;
if (InjectDLL(processId, fullDllPath)) {
std::cout << "DLL注入成功" << std::endl;
}
system("pause");
return 0;
}

View File

@ -0,0 +1,28 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.12.35527.113 d17.12
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MPQInjector", "MPQInjector.vcxproj", "{D36EBCA6-A622-444D-A9DC-602E0798958F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D36EBCA6-A622-444D-A9DC-602E0798958F}.Debug|x64.ActiveCfg = Debug|x64
{D36EBCA6-A622-444D-A9DC-602E0798958F}.Debug|x64.Build.0 = Debug|x64
{D36EBCA6-A622-444D-A9DC-602E0798958F}.Debug|x86.ActiveCfg = Debug|Win32
{D36EBCA6-A622-444D-A9DC-602E0798958F}.Debug|x86.Build.0 = Debug|Win32
{D36EBCA6-A622-444D-A9DC-602E0798958F}.Release|x64.ActiveCfg = Release|x64
{D36EBCA6-A622-444D-A9DC-602E0798958F}.Release|x64.Build.0 = Release|x64
{D36EBCA6-A622-444D-A9DC-602E0798958F}.Release|x86.ActiveCfg = Release|Win32
{D36EBCA6-A622-444D-A9DC-602E0798958F}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,135 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>17.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{d36ebca6-a622-444d-a9dc-602e0798958f}</ProjectGuid>
<RootNamespace>MPQInjector</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="MPQInjector.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="源文件">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="头文件">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="资源文件">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="MPQInjector.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<ProjectOutputs>
<ProjectOutput>
<FullPath>D:\sm_az\Tool\MPQDumper\MPQInjector\Debug\MPQInjector.exe</FullPath>
</ProjectOutput>
</ProjectOutputs>
<ContentFiles />
<SatelliteDlls />
<NonRecipeFileRefs />
</Project>

Binary file not shown.

View File

@ -0,0 +1,2 @@
 MPQInjector.cpp
MPQInjector.vcxproj -> D:\sm_az\Tool\MPQDumper\MPQInjector\Debug\MPQInjector.exe

Binary file not shown.

View File

@ -0,0 +1 @@
D:\sm_az\Tool\MPQDumper\MPQInjector\MPQInjector.cpp;D:\sm_az\Tool\MPQDumper\MPQInjector\MPQInjector\Debug\MPQInjector.obj

View File

@ -0,0 +1,2 @@
PlatformToolSet=v143:VCToolArchitecture=Native32Bit:VCToolsVersion=14.42.34433:TargetPlatformVersion=10.0.26100.0:
Debug|Win32|D:\sm_az\Tool\MPQDumper\MPQInjector\|

View File

@ -0,0 +1,2 @@
^D:\SM_AZ\TOOL\MPQDUMPER\MPQINJECTOR\MPQINJECTOR\DEBUG\MPQINJECTOR.OBJ
D:\sm_az\Tool\MPQDumper\MPQInjector\MPQInjector\Debug\MPQInjector.ilk

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<ProjectOutputs>
<ProjectOutput>
<FullPath>D:\sm_az\Tool\MPQDumper\MPQInjector\Release\MPQInjector.exe</FullPath>
</ProjectOutput>
</ProjectOutputs>
<ContentFiles />
<SatelliteDlls />
<NonRecipeFileRefs />
</Project>

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,7 @@
 MPQInjector.cpp
正在生成代码
2 of 21 functions ( 9.5%) were compiled, the rest were copied from previous compilation.
0 functions were new in current compilation
0 functions had inline decision re-evaluated but remain unchanged
已完成代码的生成
MPQInjector.vcxproj -> D:\sm_az\Tool\MPQDumper\MPQInjector\Release\MPQInjector.exe

Binary file not shown.

View File

@ -0,0 +1 @@
D:\sm_az\Tool\MPQDumper\MPQInjector\MPQInjector.cpp;D:\sm_az\Tool\MPQDumper\MPQInjector\MPQInjector\Release\MPQInjector.obj

View File

@ -0,0 +1,2 @@
PlatformToolSet=v143:VCToolArchitecture=Native32Bit:VCToolsVersion=14.42.34433:TargetPlatformVersion=10.0.26100.0:
Release|Win32|D:\sm_az\Tool\MPQDumper\MPQInjector\|

View File

@ -0,0 +1,3 @@
^D:\SM_AZ\TOOL\MPQDUMPER\MPQINJECTOR\MPQINJECTOR\RELEASE\MPQINJECTOR.OBJ
D:\sm_az\Tool\MPQDumper\MPQInjector\MPQInjector\Release\MPQInjector.IPDB
D:\sm_az\Tool\MPQDumper\MPQInjector\MPQInjector\Release\MPQInjector.iobj

Binary file not shown.

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<ProjectOutputs>
<ProjectOutput>
<FullPath>D:\sm_az\Tool\MPQDumper\MPQInjector\x64\Release\MPQInjector.exe</FullPath>
</ProjectOutput>
</ProjectOutputs>
<ContentFiles />
<SatelliteDlls />
<NonRecipeFileRefs />
</Project>

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,7 @@
 MPQInjector.cpp
正在生成代码
2 of 21 functions ( 9.5%) were compiled, the rest were copied from previous compilation.
1 functions were new in current compilation
0 functions had inline decision re-evaluated but remain unchanged
已完成代码的生成
MPQInjector.vcxproj -> D:\sm_az\Tool\MPQDumper\MPQInjector\x64\Release\MPQInjector.exe

Binary file not shown.

View File

@ -0,0 +1 @@
D:\sm_az\Tool\MPQDumper\MPQInjector\MPQInjector.cpp;D:\sm_az\Tool\MPQDumper\MPQInjector\MPQInjector\x64\Release\MPQInjector.obj

View File

@ -0,0 +1,2 @@
PlatformToolSet=v143:VCToolArchitecture=Native64Bit:VCToolsVersion=14.42.34433:TargetPlatformVersion=10.0.26100.0:
Release|x64|D:\sm_az\Tool\MPQDumper\MPQInjector\|

View File

@ -0,0 +1,3 @@
^D:\SM_AZ\TOOL\MPQDUMPER\MPQINJECTOR\MPQINJECTOR\X64\RELEASE\MPQINJECTOR.OBJ
D:\sm_az\Tool\MPQDumper\MPQInjector\MPQInjector\x64\Release\MPQInjector.IPDB
D:\sm_az\Tool\MPQDumper\MPQInjector\MPQInjector\x64\Release\MPQInjector.iobj

Binary file not shown.