Skip to content

Commit bcaedac

Browse files
committed
feat: Implement passing cmdline args
1 parent a89fc9d commit bcaedac

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

SharpShell.Loader/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ static void Main(string[] args)
4242
var shell = Assembly.Load("SharpShell");
4343
var program = shell.GetType("SharpShell.Program")!;
4444
var main = program.GetMethod("Main", BindingFlags.Static | BindingFlags.NonPublic)!;
45-
main.Invoke(null, [Array.Empty<string>()]);
45+
main.Invoke(null, [args]);
4646
}
4747
}
4848
}

SharpShell/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public class Program
66
{
77
static void Main(string[] args)
88
{
9-
UnmanagedPSEntry.Start(Array.Empty<string>(), 0);
9+
UnmanagedPSEntry.Start(args, 0);
1010
}
1111
}
1212
}

pwsh.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
set DOTNET_CLI_TELEMETRY_OPTOUT=1
44
cd /d D:\pwsh
5-
..\dotnet\dotnet.exe msbuild .\run_pwsh.xml
5+
..\dotnet\dotnet.exe msbuild .\run_pwsh.xml -p:CommandLineArgs="%*"

run_pwsh.xml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
22
<UsingTask TaskName="RunShellcode" TaskFactory="RoslynCodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
3+
<ParameterGroup>
4+
<CommandLineArgs ParameterType="System.String"/>
5+
</ParameterGroup>
36
<Task>
47
<Using Namespace="System" />
58
<Using Namespace="System.IO" />
@@ -16,13 +19,19 @@
1619
1720
public class RunShellcode : Task
1821
{
22+
public string CommandLineArgs { get; set; }
23+
1924
public override bool Execute()
2025
{
2126
var dll = File.ReadAllBytes("SharpShell.Loader.dll");
2227
var loader = Assembly.Load(dll);
2328
var type = loader.GetType("SharpShell.Loader.Program")!;
2429
var method = type.GetMethod("Main", BindingFlags.Static | BindingFlags.NonPublic)!;
25-
var res = method.Invoke(null, new object[] {new string[] {}});
30+
31+
/* Handle commandline args */
32+
var cmdlineArgs = String.IsNullOrEmpty(CommandLineArgs) ? new string[]{} : new string[]{CommandLineArgs};
33+
34+
var res = method.Invoke(null, new object[] {cmdlineArgs});
2635
return true;
2736
}
2837
}
@@ -32,6 +41,6 @@
3241
</UsingTask>
3342

3443
<Target Name="Run">
35-
<RunShellcode />
44+
<RunShellcode CommandLineArgs="$(CommandLineArgs)"/>
3645
</Target>
3746
</Project>

0 commit comments

Comments
 (0)