MiddleOut: a C# Compression Tool

MiddleOut (a salute to Silicon Valley) is a tool written in C# that compresses any number of files passed to it. I wanted to learn .Net so this was my first foyer into using it as a programming language and the more I use it the more I love it! I wanted to make this tool super easy to use and as close to foolproof as I could.

MiddleOut - Initial Ideas

Chris Truncer gave me the idea to write the tool initially (the idea which came from OutFlank's Zipper tool) and, to start, wanted it to be pretty simple - take in two flags.

  • A file or directory to be zipped
  • A directory to save the zip file in
  • I wanted to expand on that idea a bit to include any number of files or directories and also do several checks before zipping the files. This way, if the user passes a file that is nonexistent, the program will let the user know the filepath given is bad and to try again rather than spitting out .Net errors.

    MiddleOut - The Code

    The first part of the program takes in any number of files and directories but reserves the final argument for the zip file name. The snippet below is the entry point for the program.

    Some validation is done in the middle of the program to make sure everything that was passed in is in the correct format and the file/directory exists. Wildcards are also accepted and accounted for in the validation section of code. Below is a code snippet showing how the program loops through the arguments and checks for certain characters as well as validates the file or directory.

    The zipping code block is fairly simple in the sense that it just loops over the list of files and/or directories to be compressed and adds them to a compression archive.

    Since this is written in C#, it can be used with Beacon's Execute-Assembly command if the need arrises :).

    Final Thoughts and Link

    I wanted to use this opportunity to learn C# as I go and solve problems as they come up. A link to the code is below, feel free to check it out and let me know how it goes!

    FortyNorthSecurity/MiddleOut
    A small .NET compression utility. Contribute to FortyNorthSecurity/MiddleOut development by creating an account on GitHub.

    If you have any questions or pull requests, you can contact us on Twitter, LinkedIn, Facebook, and of course our website.