Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AvaloniaUI #41

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
26 changes: 26 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/Bootstrapper/bin/Debug/netcoreapp2.1/Bootstrapper.dll",
"args": [],
"cwd": "${workspaceFolder}/Bootstrapper/bin/Debug/netcoreapp2.1",
"console": "internalConsole",
"stopAtEntry": true,
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}
17 changes: 17 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet build /p:GenerateFullPaths=true",
"type": "shell",
"group": "build",
"presentation": {
"reveal": "silent"
},
"problemMatcher": "$msCompile"
}
]
}
123 changes: 17 additions & 106 deletions Bootstrapper/Bootstrapper.csproj
Original file line number Diff line number Diff line change
@@ -1,115 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{FCAD4340-866B-4153-8A55-311224B764F6}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Bootstrapper</RootNamespace>
<AssemblyName>Bootstrapper</AssemblyName>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\build\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\distribution\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup>
<StartupObject>
</StartupObject>
</PropertyGroup>
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\packages\NLog.4.5.6\lib\net45\NLog.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.ServiceModel" />
<Reference Include="System.Transactions" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<ProjectReference Include="..\Sharlayan\Sharlayan.csproj"/>
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<PackageReference Include="NLog.Config" Version="4.5.9"/>
<PackageReference Include="NLog.Schema" Version="4.5.9"/>
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="Bootstrapper.exe.nlog">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<Content Include="NLog.config">
<None Update="Bootstrapper.exe.nlog">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Include="NLog.xsd">
<SubType>Designer</SubType>
</None>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Sharlayan\Sharlayan.csproj">
<Project>{49C85043-6646-46FD-A262-E2EA0ED1DF82}</Project>
<Name>Sharlayan</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyInformationalVersionAttribute>false</GenerateAssemblyInformationalVersionAttribute>
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
</PropertyGroup>
</Project>
31 changes: 25 additions & 6 deletions Bootstrapper/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace Bootstrapper {
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
using System.Xml;
using System.Xml.Linq;
Expand Down Expand Up @@ -43,7 +44,25 @@ static void Main(string[] args) {
StatusItem status = StatusEffectLookup.GetStatusInfo(2);
MapItem zone = ZoneLookup.GetZoneInfo(138);

Process process = Process.GetProcessesByName("ffxiv_dx11").FirstOrDefault();
var processName = "ffxiv_dx11";
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) {
processName = "ffxiv_dx11.exe";
}

Process process = Process.GetProcessesByName(processName).FirstOrDefault();

if (process == null && RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) {
var ps = new Process();
ps.StartInfo = new ProcessStartInfo("ps", "-Ao pid,command");
ps.StartInfo.RedirectStandardOutput = true;
ps.Start();
var content = ps.StandardOutput.ReadToEnd();
ps.WaitForExit(2000);

var pid = content.Split(Environment.NewLine).Where(x => x.Contains(processName)).Select(x => Enumerable.FirstOrDefault(x.Split(' '))).FirstOrDefault(x => x != null);
if (!string.IsNullOrEmpty(pid))
process = Process.GetProcessById(int.Parse(pid));
}

if (process != null) {
MemoryHandler.Instance.SetProcess(
Expand All @@ -52,16 +71,16 @@ static void Main(string[] args) {
Process = process,
});

while (Scanner.Instance.IsScanning) {
Thread.Sleep(1000);
Console.WriteLine("Scanning...");
}

MemoryHandler.Instance.SignaturesFoundEvent += delegate(object sender, SignaturesFoundEvent e) {
foreach (KeyValuePair<string, Signature> kvp in e.Signatures) {
Console.WriteLine($"{kvp.Key} => {kvp.Value.GetAddress():X}");
}
};

while (Scanner.Instance.IsScanning) {
Thread.Sleep(1000);
Console.WriteLine("Scanning...");
}
}

Console.WriteLine("To exit this application press \"Enter\".");
Expand Down
8 changes: 0 additions & 8 deletions Bootstrapper/packages.config

This file was deleted.

21 changes: 9 additions & 12 deletions Sharlayan.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30011.22
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sharlayan", "Sharlayan\Sharlayan.csproj", "{49C85043-6646-46FD-A262-E2EA0ED1DF82}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sharlayan", "Sharlayan\Sharlayan.csproj", "{1C0EBCC7-5550-48C8-9492-27853C02B76B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bootstrapper", "Bootstrapper\Bootstrapper.csproj", "{FCAD4340-866B-4153-8A55-311224B764F6}"
EndProject
Expand All @@ -20,17 +20,14 @@ Global
ReleaseDeploy|Any CPU = ReleaseDeploy|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{49C85043-6646-46FD-A262-E2EA0ED1DF82}.Debug|Any CPU.ActiveCfg = Debug|x86
{49C85043-6646-46FD-A262-E2EA0ED1DF82}.Debug|Any CPU.Build.0 = Debug|x86
{49C85043-6646-46FD-A262-E2EA0ED1DF82}.Release|Any CPU.ActiveCfg = Release|x86
{49C85043-6646-46FD-A262-E2EA0ED1DF82}.Release|Any CPU.Build.0 = Release|x86
{49C85043-6646-46FD-A262-E2EA0ED1DF82}.ReleaseDeploy|Any CPU.ActiveCfg = ReleaseDeploy|x86
{49C85043-6646-46FD-A262-E2EA0ED1DF82}.ReleaseDeploy|Any CPU.Build.0 = ReleaseDeploy|x86
{FCAD4340-866B-4153-8A55-311224B764F6}.Debug|Any CPU.ActiveCfg = Debug|x86
{FCAD4340-866B-4153-8A55-311224B764F6}.Debug|Any CPU.Build.0 = Debug|x86
{FCAD4340-866B-4153-8A55-311224B764F6}.Release|Any CPU.ActiveCfg = Release|x86
{FCAD4340-866B-4153-8A55-311224B764F6}.Release|Any CPU.Build.0 = Release|x86
{FCAD4340-866B-4153-8A55-311224B764F6}.ReleaseDeploy|Any CPU.ActiveCfg = Release|x86
{1C0EBCC7-5550-48C8-9492-27853C02B76B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1C0EBCC7-5550-48C8-9492-27853C02B76B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1C0EBCC7-5550-48C8-9492-27853C02B76B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1C0EBCC7-5550-48C8-9492-27853C02B76B}.Release|Any CPU.Build.0 = Release|Any CPU
{FCAD4340-866B-4153-8A55-311224B764F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FCAD4340-866B-4153-8A55-311224B764F6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FCAD4340-866B-4153-8A55-311224B764F6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FCAD4340-866B-4153-8A55-311224B764F6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
45 changes: 6 additions & 39 deletions Sharlayan/MemoryHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace Sharlayan {
using Sharlayan.Events;
using Sharlayan.Models;
using Sharlayan.Models.Structures;
using Sharlayan.OS;
using Sharlayan.Utilities;

using BitConverter = Sharlayan.Utilities.BitConverter;
Expand Down Expand Up @@ -61,7 +62,7 @@ public static MemoryHandler Instance {

internal bool UseLocalCache { get; set; }

private List<ProcessModule> SystemModules { get; set; } = new List<ProcessModule>();
internal List<ProcessModule> SystemModules { get; private set; } = new List<ProcessModule>();

public byte GetByte(IntPtr address, long offset = 0) {
byte[] data = new byte[1];
Expand Down Expand Up @@ -169,9 +170,8 @@ public string GetStringFromBytes(byte[] source, int offset = 0, int size = 256)
}

public T GetStructure<T>(IntPtr address, int offset = 0) {
IntPtr lpNumberOfBytesRead;
IntPtr buffer = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(T)));
UnsafeNativeMethods.ReadProcessMemory(this.ProcessModel.Process.Handle, address + offset, buffer, new IntPtr(Marshal.SizeOf(typeof(T))), out lpNumberOfBytesRead);
NativeMemoryHandler.Instance.ReadMemory(this.ProcessModel.Process.Handle, address + offset, buffer, new IntPtr(Marshal.SizeOf(typeof(T))));
var retValue = (T) Marshal.PtrToStructure(buffer, typeof(T));
Marshal.FreeCoTaskMem(buffer);
return retValue;
Expand All @@ -196,8 +196,7 @@ public ulong GetUInt64(IntPtr address, long offset = 0) {
}

public bool Peek(IntPtr address, byte[] buffer) {
IntPtr lpNumberOfBytesRead;
return UnsafeNativeMethods.ReadProcessMemory(Instance.ProcessHandle, address, buffer, new IntPtr(buffer.Length), out lpNumberOfBytesRead);
return NativeMemoryHandler.Instance.ReadMemory(Instance.ProcessHandle, address, buffer);
}

public IntPtr ReadPointer(IntPtr address, long offset = 0) {
Expand Down Expand Up @@ -245,7 +244,7 @@ public void SetProcess(ProcessModel processModel, string gameLanguage = "English
this.UnsetProcess();

try {
this.ProcessHandle = UnsafeNativeMethods.OpenProcess(UnsafeNativeMethods.ProcessAccessFlags.PROCESS_VM_ALL, false, (uint) this.ProcessModel.ProcessID);
this.ProcessHandle = NativeMemoryHandler.Instance.OpenProcess(this.ProcessModel.ProcessID);
}
catch (Exception) {
this.ProcessHandle = processModel.Process.Handle;
Expand Down Expand Up @@ -283,7 +282,7 @@ public void UnsetProcess() {

try {
if (this.IsAttached) {
UnsafeNativeMethods.CloseHandle(Instance.ProcessHandle);
NativeMemoryHandler.Instance.CloseHandle(Instance.ProcessHandle);
}
}
catch (Exception) {
Expand All @@ -295,38 +294,6 @@ public void UnsetProcess() {
}
}

internal ProcessModule GetModuleByAddress(IntPtr address) {
try {
for (var i = 0; i < this.SystemModules.Count; i++) {
ProcessModule module = this.SystemModules[i];
var baseAddress = this.ProcessModel.IsWin64
? module.BaseAddress.ToInt64()
: module.BaseAddress.ToInt32();
if (baseAddress <= (long) address && baseAddress + module.ModuleMemorySize >= (long) address) {
return module;
}
}

return null;
}
catch (Exception) {
return null;
}
}

internal bool IsSystemModule(IntPtr address) {
ProcessModule moduleByAddress = this.GetModuleByAddress(address);
if (moduleByAddress != null) {
foreach (ProcessModule module in this.SystemModules) {
if (module.ModuleName == moduleByAddress.ModuleName) {
return true;
}
}
}

return false;
}

internal void ResolveMemoryStructures(ProcessModel processModel, string patchVersion = "latest") {
this.Structures = APIHelper.GetStructures(processModel, patchVersion);
}
Expand Down
16 changes: 16 additions & 0 deletions Sharlayan/OS/INativeMemoryHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Sharlayan.Models;

namespace Sharlayan.OS {
public interface INativeMemoryHandler
{
bool ReadMemory(IntPtr handle, IntPtr address, byte[] buffer);
bool ReadMemory(IntPtr handle, IntPtr address, byte[] buffer, IntPtr size);
bool ReadMemory(IntPtr handle, IntPtr address, IntPtr buffer, IntPtr size);
IntPtr OpenProcess(int processId);
int CloseHandle(IntPtr hObject);
IList<NativeMemoryRegionInfo> LoadRegions(IntPtr handle, ProcessModel process, List<ProcessModule> systemModules, bool scanAllRegions);
}
}
Loading