Skip to content

Commit

Permalink
[功能] CxdecStringDumper
Browse files Browse the repository at this point in the history
  • Loading branch information
YeLikesss committed Jun 9, 2024
1 parent 810de09 commit 1829eb0
Show file tree
Hide file tree
Showing 15 changed files with 1,244 additions and 61 deletions.
169 changes: 132 additions & 37 deletions CxdecExtractorLoader/CxdecExtractorLoader.cpp
Original file line number Diff line number Diff line change
@@ -1,62 +1,157 @@
#include <windows.h>
#include <detours.h>
#include <Shlwapi.h>
#pragma comment(lib, "shlwapi.lib")

#include "path.h"
#include "util.h"
#include "directory.h"
#include "encoding.h"
#include "resource.h"

#pragma comment(linker, "/MERGE:\".detourd=.data\"")
#pragma comment(linker, "/MERGE:\".detourc=.rdata\"")

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nShowCmd)
{
UNREFERENCED_PARAMETER(hPrevInstance);
constexpr size_t MaxPath = 1024u;
#ifdef _UNICODE
#if defined _M_IX86
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_X64
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#else
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#endif
#endif

wchar_t appFullPathW[MaxPath];
wchar_t gameFullPathW[MaxPath];
GetModuleFileNameW(hInstance, appFullPathW, MaxPath);

int argc = 0;
LPWSTR* argv = CommandLineToArgvW(lpCmdLine, &argc);
if (argc)
{
wchar_t* arg = argv[0];
memcpy(gameFullPathW, arg, (lstrlenW(arg) + 1) * 2);
static std::wstring g_LoaderFullPath; //加载器全路径
static std::wstring g_LoaderCurrentDirectory; //加载器目录
static std::wstring g_KrkrExeFullPath; //Krkr游戏主程序全路径
static std::wstring g_KrkrExeDirectory; //Krkr游戏目录

if (lstrcmpW(appFullPathW, gameFullPathW))
/// <summary>
/// 主窗体消息循环
/// </summary>
/// <param name="hwnd">窗口句柄</param>
/// <param name="msg">消息</param>
/// <param name="wParam"></param>
/// <param name="lParam"></param>
INT_PTR CALLBACK LoaderDialogWindProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_COMMAND:
{
wchar_t gameCurrentDirectory[MaxPath];
char injectDllFullPathA[MaxPath];

std::wstring injectDllFileName = std::wstring();
switch (LOWORD(wParam))
{
memcpy(gameCurrentDirectory, gameFullPathW, MaxPath);
*(PathFindFileNameW(gameCurrentDirectory) - 1u) = L'\0';
case IDC_Extractor:
{
injectDllFileName = L"CxdecExtractorUI.dll";
break;
}
case IDC_StringDumper:
{
injectDllFileName = L"CxdecStringDumper.dll";
break;
}
case IDC_KeyDumper:
{
//NotImpl
::MessageBoxW(nullptr, L"此功能暂未实现", L"错误", MB_OK);
break;
}
}

if (!injectDllFileName.empty())
{
constexpr const char InjectDllNameA[] = "CxdecExtractorUI.dll";
GetModuleFileNameA(hInstance, injectDllFullPathA, MaxPath);
char* dllName = PathFindFileNameA(injectDllFullPathA);
memcpy(dllName, InjectDllNameA, sizeof(InjectDllNameA));
}
std::wstring injectDllFullPath = Path::Combine(g_LoaderCurrentDirectory, injectDllFileName);
std::string injectDllFullPathA = Encoding::UnicodeToAnsi(injectDllFullPath, Encoding::CodePage::ACP);

STARTUPINFO si{ 0 };
si.cb = sizeof(si);
PROCESS_INFORMATION pi{ 0 };
STARTUPINFOW si{ };
si.cb = sizeof(si);
PROCESS_INFORMATION pi{ };

if (DetourCreateProcessWithDllW(gameFullPathW, NULL, NULL, NULL, FALSE, 0, NULL, gameCurrentDirectory, &si, &pi, injectDllFullPathA, NULL))
{
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
if (DetourCreateProcessWithDllW(g_KrkrExeFullPath.c_str(), NULL, NULL, NULL, FALSE, 0u, NULL, g_KrkrExeDirectory.c_str(), &si, &pi, injectDllFullPathA.c_str(), NULL))
{
::CloseHandle(pi.hThread);
::CloseHandle(pi.hProcess);

//运行成功 关闭窗口
::PostMessageW(hwnd, WM_CLOSE, 0u, 0u);
}
else
{
::MessageBoxW(nullptr, L"创建进程错误", L"错误", MB_OK);
}
}
else
return TRUE;
}
case WM_CLOSE:
{
::DestroyWindow(hwnd);
return TRUE;
}
case WM_DESTROY:
{
::PostQuitMessage(0);
return TRUE;
}
}
return FALSE;
}


int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nShowCmd)
{
UNREFERENCED_PARAMETER(hPrevInstance);

std::wstring loaderFullPath = Util::GetAppPathW();
std::wstring loaderCurrentDirectory = Path::GetDirectoryName(loaderFullPath);
std::wstring krkrExeFullPath = std::wstring();
std::wstring krkrExeDirectory = std::wstring();

//获取启动参数
{
int argc = 0;
LPWSTR* argv = ::CommandLineToArgvW(lpCmdLine, &argc);
if (argc)
{
wchar_t* arg = argv[0];

krkrExeFullPath = std::wstring(arg);
krkrExeDirectory = Path::GetDirectoryName(krkrExeFullPath);
}
::LocalFree(argv);
}

g_LoaderFullPath = loaderFullPath;
g_LoaderCurrentDirectory = loaderCurrentDirectory;
g_KrkrExeFullPath = krkrExeFullPath;
g_KrkrExeDirectory = krkrExeDirectory;

//启动加载器
{
if (!krkrExeFullPath.empty() && krkrExeFullPath != loaderFullPath)
{
HWND hwnd = ::CreateDialogParamW((HINSTANCE)hInstance, MAKEINTRESOURCEW(IDD_MainForm), NULL, LoaderDialogWindProc, 0u);
::ShowWindow(hwnd, SW_NORMAL);

MSG msg{ };
while (BOOL ret = ::GetMessageW(&msg, NULL, 0u, 0u))
{
MessageBoxW(nullptr, L"创建进程错误", L"错误", MB_OK);
if (ret == -1)
{
return -1;
}
else
{
::TranslateMessage(&msg);
::DispatchMessageW(&msg);
}
}
}
else
{
MessageBoxW(nullptr, L"请拖拽游戏主程序到启动器", L"错误", MB_OK);
::MessageBoxW(nullptr, L"请拖拽游戏主程序到启动器", L"错误", MB_OK);
}
}
LocalFree(argv);
return 0;
}
Binary file modified CxdecExtractorLoader/CxdecExtractorLoader.rc
Binary file not shown.
32 changes: 24 additions & 8 deletions CxdecExtractorLoader/CxdecExtractorLoader.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<ManagedAssembly>false</ManagedAssembly>
<EmbedManifest>false</EmbedManifest>
<GenerateManifest>false</GenerateManifest>
<EmbedManifest>true</EmbedManifest>
<GenerateManifest>true</GenerateManifest>
<LinkDelaySign>false</LinkDelaySign>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<GenerateManifest>false</GenerateManifest>
<EmbedManifest>false</EmbedManifest>
<GenerateManifest>true</GenerateManifest>
<EmbedManifest>true</EmbedManifest>
<ManagedAssembly>false</ManagedAssembly>
<LinkDelaySign>false</LinkDelaySign>
</PropertyGroup>
Expand All @@ -63,11 +63,11 @@
<WarningLevel>Level3</WarningLevel>
<PreprocessorDefinitions>_WIN32_WINNT=0x601;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>Default</LanguageStandard>
<LanguageStandard>stdcpp20</LanguageStandard>
<BufferSecurityCheck>false</BufferSecurityCheck>
<ExceptionHandling>false</ExceptionHandling>
<EnableEnhancedInstructionSet>AdvancedVectorExtensions2</EnableEnhancedInstructionSet>
<AdditionalIncludeDirectories>$(SolutionDir)Detours;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir)Detours;$(SolutionDir)Common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<SDLCheck>false</SDLCheck>
<GuardEHContMetadata>false</GuardEHContMetadata>
Expand Down Expand Up @@ -108,11 +108,11 @@
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>_WIN32_WINNT=0x601;WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>Default</LanguageStandard>
<LanguageStandard>stdcpp20</LanguageStandard>
<BufferSecurityCheck>false</BufferSecurityCheck>
<ExceptionHandling>false</ExceptionHandling>
<EnableEnhancedInstructionSet>AdvancedVectorExtensions2</EnableEnhancedInstructionSet>
<AdditionalIncludeDirectories>$(SolutionDir)Detours;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir)Detours;$(SolutionDir)Common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<RuntimeTypeInfo>false</RuntimeTypeInfo>
<CompileAsManaged>false</CompileAsManaged>
Expand Down Expand Up @@ -154,6 +154,14 @@
</Manifest>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\Common\directory.cpp" />
<ClCompile Include="..\Common\encoding.cpp" />
<ClCompile Include="..\Common\file.cpp" />
<ClCompile Include="..\Common\log.cpp" />
<ClCompile Include="..\Common\path.cpp" />
<ClCompile Include="..\Common\pe.cpp" />
<ClCompile Include="..\Common\stringhelper.cpp" />
<ClCompile Include="..\Common\util.cpp" />
<ClCompile Include="..\Detours\creatwth.cpp" />
<ClCompile Include="..\Detours\detours.cpp" />
<ClCompile Include="..\Detours\disasm.cpp" />
Expand All @@ -162,6 +170,14 @@
<ClCompile Include="CxdecExtractorLoader.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\Common\directory.h" />
<ClInclude Include="..\Common\encoding.h" />
<ClInclude Include="..\Common\file.h" />
<ClInclude Include="..\Common\log.h" />
<ClInclude Include="..\Common\path.h" />
<ClInclude Include="..\Common\pe.h" />
<ClInclude Include="..\Common\stringhelper.h" />
<ClInclude Include="..\Common\util.h" />
<ClInclude Include="..\Detours\detours.h" />
<ClInclude Include="resource.h" />
</ItemGroup>
Expand Down
51 changes: 51 additions & 0 deletions CxdecExtractorLoader/CxdecExtractorLoader.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
<Filter Include="Detours">
<UniqueIdentifier>{1a3862fc-2e9c-40b5-9852-dc494c9ce530}</UniqueIdentifier>
</Filter>
<Filter Include="Common">
<UniqueIdentifier>{79160863-3116-4b56-8ddc-4a8907257830}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="CxdecExtractorLoader.cpp">
Expand All @@ -28,12 +31,60 @@
<ClCompile Include="..\Detours\modules.cpp">
<Filter>Detours</Filter>
</ClCompile>
<ClCompile Include="..\Common\directory.cpp">
<Filter>Common</Filter>
</ClCompile>
<ClCompile Include="..\Common\encoding.cpp">
<Filter>Common</Filter>
</ClCompile>
<ClCompile Include="..\Common\file.cpp">
<Filter>Common</Filter>
</ClCompile>
<ClCompile Include="..\Common\log.cpp">
<Filter>Common</Filter>
</ClCompile>
<ClCompile Include="..\Common\path.cpp">
<Filter>Common</Filter>
</ClCompile>
<ClCompile Include="..\Common\pe.cpp">
<Filter>Common</Filter>
</ClCompile>
<ClCompile Include="..\Common\stringhelper.cpp">
<Filter>Common</Filter>
</ClCompile>
<ClCompile Include="..\Common\util.cpp">
<Filter>Common</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\Detours\detours.h">
<Filter>Detours</Filter>
</ClInclude>
<ClInclude Include="resource.h" />
<ClInclude Include="..\Common\directory.h">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="..\Common\encoding.h">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="..\Common\file.h">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="..\Common\log.h">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="..\Common\path.h">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="..\Common\pe.h">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="..\Common\stringhelper.h">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="..\Common\util.h">
<Filter>Common</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="CxdecExtractorLoader.rc" />
Expand Down
10 changes: 7 additions & 3 deletions CxdecExtractorLoader/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@
// Microsoft Visual C++ 生成的包含文件。
// 供 CxdecExtractorLoader.rc 使用
//
#define IDI_ICON1 101
#define IDI_MainIcon 101
#define IDD_MainForm 102
#define IDC_Extractor 1001
#define IDC_StringDumper 1002
#define IDC_KeyDumper 1003

// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 102
#define _APS_NEXT_RESOURCE_VALUE 104
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_CONTROL_VALUE 1004
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
Loading

0 comments on commit 1829eb0

Please sign in to comment.