Skip to content

Instantly share code, notes, and snippets.

@jborean93
Last active October 30, 2023 22:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jborean93/d45fcf5eca04dfe79dadb2e0c8c584c2 to your computer and use it in GitHub Desktop.
Save jborean93/d45fcf5eca04dfe79dadb2e0c8c584c2 to your computer and use it in GitHub Desktop.
Code that can be used to generate an executable that can print how it receives arguments
#include<stdio.h>
// gcc print_argv.c -o print_argv
int main(int argc, char *argv[])
{
int i;
for(i = 1;i < argc;i++)
{
printf("[%d] %s\n", i, argv[i]);
}
return 0;
}
Add-Type -OutputType ConsoleApplication -OutputAssembly print_argv.exe -TypeDefinition @'
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace PrintArgv
{
class Program
{
[DllImport("Kernel32.dll")]
public static extern IntPtr GetCommandLineW();
static void Main(string[] args)
{
IntPtr cmdLinePtr = GetCommandLineW();
string cmdLine = Marshal.PtrToStringUni(cmdLinePtr);
Console.WriteLine(cmdLine);
for (int i = 0; i < args.Length; i++)
{
Console.WriteLine("[{0}] {1}", i, args[i]);
}
}
}
}
'@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment