Last active
October 30, 2023 22:25
-
-
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
This file contains hidden or 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
#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; | |
} |
This file contains hidden or 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
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