Skip to content

Commit

Permalink
Added: .NET 7 Target
Browse files Browse the repository at this point in the history
  • Loading branch information
Sewer56 committed Jul 5, 2022
1 parent e0f3258 commit 9078b84
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 13 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/build-and-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ jobs:
# Optional SDK version(s) to use. If not provided, will install global.json version when available. Examples: 2.2.104, 3.1, 3.1.x
dotnet-version: 6.0.x

- name: Setup .NET Core SDK 7.X
uses: actions/setup-dotnet@v1.9.0
with:
# Optional SDK version(s) to use. If not provided, will install global.json version when available. Examples: 2.2.104, 3.1, 3.1.x
dotnet-version: 7.0.x
include-prerelease: true

# Required for C#10 features.
- name: Setup Node.js
uses: actions/setup-node@v2
Expand Down
10 changes: 5 additions & 5 deletions source/Reloaded.Hooks/AsmHook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public AsmHook(byte[] asmCode, nuint functionAddress, AsmHookOptions options = d
options.hookLength = Utilities.GetHookLength(functionAddress, options.MaxOpcodeSize, _is64Bit);

CurrentProcess.SafeReadRaw(functionAddress, out byte[] originalFunction, options.hookLength);
nuint jumpBackAddress = (UIntPtr)functionAddress + options.hookLength;
nuint jumpBackAddress = functionAddress + (nuint)options.hookLength;

/* Size calculations for buffer, must have sufficient space. */

Expand Down Expand Up @@ -169,11 +169,11 @@ private nuint MakeHookStub(MemoryBuffer buffer, IcedPatcher patcher, byte[] asmC
{
case AsmHookBehaviour.ExecuteFirst:
bytes.AddRange(asmCode);
bytes.AddRange(patcher.EncodeForNewAddress((UIntPtr)buffer.Properties.WritePointer + bytes.Count));
bytes.AddRange(patcher.EncodeForNewAddress(buffer.Properties.WritePointer + (nuint)bytes.Count));
break;

case AsmHookBehaviour.ExecuteAfter:
bytes.AddRange(patcher.EncodeForNewAddress((UIntPtr)buffer.Properties.WritePointer + bytes.Count));
bytes.AddRange(patcher.EncodeForNewAddress(buffer.Properties.WritePointer + (nuint)bytes.Count));
bytes.AddRange(asmCode);
break;

Expand All @@ -185,7 +185,7 @@ private nuint MakeHookStub(MemoryBuffer buffer, IcedPatcher patcher, byte[] asmC
throw new ArgumentOutOfRangeException(nameof(behaviour), behaviour, null);
}

var jmpBackBytes = Utilities.AssembleRelativeJump((UIntPtr)buffer.Properties.WritePointer + bytes.Count, jumpBackAddress, _is64Bit);
var jmpBackBytes = Utilities.AssembleRelativeJump(buffer.Properties.WritePointer + (nuint)bytes.Count, jumpBackAddress, _is64Bit);
bytes.AddRange(jmpBackBytes);
return buffer.Add(bytes.ToArray(), 1); // Buffer is pre-aligned
}
Expand All @@ -195,7 +195,7 @@ private nuint MakeOriginalStub(MemoryBuffer buffer, IcedPatcher patcher, byte[]
var bytes = new List<byte>(originalCode.Length);
bytes.AddRange(patcher.EncodeForNewAddress(buffer.Properties.WritePointer));

var jmpBackBytes = Utilities.AssembleRelativeJump((UIntPtr)buffer.Properties.WritePointer + bytes.Count, jumpBackAddress, _is64Bit);
var jmpBackBytes = Utilities.AssembleRelativeJump(buffer.Properties.WritePointer + (nuint)bytes.Count, jumpBackAddress, _is64Bit);
bytes.AddRange(jmpBackBytes);
return buffer.Add(bytes.ToArray(), 1); // Buffer is pre-aligned
}
Expand Down
2 changes: 1 addition & 1 deletion source/Reloaded.Hooks/Hook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private void CreateHook(nuint functionAddress, int minHookLength = -1, FunctionH

var functionPatcher = new FunctionPatcher(_is64Bit, options);
var functionPatch = functionPatcher.Patch(originalFunction.ToList(), functionAddress);
nuint hookEndAddress = (UIntPtr)functionAddress + minHookLength;
nuint hookEndAddress = functionAddress + (nuint)minHookLength;

/* Second wave of patching. */
var icedPatcher = new IcedPatcher(_is64Bit, functionPatch.NewFunction.ToArray(), functionAddress);
Expand Down
4 changes: 2 additions & 2 deletions source/Reloaded.Hooks/Internal/FunctionPatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ push 0x612403
*/

FunctionPatch functionPatch = new FunctionPatch();
nuint reloadedHookEndAddress = (UIntPtr)baseAddress + oldFunction.Count; // End of our own hook.
nuint reloadedHookEndAddress = baseAddress + (nuint)oldFunction.Count; // End of our own hook.

var oldFunctionArr = oldFunction.ToArray();
var decoder = Decoder.Create(_is64Bit ? 64 : 32, new ByteArrayCodeReader(oldFunctionArr));
Expand Down Expand Up @@ -363,7 +363,7 @@ internal void GetSearchRange(ref nuint searchPointer, out nuint searchLength)
foreach (ProcessModule module in GetCachedModules())
{
nuint minimumAddress = module.BaseAddress.ToUnsigned();
nuint maximumAddress = (UIntPtr)module.BaseAddress.ToUnsigned() + module.ModuleMemorySize;
nuint maximumAddress = module.BaseAddress.ToUnsigned() + (nuint)module.ModuleMemorySize;

if (searchPointer >= minimumAddress && searchPointer <= maximumAddress)
{
Expand Down
5 changes: 2 additions & 3 deletions source/Reloaded.Hooks/Reloaded.Hooks.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net5.0;netstandard2.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<TargetFrameworks>net7.0;net5.0;netstandard2.0</TargetFrameworks>
<Authors>Sewer56</Authors>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ internal class VTableEntryHook<TFunction> : IHook<TFunction>
internal unsafe VTableEntryHook(HookedObjectVirtualFunctionTable vTableHook, nuint originalVirtualFunctionTableAddress, int index,
TFunction function)
{
CurrentProcess.SafeRead((UIntPtr)originalVirtualFunctionTableAddress + (index * sizeof(nuint)), out nuint originalFunctionAddress);
CurrentProcess.SafeRead(originalVirtualFunctionTableAddress + (nuint)(index * sizeof(nuint)), out nuint originalFunctionAddress);

_vTableHook = vTableHook;
_index = index;
Expand Down
2 changes: 1 addition & 1 deletion source/Reloaded.Hooks/Tools/VirtualFunctionTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public static List<TableEntry> GetAddresses(nuint tablePointer, int numberOfMeth
// Using the size of the IntPtr allows for both x64 and x86 support.
for (int i = 0; i < numberOfMethods; i++)
{
var targetAddress = (UIntPtr)tablePointer + (IntPtr.Size * i);
var targetAddress = tablePointer + (nuint)(IntPtr.Size * i);

CurrentProcess.SafeRead(targetAddress, out IntPtr functionPtr);
tablePointers.Add(new TableEntry
Expand Down

0 comments on commit 9078b84

Please sign in to comment.