Skip to content

Commit

Permalink
Patcher: unify Linux/Windows implementation
Browse files Browse the repository at this point in the history
Signed-off-by: Reece Dunham <me@rdil.rocks>
  • Loading branch information
RDIL committed Nov 20, 2023
1 parent ba47d1d commit 3a2dbee
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 42 deletions.
3 changes: 0 additions & 3 deletions patcher/BuildCI.cmd

This file was deleted.

24 changes: 1 addition & 23 deletions patcher/HitmanPatcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;PLATFORM_STEAM;PLATFORM_EPIC;PLATFORM_GOG;PLATFORM_SCARLETT;TARGET_WINDOWS</DefineConstants>
<DefineConstants>DEBUG;TRACE;PLATFORM_STEAM;PLATFORM_EPIC;PLATFORM_GOG;PLATFORM_SCARLETT</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
Expand All @@ -54,35 +54,13 @@

<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE;PLATFORM_STEAM;PLATFORM_EPIC;TARGET_WINDOWS</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Linux Release|x64' ">
<DefineConstants>TRACE;PLATFORM_STEAM;PLATFORM_EPIC</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
<OutputPath>bin\x64\Linux.Release\</OutputPath>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Linux Debug|x64' ">
<DebugSymbols>true</DebugSymbols>
<DefineConstants>DEBUG;TRACE;PLATFORM_STEAM;PLATFORM_EPIC;PLATFORM_GOG;PLATFORM_SCARLETT</DefineConstants>
<DebugType>full</DebugType>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
<OutputPath>bin\x64\Linux.Debug\</OutputPath>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>

<PropertyGroup>
Expand Down
6 changes: 0 additions & 6 deletions patcher/HitmanPatcher.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,12 @@ Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Release|x64 = Release|x64
Linux Release|x64 = Linux Release|x64
Linux Debug|x64 = Linux Debug|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0487D44B-B3E1-4A6E-91E0-47016C391A20}.Debug|x64.ActiveCfg = Debug|x64
{0487D44B-B3E1-4A6E-91E0-47016C391A20}.Debug|x64.Build.0 = Debug|x64
{0487D44B-B3E1-4A6E-91E0-47016C391A20}.Release|x64.ActiveCfg = Release|x64
{0487D44B-B3E1-4A6E-91E0-47016C391A20}.Release|x64.Build.0 = Release|x64
{0487D44B-B3E1-4A6E-91E0-47016C391A20}.Linux Release|x64.ActiveCfg = Linux Release|x64
{0487D44B-B3E1-4A6E-91E0-47016C391A20}.Linux Release|x64.Build.0 = Linux Release|x64
{0487D44B-B3E1-4A6E-91E0-47016C391A20}.Linux Debug|x64.ActiveCfg = Linux Debug|x64
{0487D44B-B3E1-4A6E-91E0-47016C391A20}.Linux Debug|x64.Build.0 = Linux Debug|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 0 additions & 2 deletions patcher/MemoryPatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public static void PatchAllProcesses(ILoggingProvider logger, Options patchOptio
patchedprocesses.Add(process.Id);
try
{
#if TARGET_WINDOWS
bool dontPatch = false;
try
{
Expand All @@ -88,7 +87,6 @@ public static void PatchAllProcesses(ILoggingProvider logger, Options patchOptio
process.Dispose();
continue;
}
#endif

if (MemoryPatcher.Patch(process, patchOptions))
{
Expand Down
8 changes: 0 additions & 8 deletions patcher/Pinvoke.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
#if TARGET_WINDOWS
using System.ComponentModel;
using System.Diagnostics;
#endif
using System.Runtime.InteropServices;

namespace HitmanPatcher
Expand All @@ -29,15 +27,12 @@ public enum MemProtection : uint
[Flags]
public enum ProcessAccess : uint
{
#if TARGET_WINDOWS
PROCESS_QUERY_INFORMATION = 0x0400, // Required to retrieve certain information about a process.
#endif
PROCESS_VM_READ = 0x0010, // Required to read memory in a process using ReadProcessMemory.
PROCESS_VM_WRITE = 0x0020, // Required to write to memory in a process using WriteProcessMemory.
PROCESS_VM_OPERATION = 0x0008 // Required to perform an operation on the address space of a process using VirtualProtectEx
}

#if TARGET_WINDOWS
// from https://docs.microsoft.com/en-us/windows/win32/api/winternl/nf-winternl-ntqueryinformationprocess
public enum PROCESSINFOCLASS
{
Expand All @@ -60,7 +55,6 @@ public struct PROCESS_BASIC_INFORMATION
public IntPtr UniqueProcessId;
public IntPtr Reserved3;
}
#endif

public static class Pinvoke
{
Expand All @@ -79,7 +73,6 @@ public static class Pinvoke
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool VirtualProtectEx([In] IntPtr hProcess, [In] IntPtr lpAddress, [In] UIntPtr dwSize, [In] MemProtection flNewProtect, [Out] out MemProtection lpflOldProtect);

#if TARGET_WINDOWS
[DllImport("ntdll.dll")]
public static extern int NtQueryInformationProcess(IntPtr hProcess, PROCESSINFOCLASS processInformationClass, out PROCESS_BASIC_INFORMATION processInformation, uint processInformationLength, out uint returnLength);

Expand Down Expand Up @@ -109,6 +102,5 @@ public static int GetProcessParentPid(Process process)

return PEB.Reserved3.ToInt32(); // undocumented, but should hold the parent PID
}
#endif
}
}

0 comments on commit 3a2dbee

Please sign in to comment.