Skip to content

Commit

Permalink
feat: Implement passing cmdline args
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxuser committed Sep 13, 2024
1 parent a89fc9d commit bcaedac
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion SharpShell.Loader/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static void Main(string[] args)
var shell = Assembly.Load("SharpShell");
var program = shell.GetType("SharpShell.Program")!;
var main = program.GetMethod("Main", BindingFlags.Static | BindingFlags.NonPublic)!;
main.Invoke(null, [Array.Empty<string>()]);
main.Invoke(null, [args]);
}
}
}
2 changes: 1 addition & 1 deletion SharpShell/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class Program
{
static void Main(string[] args)
{
UnmanagedPSEntry.Start(Array.Empty<string>(), 0);
UnmanagedPSEntry.Start(args, 0);
}
}
}
2 changes: 1 addition & 1 deletion pwsh.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

set DOTNET_CLI_TELEMETRY_OPTOUT=1
cd /d D:\pwsh
..\dotnet\dotnet.exe msbuild .\run_pwsh.xml
..\dotnet\dotnet.exe msbuild .\run_pwsh.xml -p:CommandLineArgs="%*"
13 changes: 11 additions & 2 deletions run_pwsh.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask TaskName="RunShellcode" TaskFactory="RoslynCodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
<ParameterGroup>
<CommandLineArgs ParameterType="System.String"/>
</ParameterGroup>
<Task>
<Using Namespace="System" />
<Using Namespace="System.IO" />
Expand All @@ -16,13 +19,19 @@
public class RunShellcode : Task
{
public string CommandLineArgs { get; set; }
public override bool Execute()
{
var dll = File.ReadAllBytes("SharpShell.Loader.dll");
var loader = Assembly.Load(dll);
var type = loader.GetType("SharpShell.Loader.Program")!;
var method = type.GetMethod("Main", BindingFlags.Static | BindingFlags.NonPublic)!;
var res = method.Invoke(null, new object[] {new string[] {}});
/* Handle commandline args */
var cmdlineArgs = String.IsNullOrEmpty(CommandLineArgs) ? new string[]{} : new string[]{CommandLineArgs};
var res = method.Invoke(null, new object[] {cmdlineArgs});
return true;
}
}
Expand All @@ -32,6 +41,6 @@
</UsingTask>

<Target Name="Run">
<RunShellcode />
<RunShellcode CommandLineArgs="$(CommandLineArgs)"/>
</Target>
</Project>

0 comments on commit bcaedac

Please sign in to comment.