Skip to content

Instantly share code, notes, and snippets.

@silentbreaksec
Created November 6, 2019 22:19
Show Gist options
  • Save silentbreaksec/ab9b76e0ace114182265ac648216c725 to your computer and use it in GitHub Desktop.
Save silentbreaksec/ab9b76e0ace114182265ac648216c725 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();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment