-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Processory.Insight): add memory reading and logging for screen c…
…lient feat(solution): integrate .editorconfig into solution items feat(MemoryReader): introduce new MemoryReader class for process memory access refactor(ProcessoryClient): enhance class with MemoryReader and modify property access feat(Processory.csproj): enable unsafe blocks and add multiple analyzer packages refactor(ProcessService): modify access modifiers and property usage for consistency
- Loading branch information
Showing
6 changed files
with
95 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System.Diagnostics; | ||
using System.Runtime.CompilerServices; | ||
using Processory.Native; | ||
|
||
namespace Processory.Memory; | ||
|
||
public class MemoryReader { | ||
protected readonly ProcessoryClient ProcessoryClient; | ||
|
||
public MemoryReader(ProcessoryClient processoryClient) { | ||
this.ProcessoryClient = processoryClient; | ||
} | ||
|
||
public byte[] Read(UIntPtr address, int size) { | ||
var buffer = new byte[size]; | ||
var bytesRead = MethodsNative.ReadProcessMemory(ProcessoryClient.ProcessHandle, address, buffer, (UIntPtr)size, out UIntPtr _); | ||
|
||
if (!bytesRead) { | ||
return Array.Empty<byte>(); | ||
} | ||
|
||
return buffer; | ||
} | ||
|
||
public T Read<T>(ulong offset) | ||
where T : unmanaged { | ||
T value = default; | ||
ReadRef(offset, ref value); | ||
return value; | ||
} | ||
|
||
private unsafe bool ReadProcessMemory(UIntPtr location, void* buffer, nuint numBytes) { | ||
return MethodsNative.ReadProcessMemory(ProcessoryClient.ProcessHandle, location, (UIntPtr)buffer, numBytes, out _); | ||
} | ||
|
||
public unsafe void ReadRef<T>(ulong offset, ref T value) | ||
where T : unmanaged { | ||
void* buffer = Unsafe.AsPointer(ref value); | ||
if (!ReadProcessMemory((UIntPtr)offset, buffer, (nuint)sizeof(T))) { | ||
// ThrowHelpers.ThrowReadExternalMemoryExceptionWindows(offset, sizeof(T)); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,20 @@ | ||
using Processory.Memory; | ||
using Processory.Services; | ||
|
||
namespace Processory; | ||
|
||
public class ProcessoryClient { // Renamed from Processory to ProcessoryClient | ||
//private readonly nint _processHandle; | ||
public readonly string _processName; | ||
public ProcessService ProcessService; | ||
public class ProcessoryClient { | ||
public MemoryReader MemoryReader { get; set; } | ||
public ProcessService ProcessService { get; set; } | ||
public string ProcessName { get; } | ||
public nint ProcessHandle { get; } | ||
|
||
public ProcessoryClient(string processName) { | ||
_processName = processName; | ||
ProcessName = processName; | ||
ProcessService = new ProcessService(this); | ||
// _processHandle = GetProcessHandle(); | ||
MemoryReader = new MemoryReader(this); | ||
ProcessHandle = ProcessService.GetProcessHandle(); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters