Skip to content

Instantly share code, notes, and snippets.

@NotMedic
Forked from silentbreaksec/snippet.cs
Created March 24, 2020 23:55
Show Gist options
  • Save NotMedic/546a454dd45f87953264f22aebed8f67 to your computer and use it in GitHub Desktop.
Save NotMedic/546a454dd45f87953264f22aebed8f67 to your computer and use it in GitHub Desktop.
Convert C# EXE to Assembly
[DllImport("shell32.dll", SetLastError = true)]
static extern IntPtr CommandLineToArgvW([MarshalAs(UnmanagedType.LPWStr)] string lpCmdLine, out int pNumArgs);
public static string[] CommandLineToArgs(string commandLine)
{
int argc;
var argv = CommandLineToArgvW(commandLine, out argc);
if (argv == IntPtr.Zero)
throw new System.ComponentModel.Win32Exception();
try
{
var args = new string[argc];
for (var i = 0; i < args.Length; i++)
{
var p = Marshal.ReadIntPtr(argv, i * IntPtr.Size);
args[i] = Marshal.PtrToStringUni(p);
}
return args;
}
finally
{
Marshal.FreeHGlobal(argv);
}
}
public static string Execute(string commandLine)
{
var sw = new StringWriter();
Console.SetOut(sw);
Console.SetError(sw);
Main(CommandLineToArgs(commandLine));
return sw.ToString();
}
@NotMedic
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment