Initial version
This commit is contained in:
1 parent
63379b43d7
commit
cc1b1a13a1
9 files changed
+675
-123
No files matched your search
+10
-81
@@ -2,7 +2,7 @@
|
|||||||
## Ignore Visual Studio temporary files, build results, and
|
## Ignore Visual Studio temporary files, build results, and
|
||||||
## files generated by popular Visual Studio add-ons.
|
## files generated by popular Visual Studio add-ons.
|
||||||
##
|
##
|
||||||
## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
|
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
|
||||||
|
|
||||||
# User-specific files
|
# User-specific files
|
||||||
*.rsuser
|
*.rsuser
|
||||||
@@ -14,9 +14,6 @@
|
|||||||
# User-specific files (MonoDevelop/Xamarin Studio)
|
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||||
*.userprefs
|
*.userprefs
|
||||||
|
|
||||||
# Mono auto generated files
|
|
||||||
mono_crash.*
|
|
||||||
|
|
||||||
# Build results
|
# Build results
|
||||||
[Dd]ebug/
|
[Dd]ebug/
|
||||||
[Dd]ebugPublic/
|
[Dd]ebugPublic/
|
||||||
@@ -24,14 +21,10 @@ mono_crash.*
|
|||||||
[Rr]eleases/
|
[Rr]eleases/
|
||||||
x64/
|
x64/
|
||||||
x86/
|
x86/
|
||||||
[Ww][Ii][Nn]32/
|
|
||||||
[Aa][Rr][Mm]/
|
|
||||||
[Aa][Rr][Mm]64/
|
|
||||||
bld/
|
bld/
|
||||||
[Bb]in/
|
[Bb]in/
|
||||||
[Oo]bj/
|
[Oo]bj/
|
||||||
[Ll]og/
|
[Ll]og/
|
||||||
[Ll]ogs/
|
|
||||||
|
|
||||||
# Visual Studio 2015/2017 cache/options directory
|
# Visual Studio 2015/2017 cache/options directory
|
||||||
.vs/
|
.vs/
|
||||||
@@ -45,10 +38,9 @@ Generated\ Files/
|
|||||||
[Tt]est[Rr]esult*/
|
[Tt]est[Rr]esult*/
|
||||||
[Bb]uild[Ll]og.*
|
[Bb]uild[Ll]og.*
|
||||||
|
|
||||||
# NUnit
|
# NUNIT
|
||||||
*.VisualState.xml
|
*.VisualState.xml
|
||||||
TestResult.xml
|
TestResult.xml
|
||||||
nunit-*.xml
|
|
||||||
|
|
||||||
# Build Results of an ATL Project
|
# Build Results of an ATL Project
|
||||||
[Dd]ebugPS/
|
[Dd]ebugPS/
|
||||||
@@ -63,9 +55,6 @@ project.lock.json
|
|||||||
project.fragment.lock.json
|
project.fragment.lock.json
|
||||||
artifacts/
|
artifacts/
|
||||||
|
|
||||||
# ASP.NET Scaffolding
|
|
||||||
ScaffoldingReadMe.txt
|
|
||||||
|
|
||||||
# StyleCop
|
# StyleCop
|
||||||
StyleCopReport.xml
|
StyleCopReport.xml
|
||||||
|
|
||||||
@@ -91,7 +80,6 @@ StyleCopReport.xml
|
|||||||
*.tmp_proj
|
*.tmp_proj
|
||||||
*_wpftmp.csproj
|
*_wpftmp.csproj
|
||||||
*.log
|
*.log
|
||||||
*.tlog
|
|
||||||
*.vspscc
|
*.vspscc
|
||||||
*.vssscc
|
*.vssscc
|
||||||
.builds
|
.builds
|
||||||
@@ -133,6 +121,9 @@ _ReSharper*/
|
|||||||
*.[Rr]e[Ss]harper
|
*.[Rr]e[Ss]harper
|
||||||
*.DotSettings.user
|
*.DotSettings.user
|
||||||
|
|
||||||
|
# JustCode is a .NET coding add-in
|
||||||
|
.JustCode
|
||||||
|
|
||||||
# TeamCity is a build add-in
|
# TeamCity is a build add-in
|
||||||
_TeamCity*
|
_TeamCity*
|
||||||
|
|
||||||
@@ -143,11 +134,6 @@ _TeamCity*
|
|||||||
.axoCover/*
|
.axoCover/*
|
||||||
!.axoCover/settings.json
|
!.axoCover/settings.json
|
||||||
|
|
||||||
# Coverlet is a free, cross platform Code Coverage Tool
|
|
||||||
coverage*.json
|
|
||||||
coverage*.xml
|
|
||||||
coverage*.info
|
|
||||||
|
|
||||||
# Visual Studio code coverage results
|
# Visual Studio code coverage results
|
||||||
*.coverage
|
*.coverage
|
||||||
*.coveragexml
|
*.coveragexml
|
||||||
@@ -195,8 +181,6 @@ PublishScripts/
|
|||||||
|
|
||||||
# NuGet Packages
|
# NuGet Packages
|
||||||
*.nupkg
|
*.nupkg
|
||||||
# NuGet Symbol Packages
|
|
||||||
*.snupkg
|
|
||||||
# The packages folder can be ignored because of Package Restore
|
# The packages folder can be ignored because of Package Restore
|
||||||
**/[Pp]ackages/*
|
**/[Pp]ackages/*
|
||||||
# except build/, which is used as an MSBuild target.
|
# except build/, which is used as an MSBuild target.
|
||||||
@@ -221,14 +205,12 @@ BundleArtifacts/
|
|||||||
Package.StoreAssociation.xml
|
Package.StoreAssociation.xml
|
||||||
_pkginfo.txt
|
_pkginfo.txt
|
||||||
*.appx
|
*.appx
|
||||||
*.appxbundle
|
|
||||||
*.appxupload
|
|
||||||
|
|
||||||
# Visual Studio cache files
|
# Visual Studio cache files
|
||||||
# files ending in .cache can be ignored
|
# files ending in .cache can be ignored
|
||||||
*.[Cc]ache
|
*.[Cc]ache
|
||||||
# but keep track of directories ending in .cache
|
# but keep track of directories ending in .cache
|
||||||
!?*.[Cc]ache/
|
!*.[Cc]ache/
|
||||||
|
|
||||||
# Others
|
# Others
|
||||||
ClientBin/
|
ClientBin/
|
||||||
@@ -272,9 +254,6 @@ ServiceFabricBackup/
|
|||||||
*.bim.layout
|
*.bim.layout
|
||||||
*.bim_*.settings
|
*.bim_*.settings
|
||||||
*.rptproj.rsuser
|
*.rptproj.rsuser
|
||||||
*- [Bb]ackup.rdl
|
|
||||||
*- [Bb]ackup ([0-9]).rdl
|
|
||||||
*- [Bb]ackup ([0-9][0-9]).rdl
|
|
||||||
|
|
||||||
# Microsoft Fakes
|
# Microsoft Fakes
|
||||||
FakesAssemblies/
|
FakesAssemblies/
|
||||||
@@ -295,17 +274,6 @@ node_modules/
|
|||||||
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
|
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
|
||||||
*.vbw
|
*.vbw
|
||||||
|
|
||||||
# Visual Studio 6 auto-generated project file (contains which files were open etc.)
|
|
||||||
*.vbp
|
|
||||||
|
|
||||||
# Visual Studio 6 workspace and project file (working project files containing files to include in project)
|
|
||||||
*.dsw
|
|
||||||
*.dsp
|
|
||||||
|
|
||||||
# Visual Studio 6 technical files
|
|
||||||
*.ncb
|
|
||||||
*.aps
|
|
||||||
|
|
||||||
# Visual Studio LightSwitch build output
|
# Visual Studio LightSwitch build output
|
||||||
**/*.HTMLClient/GeneratedArtifacts
|
**/*.HTMLClient/GeneratedArtifacts
|
||||||
**/*.DesktopClient/GeneratedArtifacts
|
**/*.DesktopClient/GeneratedArtifacts
|
||||||
@@ -321,6 +289,10 @@ paket-files/
|
|||||||
# FAKE - F# Make
|
# FAKE - F# Make
|
||||||
.fake/
|
.fake/
|
||||||
|
|
||||||
|
# JetBrains Rider
|
||||||
|
.idea/
|
||||||
|
*.sln.iml
|
||||||
|
|
||||||
# CodeRush personal settings
|
# CodeRush personal settings
|
||||||
.cr/personal
|
.cr/personal
|
||||||
|
|
||||||
@@ -362,53 +334,10 @@ ASALocalRun/
|
|||||||
# Local History for Visual Studio
|
# Local History for Visual Studio
|
||||||
.localhistory/
|
.localhistory/
|
||||||
|
|
||||||
# Visual Studio History (VSHistory) files
|
|
||||||
.vshistory/
|
|
||||||
|
|
||||||
# BeatPulse healthcheck temp database
|
|
||||||
healthchecksdb
|
|
||||||
|
|
||||||
# Backup folder for Package Reference Convert tool in Visual Studio 2017
|
|
||||||
MigrationBackup/
|
|
||||||
|
|
||||||
# Ionide (cross platform F# VS Code tools) working folder
|
|
||||||
.ionide/
|
|
||||||
|
|
||||||
# Fody - auto-generated XML schema
|
|
||||||
FodyWeavers.xsd
|
|
||||||
|
|
||||||
# VS Code files for those working on multiple tools
|
|
||||||
.vscode/*
|
|
||||||
!.vscode/settings.json
|
|
||||||
!.vscode/tasks.json
|
|
||||||
!.vscode/launch.json
|
|
||||||
!.vscode/extensions.json
|
|
||||||
*.code-workspace
|
|
||||||
|
|
||||||
# Local History for Visual Studio Code
|
|
||||||
.history/
|
|
||||||
|
|
||||||
# Windows Installer files from build outputs
|
|
||||||
*.cab
|
|
||||||
*.msi
|
|
||||||
*.msix
|
|
||||||
*.msm
|
|
||||||
*.msp
|
|
||||||
|
|
||||||
# JetBrains Rider
|
|
||||||
*.sln.iml
|
|
||||||
|
|
||||||
# ---> VisualStudioCode
|
# ---> VisualStudioCode
|
||||||
.vscode/*
|
.vscode/*
|
||||||
!.vscode/settings.json
|
!.vscode/settings.json
|
||||||
!.vscode/tasks.json
|
!.vscode/tasks.json
|
||||||
!.vscode/launch.json
|
!.vscode/launch.json
|
||||||
!.vscode/extensions.json
|
!.vscode/extensions.json
|
||||||
!.vscode/*.code-snippets
|
|
||||||
|
|
||||||
# Local History for Visual Studio Code
|
|
||||||
.history/
|
|
||||||
|
|
||||||
# Built Visual Studio Code Extensions
|
|
||||||
*.vsix
|
|
||||||
|
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.4.33110.190
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EonaCat.MemoryManager", "EonaCat.MemoryManager\EonaCat.MemoryManager.csproj", "{077F253D-4E1D-0990-DA9E-3117FAC1DA26}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{077F253D-4E1D-0990-DA9E-3117FAC1DA26}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{077F253D-4E1D-0990-DA9E-3117FAC1DA26}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{077F253D-4E1D-0990-DA9E-3117FAC1DA26}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{077F253D-4E1D-0990-DA9E-3117FAC1DA26}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {FBE67F06-CBF4-4673-A8E8-EF31FC3038E8}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFrameworks>
|
||||||
|
net8.0-windows;
|
||||||
|
</TargetFrameworks>
|
||||||
|
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||||
|
<PackageId>EonaCat.MemoryManager</PackageId>
|
||||||
|
<Authors>EonaCat (Jeroen Saey)</Authors>
|
||||||
|
<Company>EonaCat (Jeroen Saey)</Company>
|
||||||
|
<Product>EonaCat MemoryManager</Product>
|
||||||
|
<Copyright>EonaCat (Jeroen Saey)</Copyright>
|
||||||
|
<PackageProjectUrl>https://www.nuget.org/packages/EonaCat.MemoryManager/</PackageProjectUrl>
|
||||||
|
<PackageTags>EonaCat, Memory, Manager, Processes, Manipulation, Jeroen, Saey</PackageTags>
|
||||||
|
<PackageReleaseNotes></PackageReleaseNotes>
|
||||||
|
<Description>EonaCat MemoryManager</Description>
|
||||||
|
<Version>1.0.0</Version>
|
||||||
|
<AssemblyVersion>1.0.0.0</AssemblyVersion>
|
||||||
|
<FileVersion>1.0.0.0</FileVersion>
|
||||||
|
<PackageIcon>icon.png</PackageIcon>
|
||||||
|
<Title>EonaCat.MemoryManager</Title>
|
||||||
|
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||||
|
<ProduceReferenceAssembly>False</ProduceReferenceAssembly>
|
||||||
|
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||||
|
<PackageLicenseFile>LICENSE</PackageLicenseFile>
|
||||||
|
|
||||||
|
<PackageRequireLicenseAcceptance>False</PackageRequireLicenseAcceptance>
|
||||||
|
|
||||||
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="..\icon.png">
|
||||||
|
<Pack>True</Pack>
|
||||||
|
<PackagePath>\</PackagePath>
|
||||||
|
</None>
|
||||||
|
<None Include="..\LICENSE">
|
||||||
|
<Pack>True</Pack>
|
||||||
|
<PackagePath>\</PackagePath>
|
||||||
|
</None>
|
||||||
|
<None Include="..\README.md">
|
||||||
|
<Pack>True</Pack>
|
||||||
|
<PackagePath>\</PackagePath>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="EonaCat.Win32Api" Version="1.0.3" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@@ -0,0 +1,173 @@
|
|||||||
|
using EonaCat.Win32Api.WindowsAPI;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace EonaCat.MemoryManager
|
||||||
|
{
|
||||||
|
public class MemoryManager
|
||||||
|
{
|
||||||
|
private readonly IntPtr _processHandle;
|
||||||
|
|
||||||
|
public MemoryManager(IntPtr processHandle)
|
||||||
|
{
|
||||||
|
_processHandle = processHandle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] ReadBytes(IntPtr address, int size)
|
||||||
|
{
|
||||||
|
byte[] buffer = new byte[size];
|
||||||
|
ApiKernel32.ReadProcessMemory(_processHandle, address, buffer, size, out _);
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteBytes(IntPtr address, byte[] data)
|
||||||
|
{
|
||||||
|
ApiKernel32.WriteProcessMemory(_processHandle, address, data, data.Length, out _);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IntPtr ReadPointer(IntPtr baseAddress, int[] offsets)
|
||||||
|
{
|
||||||
|
IntPtr address = baseAddress;
|
||||||
|
byte[] buffer = new byte[IntPtr.Size];
|
||||||
|
|
||||||
|
for (int i = 0; i < offsets.Length; i++)
|
||||||
|
{
|
||||||
|
ApiKernel32.ReadProcessMemory(_processHandle, address, buffer, buffer.Length, out _);
|
||||||
|
address = (IntPtr)(IntPtr.Size == 4 ? BitConverter.ToInt32(buffer, 0) : BitConverter.ToInt64(buffer, 0));
|
||||||
|
address = IntPtr.Add(address, offsets[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T ReadValue<T>(IntPtr address) where T : unmanaged
|
||||||
|
{
|
||||||
|
int size = Marshal.SizeOf<T>();
|
||||||
|
byte[] buffer = ReadBytes(address, size);
|
||||||
|
|
||||||
|
unsafe
|
||||||
|
{
|
||||||
|
fixed (byte* ptr = buffer)
|
||||||
|
{
|
||||||
|
return *(T*)ptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteValue<T>(IntPtr address, T value) where T : unmanaged
|
||||||
|
{
|
||||||
|
int size = Marshal.SizeOf<T>();
|
||||||
|
byte[] buffer = new byte[size];
|
||||||
|
|
||||||
|
unsafe
|
||||||
|
{
|
||||||
|
fixed (byte* ptr = buffer)
|
||||||
|
{
|
||||||
|
*(T*)ptr = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
WriteBytes(address, buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public T ReadStruct<T>(IntPtr address) where T : class
|
||||||
|
{
|
||||||
|
int size = Marshal.SizeOf<T>();
|
||||||
|
byte[] buffer = ReadBytes(address, size);
|
||||||
|
GCHandle handle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
|
||||||
|
T value = Marshal.PtrToStructure<T>(handle.AddrOfPinnedObject());
|
||||||
|
handle.Free();
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteStruct<T>(IntPtr address, T value) where T : class
|
||||||
|
{
|
||||||
|
int size = Marshal.SizeOf<T>();
|
||||||
|
byte[] buffer = new byte[size];
|
||||||
|
IntPtr ptr = Marshal.AllocHGlobal(size);
|
||||||
|
Marshal.StructureToPtr(value, ptr, false);
|
||||||
|
Marshal.Copy(ptr, buffer, 0, size);
|
||||||
|
Marshal.FreeHGlobal(ptr);
|
||||||
|
WriteBytes(address, buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public object ReadValue(IntPtr address, Type type)
|
||||||
|
{
|
||||||
|
int size = Marshal.SizeOf(type);
|
||||||
|
byte[] buffer = ReadBytes(address, size);
|
||||||
|
|
||||||
|
GCHandle handle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
|
||||||
|
object value = Marshal.PtrToStructure(handle.AddrOfPinnedObject(), type);
|
||||||
|
handle.Free();
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteValue(IntPtr address, object value, Type type)
|
||||||
|
{
|
||||||
|
int size = Marshal.SizeOf(type);
|
||||||
|
byte[] buffer = new byte[size];
|
||||||
|
IntPtr ptr = Marshal.AllocHGlobal(size);
|
||||||
|
Marshal.StructureToPtr(value, ptr, false);
|
||||||
|
Marshal.Copy(ptr, buffer, 0, size);
|
||||||
|
Marshal.FreeHGlobal(ptr);
|
||||||
|
WriteBytes(address, buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string ReadStringAscii(IntPtr address, int maxLength)
|
||||||
|
{
|
||||||
|
byte[] buffer = ReadBytes(address, maxLength);
|
||||||
|
int length = Array.IndexOf<byte>(buffer, 0);
|
||||||
|
if (length < 0) length = maxLength;
|
||||||
|
return System.Text.Encoding.ASCII.GetString(buffer, 0, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string ReadStringUnicode(IntPtr address, int maxLength)
|
||||||
|
{
|
||||||
|
byte[] buffer = ReadBytes(address, maxLength * 2);
|
||||||
|
int length = 0;
|
||||||
|
for (int i = 0; i < maxLength; i++)
|
||||||
|
{
|
||||||
|
if (buffer[i * 2] == 0 && buffer[i * 2 + 1] == 0)
|
||||||
|
{
|
||||||
|
length = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (length == 0) length = maxLength;
|
||||||
|
return System.Text.Encoding.Unicode.GetString(buffer, 0, length * 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteStringAscii(IntPtr address, string value)
|
||||||
|
{
|
||||||
|
byte[] buffer = System.Text.Encoding.ASCII.GetBytes(value + '\0');
|
||||||
|
WriteBytes(address, buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteStringUnicode(IntPtr address, string value)
|
||||||
|
{
|
||||||
|
byte[] buffer = System.Text.Encoding.Unicode.GetBytes(value + '\0');
|
||||||
|
WriteBytes(address, buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public T[] ReadArray<T>(IntPtr address, int count) where T : unmanaged
|
||||||
|
{
|
||||||
|
int size = Marshal.SizeOf<T>() * count;
|
||||||
|
byte[] buffer = ReadBytes(address, size);
|
||||||
|
T[] result = new T[count];
|
||||||
|
Buffer.BlockCopy(buffer, 0, result, 0, size);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteArray<T>(IntPtr address, T[] array) where T : unmanaged
|
||||||
|
{
|
||||||
|
int size = Marshal.SizeOf<T>() * array.Length;
|
||||||
|
byte[] buffer = new byte[size];
|
||||||
|
Buffer.BlockCopy(array, 0, buffer, 0, size);
|
||||||
|
WriteBytes(address, buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
using EonaCat.Win32Api.WindowsAPI;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace EonaCat.MemoryManager
|
||||||
|
{
|
||||||
|
public static class PatternScanner
|
||||||
|
{
|
||||||
|
public static IntPtr FindPattern(IntPtr processHandle, IntPtr startAddress, int size, byte[] pattern, string mask)
|
||||||
|
{
|
||||||
|
byte[] buffer = new byte[size];
|
||||||
|
ApiKernel32.ReadProcessMemory(processHandle, startAddress, buffer, size, out _);
|
||||||
|
|
||||||
|
for (int i = 0; i < size - pattern.Length; i++)
|
||||||
|
{
|
||||||
|
bool found = true;
|
||||||
|
for (int j = 0; j < pattern.Length; j++)
|
||||||
|
{
|
||||||
|
if (mask[j] == 'x' && buffer[i + j] != pattern[j])
|
||||||
|
{
|
||||||
|
found = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (found)
|
||||||
|
{
|
||||||
|
return IntPtr.Add(startAddress, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return IntPtr.Zero;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IntPtr FindPatternInModules(ProcessManager procManager, string patternStr)
|
||||||
|
{
|
||||||
|
byte[] pattern = ParsePattern(patternStr);
|
||||||
|
string mask = PatternToMask(patternStr);
|
||||||
|
|
||||||
|
foreach (ProcessModule module in procManager.Process.Modules)
|
||||||
|
{
|
||||||
|
IntPtr address = FindPattern(procManager.ProcessHandle, module.BaseAddress, module.ModuleMemorySize, pattern, mask);
|
||||||
|
if (address != IntPtr.Zero)
|
||||||
|
{
|
||||||
|
return address;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return IntPtr.Zero;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] ParsePattern(string patternString)
|
||||||
|
{
|
||||||
|
string[] split = patternString.Split(' ');
|
||||||
|
byte[] pattern = new byte[split.Length];
|
||||||
|
for (int i = 0; i < split.Length; i++)
|
||||||
|
{
|
||||||
|
pattern[i] = (split[i] == "??" || split[i] == "?") ? (byte)0x00 : Convert.ToByte(split[i], 16);
|
||||||
|
}
|
||||||
|
return pattern;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string PatternToMask(string patternString)
|
||||||
|
{
|
||||||
|
string[] split = patternString.Split(' ');
|
||||||
|
string mask = "";
|
||||||
|
foreach (string part in split)
|
||||||
|
{
|
||||||
|
mask += (part == "??" || part == "?") ? "?" : "x";
|
||||||
|
}
|
||||||
|
return mask;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
using EonaCat.Win32Api.WindowsAPI;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
|
||||||
|
namespace EonaCat.MemoryManager
|
||||||
|
{
|
||||||
|
public class ProcessManager
|
||||||
|
{
|
||||||
|
public IntPtr ProcessHandle { get; private set; }
|
||||||
|
public Process Process { get; private set; }
|
||||||
|
|
||||||
|
public bool Attach(string processName)
|
||||||
|
{
|
||||||
|
Process[] processes = Process.GetProcessesByName(processName);
|
||||||
|
if (processes.Length == 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Process = processes[0];
|
||||||
|
ProcessHandle = ApiKernel32.OpenProcess(0x1F0FFF, false, Process.Id);
|
||||||
|
return ProcessHandle != IntPtr.Zero;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Detach()
|
||||||
|
{
|
||||||
|
if (ProcessHandle != IntPtr.Zero)
|
||||||
|
{
|
||||||
|
ApiKernel32.CloseHandle(ProcessHandle);
|
||||||
|
}
|
||||||
|
|
||||||
|
ProcessHandle = IntPtr.Zero;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<string> ListProcesses()
|
||||||
|
{
|
||||||
|
List<string> processNames = new List<string>();
|
||||||
|
Process[] processes = Process.GetProcesses();
|
||||||
|
foreach (var process in processes)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
processNames.Add($"{process.ProcessName} ({process.Id})");
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
return processNames;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IntPtr GetModuleBaseAddress(string moduleName)
|
||||||
|
{
|
||||||
|
foreach (ProcessModule module in Process.Modules)
|
||||||
|
{
|
||||||
|
if (module.ModuleName.Equals(moduleName, StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
return module.BaseAddress;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return IntPtr.Zero;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,73 +1,204 @@
|
|||||||
Apache License
|
|
||||||
Version 2.0, January 2004
|
Apache License
|
||||||
http://www.apache.org/licenses/
|
Version 2.0, January 2004
|
||||||
|
http://www.apache.org/licenses/
|
||||||
|
https://EonaCat.com/license/
|
||||||
|
|
||||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
OF SOFTWARE BY EONACAT (JEROEN SAEY)
|
||||||
|
|
||||||
1. Definitions.
|
1. Definitions.
|
||||||
|
|
||||||
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
|
"License" shall mean the terms and conditions for use, reproduction,
|
||||||
|
and distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
|
"Licensor" shall mean the copyright owner or entity authorized by
|
||||||
|
the copyright owner that is granting the License.
|
||||||
|
|
||||||
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
"Legal Entity" shall mean the union of the acting entity and all
|
||||||
|
other entities that control, are controlled by, or are under common
|
||||||
|
control with that entity. For the purposes of this definition,
|
||||||
|
"control" means (i) the power, direct or indirect, to cause the
|
||||||
|
direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
|
"You" (or "Your") shall mean an individual or Legal Entity
|
||||||
|
exercising permissions granted by this License.
|
||||||
|
|
||||||
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
|
including but not limited to software source code, documentation
|
||||||
|
source, and configuration files.
|
||||||
|
|
||||||
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
|
"Object" form shall mean any form resulting from mechanical
|
||||||
|
transformation or translation of a Source form, including but
|
||||||
|
not limited to compiled object code, generated documentation,
|
||||||
|
and conversions to other media types.
|
||||||
|
|
||||||
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
|
"Work" shall mean the work of authorship, whether in Source or
|
||||||
|
Object form, made available under the License, as indicated by a
|
||||||
|
copyright notice that is included in or attached to the work
|
||||||
|
(an example is provided in the Appendix below).
|
||||||
|
|
||||||
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
"Derivative Works" shall mean any work, whether in Source or Object
|
||||||
|
form, that is based on (or derived from) the Work and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship. For the purposes
|
||||||
|
of this License, Derivative Works shall not include works that remain
|
||||||
|
separable from, or merely link (or bind by name) to the interfaces of,
|
||||||
|
the Work and Derivative Works thereof.
|
||||||
|
|
||||||
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
|
"Contribution" shall mean any work of authorship, including
|
||||||
|
the original version of the Work and any modifications or additions
|
||||||
|
to that Work or Derivative Works thereof, that is intentionally
|
||||||
|
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||||
|
or by an individual or Legal Entity authorized to submit on behalf of
|
||||||
|
the copyright owner. For the purposes of this definition, "submitted"
|
||||||
|
means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems,
|
||||||
|
and issue tracking systems that are managed by, or on behalf of, the
|
||||||
|
Licensor for the purpose of discussing and improving the Work, but
|
||||||
|
excluding communication that is conspicuously marked or otherwise
|
||||||
|
designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||||
|
on behalf of whom a Contribution has been received by Licensor and
|
||||||
|
subsequently incorporated within the Work.
|
||||||
|
|
||||||
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the
|
||||||
|
Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
|
3. Grant of Patent License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
(except as stated in this section) patent license to make, have made,
|
||||||
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||||
|
where such license applies only to those patent claims licensable
|
||||||
|
by such Contributor that are necessarily infringed by their
|
||||||
|
Contribution(s) alone or by combination of their Contribution(s)
|
||||||
|
with the Work to which such Contribution(s) was submitted. If You
|
||||||
|
institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||||
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
|
or contributory patent infringement, then any patent licenses
|
||||||
|
granted to You under this License for that Work shall terminate
|
||||||
|
as of the date such litigation is filed.
|
||||||
|
|
||||||
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
|
4. Redistribution. You may reproduce and distribute copies of the
|
||||||
|
Work or Derivative Works thereof in any medium, with or without
|
||||||
|
modifications, and in Source or Object form, provided that You
|
||||||
|
meet the following conditions:
|
||||||
|
|
||||||
(a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
(a) You must give any other recipients of the Work or
|
||||||
|
Derivative Works a copy of this License; and
|
||||||
|
|
||||||
(b) You must cause any modified files to carry prominent notices stating that You changed the files; and
|
(b) You must cause any modified files to carry prominent notices
|
||||||
|
stating that You changed the files; and
|
||||||
|
|
||||||
(c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
|
(c) You must retain, in the Source form of any Derivative Works
|
||||||
|
that You distribute, all copyright, patent, trademark, and
|
||||||
|
attribution notices from the Source form of the Work,
|
||||||
|
excluding those notices that do not pertain to any part of
|
||||||
|
the Derivative Works; and
|
||||||
|
|
||||||
(d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
|
(d) If the Work includes a "NOTICE" text file as part of its
|
||||||
|
distribution, then any Derivative Works that You distribute must
|
||||||
|
include a readable copy of the attribution notices contained
|
||||||
|
within such NOTICE file, excluding those notices that do not
|
||||||
|
pertain to any part of the Derivative Works, in at least one
|
||||||
|
of the following places: within a NOTICE text file distributed
|
||||||
|
as part of the Derivative Works; within the Source form or
|
||||||
|
documentation, if provided along with the Derivative Works; or,
|
||||||
|
within a display generated by the Derivative Works, if and
|
||||||
|
wherever such third-party notices normally appear. The contents
|
||||||
|
of the NOTICE file are for informational purposes only and
|
||||||
|
do not modify the License. You may add Your own attribution
|
||||||
|
notices within Derivative Works that You distribute, alongside
|
||||||
|
or as an addendum to the NOTICE text from the Work, provided
|
||||||
|
that such additional attribution notices cannot be construed
|
||||||
|
as modifying the License.
|
||||||
|
|
||||||
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
|
You may add Your own copyright statement to Your modifications and
|
||||||
|
may provide additional or different license terms and conditions
|
||||||
|
for use, reproduction, or distribution of Your modifications, or
|
||||||
|
for any such Derivative Works as a whole, provided Your use,
|
||||||
|
reproduction, and distribution of the Work otherwise complies with
|
||||||
|
the conditions stated in this License.
|
||||||
|
|
||||||
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||||
|
any Contribution intentionally submitted for inclusion in the Work
|
||||||
|
by You to the Licensor shall be under the terms and conditions of
|
||||||
|
this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify
|
||||||
|
the terms of any separate license agreement you may have executed
|
||||||
|
with Licensor regarding such Contributions.
|
||||||
|
|
||||||
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
|
6. Trademarks. This License does not grant permission to use the trade
|
||||||
|
names, trademarks, service marks, or product names of the Licensor,
|
||||||
|
except as required for reasonable and customary use in describing the
|
||||||
|
origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||||
|
agreed to in writing, Licensor provides the Work (and each
|
||||||
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
implied, including, without limitation, any warranties or conditions
|
||||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||||
|
appropriateness of using or redistributing the Work and assume any
|
||||||
|
risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
|
8. Limitation of Liability. In no event and under no legal theory,
|
||||||
|
whether in tort (including negligence), contract, or otherwise,
|
||||||
|
unless required by applicable law (such as deliberate and grossly
|
||||||
|
negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
|
liable to You for damages, including any direct, indirect, special,
|
||||||
|
incidental, or consequential damages of any character arising as a
|
||||||
|
result of this License or out of the use or inability to use the
|
||||||
|
Work (including but not limited to damages for loss of goodwill,
|
||||||
|
work stoppage, computer failure or malfunction, or any and all
|
||||||
|
other commercial damages or losses), even if such Contributor
|
||||||
|
has been advised of the possibility of such damages.
|
||||||
|
|
||||||
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
|
9. Accepting Warranty or Additional Liability. While redistributing
|
||||||
|
the Work or Derivative Works thereof, You may choose to offer,
|
||||||
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||||
|
or other liability obligations and/or rights consistent with this
|
||||||
|
License. However, in accepting such obligations, You may act only
|
||||||
|
on Your own behalf and on Your sole responsibility, not on behalf
|
||||||
|
of any other Contributor, and only if You agree to indemnify,
|
||||||
|
defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason
|
||||||
|
of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
APPENDIX: How to apply the Apache License to your work.
|
APPENDIX: How to apply the Apache License to your work.
|
||||||
|
|
||||||
To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
|
To apply the Apache License to your work, attach the following
|
||||||
|
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||||
|
replaced with your own identifying information. (Don't include
|
||||||
|
the brackets!) The text should be enclosed in the appropriate
|
||||||
|
comment syntax for the file format. We also recommend that a
|
||||||
|
file or class name and description of purpose be included on the
|
||||||
|
same "printed page" as the copyright notice for easier
|
||||||
|
identification within third-party archives.
|
||||||
|
|
||||||
Copyright 2025 EonaCat
|
Copyright [yyyy] [name of copyright owner]
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
Unless required by applicable law or agreed to in writing, software
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
@@ -1,3 +1,107 @@
|
|||||||
# EonaCat.MemoryManager
|
# EonaCat.MemoryManager
|
||||||
|
|
||||||
EonaCat.MemoryManager
|
Process and Memory Management Library for .NET using EonaCat.MemoryManager.
|
||||||
|
|
||||||
|
#### Example Usage:
|
||||||
|
```Csharp
|
||||||
|
var procManager = new ProcessManager();
|
||||||
|
|
||||||
|
// Attach to process (e.g. "notepad")
|
||||||
|
string targetProcess = "notepad";
|
||||||
|
if (!procManager.Attach(targetProcess))
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Failed to attach to {targetProcess}.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Console.WriteLine($"Attached to {targetProcess} (PID {procManager.Process.Id})");
|
||||||
|
|
||||||
|
var memManager = new MemoryManager(procManager.ProcessHandle);
|
||||||
|
|
||||||
|
IntPtr baseAddress = procManager.GetModuleBaseAddress(targetProcess + ".exe");
|
||||||
|
Console.WriteLine($"Base address: 0x{baseAddress.ToInt64():X}");
|
||||||
|
|
||||||
|
// Example offsets for pointer chaining (replace with real offsets)
|
||||||
|
int[] offsets = { 0x10, 0x20, 0x8 };
|
||||||
|
IntPtr pointerAddress = memManager.ReadPointer(baseAddress, offsets);
|
||||||
|
Console.WriteLine($"Pointer resolved to: 0x{pointerAddress.ToInt64():X}");
|
||||||
|
|
||||||
|
// --- 1. Read/Write unmanaged primitive (int) ---
|
||||||
|
int intVal = memManager.ReadValue<int>(pointerAddress);
|
||||||
|
Console.WriteLine($"Read int: {intVal}");
|
||||||
|
|
||||||
|
memManager.WriteValue(pointerAddress, 9999);
|
||||||
|
Console.WriteLine("Wrote int: 9999");
|
||||||
|
|
||||||
|
// --- 2. Read/Write managed struct ---
|
||||||
|
var vec3 = memManager.ReadStruct<Vector3>(pointerAddress);
|
||||||
|
Console.WriteLine($"Read Vector3: X={vec3.X}, Y={vec3.Y}, Z={vec3.Z}");
|
||||||
|
|
||||||
|
var newVec = new Vector3 { X = 1.1f, Y = 2.2f, Z = 3.3f };
|
||||||
|
memManager.WriteStruct(pointerAddress, newVec);
|
||||||
|
Console.WriteLine("Wrote new Vector3");
|
||||||
|
|
||||||
|
// --- 3. Read/Write strings ---
|
||||||
|
string asciiStr = memManager.ReadStringAscii(pointerAddress, 50);
|
||||||
|
Console.WriteLine($"Read ASCII string: {asciiStr}");
|
||||||
|
|
||||||
|
memManager.WriteStringAscii(pointerAddress, "Hello ASCII!");
|
||||||
|
Console.WriteLine("Wrote ASCII string: Hello ASCII!");
|
||||||
|
|
||||||
|
string unicodeStr = memManager.ReadStringUnicode(pointerAddress, 50);
|
||||||
|
Console.WriteLine($"Read Unicode string: {unicodeStr}");
|
||||||
|
|
||||||
|
memManager.WriteStringUnicode(pointerAddress, "Hello Unicode!");
|
||||||
|
Console.WriteLine("Wrote Unicode string: Hello Unicode!");
|
||||||
|
|
||||||
|
// --- 4. Read/Write array of floats ---
|
||||||
|
float[] floatArray = memManager.ReadArray<float>(pointerAddress, 5);
|
||||||
|
Console.WriteLine("Read float array:");
|
||||||
|
foreach (var f in floatArray) Console.WriteLine(f);
|
||||||
|
|
||||||
|
float[] newArray = { 9.9f, 8.8f, 7.7f, 6.6f, 5.5f };
|
||||||
|
memManager.WriteArray(pointerAddress, newArray);
|
||||||
|
Console.WriteLine("Wrote float array");
|
||||||
|
|
||||||
|
// --- 5. Non-generic Read/Write ---
|
||||||
|
object objVal = memManager.ReadValue(pointerAddress, typeof(Vector3));
|
||||||
|
Vector3 vecFromObj = (Vector3)objVal;
|
||||||
|
Console.WriteLine($"Non-generic read Vector3: X={vecFromObj.X}, Y={vecFromObj.Y}, Z={vecFromObj.Z}");
|
||||||
|
|
||||||
|
memManager.WriteValue(pointerAddress, newVec, typeof(Vector3));
|
||||||
|
Console.WriteLine("Non-generic wrote Vector3");
|
||||||
|
|
||||||
|
// Cleanup
|
||||||
|
procManager.Detach();
|
||||||
|
Console.WriteLine("Detached from process.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Example struct (must match memory layout)
|
||||||
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
public class Vector3
|
||||||
|
{
|
||||||
|
public float X;
|
||||||
|
public float Y;
|
||||||
|
public float Z;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Notes:
|
||||||
|
Run your target process (e.g., Notepad).
|
||||||
|
|
||||||
|
Adjust the targetProcess variable to match your process name.
|
||||||
|
|
||||||
|
Replace the pointer offsets with valid ones for your target process.
|
||||||
|
|
||||||
|
Adjust the read/write addresses or pattern scan results accordingly.
|
||||||
|
|
||||||
|
#### This example covers:
|
||||||
|
|
||||||
|
Unmanaged primitive read/write (int)
|
||||||
|
|
||||||
|
Managed struct read/write (Vector3 class)
|
||||||
|
|
||||||
|
ASCII and Unicode string read/write
|
||||||
|
|
||||||
|
Array of unmanaged types (float) read/write
|
||||||
|
|
||||||
|
Non-generic object-based read/write
|
||||||
Reference in new issue
Block a user