Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

Commit 7ee5d7c

Browse files
authored
Add files via upload
1 parent 25632df commit 7ee5d7c

18 files changed

+373
-0
lines changed

UniversalBinaryPatcher.sln

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.3.32901.215
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UniversalBinaryPatcher", "UniversalBinaryPatcher\UniversalBinaryPatcher.vcxproj", "{CF5F7A1C-36E6-487E-8341-0650E06523FD}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|x64 = Debug|x64
11+
Debug|x86 = Debug|x86
12+
Release|x64 = Release|x64
13+
Release|x86 = Release|x86
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{CF5F7A1C-36E6-487E-8341-0650E06523FD}.Debug|x64.ActiveCfg = Debug|x64
17+
{CF5F7A1C-36E6-487E-8341-0650E06523FD}.Debug|x64.Build.0 = Debug|x64
18+
{CF5F7A1C-36E6-487E-8341-0650E06523FD}.Debug|x86.ActiveCfg = Debug|Win32
19+
{CF5F7A1C-36E6-487E-8341-0650E06523FD}.Debug|x86.Build.0 = Debug|Win32
20+
{CF5F7A1C-36E6-487E-8341-0650E06523FD}.Release|x64.ActiveCfg = Release|x64
21+
{CF5F7A1C-36E6-487E-8341-0650E06523FD}.Release|x64.Build.0 = Release|x64
22+
{CF5F7A1C-36E6-487E-8341-0650E06523FD}.Release|x86.ActiveCfg = Release|Win32
23+
{CF5F7A1C-36E6-487E-8341-0650E06523FD}.Release|x86.Build.0 = Release|Win32
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {B7A0841A-39BC-4018-A075-612D1FCEFFCE}
30+
EndGlobalSection
31+
EndGlobal

UniversalBinaryPatcher/Main.cpp

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
#include <windows.h>
2+
#include <vector>
3+
#include <fstream>
4+
#include <sstream>
5+
#include <iostream>
6+
#include <iomanip>
7+
#include <string>
8+
9+
typedef unsigned char BYTE;
10+
int offset = 0;
11+
std::string data;
12+
char instruction = ' ';
13+
std::vector<BYTE> fileData;
14+
15+
/// instruction var
16+
uint64_t iOffset = 0;
17+
int icHex;
18+
std::vector<BYTE> iHex;
19+
20+
21+
void finishPatch(const char* file)
22+
{
23+
std::ofstream mainFile(file, std::ios::binary);
24+
for (int i = 0; i < fileData.size(); i++)
25+
{
26+
mainFile << fileData.at(i);
27+
}
28+
}
29+
30+
31+
void patch()
32+
{
33+
for (int i = 0; i < iHex.size(); i++)
34+
{
35+
fileData.at(iOffset + i) = iHex.at(i);
36+
}
37+
iHex.clear();
38+
}
39+
40+
41+
42+
43+
void executeInstructions()
44+
{
45+
std::ifstream inst("code.UBPI");
46+
char ch;
47+
while (inst >> std::noskipws >> ch) {
48+
49+
if (ch == ' ' || ch == '\n')
50+
{
51+
if (instruction == 'h')
52+
{
53+
if (data == "end")
54+
{
55+
patch();
56+
instruction = ' ';
57+
}
58+
if ((ch == ' ' || ch == '\n') && instruction == 'h')
59+
{
60+
std::istringstream buffer(data);
61+
buffer >> std::hex >> icHex;
62+
iHex.push_back(icHex);
63+
}
64+
}
65+
if (instruction == 'o')
66+
{
67+
std::istringstream buffer(data);
68+
buffer >> std::hex >> iOffset;
69+
instruction = 'h';
70+
}
71+
if (data == "offset")
72+
{
73+
instruction = 'o';
74+
}
75+
data = "";
76+
}
77+
else
78+
{
79+
data = data + ch;
80+
}
81+
}
82+
inst.close();
83+
}
84+
85+
86+
std::vector<BYTE> processFile(const char* filename)
87+
{
88+
// open the file:
89+
std::streampos fileSize;
90+
std::ifstream file(filename, std::ios::binary);
91+
std::ofstream("backup.exe", std::ios_base::binary) << file.rdbuf();
92+
std::cout << "File was successfuly backed up\n";
93+
94+
// get its size:
95+
file.seekg(0, std::ios::end);
96+
fileSize = file.tellg();
97+
file.seekg(0, std::ios::beg);
98+
99+
// read the data:
100+
std::vector<BYTE> fileData(fileSize);
101+
file.read((char*)&fileData[0], fileSize);
102+
file.close();
103+
return fileData;
104+
}
105+
106+
107+
void readFile(int from, size_t to)
108+
{
109+
std::cout << std::showbase << std::internal << std::setfill('0');
110+
if (from >= 0 && to <= fileData.size())
111+
{
112+
std::cout << std::setw(8) << std::hex << (unsigned int)offset << ' ';
113+
for (int i = from; i < to; i++)
114+
{
115+
if ((i + 1) % 8 == 0)
116+
{
117+
std::cout << std::hex << (unsigned int)fileData.at(i) << '\t';
118+
for (int x = (i - 7); x <= i; x++)
119+
{
120+
if (fileData.at(x) >= 33 && fileData.at(x) != 127 && fileData.at(x) != 129 && fileData.at(x) != 141 && fileData.at(x) != 143 && fileData.at(x) != 144 && fileData.at(x) != 157 && fileData.at(x) != 160 && fileData.at(x) != 173 && fileData.at(x) != 255)
121+
{
122+
std::cout << fileData.at(x);
123+
}
124+
else
125+
{
126+
std::cout << '.';
127+
}
128+
}
129+
std::cout << std::endl;
130+
offset = offset + 8;
131+
std::cout << std::setw(8) << std::hex << (unsigned int)offset << ' ';
132+
}
133+
else
134+
{
135+
std::cout << std::hex << (unsigned int)fileData.at(i) << '\t';
136+
}
137+
}
138+
}
139+
else
140+
{
141+
std::cout << "Error the observable hex values were outside the scope of the file";
142+
}
143+
std::cout << std::endl;
144+
offset = 0;
145+
}
146+
147+
148+
int main(int argc, char** argv)
149+
{
150+
SetConsoleTitle("Universal Binary Patcher");
151+
if (argc > 0)
152+
{
153+
fileData = processFile(argv[1]);
154+
//readFile(0, fileData.size());
155+
executeInstructions();
156+
finishPatch(argv[1]);
157+
//readFile( 0, fileData.size());
158+
}
159+
else
160+
{
161+
std::cout << "Drop the patchable file on the executable to patch it\n";
162+
}
163+
std::cout << std::endl;
164+
system("pause");
165+
return 0;
166+
}
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|Win32">
9+
<Configuration>Release</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
<ProjectConfiguration Include="Debug|x64">
13+
<Configuration>Debug</Configuration>
14+
<Platform>x64</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="Release|x64">
17+
<Configuration>Release</Configuration>
18+
<Platform>x64</Platform>
19+
</ProjectConfiguration>
20+
</ItemGroup>
21+
<ItemGroup>
22+
<ClCompile Include="Main.cpp" />
23+
</ItemGroup>
24+
<PropertyGroup Label="Globals">
25+
<VCProjectVersion>16.0</VCProjectVersion>
26+
<Keyword>Win32Proj</Keyword>
27+
<ProjectGuid>{cf5f7a1c-36e6-487e-8341-0650e06523fd}</ProjectGuid>
28+
<RootNamespace>UniversalBinaryPatcher</RootNamespace>
29+
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
30+
</PropertyGroup>
31+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
32+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
33+
<ConfigurationType>Application</ConfigurationType>
34+
<UseDebugLibraries>true</UseDebugLibraries>
35+
<PlatformToolset>v143</PlatformToolset>
36+
<CharacterSet>Unicode</CharacterSet>
37+
</PropertyGroup>
38+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
39+
<ConfigurationType>Application</ConfigurationType>
40+
<UseDebugLibraries>false</UseDebugLibraries>
41+
<PlatformToolset>v143</PlatformToolset>
42+
<WholeProgramOptimization>true</WholeProgramOptimization>
43+
<CharacterSet>Unicode</CharacterSet>
44+
</PropertyGroup>
45+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
46+
<ConfigurationType>Application</ConfigurationType>
47+
<UseDebugLibraries>true</UseDebugLibraries>
48+
<PlatformToolset>v143</PlatformToolset>
49+
<CharacterSet>MultiByte</CharacterSet>
50+
</PropertyGroup>
51+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
52+
<ConfigurationType>Application</ConfigurationType>
53+
<UseDebugLibraries>false</UseDebugLibraries>
54+
<PlatformToolset>v143</PlatformToolset>
55+
<WholeProgramOptimization>true</WholeProgramOptimization>
56+
<CharacterSet>MultiByte</CharacterSet>
57+
</PropertyGroup>
58+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
59+
<ImportGroup Label="ExtensionSettings">
60+
</ImportGroup>
61+
<ImportGroup Label="Shared">
62+
</ImportGroup>
63+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
64+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
65+
</ImportGroup>
66+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
67+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
68+
</ImportGroup>
69+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
70+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
71+
</ImportGroup>
72+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
73+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
74+
</ImportGroup>
75+
<PropertyGroup Label="UserMacros" />
76+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
77+
<ClCompile>
78+
<WarningLevel>Level3</WarningLevel>
79+
<SDLCheck>true</SDLCheck>
80+
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
81+
<ConformanceMode>true</ConformanceMode>
82+
</ClCompile>
83+
<Link>
84+
<SubSystem>Console</SubSystem>
85+
<GenerateDebugInformation>true</GenerateDebugInformation>
86+
</Link>
87+
</ItemDefinitionGroup>
88+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
89+
<ClCompile>
90+
<WarningLevel>Level3</WarningLevel>
91+
<FunctionLevelLinking>true</FunctionLevelLinking>
92+
<IntrinsicFunctions>true</IntrinsicFunctions>
93+
<SDLCheck>true</SDLCheck>
94+
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
95+
<ConformanceMode>true</ConformanceMode>
96+
</ClCompile>
97+
<Link>
98+
<SubSystem>Console</SubSystem>
99+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
100+
<OptimizeReferences>true</OptimizeReferences>
101+
<GenerateDebugInformation>true</GenerateDebugInformation>
102+
</Link>
103+
</ItemDefinitionGroup>
104+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
105+
<ClCompile>
106+
<WarningLevel>Level3</WarningLevel>
107+
<SDLCheck>true</SDLCheck>
108+
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
109+
<ConformanceMode>true</ConformanceMode>
110+
</ClCompile>
111+
<Link>
112+
<SubSystem>Console</SubSystem>
113+
<GenerateDebugInformation>true</GenerateDebugInformation>
114+
</Link>
115+
</ItemDefinitionGroup>
116+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
117+
<ClCompile>
118+
<WarningLevel>Level3</WarningLevel>
119+
<FunctionLevelLinking>true</FunctionLevelLinking>
120+
<IntrinsicFunctions>true</IntrinsicFunctions>
121+
<SDLCheck>true</SDLCheck>
122+
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
123+
<ConformanceMode>true</ConformanceMode>
124+
</ClCompile>
125+
<Link>
126+
<SubSystem>Console</SubSystem>
127+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
128+
<OptimizeReferences>true</OptimizeReferences>
129+
<GenerateDebugInformation>true</GenerateDebugInformation>
130+
</Link>
131+
</ItemDefinitionGroup>
132+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
133+
<ImportGroup Label="ExtensionTargets">
134+
</ImportGroup>
135+
</Project>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<Filter Include="Source Files">
5+
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
6+
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
7+
</Filter>
8+
<Filter Include="Header Files">
9+
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
10+
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
11+
</Filter>
12+
<Filter Include="Resource Files">
13+
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
14+
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
15+
</Filter>
16+
</ItemGroup>
17+
<ItemGroup>
18+
<ClCompile Include="Main.cpp">
19+
<Filter>Source Files</Filter>
20+
</ClCompile>
21+
</ItemGroup>
22+
</Project>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup />
4+
</Project>
654 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
PlatformToolSet=v143:VCToolArchitecture=Native64Bit:VCToolsVersion=14.33.31629:TargetPlatformVersion=10.0.19041.0:
2+
Debug|x64|C:\Users\atusz\source\repos\UniversalBinaryPatcher\|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project>
3+
<ProjectOutputs>
4+
<ProjectOutput>
5+
<FullPath>C:\Users\atusz\source\repos\UniversalBinaryPatcher\x64\Debug\UniversalBinaryPatcher.exe</FullPath>
6+
</ProjectOutput>
7+
</ProjectOutputs>
8+
<ContentFiles />
9+
<SatelliteDlls />
10+
<NonRecipeFileRefs />
11+
</Project>
Binary file not shown.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
 Main.cpp
2+
UniversalBinaryPatcher.vcxproj -> C:\Users\atusz\source\repos\UniversalBinaryPatcher\x64\Debug\UniversalBinaryPatcher.exe
371 KB
Binary file not shown.
588 KB
Binary file not shown.

0 commit comments

Comments
 (0)