Skip to content

Commit

Permalink
Add Hooking Patterns to settings
Browse files Browse the repository at this point in the history
  • Loading branch information
elishacloud committed Dec 5, 2024
1 parent 57267cb commit b897ed7
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@
[submodule "External/imgui"]
path = External/imgui
url = https://github.com/ocornut/imgui
[submodule "External/Hooking.Patterns"]
path = External/Hooking.Patterns
url = https://github.com/ThirteenAG/Hooking.Patterns
2 changes: 1 addition & 1 deletion Dllmain/BuildNo.rc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define BUILD_NUMBER 7355
#define BUILD_NUMBER 7356
1 change: 1 addition & 0 deletions External/Hooking.Patterns
Submodule Hooking.Patterns added at 961c83
2 changes: 2 additions & 0 deletions Settings/AllSettings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,5 @@ VerificationBytes = 0x00
ResetMemoryAfter = 0
AddressPointer = 0x00000000
BytesToWrite = 0x00
PatternString =
BytesToWrite = 0x00
14 changes: 14 additions & 0 deletions Settings/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <regex>
#include <algorithm>
#include "Settings.h"
#include "External\Hooking.Patterns\Hooking.Patterns.h"
#include "Dllmain\Dllmain.h"
#include "Wrappers\wrapper.h"
#include "Logging\Logging.h"
Expand Down Expand Up @@ -333,6 +334,19 @@ void __stdcall Settings::ParseCallback(char* name, char* value)
SetValue(name, value, &Config.MemoryInfo[AddressPointerCount++].AddressPointer);
return;
}
if (!_stricmp(name, "PatternString"))
{
std::string PatterString(value);
auto pattern = hook::pattern(value);
if (Config.MemoryInfo.size() < AddressPointerCount + 1)
{
MEMORYINFO newMemoryInfo;
Config.MemoryInfo.push_back(newMemoryInfo);
}
Config.MemoryInfo[AddressPointerCount].PatternString.assign(value);
Config.MemoryInfo[AddressPointerCount++].AddressPointer = pattern.size() > 0UL ? pattern.get(0).get<uint32_t*>(0) : nullptr;
return;
}
if (!_stricmp(name, "BytesToWrite"))
{
if (Config.MemoryInfo.size() < BytesToWriteCount + 1)
Expand Down
1 change: 1 addition & 0 deletions Settings/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ typedef unsigned char byte;
struct MEMORYINFO // Used for hot patching memory
{
void* AddressPointer = nullptr; // Hot patch address
std::string PatternString; // Hot patch pattern
std::vector<byte> Bytes; // Hot patch bytes
};

Expand Down
9 changes: 8 additions & 1 deletion Utils/WriteMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,14 @@ DWORD WINAPI WriteMemory::StartThreadFunc(LPVOID pvParam)
// Main sub for writing to the memory of the application
void WriteMemory::WriteMemory()
{
if (CheckMemoryAddress(Config.VerifyMemoryInfo.AddressPointer, &Config.VerifyMemoryInfo.Bytes[0], Config.VerifyMemoryInfo.Bytes.size()))
for (size_t x = 0; x < Config.MemoryInfo.size(); x++)
{
Logging::Log() << __FUNCTION__ << " Found Address: " << Config.MemoryInfo[x].AddressPointer <<
(!Config.MemoryInfo[x].PatternString.empty() ? std::string(" Pattern: " + Config.MemoryInfo[x].PatternString).c_str() : "");
}

if (((DWORD)Config.VerifyMemoryInfo.AddressPointer == 0xFF && Config.VerifyMemoryInfo.Bytes[0] == 0xFF) ||
CheckMemoryAddress(Config.VerifyMemoryInfo.AddressPointer, &Config.VerifyMemoryInfo.Bytes[0], Config.VerifyMemoryInfo.Bytes.size()))
{
// Logging
Logging::Log() << __FUNCTION__ << " Writing bytes to memory...";
Expand Down
2 changes: 2 additions & 0 deletions dxwrapper.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,7 @@ copy /Y "$(ProjectDir)Settings\Settings.ini" "$(TargetDir)Build\dxwrapper.ini" &
<ClCompile Include="External\dinputto8\Versions\IDirectInputDeviceA.cpp" />
<ClCompile Include="External\dinputto8\Versions\IDirectInputDeviceW.cpp" />
<ClCompile Include="External\dinputto8\Versions\IDirectInputW.cpp" />
<ClCompile Include="External\Hooking.Patterns\Hooking.Patterns.cpp" />
<ClCompile Include="External\Hooking\Hook.cpp" />
<ClCompile Include="External\Hooking\HotPatch.cpp" />
<ClCompile Include="External\Hooking\IATPatch.cpp" />
Expand Down Expand Up @@ -1264,6 +1265,7 @@ copy /Y "$(ProjectDir)Settings\Settings.ini" "$(TargetDir)Build\dxwrapper.ini" &
<ClInclude Include="External\dinputto8\Versions\IDirectInputDeviceA.h" />
<ClInclude Include="External\dinputto8\Versions\IDirectInputDeviceW.h" />
<ClInclude Include="External\dinputto8\Versions\IDirectInputW.h" />
<ClInclude Include="External\Hooking.Patterns\Hooking.Patterns.h" />
<ClInclude Include="External\Hooking\Hook.h" />
<ClInclude Include="External\Logging\Logging.h" />
<ClInclude Include="External\MemoryModule\MemoryModule.h" />
Expand Down
9 changes: 9 additions & 0 deletions dxwrapper.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@
<Filter Include="ddraw\Shaders">
<UniqueIdentifier>{6679859a-ec10-4d1f-9fc3-7426d4436a23}</UniqueIdentifier>
</Filter>
<Filter Include="External\Hooking.Patterns">
<UniqueIdentifier>{a97108cd-8745-4ced-8e19-d702a7e16847}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="libraries\dwmapi.cpp">
Expand Down Expand Up @@ -886,6 +889,9 @@
<ClCompile Include="DDrawCompat\v0.3.2\Win32\Version.cpp">
<Filter>DDrawCompat\v0.3.2</Filter>
</ClCompile>
<ClCompile Include="External\Hooking.Patterns\Hooking.Patterns.cpp">
<Filter>External\Hooking.Patterns</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="Settings\AllSettings.ini">
Expand Down Expand Up @@ -1877,6 +1883,9 @@
<ClInclude Include="Dllmain\Resource.h">
<Filter>Dllmain</Filter>
</ClInclude>
<ClInclude Include="External\Hooking.Patterns\Hooking.Patterns.h">
<Filter>External\Hooking.Patterns</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Dllmain\BuildNo.rc">
Expand Down

0 comments on commit b897ed7

Please sign in to comment.