CMUNGE

A tool for encrypting and compacting C source code


Contents

Description

CMUNGE is a simple tool for encrypting and compacting C source code, while leaving it syntactically and semantically unchanged. It does this by:
  1. Recursively in-lining `user-defined' #include files. (#include files that are located in the directory "/usr/include", or whose names are enclosed in <...>, are taken to be `system-defined' files and are not in-lined, to preserve portability.)

  2. Renaming C identifiers, except those in the C Standard Library, with names like l1 (i.e. letter-l one), l2, l3, etc.

  3. Removing comments and blank lines, converting multiple consecutive whitespace characters (including `\n') into single blanks, removing all unnecessary whitespace between tokens (i.e. only putting a single blank as a separator between tokens where it is really required), and then outputting the transformed code in lines of least N characters long, where N is a user-specified minimum line length (with a default value of 90).

  4. Renaming the generated output files, e.g. "f1.c", "f2.c", etc.
It accepts ANSI and K & R C as its input language. Incidentally, I refer to this process as `munging' the code (where `munge' rhymes with `gunge'); hence the name CMUNGE.

For example, CMUNGE converts the following C source code:

        /*------------------------------------------------------*/
        /* dos2unix:  Converts DOS text files to Unix ones by   */
        /* removing the `^M' character at the end of each line. */
        /*------------------------------------------------------*/
        #include <stdio.h>
        main ()
        {
                int c;

                while ((c = getchar()) != EOF)
                        if (c != '\015')        /* ^M */
                                putchar (c);
        }
into:
        #include <stdio.h>
        main(){int l1;while((l1=getchar())!=EOF)if(l1!='\015')putchar(l1);}
Admittedly this is a very simple example for the sake of brevity. CMUNGE is really intended to be useful for large codes.

CMUNGE provides facilities for protecting parts of the source code from translation, for preventing the in-lining of selected #include files, and for preventing the renaming of selected identifiers. It creates dictionaries that translate the original identifiers and filenames into the new ones and vice versa, by means of which the user can relate the output code to the original if necessary (albeit not easily!).

The purpose of CMUNGE is to allow C source code to be distributed in a form that is unsuitable for modification or further development while still preserving its portability, with the benefit of making it much more compact (e.g. for my C source code I typically obtain compression factors of 4 - 5 as a result of munging it).

The CMUNGE software comprises 2 C programs and a `csh' (`C shell') driver script. Therefore installation is simply a matter of compiling 2 C programs, which can be done with an ANSI or K & R C compiler. Since the driver program is a `csh' script, it assumes a Unix-like operating system.

Usage

The usage of the CMUNGE command is:
  cmunge [options] files...

  Options:
    -I include-dir      -- Search directory `include-dir' for #include files.
    -d output-dir       -- Write the output file(s) to directory
                             `output-dir'.  (Default: current directory.)
    -f output-file-rootname
                        -- Output files have names starting with the
                             string `output-file-rootname' followed by ".c"
                             if there is one output file, or "1.c", "2.c",
                             etc, if there is more than one.  E.g. `-f f'
                             causes the output files to be named "f.c"
                             or "f1.c", "f2.c", etc.  (Default: f).
    -l min-output-linelen
                        -- Make lines of the output file(s) at least
                             `min-output-linelen' characters long.
                             (Default: 90.)
    -p prefix-letter    -- Give the translated C identifiers names
                             consisting of the letter `prefix-letter'
                             followed by a number.  E.g. `-p l' causes
                             the translated identifiers to be called
                             l1, l2, etc.  (Default: l).
    -v version-string   -- Insert string `version-string' as a C comment
                             in the first line of each output file.
                             (Default: no comment is written.)
    -<anything else>    -- Other arguments are passed directly to the
                             C pre-processor, `cpp'.  E.g. argument
                             `-Dname=def' is passed directly to `cpp'.
    files...            -- The input C source file(s) to be `munged'.
  
  Spaces are optional between option letters and their accompanying arguments.

Download

CMUNGE Release Package, version 1.0, August 1998. (Gzipped tarfile, 28 Kb).

Munged CMUNGE Release Package, version 1.0, August 1998. (Gzipped tarfile, 14 Kb).
This is exactly the same software, but with its C files `munged'!

History

CMUNGE was developed by John Merlin in December 1993. It has been used by the author to package the releases of SHPF and IDA, which are quite substantial software packages. CMUNGE was made available on the World Wide Web in August 1998.

I should point out that it has not yet been packaged as well as it should be for a public release. For example, there is no CMUNGE man page as yet (although the cmunge command generates the usage information shown above if it is used incorrectly). Prior to this release it has just been used by the author and his colleagues, but it has been made publicly available now in case it is more widely useful. I will rectify these deficiencies if there is sufficient demand. Please send any comments, questions, etc. to jhm@vcpc.univie.ac.at.


John Merlin (jhm@vcpc.univie.ac.at).
Last updated Thu Aug 27 1998.