提交 09d5440c 编写于 作者: Peacoor Zomboss's avatar Peacoor Zomboss

Init Commit

上级
# binary
*.exe
*.dll
*.o
*.a
*.obj
*.zip
# visual studio
.vs/
x64/
x86/
[Dd]ebug/
[Rr]elease/
*.user
# vscode
.vscode/
CXX = g++
CXXFLAGS = -O2
DLLSRC = hook.cpp hookdll.cpp sockqueue.cpp
DLLOBJ = $(DLLSRC:.cpp=.o)
EXESRC = inject2civ6.cpp
EXEOBJ = $(EXESRC:.cpp=.o)
OUTPUT = ./bin/
DLL = $(OUTPUT)hookdll.dll
EXE = $(OUTPUT)inject2civ6.exe
all: check $(DLL) $(EXE)
$(DLL): $(DLLOBJ)
$(CXX) -o $@ $(DLLOBJ) -l ws2_32 -shared
$(EXE): $(EXEOBJ)
$(CXX) -o $@ $(EXEOBJ) -mwindows
check:
@ if not exist bin md bin
clean:
del *.o
del bin\*.exe bin\*.dll
# 文明6 hook sendto
经测试,文明6局域网找房间是使用sendto向62900-62999这100个端口发udp广播,同时监听sendto的那个端口,把接收到的房间信息放入游戏房间列表,玩家进入房间后就与对方通过62056号端口直接udp通信了
但是由于Windows下使用sendto发送广播系统一般会用默认网卡,除非去改网卡的跃点,不然udp广播是不会发到虚拟网卡的
解决方法之一是拦截系统所有的udp广播转发到每一张网卡,而本仓库采用的是另一种方法,即hook游戏进程的sendto函数,实现udp广播的转发
不过由于不同游戏的机制不一样,所以对每一款游戏都要抓包分析一下然后才能确定,不过在本仓库代码基础上,可以进一步根据游戏机制hook其他联网函数,实现想要的效果
而且有的游戏可能会检测不允许dll注入,这个方法也就不行了
# 使用方法
确保dll和exe在同一个文件夹,确保dll名字是"hookdll.dll",然后双击运行"inject2civ6.exe",如果出错照着提示就可以了
# 编译说明
仅兼容Windows平台,不兼容其他平台,同时只支持x86架构,不支持arm等
本程序使用vscode+mingw64环境开发,然后再适配visual studio,所以使用vs可能面临一些警告(尽可能减少)
mingw64的g++版本为8.5.0,理论兼容更新的版本
vs用的2022版(17.4),不确定是不是兼容老版本
因为文明6是64位的,所以要以64位模式编译代码
## mingw64
确保安装了mingw64并配置环境变量,在当前目录下打开命令行,运行mingw32-make即可,生成的二进制可以在bin目录下找到
## visual studio
依次打开两个工程,都选择x64 release,生成解决方案,在x64\Release目录下就可以找到编译好的文件。
#include <windows.h>
#include "hook.h"
union ptr64_union
{
void *ptr;
struct
{
long lo;
long hi;
};
};
Hook::Hook(void *func_ptr, void *fake_func):func_ptr(func_ptr)
{
ptr64_union ptr64;
ptr64.ptr = fake_func;
// 允许func_ptr处前14字节虚拟内存可运行可读可写
VirtualProtect(func_ptr, 14, PAGE_EXECUTE_READWRITE, NULL);
new_code[0] = 0x68; // push xxx
*(long *)&new_code[1] = ptr64.lo; // xxx,即地址的低4位
new_code[5] = 0xC7;
new_code[6] = 0x44;
new_code[7] = 0x24;
new_code[8] = 0x04; // mov dword [rsp+4], yyy
*(long *)&new_code[9] = ptr64.hi; // yyy,即地址的高4位
new_code[13] = 0xC3; // ret
/* 打个比方,生成的代码是这样的
68 44332211 push 0x11223344
C7442404 88776655 mov dword [rsp+4], 0x55667788
C3 ret
那么实际跳转到的地址是0x5566778811223344
*/
// 保存原来的入口代码
ReadProcessMemory(GetCurrentProcess(), func_ptr, &old_code, 14, NULL);
}
void Hook::dohook()
{
WriteProcessMemory(GetCurrentProcess(), func_ptr, &new_code, 14, NULL);
}
void Hook::unhook()
{
WriteProcessMemory(GetCurrentProcess(), func_ptr, &old_code, 14, NULL);
}
#pragma once
#include <windows.h>
class Hook
{
private:
char old_code[14]; // 存放原来的代码
char new_code[14]; // hook跳转的代码
void *func_ptr; // 被hook函数的地址
public:
Hook(void *func_ptr, void *fake_func);
void dohook();
void unhook();
};
#include <winsock2.h>
#include <windows.h>
#include <vector>
#include "hook.h"
#include "sockqueue.h"
#ifdef _MSC_VER
#pragma comment (lib, "ws2_32.lib") // 比较坑啊,在项目设置里加没用
#endif
Hook *sendto_hook;
SockQueue sockqueue;
// 枚举当前所有可用网卡的IPv4地址
std::vector<in_addr> enum_addr()
{
static std::vector<in_addr> list;
hostent *phost = gethostbyname(""); // 获取本机网卡
if (phost) {
if (phost->h_length == list.size()) // 数量相同直接返回
return list;
char **ppc = phost->h_addr_list; // 获取地址列表
if (ppc) {
list.clear();
// 遍历列表添加到容器
while (*ppc) {
in_addr addr;
memcpy(&addr, *ppc, sizeof(in_addr));
list.push_back(addr);
ppc++;
}
}
}
return list;
}
// hook后替换的函数
int WINAPI fake_sendto(SOCKET s, const char *buf, int len, int flags, const sockaddr *to, int tolen)
{
sendto_hook->unhook(); // 暂时取消hook,这个方法对多线程效果不好
int result = -1;
sockaddr_in *toaddr = (sockaddr_in *)to;
if (toaddr->sin_addr.S_un.S_addr != INADDR_BROADCAST) {
result = sendto(s, buf, len, flags, to, tolen); // 非广播直接原样发送
}
else {
sockaddr_in addr_self;
int namelen = sizeof(sockaddr_in);
getsockname(s, (sockaddr *)&addr_self, &namelen); // 获取原sockaddr
if (addr_self.sin_port == 0) {
// 如果没有端口号,先原样发送,这样系统才会分配一个端口号
result = sendto(s, buf, len, flags, to, tolen);
getsockname(s, (sockaddr *)&addr_self, &namelen); // 重新获取
}
std::vector<in_addr> list = enum_addr();
// 向列表中的每一个地址转发广播
for (int i = 0; i < list.size(); i++) {
addr_self.sin_addr = list[i]; // 把新的地址换上去,然后发送
SOCKET sock = socket(AF_INET, SOCK_DGRAM, 0);
BOOL opt = TRUE;
setsockopt(sock, SOL_SOCKET, SO_BROADCAST, (char *)&opt, sizeof(BOOL)); // 广播
setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *)&opt, sizeof(BOOL)); // 重用地址端口
bind(sock, (sockaddr *)&addr_self, sizeof(sockaddr)); // 绑定到地址端口
result = sendto(sock, buf, len, flags, to, tolen);
sockqueue.add(sock); // 加到socket队列里
}
}
sendto_hook->dohook(); // 重新hook
return result;
}
BOOL APIENTRY DllMain(HINSTANCE hinstdll, DWORD reason, LPVOID reserved)
{
if (reason == DLL_PROCESS_ATTACH) {
sendto_hook = new Hook((void *)sendto, (void *)fake_sendto);
sendto_hook->dohook();
}
else if (reason == DLL_PROCESS_DETACH) {
sendto_hook->unhook();
delete sendto_hook;
}
return TRUE;
}

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.3.32804.467
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "hookdll", "hookdll.vcxproj", "{D50931C7-9649-491F-8776-C11FE1E2A574}"
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
{D50931C7-9649-491F-8776-C11FE1E2A574}.Debug|x64.ActiveCfg = Debug|x64
{D50931C7-9649-491F-8776-C11FE1E2A574}.Debug|x64.Build.0 = Debug|x64
{D50931C7-9649-491F-8776-C11FE1E2A574}.Debug|x86.ActiveCfg = Debug|Win32
{D50931C7-9649-491F-8776-C11FE1E2A574}.Debug|x86.Build.0 = Debug|Win32
{D50931C7-9649-491F-8776-C11FE1E2A574}.Release|x64.ActiveCfg = Release|x64
{D50931C7-9649-491F-8776-C11FE1E2A574}.Release|x64.Build.0 = Release|x64
{D50931C7-9649-491F-8776-C11FE1E2A574}.Release|x86.ActiveCfg = Release|Win32
{D50931C7-9649-491F-8776-C11FE1E2A574}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {DFD173F5-5E85-497C-843C-7EBFA953A343}
EndGlobalSection
EndGlobal
<?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>
<ProjectGuid>{D50931C7-9649-491F-8776-C11FE1E2A574}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
</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" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;HOOKDLL_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<Optimization>Disabled</Optimization>
<AdditionalModuleDependencies>
</AdditionalModuleDependencies>
</ClCompile>
<Link>
<TargetMachine>MachineX86</TargetMachine>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<EntryPointSymbol>
</EntryPointSymbol>
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;HOOKDLL_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<AdditionalModuleDependencies>
</AdditionalModuleDependencies>
</ClCompile>
<Link>
<TargetMachine>MachineX86</TargetMachine>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<EntryPointSymbol>
</EntryPointSymbol>
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<AdditionalModuleDependencies>
</AdditionalModuleDependencies>
</ClCompile>
<Link>
<EntryPointSymbol>
</EntryPointSymbol>
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<AdditionalModuleDependencies>
</AdditionalModuleDependencies>
</ClCompile>
<Link>
<EntryPointSymbol>
</EntryPointSymbol>
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="hook.cpp" />
<ClCompile Include="hookdll.cpp" />
<ClCompile Include="sockqueue.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="hook.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<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</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="hook.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="hookdll.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="sockqueue.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="hook.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
\ No newline at end of file
/* 因为巨硬的大坑,这个文件是用UTF-8带BOM保存的,这样才能编译后面MessageBoxW的部分,
* 同样因为巨硬大坑,才会用MessageBoxW,不然中文不好正常显示了
*/
// 不要UNICODE,这个是针对一系列系统API的
#ifdef UNICODE
#undef UNICODE
#endif
#ifdef _UNICODE
#undef _UNICODE
#endif
#include <windows.h>
#include <tlhelp32.h>
#include <shlobj.h>
#include <shellapi.h>
#ifdef _MSC_VER
#pragma comment(linker, "/subsystem:windows /entry:mainCRTStartup") // 巨硬特色
#endif
// 查找文明6的进程(DX11和DX12),需要tlhelp32.h
DWORD get_civ6_proc()
{
HANDLE procsnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
PROCESSENTRY32 procentry;
procentry.dwSize = sizeof(PROCESSENTRY32);
Process32First(procsnapshot, &procentry);
if (strcmp(procentry.szExeFile, "CivilizationVI.exe") == 0 ||
strcmp(procentry.szExeFile, "CivilizationVI_DX12.exe") == 0) {
CloseHandle(procsnapshot);
return procentry.th32ProcessID;
}
while (Process32Next(procsnapshot, &procentry)) {
if (strcmp(procentry.szExeFile, "CivilizationVI.exe") == 0 ||
strcmp(procentry.szExeFile, "CivilizationVI_DX12.exe") == 0) {
CloseHandle(procsnapshot);
return procentry.th32ProcessID;
}
}
CloseHandle(procsnapshot);
return 0;
}
// 把DLL注入进程
bool inject(DWORD pid)
{
char dll_name[MAX_PATH];
DWORD len = GetModuleFileNameA(NULL, dll_name, MAX_PATH); // 获取exe绝对路径
for (int i = len - 1; i > 0; i--)
if (dll_name[i] == '\\') {
dll_name[i] = '\0'; // 把最后一个反斜杠换成0
break;
}
strcat(dll_name, "\\hookdll.dll"); // 拼接dll名
int namelen = strlen(dll_name) + 1;
HANDLE hproc = 0;
LPVOID pmem = NULL;
HANDLE hthread = 0;
bool result = false;
hproc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid); // 打开进程
if (hproc == 0) goto finally;
pmem = VirtualAllocEx(hproc, NULL, namelen, MEM_COMMIT, PAGE_READWRITE); // 申请内存
if (pmem == NULL) goto finally;
WriteProcessMemory(hproc, pmem, dll_name, namelen, NULL); // 把dll路径写进去
hthread = CreateRemoteThread(hproc, NULL, 0, (LPTHREAD_START_ROUTINE)LoadLibraryA, pmem, 0, NULL); // 创建远程线程注入
if (hthread == 0) goto finally;
WaitForSingleObject(hthread, INFINITE); // 等待线程执行
DWORD threadres;
GetExitCodeThread(hthread, &threadres); // 获取返回值
result = threadres != 0; // LoadLibraryA错误返回0
// 安全释放相应资源
finally:
if (pmem)
VirtualFreeEx(hproc, pmem, 0, MEM_RELEASE);
if (hthread != 0)
CloseHandle(hthread);
if (hproc != 0)
CloseHandle(hproc);
return result;
}
// 以管理员权限重新运行当前程序,需要shellapi.h
bool runas_admin()
{
char exename[MAX_PATH];
GetModuleFileNameA(NULL, exename, MAX_PATH); // 同上
// 详见 https://learn.microsoft.com/en-us/windows/win32/api/shellapi/ns-shellapi-shellexecuteinfoa
SHELLEXECUTEINFOA sei;
memset(&sei, 0, sizeof(sei));
sei.cbSize = sizeof(sei);
sei.fMask = SEE_MASK_FLAG_DDEWAIT | SEE_MASK_FLAG_NO_UI; // 设置等待+不显示错误框
sei.lpVerb = "runas";
sei.lpFile = exename;
sei.nShow = SW_SHOWNORMAL;
return ShellExecuteExA(&sei);
}
int main()
{
int msgres = 0;
bool isadmin = IsUserAnAdmin(); // 检测当前是否有管理员权限,需要shlobj.h
DWORD civ6pid = get_civ6_proc(); // 获取游戏进程
// 循环检测游戏进程,提醒用户启动游戏
while (civ6pid == 0) {
msgres = MessageBoxW(0, L"请先运行游戏,然后点击重试", L"错误", MB_RETRYCANCEL | MB_ICONERROR);
if (msgres == IDRETRY)
civ6pid = get_civ6_proc();
else
return 0;
}
retry_inject:
// 尝试注入
if (inject(civ6pid)) {
MessageBoxW(0, L"注入成功!", L"成功", MB_OK);
}
else {
// 如果管理员权限也失败了,一般是dll和exe不在同一目录或者dll被改名了,或者编译了32位的
// 杀毒软件应该不会光顾吧?
if (isadmin) {
// 一般情况下是走不到这里来的
msgres = MessageBoxW(0, L"注入失败", L"错误", MB_RETRYCANCEL | MB_ICONERROR);
if (msgres == IDRETRY)
goto retry_inject;
return 0;
}
else {
// 有的时候比如steam运行游戏可能是带管理员权限的,这个时候要注入程序也要有管理员权限
msgres = MessageBoxW(0, L"注入失败,是否以管理员权限重试?", L"错误", MB_ICONERROR | MB_RETRYCANCEL);
if (msgres == IDRETRY) {
retry_runas:
if (runas_admin()) // 成功运行就退出自己
return 0;
msgres = MessageBoxW(0, L"请在弹出的窗口中点击“是”", L"错误", MB_ICONERROR | MB_RETRYCANCEL);
if (msgres == IDRETRY)
goto retry_runas;
return 0;
}
return 0;
}
}
}

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.3.32804.467
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "inject2civ6", "inject2civ6.vcxproj", "{8ED33588-55B7-45D4-A039-E148A667E320}"
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
{8ED33588-55B7-45D4-A039-E148A667E320}.Debug|x64.ActiveCfg = Debug|x64
{8ED33588-55B7-45D4-A039-E148A667E320}.Debug|x64.Build.0 = Debug|x64
{8ED33588-55B7-45D4-A039-E148A667E320}.Debug|x86.ActiveCfg = Debug|Win32
{8ED33588-55B7-45D4-A039-E148A667E320}.Debug|x86.Build.0 = Debug|Win32
{8ED33588-55B7-45D4-A039-E148A667E320}.Release|x64.ActiveCfg = Release|x64
{8ED33588-55B7-45D4-A039-E148A667E320}.Release|x64.Build.0 = Release|x64
{8ED33588-55B7-45D4-A039-E148A667E320}.Release|x86.ActiveCfg = Release|Win32
{8ED33588-55B7-45D4-A039-E148A667E320}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {442DED28-236E-40B5-B6ED-26F6FC4C2EAA}
EndGlobalSection
EndGlobal
<?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>
<ProjectGuid>{8ED33588-55B7-45D4-A039-E148A667E320}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
</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>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
</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" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<Optimization>Disabled</Optimization>
</ClCompile>
<Link>
<TargetMachine>MachineX86</TargetMachine>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<TargetMachine>MachineX86</TargetMachine>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="inject2civ6.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<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</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="inject2civ6.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
\ No newline at end of file
#include "sockqueue.h"
SockQueue::SockQueue()
{
memset(&socks, 0, MAX_SOCK_QUEUE * sizeof(SOCKET));
current = 0;
}
SockQueue::~SockQueue()
{
for (int i = 0; i < MAX_SOCK_QUEUE; i++)
if (socks[i] != 0)
closesocket(socks[i]);
}
void SockQueue::add(SOCKET s)
{
if (socks[current] != 0)
closesocket(socks[current]);
socks[current++] = s;
if (current == MAX_SOCK_QUEUE)
current = 0;
}
#pragma once
#include <winsock2.h>
#define MAX_SOCK_QUEUE 64
// Socket循环队列,使socket排队关闭而不是立即关闭
class SockQueue
{
private:
SOCKET socks[MAX_SOCK_QUEUE];
int current;
public:
SockQueue();
~SockQueue();
void add(SOCKET s);
};
# 许可证
本仓库所有代码均使用MIT License
内容如下:
Copyright © 2023 Peacoor Zomboss
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
你也可以在<https://mit-license.org/>找到这些内容。
回到[Readme](Readme.md)
# 杂项
记录一些杂七杂八的文章所用到的代码
<https://blog.csdn.net/PeaZomboss>
<https://www.cnblogs.com/PeaZomboss/>
由于水平有限,如有错误欢迎指出
# 目录说明
每个目录均是某一篇文章的代码,具体见每个目录下的Readme说明(包含简介和编译方法)
目录命名规则:年(后两位)月(两位)日(两位)-内容
时间为创建文件夹的时间
例如:"230101-helloworld",代表这个文件夹是2023年1月1日创建,内容是helloworld
# 许可证
本仓库采用MIT License,具体见[License](License.md)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册