mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-02-12 11:04:38 +01:00
WIP launcher
This commit is contained in:
parent
57e046cd71
commit
a73a479f73
6 changed files with 62 additions and 91 deletions
|
|
@ -1,8 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Pipes;
|
||||
using System.Text;
|
||||
using CoreHook.BinaryInjection;
|
||||
using CoreHook.BinaryInjection.RemoteInjection;
|
||||
using CoreHook.BinaryInjection.RemoteInjection.Configuration;
|
||||
using CoreHook.IPC.Platform;
|
||||
|
|
@ -25,24 +24,55 @@ namespace Dalamud.Injector
|
|||
|
||||
public void Relaunch(uint pid)
|
||||
{
|
||||
// TODO
|
||||
// 1. Open process `pid` with handle
|
||||
// 2. Read command arguments (requires reading PEB)
|
||||
// 3. Construct new arguments
|
||||
// 3.1 Decrypt arguments acquired from step.2 (possible key space is very small so it's feasible to do this)
|
||||
// 3.2 Manipulate arguments as needed
|
||||
// 3.3 Re-encrypt arguments with new timestamp
|
||||
// 4 Launch a new process with new argument which was computed from step.3
|
||||
// 5 Attempt to inject into that process.
|
||||
// 6. If all succeeded, terminate the old process.
|
||||
//
|
||||
// delegate Step 3 to 5 to Launch() maybe?
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Injects Dalamud into the process. See remarks for process state prerequisites.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// TODO: CREATE_SUSPENDED -> entrypoint explainations
|
||||
/// </remarks>
|
||||
/// <param name="pid">A process id to inject Dalamud into.</param>
|
||||
public void Inject(uint pid)
|
||||
{
|
||||
|
||||
// Please keep in mind that this config values (especially ClrRootPath) assumes that
|
||||
// Dalamud is compiled as self-contained to avoid requiring people to pre-install specific .NET Core version.
|
||||
// https://docs.microsoft.com/en-us/dotnet/core/deploying/
|
||||
var corehookConfig = new RemoteInjectorConfiguration
|
||||
{
|
||||
ClrBootstrapLibrary = "",
|
||||
ClrRootPath = "",
|
||||
DetourLibrary = "",
|
||||
HostLibrary = "",
|
||||
InjectionPipeName = "",
|
||||
PayloadLibrary = "",
|
||||
InjectionPipeName = $"Dalamud-{pid}-CoreHook",
|
||||
ClrRootPath = m_options.BinaryDirectory, // `dotnet.runtimeconfig.json` is not needed for self-contained app.
|
||||
ClrBootstrapLibrary = Path.Combine(m_options.BinaryDirectory, "CoreHook.CoreLoad.dll"),
|
||||
DetourLibrary = Path.Combine(m_options.BinaryDirectory, "corehook64.dll"),
|
||||
HostLibrary = Path.Combine(m_options.BinaryDirectory, "coreload64.dll"),
|
||||
PayloadLibrary = Path.Combine(m_options.BinaryDirectory, "Dalamud.dll"),
|
||||
VerboseLog = false,
|
||||
};
|
||||
|
||||
RemoteInjector.Inject((int)pid, corehookConfig, new PipePlatform(), m_options.RootDirectory);
|
||||
try
|
||||
{
|
||||
RemoteInjector.Inject((int)pid, corehookConfig, new PipePlatform(), m_options.RootDirectory);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
const string message = "Failed to inject Dalamud library into the process.";
|
||||
|
||||
// Could not inject Dalamud for whatever reason; it could be process is not actually running, insufficient os privilege, or whatever the thing SE put in their game;
|
||||
// Therefore there's not much we can do on this side; You have to trobleshoot by yourself somehow.
|
||||
throw new DalamudLauncherException(pid, message, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,13 +12,16 @@ namespace Dalamud.Injector
|
|||
};
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// A directory to where Dalamud data is located.
|
||||
/// </summary>
|
||||
public string RootDirectory { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// A directory to where `Dalamud.dll` and its dependencies are located.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This path doesn't need to be the same directory as where the launcher is located.
|
||||
/// </remarks>
|
||||
public string BinaryDirectory { get; set; } = "";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,26 +1,27 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Dalamud.Injector
|
||||
{
|
||||
public class DalamudException : Exception
|
||||
{
|
||||
public DalamudException() : base() { }
|
||||
|
||||
public DalamudException(string message) : base(message) { }
|
||||
|
||||
public DalamudException(string message, Exception inner) : base(message, inner) { }
|
||||
}
|
||||
|
||||
public partial class DalamudProcessException : DalamudException
|
||||
/// <summary>
|
||||
/// An error that is thrown when injecting Dalamud into the process failed.
|
||||
/// </summary>
|
||||
public partial class DalamudLauncherException : Exception
|
||||
{
|
||||
/// <summary>
|
||||
/// A target process id that was attempted to.
|
||||
/// </summary>
|
||||
public uint ProcessId { get; }
|
||||
}
|
||||
|
||||
public partial class DalamudProcessException
|
||||
public partial class DalamudLauncherException
|
||||
{
|
||||
public DalamudProcessException(uint pid, string message) : base(message)
|
||||
public DalamudLauncherException() : base() { }
|
||||
|
||||
public DalamudLauncherException(string message) : base(message) { }
|
||||
|
||||
public DalamudLauncherException(string message, Exception inner) : base(message, inner) { }
|
||||
|
||||
public DalamudLauncherException(uint pid, string message, Exception inner) : base(message, inner)
|
||||
{
|
||||
ProcessId = pid;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>Library</OutputType>
|
||||
<TargetFramework>net472</TargetFramework>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<LangVersion>preview</LangVersion>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<nullable>enable</nullable>
|
||||
|
|
@ -14,20 +14,15 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Lumina" Version="1.0.0-preview7" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
|
||||
<PackageReference Include="PropertyChanged.Fody" Version="2.6.1" />
|
||||
<PackageReference Include="Serilog" Version="2.6.0" />
|
||||
<PackageReference Include="Serilog.Sinks.Async" Version="1.1.0" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="4.0.0" />
|
||||
<PackageReference Include="SharpDX.Desktop" Version="4.2.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System.Net.Http" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Configuration\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\lib\CoreHook\src\CoreHook.CoreLoad\CoreHook.CoreLoad.csproj" />
|
||||
<ProjectReference Include="..\lib\CoreHook\src\CoreHook\CoreHook.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -1,4 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
|
||||
<PropertyChanged />
|
||||
</Weavers>
|
||||
|
|
@ -1,54 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
||||
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. -->
|
||||
<xs:element name="Weavers">
|
||||
<xs:complexType>
|
||||
<xs:all>
|
||||
<xs:element name="PropertyChanged" minOccurs="0" maxOccurs="1">
|
||||
<xs:complexType>
|
||||
<xs:attribute name="InjectOnPropertyNameChanged" type="xs:boolean">
|
||||
<xs:annotation>
|
||||
<xs:documentation>Used to control if the On_PropertyName_Changed feature is enabled.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="EventInvokerNames" type="xs:string">
|
||||
<xs:annotation>
|
||||
<xs:documentation>Used to change the name of the method that fires the notify event. This is a string that accepts multiple values in a comma separated form.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="CheckForEquality" type="xs:boolean">
|
||||
<xs:annotation>
|
||||
<xs:documentation>Used to control if equality checks should be inserted. If false, equality checking will be disabled for the project.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="CheckForEqualityUsingBaseEquals" type="xs:boolean">
|
||||
<xs:annotation>
|
||||
<xs:documentation>Used to control if equality checks should use the Equals method resolved from the base class.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="UseStaticEqualsFromBase" type="xs:boolean">
|
||||
<xs:annotation>
|
||||
<xs:documentation>Used to control if equality checks should use the static Equals method resolved from the base class.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:all>
|
||||
<xs:attribute name="VerifyAssembly" type="xs:boolean">
|
||||
<xs:annotation>
|
||||
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="VerifyIgnoreCodes" type="xs:string">
|
||||
<xs:annotation>
|
||||
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="GenerateXsd" type="xs:boolean">
|
||||
<xs:annotation>
|
||||
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:schema>
|
||||
Loading…
Add table
Add a link
Reference in a new issue