View Piped Data and Arguments with Argsposer

I occasionally run into the issue of wanting to inspect a link despite not having a protocol handler for it that lets me inspect it.  For instance, VMWare has a specialty link that lets a user open a remote virtual machine in a local instance of VMWare Workstation.  There are several other application-specific link handlers out there, and a majority of them will suppress the actual link in favor of just doing what you ask it to do – open the thing!

If the link is generated via JavaScript then it can be tough to unmask it.  When you use a program as a link handler, the link is passed as the first argument to said program.  So I made a quick C# program that just echoes its arguments.  You can find it on GitHub as an entire SLN, but the file the does all the magic is here:

using System;
using System.Threading;

namespace Argsposer
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Argsposer v.1 - The Only Version You Need");
            Console.WriteLine("─────────────────────────────────────────");
            Console.WriteLine("Command Line Arguments:");
            if (args.Length == 0)
            {
                Console.WriteLine(" [none]");
            }
            else
            {
                for (int i = 0; i < args.Length; i++)
                {
                    Console.WriteLine(" " + i + ": '" + args[i] + "'");
                }
            }
            Console.WriteLine();
            if (Console.IsInputRedirected)
            {
                Console.WriteLine("Piped Data:");
                using (var input = Console.OpenStandardInput())
                {
                    using (var output = Console.OpenStandardOutput())
                    {
                        int bytes;
                        byte[] data = new byte[2048];
                        while ((bytes = input.Read(data, 0, data.Length)) > 0)
                        {
                            output.Write(data, 0, bytes);
                        }
                    }
                }
            }
            else
            {
                Console.WriteLine("No piped data.");
            }
            Console.WriteLine();
            Console.Write("Ctrl-C to exit...");
            Thread.Sleep(Timeout.Infinite);
        }
    }
}

I joke that version 1.0 is “the only version you need,” but in all honesty the chances of me updating this are incredibly slim.  It’s a simple problem with a simple solution.  There are other uses than the niche use case I mentioned here, and a few are mentioned on the project homepage.

Leave a Reply

Your email address will not be published. Required fields are marked *