Created
November 6, 2019 22:19
-
-
Save silentbreaksec/ab9b76e0ace114182265ac648216c725 to your computer and use it in GitHub Desktop.
Convert C# EXE to Assembly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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