Skip to content

Commit

Permalink
Code compiler fix multi byte writing not working
Browse files Browse the repository at this point in the history
  • Loading branch information
Sajidur78 committed Oct 12, 2023
1 parent 2a24246 commit e160169
Showing 1 changed file with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
#pragma warning disable

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
Expand Down Expand Up @@ -39,20 +41,20 @@ public static bool IsAligned(nint address)
public static long ASLR(long address)
=> ModuleBase + (address - (IntPtr.Size == 8 ? 0x140000000 : 0x400000));

public static void Write(IntPtr address, IntPtr dataPtr, IntPtr length)
public static void Write(IntPtr destination, IntPtr source, IntPtr length)
{
if (!IsMemoryWritable(address))
if (!IsMemoryWritable(destination))
{
return;
}

if (IsAligned(address) && IsAligned(dataPtr))
if (IsAligned(destination) && IsAligned(source))
{
Unsafe.CopyBlock(dataPtr.ToPointer(), address.ToPointer(), (uint)length);
Unsafe.CopyBlock(destination, source, (uint)length);
}
else
{
Unsafe.CopyBlockUnaligned(dataPtr.ToPointer(), address.ToPointer(), (uint)length);
Unsafe.CopyBlockUnaligned(destination, source, (uint)length);
}
}

Expand Down Expand Up @@ -316,6 +318,10 @@ public static TTo BitCast<TFrom, TTo>(TFrom source)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static extern void Copy<T>(ref T destination, void* source);

[CompilerGenerated]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static extern void CopyBlock(IntPtr destination, IntPtr source, uint byteCount);

[CompilerGenerated]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static extern void CopyBlock(void* destination, void* source, uint byteCount);
Expand All @@ -324,6 +330,10 @@ public static TTo BitCast<TFrom, TTo>(TFrom source)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static extern void CopyBlock(ref byte destination, ref byte source, uint byteCount);

[CompilerGenerated]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static extern void CopyBlockUnaligned(IntPtr destination, IntPtr source, uint byteCount);

[CompilerGenerated]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static extern void CopyBlockUnaligned(void* destination, void* source, uint byteCount);
Expand Down

0 comments on commit e160169

Please sign in to comment.