mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-02-15 20:37:42 +01:00
Add GetImageFilePath
This commit is contained in:
parent
6f6792f27e
commit
2e4796f8bf
6 changed files with 39 additions and 5 deletions
|
|
@ -21,7 +21,8 @@ namespace Dalamud.Bootstrap
|
||||||
{
|
{
|
||||||
commandLine = commandLine ?? "";
|
commandLine = commandLine ?? "";
|
||||||
|
|
||||||
throw new NotImplementedException("TODO");
|
|
||||||
|
//throw new NotImplementedException("TODO");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -54,6 +55,8 @@ namespace Dalamud.Bootstrap
|
||||||
// Acquire the process handle and read the command line
|
// Acquire the process handle and read the command line
|
||||||
using var process = Process.Open(pid);
|
using var process = Process.Open(pid);
|
||||||
|
|
||||||
|
var exePath = process.GetImageFilePath();
|
||||||
|
|
||||||
var argument = ReadArgumentFromProcess(process);
|
var argument = ReadArgumentFromProcess(process);
|
||||||
|
|
||||||
var newTick = (uint)Environment.TickCount;
|
var newTick = (uint)Environment.TickCount;
|
||||||
|
|
@ -66,7 +69,6 @@ namespace Dalamud.Bootstrap
|
||||||
|
|
||||||
var encryptedArgument = new EncryptedArgument(newArgument, newKey);
|
var encryptedArgument = new EncryptedArgument(newArgument, newKey);
|
||||||
|
|
||||||
|
|
||||||
// TODO: launch new exe with the argument from encryptedArgument.ToString()
|
// TODO: launch new exe with the argument from encryptedArgument.ToString()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ using Microsoft.Win32.SafeHandles;
|
||||||
using System;
|
using System;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
namespace Dalamud.Bootstrap
|
namespace Dalamud.Bootstrap
|
||||||
{
|
{
|
||||||
|
|
@ -210,5 +211,22 @@ namespace Dalamud.Bootstrap
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string GetImageFilePath()
|
||||||
|
{
|
||||||
|
var buffer = new StringBuilder(300);
|
||||||
|
|
||||||
|
// From docs:
|
||||||
|
// On input, specifies the size of the lpExeName buffer, in characters.
|
||||||
|
// On success, receives the number of characters written to the buffer, not including the null-terminating character.
|
||||||
|
var size = buffer.Capacity;
|
||||||
|
|
||||||
|
if (!Win32.QueryFullProcessImageNameW(m_handle, 0, buffer, ref size))
|
||||||
|
{
|
||||||
|
ProcessException.ThrowLastOsError(GetPid());
|
||||||
|
}
|
||||||
|
|
||||||
|
return buffer.ToString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ namespace Dalamud.Bootstrap.Windows
|
||||||
|
|
||||||
internal ProcessException(string message, uint pid, Exception innerException) : base(message, innerException) => Pid = pid;
|
internal ProcessException(string message, uint pid, Exception innerException) : base(message, innerException) => Pid = pid;
|
||||||
|
|
||||||
internal static ProcessException ThrowLastOsError(uint pid)
|
internal static void ThrowLastOsError(uint pid)
|
||||||
{
|
{
|
||||||
var inner = new Win32Exception();
|
var inner = new Win32Exception();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
using Microsoft.Win32.SafeHandles;
|
using Microsoft.Win32.SafeHandles;
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
namespace Dalamud.Bootstrap.Windows
|
namespace Dalamud.Bootstrap.Windows
|
||||||
{
|
{
|
||||||
|
|
@ -27,7 +28,7 @@ namespace Dalamud.Bootstrap.Windows
|
||||||
[DllImport("kernel32", CallingConvention = CallingConvention.Winapi, SetLastError = true)]
|
[DllImport("kernel32", CallingConvention = CallingConvention.Winapi, SetLastError = true)]
|
||||||
public static extern void* LocalFree(void* hMem);
|
public static extern void* LocalFree(void* hMem);
|
||||||
|
|
||||||
[DllImport("shell32", CallingConvention = CallingConvention.Winapi, SetLastError = true)]
|
[DllImport("shell32", CallingConvention = CallingConvention.Winapi, SetLastError = true, ExactSpelling = true)]
|
||||||
public static extern char** CommandLineToArgvW(void* lpCmdLine, int* pNumArgs);
|
public static extern char** CommandLineToArgvW(void* lpCmdLine, int* pNumArgs);
|
||||||
|
|
||||||
[DllImport("kernel32", CallingConvention = CallingConvention.Winapi)]
|
[DllImport("kernel32", CallingConvention = CallingConvention.Winapi)]
|
||||||
|
|
@ -36,6 +37,10 @@ namespace Dalamud.Bootstrap.Windows
|
||||||
[DllImport("kernel32", CallingConvention = CallingConvention.Winapi, SetLastError = true)]
|
[DllImport("kernel32", CallingConvention = CallingConvention.Winapi, SetLastError = true)]
|
||||||
[return: MarshalAs(UnmanagedType.Bool)]
|
[return: MarshalAs(UnmanagedType.Bool)]
|
||||||
public static extern bool GetProcessTimes(SafeProcessHandle hProcess, FileTime* lpCreationTime, FileTime* lpExitTime, FileTime* lpKernelTime, FileTime* lpUserTime);
|
public static extern bool GetProcessTimes(SafeProcessHandle hProcess, FileTime* lpCreationTime, FileTime* lpExitTime, FileTime* lpKernelTime, FileTime* lpUserTime);
|
||||||
|
|
||||||
|
[DllImport("kernel32", CallingConvention = CallingConvention.Winapi, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)]
|
||||||
|
[return: MarshalAs(UnmanagedType.Bool)]
|
||||||
|
public static extern bool QueryFullProcessImageNameW(SafeProcessHandle hProcess, uint dwFlags, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder lpExeName, ref int lpdwSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,15 @@ namespace Dalamud.Injector
|
||||||
internal static class Program
|
internal static class Program
|
||||||
{
|
{
|
||||||
private static void Main(string[] args)
|
private static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
var boot = new Bootstrapper(new BootstrapperOptions
|
||||||
|
{
|
||||||
|
BinaryDirectory = "",
|
||||||
|
RootDirectory = "",
|
||||||
|
});
|
||||||
|
|
||||||
|
boot.Launch("", "");
|
||||||
|
|
||||||
Parser.Default.ParseArguments<InjectOptions, LaunchOptions>(args)
|
Parser.Default.ParseArguments<InjectOptions, LaunchOptions>(args)
|
||||||
.WithParsed<InjectOptions>(Inject)
|
.WithParsed<InjectOptions>(Inject)
|
||||||
.WithParsed<LaunchOptions>(Launch);
|
.WithParsed<LaunchOptions>(Launch);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue