Skip to content

Commit

Permalink
Fixed Error 126
Browse files Browse the repository at this point in the history
  • Loading branch information
Dheix committed Mar 27, 2024
1 parent 984aa34 commit 03a448b
Show file tree
Hide file tree
Showing 6 changed files with 3,044 additions and 110 deletions.
6 changes: 6 additions & 0 deletions SwDevTools.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
DebugTest|x64 = DebugTest|x64
DebugTest|x86 = DebugTest|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
Expand All @@ -17,6 +19,10 @@ Global
{8E609C99-B2C1-4E04-8620-A1E036D919CB}.Debug|x64.Build.0 = Debug|x64
{8E609C99-B2C1-4E04-8620-A1E036D919CB}.Debug|x86.ActiveCfg = Debug|Win32
{8E609C99-B2C1-4E04-8620-A1E036D919CB}.Debug|x86.Build.0 = Debug|Win32
{8E609C99-B2C1-4E04-8620-A1E036D919CB}.DebugTest|x64.ActiveCfg = DebugTest|x64
{8E609C99-B2C1-4E04-8620-A1E036D919CB}.DebugTest|x64.Build.0 = DebugTest|x64
{8E609C99-B2C1-4E04-8620-A1E036D919CB}.DebugTest|x86.ActiveCfg = DebugTest|Win32
{8E609C99-B2C1-4E04-8620-A1E036D919CB}.DebugTest|x86.Build.0 = DebugTest|Win32
{8E609C99-B2C1-4E04-8620-A1E036D919CB}.Release|x64.ActiveCfg = Release|x64
{8E609C99-B2C1-4E04-8620-A1E036D919CB}.Release|x64.Build.0 = Release|x64
{8E609C99-B2C1-4E04-8620-A1E036D919CB}.Release|x86.ActiveCfg = Release|Win32
Expand Down
66 changes: 65 additions & 1 deletion SwDevTools.vcxproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="DebugTest|Win32">
<Configuration>DebugTest</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="DebugTest|x64">
<Configuration>DebugTest</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
Expand Down Expand Up @@ -32,6 +40,12 @@
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugTest|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
Expand All @@ -45,6 +59,12 @@
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugTest|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
Expand All @@ -60,12 +80,18 @@
<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 Condition="'$(Configuration)|$(Platform)'=='DebugTest|Win32'" Label="PropertySheets">
<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 Condition="'$(Configuration)|$(Platform)'=='DebugTest|x64'" Label="PropertySheets">
<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>
Expand All @@ -85,6 +111,21 @@
<EnableUAC>false</EnableUAC>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='DebugTest|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;SWDEVTOOLS_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
Expand Down Expand Up @@ -120,6 +161,23 @@
<EnableUAC>false</EnableUAC>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='DebugTest|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;SWDEVTOOLS_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<LanguageStandard>stdcpp20</LanguageStandard>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
Expand All @@ -130,6 +188,7 @@
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<LanguageStandard>stdcpp20</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand All @@ -143,12 +202,17 @@
<ClInclude Include="framework.h" />
<ClInclude Include="Pattern16.h" />
<ClInclude Include="pch.h" />
<ClInclude Include="sigmatch\sigmatch.hpp" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp" />
<ClCompile Include="dllmain.cpp">
<RuntimeLibrary Condition="'$(Configuration)|$(Platform)'=='DebugTest|x64'">MultiThreadedDebugDLL</RuntimeLibrary>
</ClCompile>
<ClCompile Include="pch.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='DebugTest|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='DebugTest|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
Expand Down
3 changes: 3 additions & 0 deletions SwDevTools.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
<ClInclude Include="Pattern16.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="sigmatch\sigmatch.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp">
Expand Down
150 changes: 41 additions & 109 deletions dllmain.cpp
Original file line number Diff line number Diff line change
@@ -1,76 +1,15 @@
// dllmain.cpp : Defines the entry point for the DLL application.
#pragma warning(disable : 4996) //_CRT_SECURE_NO_WARNINGS
#include "pch.h"
#include <iostream>
#include <Windows.h>
#include "Pattern16.h"
#include <tlhelp32.h>
#include <psapi.h>
#include "sigmatch/sigmatch.hpp"

bool GetPid(const wchar_t* targetProcess, DWORD* procID)
{
HANDLE snap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (snap && snap != INVALID_HANDLE_VALUE)
{
PROCESSENTRY32 pe;
pe.dwSize = sizeof(pe);
if (Process32First(snap, &pe))
{
do
{
if (!wcscmp(pe.szExeFile, targetProcess))
{
CloseHandle(snap);
*procID = pe.th32ProcessID;
return true;
}
} while (Process32Next(snap, &pe));
}
}
return false;
}

char* GetModuleBase(const wchar_t* ModuleName, DWORD procID)
{
MODULEENTRY32 ModuleEntry = { 0 };
HANDLE SnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, procID);

if (!SnapShot) return NULL;

ModuleEntry.dwSize = sizeof(ModuleEntry);

if (!Module32First(SnapShot, &ModuleEntry)) return NULL;

do
{
if (!wcscmp(ModuleEntry.szModule, ModuleName))
{
CloseHandle(SnapShot);
return (char*)ModuleEntry.modBaseAddr;
}
} while (Module32Next(SnapShot, &ModuleEntry));

CloseHandle(SnapShot);
return NULL;
}

uintptr_t FindDmaAddy(int PointerLevel, HANDLE hProcHandle, uintptr_t Offsets[], uintptr_t BaseAddress)
{
uintptr_t pointer = BaseAddress;
uintptr_t pTemp = 0;

uintptr_t pointerAddr = 0;
for (int i = 0; i < PointerLevel; i++)
{
if (i == 0)
{
ReadProcessMemory(hProcHandle, (LPCVOID)pointer, &pTemp, sizeof(pTemp), NULL);
}
pointerAddr = pTemp + Offsets[i];

ReadProcessMemory(hProcHandle, (LPCVOID)pointerAddr, &pTemp, sizeof(pTemp), NULL);
}
return pointerAddr;
}
using namespace sigmatch_literals;

DWORD WINAPI Cons()
{
Expand All @@ -79,51 +18,44 @@ DWORD WINAPI Cons()
FILE* fp;
freopen_s(&fp, "CONOUT$", "w", stdout);
*/
/*
DWORD ProcId;
GetPid(L"stormworks64.exe", &ProcId);
char* ExeBaseAddress = GetModuleBase(L"stormworks64.exe", ProcId);
*/

HANDLE ExeHandle = GetModuleHandleA("stormworks64.exe");

void* startAdress = (char*)ExeHandle;
void* endAdress = (char*)ExeHandle + (0xCD9000);

void* regionStart = (void*)startAdress;
size_t regionSize = (DWORD)endAdress;
std::string signature = "74 20 FF C3 E8 A5 FE FF FF";
void* address = Pattern16::find(regionStart, regionSize, signature);


//DWORD add = FindDmaAddy(0, ExeBaseAddress,0,(DWORD)ExeBaseAddress);
/*
std::cout << startAdress << std::endl;
std::cout << endAdress << std::endl;
*/
std::cout << address << std::endl;
char* name = (char*)((char*)address);
std::cout << name << std::endl;

char* buffer = reinterpret_cast<char*>(address);


char myStr[9] = { 0x75 , 0x20, 0xFF, 0xC3, 0xE8, 0xA5, 0xFE, 0xFF, 0xFF };
//size_t length = strlen(myStr);
size_t length = 9;

DWORD oldProtect;
VirtualProtect(buffer, length, PAGE_EXECUTE_READWRITE, &oldProtect);
memcpy(buffer, myStr, length);
VirtualProtect(buffer, length, oldProtect, nullptr);

//strcpy((char*)name, "#version460");






sigmatch::this_process_target target;
sigmatch::search_context context = target.in_module("stormworks64.exe");
sigmatch::search_result result = context.search("48 39 34 D0 74 07"_sig);


for (const std::byte* address : result.matches()) {
//std::cout << "matched: " << address << '\n';

int* addr;
addr = (int*)address;

char* buffer;
//buffer = reinterpret_cast<char*>(addr);
buffer = (char*)addr;


char myStr[6] = { 0x48 , 0x39, 0x34, 0xD0, 0x75, 0x07 };
//size_t length = strlen(myStr);
size_t length = 6;

/*
const int size = 10;
char myStr[size] = { 0x73, 0x61 ,0x6D ,0x70 ,0x6C ,0x65 ,0x20 ,0x6E ,0x65 ,0x77 };
//size_t length = strlen(myStr);
size_t length = size;
*/
//std::cout << "matched buffer: " << buffer << '\n';


DWORD oldProtect;
VirtualProtect(buffer, length, PAGE_EXECUTE_READWRITE, &oldProtect);
memcpy(buffer, myStr, length);
VirtualProtect(buffer, length, oldProtect, nullptr);

}


/*
while (1)
{
Expand All @@ -133,8 +65,8 @@ DWORD WINAPI Cons()
}
fclose(fp);
FreeConsole();
*/

return 0;

}
Expand Down
Empty file added log.txt
Empty file.
Loading

0 comments on commit 03a448b

Please sign in to comment.