Skip to content

Commit

Permalink
Patch crashpad-related function
Browse files Browse the repository at this point in the history
Signed-off-by: Still Hsu <dev@stillu.cc>
  • Loading branch information
Still34 committed Jun 10, 2022
1 parent b072b62 commit 8583fd2
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 26 deletions.
6 changes: 6 additions & 0 deletions DivaNoSpy/Mod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,15 @@ void* sigSendCloseSignal = sigScan(
"xxxx?xxxx?xxxx?xxxxx????xxx????xxx????xxxxxx????x????xxxxxxxx????xxxxx????"
);

void* sigInvokeCrashpad = sigScan(
"\x48\x89\x5C\x24\x00\x48\x89\x74\x24\x00\x48\x89\x7C\x24\x00\x55\x41\x56\x41\x57\x48\x8D\x6C\x24\x00\x48\x81\xEC\x00\x00\x00\x00\x48\x8B\x05\x00\x00\x00\x00\x48\x33\xC4\x48\x89\x45\x48\x0F\x57\xC9\xF3\x0F\x7F\x4C\x24\x00\xB9\x00\x00\x00\x00\xE8\x00\x00\x00\x00\x48\x89\x00\x48\x89\x40\x08\x48\x89\x40\x10\x66\xC7\x40\x00\x00\x00\x48\x89\x44\x24\x00\x0F\x57\xC9\xF3\x0F\x7F\x4D\x00\x45\x33\xFF\x4C\x89\x7D\x98\x4C\x89\x7D\xE0\x4C\x89\x7D\xF0\x48\xC7\x45\x00\x00\x00\x00\x00\x66\x44\x89\x7D\x00\x45\x8D\x47\x0E",
"xxxx?xxxx?xxxx?xxxxxxxxx?xxx????xxx????xxxxxxxxxxxxxxx?x????x????xxxxxxxxxxxxxx???xxxx?xxxxxxx?xxxxxxxxxxxxxxxxxx?????xxxx?xxxx"
);

extern "C" __declspec(dllexport) void Init()
{
WRITE_MEMORY(sigSendCloseSignal, uint8_t, 0xc3, 0x90, 0x90, 0x90, 0x90);
WRITE_MEMORY(sigSendHeartbeat, uint8_t, 0xc3, 0x90, 0x90, 0x90, 0x90);
WRITE_MEMORY(sigSendHardwareInfo, uint8_t, 0xc3, 0x90, 0x90);
WRITE_MEMORY(sigInvokeCrashpad, uint8_t, 0xc3, 0x90, 0x90, 0x90, 0x90);
}
31 changes: 19 additions & 12 deletions DivaScoreCap/DivaScoreCap.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{acbb0d82-1d84-4e26-a437-80acf33c3979}</ProjectGuid>
<ProjectGuid>{ACBB0D82-1D84-4E26-A437-80ACF33C3979}</ProjectGuid>
<RootNamespace>DivaScoreCap</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
Expand Down Expand Up @@ -82,7 +82,7 @@
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;DIVASCORECAP_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_DEBUG;DivaScoreCap_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
Expand All @@ -99,7 +99,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;DIVASCORECAP_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;NDEBUG;DivaScoreCap_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
Expand All @@ -116,39 +116,41 @@
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS</PreprocessorDefinitions>
<PreprocessorDefinitions>_DEBUG;DivaScoreCap_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<LanguageStandard>stdcpp20</LanguageStandard>
<LanguageStandard_C>stdc17</LanguageStandard_C>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>DebugFull</GenerateDebugInformation>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
<AdditionalDependencies>detours.lib;syelog.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PostBuildEvent />
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS</PreprocessorDefinitions>
<PreprocessorDefinitions>NDEBUG;DivaScoreCap_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<LanguageStandard>stdcpp20</LanguageStandard>
<LanguageStandard_C>stdc17</LanguageStandard_C>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>DebugFull</GenerateDebugInformation>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
<AdditionalDependencies>detours.lib;syelog.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PostBuildEvent />
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="..\Dependencies\SigScan.h" />
Expand All @@ -159,7 +161,12 @@
<ClCompile Include="..\Dependencies\SigScan.cpp" />
<ClCompile Include="dllmain.cpp" />
<ClCompile Include="Mod.cpp" />
<ClCompile Include="pch.cpp" />
<ClCompile Include="pch.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
</ClCompile>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
59 changes: 45 additions & 14 deletions DivaScoreCap/Mod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,19 @@
#include <cstdint>
#include <SigScan.h>
#include <detours.h>

#include <string>
#include <map>
typedef enum _DIVA_DIFFICULTY : uint32_t {
Easy = 0x0,
Normal = 0x1,
Hard = 0x2,
Extreme = 0x3,
ExExtreme = 0x4,
} DIVA_DIFFICULTY;
typedef struct _DIVA_PV {
DIVA_DIFFICULTY Difficulty;
unsigned int Id;
} DIVA_PV;
typedef struct _DIVA_STAT {
float CompletionRate;
} DIVA_STAT;
Expand Down Expand Up @@ -32,31 +44,50 @@ typedef struct _DIVA_SCORE {

const uint64_t DivaScoreBaseAddress = 0x00000001412F641c;
const uint64_t DivaScoreCompletionRateAddress = 0x00000001412F64E4;
const uint64_t DivaCurrentPVAddress = 0x00000001412BD22C;
const uint64_t DivaCurrentPVTitleAddress = 0x00000001412F60D8;


void* DivaScoreTrigger = sigScan(
"\x48\x89\x5C\x24\x00\x48\x89\x74\x24\x00\x48\x89\x7C\x24\x00\x55\x41\x54\x41\x55\x41\x56\x41\x57\x48\x8B\xEC\x48\x83\xEC\x60\x48\x8B\x05\x00\x00\x00\x00\x48\x33\xC4\x48\x89\x45\xF8\x48\x8B\xF9\x80\xB9\x00\x00\x00\x00\x00\x0F\x85\x00\x00\x00\x00",
"xxxx?xxxx?xxxx?xxxxxxxxxxxxxxxxxxx????xxxxxxxxxxxx?????xx????"
);
std::string GetDifficultyName(DIVA_DIFFICULTY difficulty) {
switch (difficulty) {
case DIVA_DIFFICULTY::Easy:
return "Easy";
case DIVA_DIFFICULTY::Normal:
return "Normal";
case DIVA_DIFFICULTY::Hard:
return "Hard";
case DIVA_DIFFICULTY::Extreme:
return "Extreme";
case DIVA_DIFFICULTY::ExExtreme:
return "ExExtreme";
}
return "Unknown";
}


HOOK(int, __fastcall, _PrintResult, DivaScoreTrigger, int a1) {
HANDLE hCurrentProcess = GetCurrentProcess();
HANDLE hConsoleWindow = GetConsoleWindow();
DIVA_SCORE DivaScore{};
DIVA_STAT DivaStat{};
if (hCurrentProcess) {
size_t nBufferRead;
if (ReadProcessMemory(hCurrentProcess, (LPCVOID)DivaScoreBaseAddress, &DivaScore, sizeof(DIVA_SCORE), &nBufferRead) && nBufferRead > 0) {
if (hConsoleWindow)
printf("Total: %d; Combo: %d; Cool: %d; Fine: %d; Safe: %d; Sad: %d; Worst: %d\n", DivaScore.TotalScore, DivaScore.Combo, DivaScore.Cool, DivaScore.Fine, DivaScore.Safe, DivaScore.Sad, DivaScore.Worst);
}
if (ReadProcessMemory(hCurrentProcess, (LPCVOID)DivaScoreCompletionRateAddress, &DivaStat, sizeof(DIVA_SCORE), &nBufferRead) && nBufferRead > 0) {
if (hConsoleWindow)
printf("Song completion rate: %f\n", DivaStat.CompletionRate);
DIVA_SCORE DivaScore = *(DIVA_SCORE*)DivaScoreBaseAddress;
DIVA_STAT DivaStat = *(DIVA_STAT*)DivaScoreCompletionRateAddress;
std::string& aTitleBuffer = *(std::string*)DivaCurrentPVTitleAddress;
DIVA_PV DivaPV = *(DIVA_PV*)DivaCurrentPVAddress;
if (GetConsoleWindow()) {
if (GetConsoleOutputCP() != CP_UTF8) {
SetConsoleOutputCP(CP_UTF8);
}
printf("%s (%d) - %s\n", aTitleBuffer.c_str(), DivaPV.Id, GetDifficultyName(DivaPV.Difficulty).c_str());
printf("- Total: %d; Combo: %d; Cool: %d; Fine: %d; Safe: %d; Sad: %d; Worst: %d\n", DivaScore.TotalScore, DivaScore.Combo, DivaScore.Cool, DivaScore.Fine, DivaScore.Safe, DivaScore.Sad, DivaScore.Worst);
printf("- Song completion rate: %f%\n", DivaStat.CompletionRate);
}

return original_PrintResult(a1);
};

extern "C" __declspec(dllexport) void Init()
{

INSTALL_HOOK(_PrintResult);
}

0 comments on commit 8583fd2

Please sign in to comment.