Skip to content

Commit

Permalink
Change RPC API to pass the profileFolder as the first argument to the…
Browse files Browse the repository at this point in the history
… payload.
  • Loading branch information
MeFisto94 committed Feb 27, 2024
1 parent 876daa0 commit e9956fd
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions EntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ public void Initialize()
/// <param name="applicationPath">The Path to the Application to launch</param>
/// <param name="commandLine">The CommandLine Flags to pass to the Application</param>
/// <param name="modFrameworkPath">The Path to the DLL to inject into the process (Payload)</param>
/// <param name="profileFolder">The Folder where all the mods/mods.json are located (profile folder)</param>
/// <param name="args">Additional args that are passed to the Payload side of Andraste</param>
/// <returns>The Process or null, if the application has crashed</returns>
/// <exception cref="Exception">Various Exceptions may be thrown if the application could not be started or the injection failed</exception>
public virtual Process? StartApplication(string applicationPath, string commandLine, string modFrameworkPath, params object[] args)
public virtual Process? StartApplication(string applicationPath, string commandLine, string modFrameworkPath,
string profileFolder, params object[] args)
{
if (!File.Exists(applicationPath))
{
Expand All @@ -34,7 +36,7 @@ public void Initialize()
}

Inject(applicationPath, commandLine, 0, modFrameworkPath,
modFrameworkPath, out int pid, args);
modFrameworkPath, profileFolder, out int pid, args);

try
{
Expand All @@ -46,14 +48,15 @@ public void Initialize()
}
}

public virtual void AttachToApplication(Process process, string modFrameworkPath, params object[] args)
public virtual void AttachToApplication(Process process, string modFrameworkPath, string profileFolder,
params object[] args)
{
if (!File.Exists(modFrameworkPath))
{
throw new ArgumentException("Mod Framework file does not exist", nameof(modFrameworkPath));
}

InjectRunning(process, modFrameworkPath,modFrameworkPath, args);
InjectRunning(process, modFrameworkPath,modFrameworkPath, profileFolder, args);
}

/// <summary>
Expand All @@ -67,11 +70,17 @@ public virtual void AttachToApplication(Process process, string modFrameworkPath
/// <param name="additionalCreateProcessFlags">Additional flags being passed to CreateProcess</param>
/// <param name="injectionLibrary32">The 32bit DLL to inject into the process</param>
/// <param name="injectionLibrary64">The 64bit DLL to inject into the process</param>
/// <param name="profileFolder">The Folder where all the mods/mods.json are located (profile folder)</param>
/// <param name="targetPid">The PID of the freshly created process</param>
/// <param name="args">Additional args that are passed to the Payload side of Andraste</param>
protected virtual void Inject(string applicationPath, string commandLine, int additionalCreateProcessFlags,
string injectionLibrary32, string injectionLibrary64, out int targetPid, params object[] args)
string injectionLibrary32, string injectionLibrary64, string profileFolder, out int targetPid,
params object[] args)
{
var argsArray = new object[args.Length + 1];
argsArray[0] = profileFolder;
args.CopyTo(argsArray, 1);

// start and inject into a new process
RemoteHooking.CreateAndInject(
applicationPath, // executable to run
Expand All @@ -81,15 +90,19 @@ protected virtual void Inject(string applicationPath, string commandLine, int ad
injectionLibrary32, // 32-bit library to inject (if target is 32-bit)
injectionLibrary64, // 64-bit library to inject (if target is 64-bit)
out targetPid, // retrieve the newly created process ID
args // the parameters to pass into injected library
argsArray // the parameters to pass into injected library
);
}

protected virtual void InjectRunning(Process process, string injectionLibrary32, string injectionLibrary64,
params object[] args)
string profileFolder, params object[] args)
{
var argsArray = new object[args.Length + 1];
argsArray[0] = profileFolder;
args.CopyTo(argsArray, 1);

RemoteHooking.Inject(process.Id, InjectionOptions.DoNotRequireStrongName | InjectionOptions.NoWOW64Bypass,
injectionLibrary32, injectionLibrary64, args);
injectionLibrary32, injectionLibrary64, argsArray);
}
}
#nullable restore
Expand Down

0 comments on commit e9956fd

Please sign in to comment.