ergo@netcom.UUCP (Isaac Rabinovitch) (05/28/90)
davel@cbnewsl.att.com (David Loewenstern) writes >I am looking for a program (or emacs macro) which will translate >C code into unreadable but functionally equivalent code. At minimum, >it must replace all variable names with cryptic names such as a1, i23, etc. >Ideally, it should also rename functions. Further obfuscation isn't really >necessary for my purposes, but wouldn't hurt either. I don't think I care for your purposes. The last time I encountered this sort of thing, it was a particularly arrogant chemistry prof who had developed some tutorial software he wanted to cash in on. Since he'd been paid a grant to develop the software, he was legally obligated to release the source code. But he decided he wasn't obligated to release *useable* source code. So he obfuscated it just like you're doing, so he could charge "consulting" fees to schools who wanted to play with his "free" software. Such greedy double-dipping is beneath contempt.
steve@taumet.COM (Stephen Clamage) (05/28/90)
In article <12546@netcom.UUCP> ergo@netcom.UUCP (Isaac Rabinovitch) writes: >davel@cbnewsl.att.com (David Loewenstern) writes >>I am looking for a program (or emacs macro) which will translate >>C code into unreadable but functionally equivalent code. ... > >I don't think I care for your purposes. The last time I encountered this >sort of thing, ... [example] > >Such greedy double-dipping is beneath contempt. Well, "honi soit qui mal y pense", to you. There are plenty of legitimate reasons for obfuscating code. Why do you assume Mr Loewenstern has only evil intentions? Surely you don't have to jump all over him until you find out. -- Steve Clamage, TauMetric Corp, steve@taumet.com
ergo@netcom.UUCP (Isaac Rabinovitch) (05/28/90)
steve@taumet.COM (Stephen Clamage) writes: >Well, "honi soit qui mal y pense", to you. There are plenty of >legitimate reasons for obfuscating code. Why do you assume Mr Loewenstern >has only evil intentions? Surely you don't have to jump all over him >until you find out. Such as?
libes@cme.nist.gov (Don Libes) (05/28/90)
In article <12573@netcom.UUCP> ergo@netcom.UUCP (Isaac Rabinovitch) writes: >steve@taumet.COM (Stephen Clamage) writes: >>Well, "honi soit qui mal y pense", to you. There are plenty of >>legitimate reasons for obfuscating code. Why do you assume Mr Loewenstern >>has only evil intentions? Surely you don't have to jump all over him >>until you find out. > >Such as? ... a useful way to distribute commercial products for multiple platforms. Instead of dozens of binaries, just distribute one source and let the buyer compile. For example, page 18 of this month's C Users Journal has an advertisement for a lint that comes in "shrouded source form" that is K&R and ANSI compatible, and which compiles on UNIX, DOS, VMS, VM/MVS, and several other operating systems. The vendor has covered 99% of the market with a single distribution. Not only is this clever, but certain #defines can be left unshrouded so that you have a little more control than if you just had binaries. Incidentally, this practice has been around for years. Don Libes libes@cme.nist.gov ...!uunet!cme-durer!libes
ergo@netcom.UUCP (Isaac Rabinovitch) (05/28/90)
libes@cme.nist.gov (Don Libes) writes: >>>(there are legitimate uses for a C obfuscator!) >> >>Such as? >... a useful way to distribute commercial products for multiple >platforms. Instead of dozens of binaries, just distribute one source >and let the buyer compile. Surely you jest. If the buyer has porting problems, how is he supposed to deal with it? I've never heard of non-trivial source code that didn't require tweaking on a new platform. >For example, page 18 of this month's C Users Journal has an >advertisement for a lint that comes in "shrouded source form" that is >K&R and ANSI compatible, and which compiles on UNIX, DOS, VMS, VM/MVS, >and several other operating systems. The vendor has covered 99% of >the market with a single distribution. OK then, I apologize. There are people dumb enough to consider this a sane form of distrbution. I suppose that should be legitimate enough for me!
bengsig@oracle.nl (Bjorn Engsig) (05/28/90)
I used to use such a thing at the university when we had nothing but punched cards, HASP, JCL and all that stuff, and it was quite handy to compress a working 1000 card program to a 100 card program. But who uses punched cards these days? -- Bjorn Engsig, Domain: bengsig@oracle.nl, bengsig@oracle.com Path: uunet!mcsun!orcenl!bengsig
henry@utzoo.uucp (Henry Spencer) (05/28/90)
In article <12546@netcom.UUCP> ergo@netcom.UUCP (Isaac Rabinovitch) writes: >>I am looking for a program (or emacs macro) which will translate >>C code into unreadable but functionally equivalent code... > >I don't think I care for your purposes... >Such greedy double-dipping is beneath contempt. Don't judge his purposes by your local bad examples. The usual alternatives to distributing obfuscated source are distributing only binaries (usually for machines you don't have) or not distributing at all. Which do you prefer? -- As a user I'll take speed over| Henry Spencer at U of Toronto Zoology features any day. -A.Tanenbaum| uunet!attcan!utzoo!henry henry@zoo.toronto.edu
henry@utzoo.uucp (Henry Spencer) (05/28/90)
In article <12579@netcom.UUCP> ergo@netcom.UUCP (Isaac Rabinovitch) writes: >>... a useful way to distribute commercial products for multiple >>platforms... >Surely you jest. If the buyer has porting problems, how is he supposed >to deal with it? I've never heard of non-trivial source code that didn't >require tweaking on a new platform. I've heard of quite a number of examples, and have written some. Careful coding plus thorough testing -- practices that seem increasingly unknown to most programmers, alas -- can work wonders if done conscientiously. As for how the buyer is supposed to deal with porting problems, the basic answer is "more easily than he could if he just had a binary". -- As a user I'll take speed over| Henry Spencer at U of Toronto Zoology features any day. -A.Tanenbaum| uunet!attcan!utzoo!henry henry@zoo.toronto.edu
peter@thirdi.UUCP (Peter Rowell) (05/29/90)
In article <12546@netcom.UUCP> ergo@netcom.UUCP (Isaac Rabinovitch) writes: [ in response to a request by davel@cbnewsl.att.com (David Loewenstern) ] >I don't think I care for your purposes. The last time I encountered this > [ deleted - a massive flashback into an alternate reality ] >Such greedy double-dipping is beneath contempt. Talk about jumping to conclusions! The most obvious reasons for doing this are (1) to allow users to recompile when they get new OS releases that are not ".o" compatible with previous versions, and (2) permit a modicum of portability to different systems without giving away the whole farm. Although #2 is more difficult to do, it is possible to leave the really dicey parts (normally stty stuff and other I/O related cruft) as clear text and obfuscate the more portable stuff. Making the effort to give the user some control over (possibly very expensive) commercial software is laudable. I think you owe David a *serious* apology. ---------------------------------------------------------------------------- Peter Rowell peter@thirdi.uucp Third Eye Software, Inc. ...!{apple,pyramid,sun}!thirdi!peter 535 Middlefield Road, Suite 170 (415) 321-0967 Menlo Park, CA 94025
ergo@netcom.UUCP (Isaac Rabinovitch) (05/29/90)
henry@utzoo.uucp (Henry Spencer) writes: >Don't judge his purposes by your local bad examples. The usual alternatives >to distributing obfuscated source are distributing only binaries (usually >for machines you don't have) or not distributing at all. Which do you prefer? That wasn't the choice in the case I was thinking of. It was a case of someone avoiding distributing source code he had promised to distribute. But it does seem I'm guilty of jumping to conclusions.
drh@romeo.cs.duke.edu (D. Richard Hipp) (05/29/90)
The program below reads a C program from standard input, strips away all unnecessary white space and writes the results to standard output. The result is a program which has been obfuscated. Unfortunately, this technique is probably not adequate for a secure source code distribution, since "cb" will unravel everything into a nicely indented program again. To make things really incomprehensible, one needs to change local identifiers to weird strings like "__X__88s", rewrite control structures as goto's, insert "red herring" code, and so forth. Such radical changes will require a complete parse of the input program, however, and this is more than I want to tackle right now. BTW: the program obfuscates itself without error, but I can still almost promise you that it has bugs. Use with care. -------------------------------- Cut Here ----------------------------------- #include <stdio.h> #include <string.h> #include <ctype.h> typedef enum{WHITE,ID,STRING,OP,NL}tokentype;int putx(x)char*x;{static int ccnt=0;if(x==0){if(ccnt)printf("\n");ccnt=0;}else{ccnt+=strlen(x);if( ccnt>70&&isalnum(*x)){printf("\n");ccnt=0;}printf("%s",x);}}int convert(t, x)tokentype t;char*x;{static int state=1;switch(state){case 1:putx(x); if(t==NL)state=6;if(t==ID)state=2;break;case 2:if(t==WHITE){state=3;} else if(t==NL){state=7;}else{putx(x);if(t==ID)state=2;else state=1;}break; case 3:if(t==ID){putx(" ");putx(x);state=2;}else{putx(x);if(t==WHITE)state= 3;else if(t==NL)state=7;else state=1;}break;case 4:printf("%s",x);if(t== WHITE)printf(" ");if(t==NL){printf("\n");state=6;}else if(t==OP&&*x=='\\'){ state=5;}break;case 5:printf("%s",x);if(t==WHITE)printf(" ");if(t==NL) printf("\n");if(t==OP&&*x=='\\'){state=5;}else{state=4;}break;case 6:if(t== OP&&*x=='#'){putx(0);printf("#");state=4;}else{putx(x);if(t==ID)state=2; else if(t==NL)state=6;else state=1;}break;case 7:if(t==ID){putx(" ");putx( x);state=2;}else if(t==OP&&*x=='#'){putx(0);printf("#");state=4;}else{ putx(x);if(t==WHITE)state=3;else if(t==NL)state=7;else state=1;}break;}} #define LINESIZE 500 int tokenize(fp)FILE*fp;{char line[LINESIZE];register char*cp,c;int incomment=0;char*start;tokentype t;while(fgets(line,LINESIZE,fp)){for(cp=line;( c=*cp)!=0;){if(incomment){char pc;start=cp;do{pc=c;c=*++cp;}while(c!=0&&( c!='/'||pc!='*'));if(c!=0){incomment=0;c=*++cp;}else{break;}}if(c==' '|| c=='\t'){do c=*++cp;while(c==' '||c=='\t');convert(WHITE,"");}start=cp; if(isalpha(c)||c=='_'){do c=*++cp;while(isalnum(c)||c=='_');t=ID;}else if(c=='0'){if(cp[1]=='x'||cp[1]=='X'){cp++;do c=*++cp;while(isxdigit(c));} else{do c=*++cp;while(isdigit(c)&&c!='8'&&c!='9');}t=ID;}else if(isdigit(c)){ do c=*++cp;while(isdigit(c));if(c=='.'){cp++;do c=*++cp;while(isdigit(c));} if(c=='e'||c=='E'){c=*++cp;if(c=='+'||c=='-')c=*++cp;while(isdigit(c))c=*++ cp;}t=ID;}else if(c=='"'){do{c=*++cp;if(c=='\\'){cp+=2;c=*cp;}}while(c!= 0&&c!='"');if(c)cp++;t=STRING;}else if(c=='\''){do{c=*++cp;if(c=='\\'){ cp+=2;c=*cp;}}while(c!=0&&c!='\'');if(c)cp++;t=STRING;}else if(c=='/'&& cp[1]=='*'){incomment=1;cp++;}else if(c=='\n'){cp++;t=NL;start=cp;}else{ if(c!=0)cp++;t=OP;}if(!incomment&&start<cp){c=*cp;*cp=0;convert(t,start);* cp=c;}}convert(NL,"");}return 1;}main(){tokenize(stdin);putx(0);}
gwc@root.co.uk (Geoff Clare) (05/31/90)
In <19858@duke.cs.duke.edu> drh@romeo.cs.duke.edu (D. Richard Hipp) writes: >The program below reads a C program from standard input, strips away all >unnecessary white space and writes the results to standard output. The >result is a program which has been obfuscated. BEWARE!! Removing white space can alter C code!! In fact, this is what happened when I compiled Richard's program: line 22: warning: ambiguous assignment: assignment op taken line 22: warning: old-fashioned assignment operator line 22: operands of *= have incompatible types line 22: warning: old-fashioned assignment operator line 22: operands of *= have incompatible types .... line 34: warning: ambiguous assignment: assignment op taken line 34: warning: old-fashioned assignment operator line 34: operands of *= have incompatible types This wouldn't happen with most modern compilers, but serves to demonstrate the problem. After inserting a space in all the '=*'s, the program seemed to run OK, but how do I know it's running correctly? Subtle alterations which may never be noticed are possible, e.g. the expression x = y + ++z; after processing becomes: x=y+++z; which actually parses as: x = y++ + z; This silently changes the behaviour of the code, such that it produces incorrect results and the user is none the wiser. You have been warned! -- Geoff Clare, UniSoft Limited, Saunderson House, Hayne Street, London EC1A 9HH gwc@root.co.uk (Dumb mailers: ...!uunet!root.co.uk!gwc) Tel: +44-71-315-6600
davel@cbnewsl.att.com (David Loewenstern) (06/02/90)
In article <4342@muffin.cme.nist.gov>, libes@cme.nist.gov (Don Libes) writes: > In article <12573@netcom.UUCP> ergo@netcom.UUCP (Isaac Rabinovitch) writes: > >steve@taumet.COM (Stephen Clamage) writes: > >>Well, "honi soit qui mal y pense", to you. There are plenty of > >>legitimate reasons for obfuscating code. Why do you assume Mr Loewenstern > >>has only evil intentions? Surely you don't have to jump all over him > >>until you find out. > > > >Such as? > > ... a useful way to distribute commercial products for multiple > platforms. Instead of dozens of binaries, just distribute one source > and let the buyer compile. > > For example, page 18 of this month's C Users Journal has an > advertisement for a lint that comes in "shrouded source form" that is > K&R and ANSI compatible, and which compiles on UNIX, DOS, VMS, VM/MVS, > and several other operating systems. The vendor has covered 99% of > the market with a single distribution. > > Not only is this clever, but certain #defines can be left unshrouded > so that you have a little more control than if you just had binaries. > > Incidentally, this practice has been around for years. > > Don Libes libes@cme.nist.gov ...!uunet!cme-durer!libes Thank you for sticking up for me, Don. Since I don't normally read this newsgroup, I did not realize the microfuror that I had started. I can, however, add another use: porting proprietary or otherwise restricted source code to a test platform which is accessable by outsiders. So there. 8^) By the way, Russ Fish <fish@kzin.utah.edu> has been kind enough to send me his version of a C obfuscator. It is somewhat restricted but does satisfy my requirements, and I have used it successfully (thanks, Russ). David Loewenstern <davel@whutt.att.com> AT&T Bell Laboratories 14B-253 Whippany, NJ 07981
martin@mwtech.UUCP (Martin Weitzel) (06/02/90)
In article <19858@duke.cs.duke.edu> drh@duke.cs.edu writes: [about ofuscating C code] >nicely indented program again. To make things really incomprehensible, >one needs to change local identifiers to weird strings like "__X__88s", ^^ ... and get into interference with the "implementors name space" -- Martin Weitzel, email: martin@mwtech.UUCP, voice: 49-(0)6151-6 56 83
timk@xenitec.on.ca (Tim Kuehn) (06/04/90)
In article <220@taumet.COM> steve@taumet.UUCP (Stephen Clamage) writes: >In article <12546@netcom.UUCP> ergo@netcom.UUCP (Isaac Rabinovitch) writes: >>davel@cbnewsl.att.com (David Loewenstern) writes >>>I am looking for a program (or emacs macro) which will translate >>>C code into unreadable but functionally equivalent code. ... >> >>I don't think I care for your purposes. The last time I encountered this >>sort of thing, ... [example] >> >>Such greedy double-dipping is beneath contempt. > >Well, "honi soit qui mal y pense", to you. There are plenty of >legitimate reasons for obfuscating code. yeah - like winning the next "obfuscated C programming" contest. Sounds like preperation for cheating to me! :-) (oh gasp!) ------------------------------------------------------------------------------ Timothy D. Kuehn TDK Consulting Services 119 University Ave. East, Waterloo, Ont., Canada. N2J 2W1 Office:(519)-888-0766 if no answer home: (519)-742-2036 (w/ans mach) DOS/Xenix - SW/HW. uC uP RDBMS Quality SW Guaranteed uunet!watmath!maytag!xenitec!timk timk@xenitec.on.ca ------------------------------------------------------------------------------
fish%kzin.utah.edu@cs.utah.edu (Russ Fish) (06/08/90)
Here's a copy of the short, chatty part of a posting to comp.sources.misc . Messages I've been getting mentioned these newsgroups, but it didn't seem proper to cross-post the sources, so I'll just send the discussion part here. Please correspond by mail if you'd like, I haven't been reading much netnews lately. -Russ Fish fish@cs.utah.edu (801) 581-5884 From: fish@kzin.utah.edu (Russ Fish) Path: kzin.utah.edu!fish Newsgroups: comp.sources.misc Subject: C obfuscator A friend mentioned somewhere on the net that I had once written a C obfuscator, and I've gotten numerous requests for it. So I'll post it. I make no claims for it, other than the fact that it once worked sufficently to package up a portable "opaque source" distribution of a couple hundred thousand lines of our geometric modeling system. The idea was to throw away all the information not absolutely needed by the compiler or linker, or squish it into unreadable id's. To support separate compilation of large systems, it supports an optional dictionary of global identifiers and their translations, which I generated simply by doing `nm' on the .o files and .a libraries, and bashed into the dictionary format using the usual morass of `grep', `sort', `sed', `awk', etc. Everybody seems to agree that the results are pretty unreadable. :-) That was over five years ago, and I haven't used it since. (We make binary distribution tapes for various plaforms now...) Feel free to use the code in any way that seems useful. (Pound nails with it, etc. :-) Files included below: opqcp.c "Opaque Copy". The obfuscator. opqcp.opq The result of hitting opqcp.c with opqcp. makefile misc.h A few support files, chopped down to subsets. list.h symtab.h new.c symtab.c -Russ Fish fish@cs.utah.edu (801) 581-5884 ps. Here's the germ of a slight improvement: The C keywords and punctuation characters could be squished out of the obfuscated file as well, if cpp were used to substitute them back in at compile time. Then the source files would all be COMPLETELY unreadable. (But of course, the key .h file of substitutions would have to be sent along, so it really doesn't gain that much.) -Russ Fish fish@cs.utah.edu (801) 581-5884
tomr@ashtate (Tom Rombouts) (07/19/90)
davel@cbnewsl.att.com (David Loewenstern) writes >I am looking for a program (or emacs macro) which will translate >C code into unreadable but functionally equivalent code. At minimum, >it must replace all variable names with cryptic names such as a1, i23, etc. >Ideally, it should also rename functions. Further obfuscation isn't really >necessary for my purposes, but wouldn't hurt either. A long time since the original posting, perhaps, but there is currently just such a beast posted in comp.sources.misc. I have pulled it down and looked at the sample files (which are indeed opaque!) but have not actually compiled it. Anyway, around here a code obfuscator would be redundant! :-) Tom Rombouts Torrance Techie tomr@ashtate.A-T.com V: (213) 538-7108
domo@tsa.co.uk (Dominic Dunlop) (07/20/90)
In <12546@netcom.UUCP> davel@cbnewsl.att.com (David Loewenstern) writes >I am looking for a program (or emacs macro) which will translate >C code into unreadable but functionally equivalent code. Gimpel Software of 3207 Hogarth Lane, Collegevill PA 19426, telephone (215) 584-4261, fax (215) 584-4266, is advertising a product called C Shroud for MS-DOS in recent editions of The C Users Journal (q.v.). It costs $198 (for now). Under ``Obfuscation Features'', the ad lists comment removal; identifier translation; optional replacement of if, if...else, for, while, do, continue, break for more primitive control structures; optional expansion of macros and header files; string and character constants optionally expanded to their octal or hex equivalents; optional name space merging or splitting to enhance confusion. Anybody used this thing? I haven't... -- Dominic Dunlop
donn@brat.UUCP (Donn Pedro) (07/24/90)
> davel@cbnewsl.att.com (David Loewenstern) writes > >I am looking for a program (or emacs macro) which will translate >C code into unreadable but functionally equivalent code. At minimum, >it must replace all variable names with cryptic names such as a1, i23, etc. >Ideally, it should also rename functions. Further obfuscation isn't really In the back of a few magazines on programming I have seen ads for a produce called "C Shroud". It shows a little ghost under the product info. Donn F Pedro ....................a.k.a. uunet!nwnexus!mcgp1!brat!donn else: {the known world}!uunet!nwnexus!thebes!mcgp1!brat!donn -------------------------------------------------------------------- Disclaimer: I didn't do it. Nobody saw me do it. You can't prove a thing.
gordon@osiris.cso.uiuc.edu (John Gordon) (07/25/90)
There was someting like this just recently on the net: Here it is. ---------------------------------------------------------------------------- A friend mentioned somewhere on the net that I had once written a C obfuscator, and I've gotten numerous requests for it. So I'll post it. [This is actually a second attempt to post, since I've gotten even more numerous messages, telling me that it hadn't gotten there the first time...] I make no claims for it, other than the fact that it once worked sufficently to package up a portable "opaque source" distribution of a couple hundred thousand lines of our geometric modeling system. The idea was to throw away all the information not absolutely needed by the compiler or linker, or squish it into unreadable id's. To support separate compilation of large systems, it supports an optional dictionary of global identifiers and their translations, which I generated simply by doing `nm' on the .o files and .a libraries, and bashed into the dictionary format using the usual morass of `grep', `sort', `sed', `awk', etc. Everybody seems to agree that the results are pretty unreadable. :-) That was over five years ago, and I haven't used it since. (We make binary distribution tapes for various plaforms now...) Feel free to use the code in any way that seems useful. (Pound nails with it, etc. :-) Files included below: opqcp.c "Opaque Copy". The obfuscator. opqcp.opq The result of hitting opqcp.c with opqcp. makefile misc.h A few support files, chopped down to subsets. list.h symtab.h new.c symtab.c -Russ Fish fish@cs.utah.edu (801) 581-5884 ps. Here's the germ of a slight improvement: The C keywords and punctuation characters could be squished out of the obfuscated file as well, if cpp were used to substitute them back in at compile time. Then the source files would all be COMPLETELY unreadable. (But of course, the key .h file of substitutions would have to be sent along, so it really doesn't gain that much.) Extract the rest of this message into a file, cd to an empty directory, and feed the file into a c-shell(....) [GAAAAAAACK! ! ! ! ! I repacked this as a Bourne shell shar. ++bsa] #--------------------------------CUT HERE------------------------------------- #! /bin/sh # # This is a shell archive. Save this into a file, edit it # and delete all lines above this comment. Then give this # file to sh by executing the command "sh file". The files # will be extracted into the current directory owned by # you with default permissions. # # The files contained herein are: # # -rw-r--r-- 1 allbery 3334 Jun 24 19:41 list.h # -rw-r--r-- 1 allbery 184 Jun 24 19:41 makefile # -rw-r--r-- 1 allbery 2171 Jun 24 19:41 misc.h # -rw-r--r-- 1 allbery 1728 Jun 24 19:41 new.c # -rw-r--r-- 1 allbery 17010 Jun 24 19:41 opqcp.c # -rw-r--r-- 1 allbery 8944 Jun 24 19:41 opqcp.opq # -rw-r--r-- 1 allbery 3411 Jun 24 19:41 symtab.c # -rw-r--r-- 1 allbery 2547 Jun 24 19:41 symtab.h # echo 'x - list.h' if test -f list.h; then echo 'shar: not overwriting list.h'; else sed 's/^X//' << '________This_Is_The_END________' > list.h X/* X * list.h - Definitions for list datastructures. X * X * Author: Russ Fish X * Computer Science Dept. X * University of Utah X * Date: 1 August 1980 X */ X X#ifndef LISTLINKS /* only once */ X X/*****************************************************************/ X/* TAG( list LISTHDR TLISTHDR NULLPTR P N T_P T_N ) */ X/* TAG( LISTLINKS TLISTLINKS ) */ Xtypedef /* Generalized list header. */ X struct listhdr X { X int t_tag; /* object type tag */ X struct listhdr *next,*prev; /* Backward & forward pointers */ X } X list; X X/* LISTLINKS = a type tag, followed by a LISTHDR */ X#define LISTLINKS int t_tag; struct tlist * next, * prev X#define TLISTLINKS(type) int t_tag; type * next, * prev X X/* Access for List pointer manipulations. (Previous and Next.) */ X#define P(node) ((node)->prev) X#define N(node) ((node)->next) X/* #define P(node) (((list *)(node))->prev) X * #define N(node) (((list *)(node))->next) X */ X X/* Versions of P and N with cast on result to set list subtype properly. */ X#define T_P(type,node) ((type *)(node)->prev) X#define T_N(type,node) ((type *)(node)->next) X X/* ***************************************************************** X * TAG( list_list LLIST NEW_LIST_LIST ) X * X * list of lists data structure. X */ X Xtypedef struct list_list X{ X TLISTLINKS(struct list_list); X list * l_list; X} list_list; X X#define LLIST(type,ll) (type *)ll->l_list /* get the list pointed to */ X X/*****************************************************************/ X X/* TAG( ADD INSERT REMOVE ) */ X/* ADD links new members into a list, given a pointer to the new member, and X * a pointer to the first (left) element of the list. X */ X#define ADD(new,first) ( P(new) = NULL ,N(new) = (first),\ X ( ((first)!=NULL) ? (P(first)=(new), 0) :0 ),\ X first = (new) ) X X/* INSERT links members into the middle of a list, given a pointer to the new X * member, and a pointer to the list element to insert after. X */ X#define INSERT(new,after) ( P(new) = (after),N(new) = N(after),\ X ( (N(after)!=NULL) ? (P(N(after))=(new), 0) :0),\ X N(after) = (new) ) X X/* REMOVE unlinks a list element from a list, given a pointer to the element. X */ X#define REMOVE(elt) ( ( (P(elt)!=NULL) ? (N(P(elt))=N(elt), 0) :0 ),\ X ( (N(elt)!=NULL) ? (P(N(elt))=P(elt), 0) :0) ) X X X/**************************************************************** X * TAG( TRACE FREE_LIST FIRSTP ENDP ) X * X * TRACE - Traces a linear list. X * FREE_LIST - Walks a list, freeing the elements. X * FIRSTP - Tests an element, TRUE if it is the first. X * ENDP - Tests an element, TRUE if it is the end. X */ X#define TRACE(t_var,ini) for((t_var)=(ini);(t_var)!=NULL;(t_var)=N(t_var)) X#define FREE_LIST(lst) {while(N(lst)){lst=N(lst);free(P(lst));} free(lst);} X#define FIRSTP(ptr) (P(ptr) == NULL) X#define ENDP(ptr) (N(ptr) == NULL) X X/**************************************************************** X * TAGS( DEL ) X * del deletes an element from a list, updating the base X * pointer of the list if necesary. X */ X#define DEL(elt,base) ( ( (P(elt)!=NULL) ? (N(P(elt)) = N(elt)) :0 ),\ X ( (N(elt)!=NULL) ? (P(N(elt)) = P(elt)) :0) ,\ X ( ((elt)==(base)) ? ((base)= N(base) ) :0) ) X X#endif LISTLINKS ________This_Is_The_END________ if test `wc -c < list.h` -ne 3334; then echo 'shar: list.h was damaged during transit (should have been 3334 bytes)' fi fi ; : end of overwriting check echo 'x - makefile' if test -f makefile; then echo 'shar: not overwriting makefile'; else sed 's/^X//' << '________This_Is_The_END________' > makefile X# Makefile for opqcp. X XCFLAGS = -g X XOFILES = opqcp.o symtab.o new.o Xopqcp: $(OFILES) X cc -o opqcp $(CFLAGS) $(OFILES) X Xopqcp.o: misc.h symtab.h Xsymtab.o: misc.h symtab.h Xnew.o: misc.h ________This_Is_The_END________ if test `wc -c < makefile` -ne 184; then echo 'shar: makefile was damaged during transit (should have been 184 bytes)' fi fi ; : end of overwriting check echo 'x - misc.h' if test -f misc.h; then echo 'shar: not overwriting misc.h'; else sed 's/^X//' << '________This_Is_The_END________' > misc.h X/* X * misc.h - Just the subset of defs needed for opqcp. X * X * Author: Russ Fish X * Computer Science Dept. X * University of Utah X * Date: 1 August 1980 X */ X X#ifndef MISCH /* Only once. */ X#define MISCH X X#include <stdio.h> /* Defines NULL. */ X X/***************************************************************** X * TAGS( string boolean fn byte address ) X * X * Commonly used types. X * X */ Xtypedef char * string; /* Character Strings. */ Xtypedef int boolean; /* Logical vars or values. */ X Xtypedef char byte; /* Byte is the unit of "sizeof". */ X Xtypedef char * address; X X/***************************************************************** X * TAGS( TRUE FALSE ) X */ X X#define TRUE 1 /* Logical constants. */ X#define FALSE 0 X X/***************************************************************** X * TAGS( NEW NEW_1 NEW_N new ) X * X * NEW(type,size) X * Generalized allocation function, given an object type and size (in X * bytes) to be allocated. X * X * Variants: X * NEW_1(type) - Allocate a single object of the given type. X * NEW_N(type,n) - Allocate an array of N objects of the given type. X */ Xextern address Xnew(); /* In-core allocator. */ X/* ( size ) X * int size; X */ X#define NEW(type,size) (type *)new(size) /* Macro with type cast. */ X#define NEW_1(type) (type *)new(sizeof(type)) /* Single arg, fixed size. */ X#define NEW_N(type,n) (type *)new((n)*sizeof(type)) /* Array of base type. */ X X/***************************************************************** X * TAGS( FREE free dispose ) X * X * Macros to cast the argument to dispose(). X */ X#define FREE( ptr ) dispose( (address)ptr ) X#define free( ptr ) dispose( (address)ptr ) X X/***************************************************************** X * TAG( SIZE SIZE_N msize ) X * X * SIZE returns the size (in bytes) of an allocated object. X * X * SIZE_N returns the number of objects of TYPE in ARRAY. X */ Xextern long Xmsize(); X/* ( obj ) X * address obj; X */ X#define SIZE(obj) msize( (address)obj ) X#define SIZE_N(type, array) (msize( (address)array ) / sizeof (type)) X X#endif ________This_Is_The_END________ if test `wc -c < misc.h` -ne 2171; then echo 'shar: misc.h was damaged during transit (should have been 2171 bytes)' fi fi ; : end of overwriting check echo 'x - new.c' if test -f new.c; then echo 'shar: not overwriting new.c'; else sed 's/^X//' << '________This_Is_The_END________' > new.c X/* X * new.c - Generalized allocation function. X * X * Author: Russ Fish X * Computer Science Dept. X * University of Utah X * Date: 1 August 1980 X */ X#include "misc.h" X Xtypedef union X{ X long mem_size; /* Someplace to stash the actual block size. */ X X /* Avoid messing up the double alignment of the block we are wrapping. */ X double dummy; X} mem_hdr; Xextern char * malloc(); /* Use the Std I/O Mem Alloc. */ X X/***************************************************************** X * TAG( new ) X * X * Allocate a block of storage. X * X */ Xaddress Xnew(size) Xint size; X{ X mem_hdr * retval; X X if ( (retval = (mem_hdr *) X malloc( (unsigned) (size + sizeof(mem_hdr)) )) <= 0 ) X { X fprintf( stderr, "\nNo Space in heap! %d bytes requested.\n", size); X exit( -1 ); X } X X /* Fill in the specified block size in a header word. The returned X * pointer points just AFTER the mem_hdr. Only "new", "dispose", X * "msize", and "expand" need to know about the mem_hdr. X */ X retval->mem_size = (long) size; X X return (address)( retval + 1 ); X} X X/***************************************************************** X * TAG( msize ) X * X * Report the size of a block of storage. X */ Xlong Xmsize( obj ) Xaddress obj; X{ X return ( (mem_hdr *)obj - 1 )->mem_size; X} X X/***************************************************************** X * TAG( dispose ) X * X * Free a block of storage. X */ Xdispose( obj ) Xaddress obj; X{ X /* Get the "free" compatibility macro out of the way. This is the X * only place in the system where the real "free" function is visible. X */ X# undef free X if ( obj ) X free( (char *) ((mem_hdr *)obj - 1) ); X} ________This_Is_The_END________ if test `wc -c < new.c` -ne 1728; then echo 'shar: new.c was damaged during transit (should have been 1728 bytes)' fi fi ; : end of overwriting check echo 'x - opqcp.c' if test -f opqcp.c; then echo 'shar: not overwriting opqcp.c'; else sed 's/^X//' << '________This_Is_The_END________' > opqcp.c X/* opqcp - Makes opaque copies of a group of sources to support a flavor X * of distribution with the security of an object-only version but the ability X * to recompile on a variety of machines like a source distribution. X * X * The idea is that there is a lot of information in good sources which is X * not needed by the compiler or linker, but which conveys the meaning of the X * program to a programmer. We try to write the most understandable programs X * possible, opqcp aspires to translate them into the least understandable. X * X * Comments, #includes, #define'ed constants and macros - stripped or X * expanded by pouring the source through the C preprocessor. X * X * Global symbols - translated into unreadable equivalents or preserved X * if needed to link to the program or function. A global dictionary X * must have previously been derived from the .o file symbol tables. X * (All C reserved keywords are preserved automatically.) X * X * Local identifiers - Translated into unreadable equivalents within X * a single source file. This applies to everything not in the global X * table (variables, typedefs, struct fields, etc.) X * X * Indentation/Whitespace - The tokens are packed on screen-width lines with X * all whitespace removed. X * X * Arguments (dash args precede file and destdir args.): X * -d dictfile - (Optional, may be repeated.) Contains a wordlist that is X * entered into a symbol table of global names. Lines with just a name X * mark that identifier as a clear global to preserve in the output. X * (All C reserved words are automatically preserved in this way.) X * Lines with a name and its translation separated by a blank character X * denote an opaque global which is translated the same everywhere. X * All other symbols will be locally translated and may be different in X * each source file. X * X * -Idir - (Optional, may be repeated.) Include directory arguments passed X * on to the C preprocessor. X * X * -f - Filter mode, just opacifies stdin to stdout. File and X * directory arguments are ignored and the input must already have X * been run through "cc -E" if preprocessing is desired. X * X * -t - Token trace (for testing). Forces filter mode, prints token X * types and values. X * X * filenames.c - (Required except in filter mode, may be repeated.) X * Source files to obfuscate. X * X * destdir - (One required as the last argument except in filter mode.) X * Where to put the opaque copies of the source files. X * The copies have the same names as the originals, but opqcp X * refuses to overwrite a file with itself. X */ X X#include "misc.h" X#include "symtab.h" X#include "sys/types.h" X#include "sys/stat.h" X#include "ctype.h" X Xstring c_keywords[] = /* From K&R, appendix A, section 2.3. */ X{ X "int", "char", "float", "double", "struct", "union", "enum", "long", X "short", "unsigned", "auto", "extern", "register", "typedef", "static", X "goto", "return", "sizeof", "break", "continue", "if", "else", "for", X "do", "while", "switch", "case", "default", "entry", "fortran", "asm", X "main", /* Reserved for main program functions. */ X "void" /* Not in K&R, added since then. */ X}; Xint n_keywords = sizeof c_keywords / sizeof( string ); X Xmain( argc, argv ) Xint argc; Xstring argv[]; X{ X boolean filter_mode = FALSE, token_trace = FALSE; X int i, j, k, l, arg_num; X hash_table * globals, * locals; X id * symbol; X string *name_ptr, *arg_ptr, arg; X static char I_args[BUFSIZ] = { '\0' }; X char buffer[BUFSIZ], buffer2[BUFSIZ]; X struct stat stat_buffer; X FILE * dict_in, * input, * output, * popen(); X dev_t input_dev; X ino_t input_inode; X string directory, name, translation, index(); X X char chr, * chr_ptr , token[BUFSIZ], * token_end, string_type; X int token_length, line_length; X enum { NONE, SYMBOL, STRING, NUMBER, OTHER } X token_type, prev_token_type; X static string token_type_strings[] = X { "none", "symbol", "string", "number", "other" }; X boolean whitespace; X /* These characters will not be separated if they occur together. */ X string op_diphthong_chars = "=!<>&|+-*/%&^"; X X /* Some simple macros to stream characters through the token recognizer. */ X# define NEW_TOKEN ( token_end = token, *token_end = '\0' ) X# define NEXT ( OUT, IN ) X# define OUT ( *token_end++ = chr, *token_end = '\0' ) X# define IN ( chr = getc( input ) ) X# define NEW_LINE ( line_length = 0 ) X X int local_counter = 0; X# define NLOCALS 5000 X static char local_names[NLOCALS][6]; X X /* Save a lot of hassle by putting the local name strings in a static X * array where they can be re-used. The var_value cells of the ids in X * a hashed symbol table are second class citizens in that they are not X * freed when the hash table is freed, although the var_name strings are. X */ X for ( i=0; i < NLOCALS/1000; i++ ) /* Initialize the local name strings. */ X for ( j=0; j<=9; j++ ) X for ( k=0; k<=9; k++ ) X for ( l=0; l<=9; l++ ) X { X chr_ptr = local_names[local_counter++]; X *chr_ptr++ = 'l'; /* Leading letter. */ X if ( i ) *chr_ptr++ = '0' + i; /* Thousands. */ X if ( i || j ) *chr_ptr++ = '0' + j; /* Hundreds. */ X if ( i || j || k ) *chr_ptr++ = '0' + k; /* Tens. */ X *chr_ptr++ = '0' + l; /* Ones. */ X *chr_ptr = '\0'; X } X X /* Start out the global dictionary with the C keywords. */ X globals = new_hash_table( 1000 ); X for ( i=0, name_ptr = c_keywords; i < n_keywords; i++, name_ptr++ ) X new_symbol( *name_ptr, globals ); X X /* Process dash arguments. */ X for ( arg_num=1, arg_ptr = &argv[1], arg = *arg_ptr; X arg_num < argc; X arg_num++, arg_ptr++, arg = *arg_ptr ) X { X if ( arg[0] != '-' ) X break; /* Only do dash args here. */ X X /* Process -d (global dictionary) args. */ X if ( strcmp( arg, "-d" ) == 0 ) X { X if ( ++arg_num >= argc-1 ) break; /* Ignore -d at the end. */ X arg = *++arg_ptr; X X if ( (dict_in = fopen( arg, "r" )) == NULL ) X { X sprintf( buffer, "opqcp: Can't open dictionary %s\n", arg ); X perror( buffer ); X exit( 1 ); X } X X while( fgets( buffer, BUFSIZ, dict_in ) != NULL ) X { X /* Trash the newline fgets puts in the buffer. */ X buffer[ strlen(buffer)-1 ] = '\0'; X X /* Optional translation is separated from name by a blank. */ X if ( (translation = index( buffer, ' ' )) != NULL ) X *translation++ = '\0'; /* Terminate the name string. */ X X /* Link in a copy of the name string. */ X name = NEW( char, strlen(buffer)+1 ); X strcpy( name, buffer ); X symbol = new_symbol( name, globals ); X X /* Translation will be NULL if symbol is to be left alone. */ X if ( translation != NULL ) X { X /* Link in a copy of the translation string. */ X symbol->var_value = NEW( char, strlen(translation)+1 ); X strcpy( symbol->var_value, translation ); X } X } X fclose( dict_in ); X } X /* Process -Idir (cpp include directory) argument(s). */ X else if ( strncmp( arg, "-I", 2 ) == 0 ) X { X strcat( I_args, " " ); X strcat( I_args, arg ); X } X /* Process a -t (token trace) argument. */ X else if ( strcmp( arg, "-t" ) == 0 ) X { X token_trace = TRUE; /* For testing. */ X goto filter; /* Forces filter mode. */ X } X /* Process a -f (filter mode) argument. */ X else if ( strcmp( arg, "-f" ) == 0 ) X { X filter: X filter_mode = TRUE; /* No-ops all of the file handling. */ X input = stdin; X output = stdout; X } X else X break; /* Out if invalid dash arg. */ X } X X /* Usage message if bad dash flag or no file and dir args . */ X if ( arg[0] == '-' || !filter_mode && argc-arg_num < 2 ) X { X fprintf( stderr, "%s\n%s\n", X "usage: opqcp [-d dict]* [-Idir]* [srcfile]+ destdir", X " or opqcp [-d dict]* -f" ); X exit( 2 ); X } X X /* Check that the last argument is a directory. */ X if ( !filter_mode ) X { X if ( stat( directory = argv[argc-1], &stat_buffer ) == -1 ) X { X sprintf( buffer, "opqcp: Can't stat directory %s\n", directory ); X perror( buffer ); X exit( 1 ); X } X if ( ! (stat_buffer.st_mode & S_IFDIR) ) X { X fprintf( stderr, "opqcp: %s is not a directory.\n", directory ); X exit( 1 ); X } X } X X /* Loop through the file arguments. */ X for ( ; filter_mode || arg_num < argc-1; arg_num++, arg_ptr++ ) X { X if ( filter_mode ) X arg = "(stdin)"; X else X { X arg = *arg_ptr; X X /* Before opening the output file, check that it isn't the same X * as the input file. (This would result in clearing the file X * before it was read!) X */ X if ( stat( arg, &stat_buffer ) == -1 ) X { X sprintf( buffer, "opqcp: Can't stat input file %s\n", arg ); X perror( buffer ); X continue; /* Go do next file arg. */ X } X /* Might as well check that it's a plain file while we're here. */ X if ( ! (stat_buffer.st_mode & S_IFREG) ) X { X fprintf( stderr, "opqcp: %s is not a plain file.\n", arg ); X continue; /* Go do next file arg. */ X } X input_dev = stat_buffer.st_dev; X input_inode = stat_buffer.st_ino; X X sprintf( buffer, "%s/%s", directory, arg ); /* Output file path. */ X if ( stat( buffer, &stat_buffer ) == 0 ) X { /* We can only stat an already existing output file. */ X /* Check for inode collision to guard against overwriting. */ X if ( stat_buffer.st_dev == input_dev && X stat_buffer.st_ino == input_inode ) X { X fprintf( stderr, "opqcp: Can't copy file %s to itself.\n", X arg ); X continue; /* Go on to next file arg. */ X } X /* Check that it's a plain file while we're here. */ X if ( ! (stat_buffer.st_mode & S_IFREG) ) X { X fprintf( stderr, "opqcp: %s is not a plain file.\n", X buffer ); X continue; /* Go on to next file arg. */ X } X } X X /* Open the opaque source file on the destination directory. */ X if ( (output = fopen( buffer, "w" )) == NULL ) X { X sprintf( buffer, "opqcp: Can't write file %s",arg ); X perror( buffer ); X continue; /* Go on to the next file. */ X } X X /* Copyright notice. */ X fputs( "/* Licensed material, Copyright ", output ); X fputs( "(c) 1985, University of Utah. */\n", output ); X X /* Read the source file through the C preprocessor. */ X sprintf( buffer2, "cc -E %s %s", I_args, arg ); X if ( (input = popen( buffer2, "r" )) == NULL ) X { X sprintf( buffer2, "opqcp: Couldn't start cpp on %s.",arg ); X perror( buffer2 ); X fclose( output ); /* It was already opened. */ X unlink( buffer ); /* Wipe out the empty output file. */ X continue; /* Go on to the next file. */ X } X } X X /* Local dictionary lasts only through a single source file. */ X locals = new_hash_table( 1000 ); X local_counter = 0; X X /* Transfer tokens from the cpp stream to a packed output file. */ X chr = '\n'; /* In effect, the end of the line before the first line. */ X NEW_LINE; /* Start first line of output. */ X prev_token_type = NONE; X /* Back here at the beginning of each token. */ X while( chr != EOF ) X { X NEW_TOKEN; /* Set up to collect a token. */ X token_type = NONE; X whitespace = FALSE; X X /* Flush whitespace before a token. */ X while( isspace( chr ) ) X { X whitespace = TRUE; X X if ( chr != '\n' ) X IN; /* Character after blank or tab. */ X else X { X IN; /* First character on a line. */ X if ( chr == '#' ) X { X /* Flush C preprocessor linenumber statements. */ X while ( chr != '\n' && chr != EOF ) X IN; /* Go until the newline is found. */ X } X } X } X X /* Identifiers, keywords, etc. Underscore is a letter. */ X if ( isalpha( chr ) || chr == '_' ) X { X token_type = SYMBOL; X X /* Grab the alpha and then alphanumeric characters. */ X NEXT; X while ( isalnum( chr ) || chr == '_' ) NEXT; X X /* Look the symbol up in the global dictionary. */ X if ( (symbol = find_symbol( token, globals )) != NULL ) X { X /* Substitute a global translation if there is one. */ X if ( symbol->var_value != NULL ) X { X strcpy( token, symbol->var_value ); X } X } X else X { X /* Look the symbol up in the local dictionary. */ X if ( (symbol = find_symbol( token, locals )) == NULL ) X { X /* New symbol, assign a local translation. */ X name = NEW( char, strlen(token)+1 ); X strcpy( name, token ); X symbol = new_symbol( name, locals ); X symbol->var_value = local_names[++local_counter]; X } X /* Translate symbol to the local equivalent. */ X strcpy( token, symbol->var_value ); X } X } X /* Character constants and strings. */ X else if ( chr == '"' || chr == '\'' ) X { X token_type = STRING; X string_type = chr; /* Remember which kind of quote. */ X NEXT; /* Stash quote, get first char of string. */ X while ( chr != string_type ) X { X if ( chr != '\\' ) X NEXT; /* Stash non-backslash char, go ahead. */ X else X /* Handle backslash escapes. */ X { X NEXT; /* Stash backslash, go to escaped char. */ X if ( string_type != '"' || chr != '\n' ) X NEXT; /* Stash escaped char, go ahead. */ X else X { X /* Weird special case. Strings can be X * continued onto the next line if they X * precede the newline with a backslash. X */ X NEXT; /* Stash escaped newline, go ahead. */ X if ( strlen(token) + line_length > 77 ) X fputs( "\n", output ); /* Break before. */ X /* Put out the string with escaped newline. */ X fputs( token, output ); X /* Start a new line and a new token. */ X NEW_LINE; NEW_TOKEN; X } X } X } X NEXT; /* Stash closing quote. */ X } X /* Numbers. (This can be a bit simplified over a real X * lexical analyzer, since it only has to correctly X * recognize all valid number forms, not detect subtle X * syntax errors.) X */ X else if ( isdigit( chr ) ) X { X number: X token_type = NUMBER; X X /* Initial numeric part. */ X if ( chr == '0' ) X { /* Could be an octal or hex constant, or just a "0". */ X NEXT; X if ( chr == 'x' || chr == 'X' ) X { X NEXT; /* Get first char of hex constant. */ X while( isdigit( chr ) || chr >= 'a' && chr <= 'f' X || chr >= 'A' && chr <= 'F' ) X NEXT; /* Read through hex constant. */ X } X else /* Octal integer constant. */ X while ( isdigit( chr ) ) NEXT; X } X else X /* Decimal integer, or part of a floating pt number. */ X while ( isdigit( chr ) ) NEXT; X X /* Optional integer "l" suffix, fraction, or exponent. */ X if ( chr == 'l' || chr == 'L' ) X NEXT; X else X { X /* Optional fractional part on floats. */ X if ( chr == '.' ) X { X NEXT; /* Get first char of fraction. */ X while ( isdigit( chr ) ) NEXT; X } X X /* Optional exponent. */ X if ( chr == 'e' || chr == 'E' ) X { X NEXT; /* Get first char of exponent. */ X /* Optional sign on exponent. */ X if ( chr == '+' || chr == '-' ) NEXT; X while ( isdigit( chr ) ) NEXT; /* Exponent. */ X } X } X } X /* Operators and single-character tokens for punctuation. */ X else if( chr != EOF ) X { X token_type = OTHER; X X /* Dot may be either a leading decimal point on a number, X * or a structure access operator. We have a number if the X * following character is a digit. X */ X if ( chr == '.' ) X { X NEXT; X if ( isdigit( chr ) ) X goto number; /* Yep, leading decimal point. */ X } X else /* Everything other than dots. */ X { X /* Keep operator diphthongs contiguous. */ X if ( index( op_diphthong_chars, chr ) != NULL ) X while ( index( op_diphthong_chars, chr ) != NULL ) X NEXT; /* Collect diphthong characters. */ X else X NEXT; /* Single-character token. */ X } X } X X if ( token_trace ) X fprintf( output, "type = %s, token = `", X token_type_strings[ (int)token_type ] ); X X /* Got a token in the buffer, pack it onto an output line. */ X token_length = strlen( token ); X if ( token_length + line_length > 77 ) /* Time for line break? */ X { X fputs( "\n", output ); /* Line break. */ X NEW_LINE; /* Start next line. */ X } X /* Need to preserve blanks between symbols or numbers, and X * between operators next to = signs so they don't run together. X */ X else if ( (prev_token_type==SYMBOL || prev_token_type==NUMBER) && X (token_type==SYMBOL || token_type==NUMBER) || X token[0] == '=' && whitespace ) /* Space before =. */ X { X fputs( " ", output ); X line_length++; X } X X /* Add token to the output stream. */ X fputs( token, output ); X line_length += token_length; X X if ( token[token_length-1] == '=' && isspace( chr ) ) X { X fputs( " ", output ); /* Space after = sign. */ X line_length++; X } X X if ( token_trace ) X fprintf( output, "'\n" ); X X prev_token_type = token_type; X } X /* EOF. */ X fputs( "\n", output ); /* End of line at end of file. */ X X if ( filter_mode ) X exit( 0 ); /* Done. */ X else X { X pclose( input ); X fclose( output ); X fr_hash_table( locals ); X } X } /* Next file. */ X} ________This_Is_The_END________ if test `wc -c < opqcp.c` -ne 17010; then echo 'shar: opqcp.c was damaged during transit (should have been 17010 bytes)' fi fi ; : end of overwriting check echo 'x - opqcp.opq' if test -f opqcp.opq; then echo 'shar: not overwriting opqcp.opq'; else sed 's/^X//' << '________This_Is_The_END________' > opqcp.opq X/* Licensed material, Copyright (c) 1985, University of Utah. */ Xextern struct l1{int l2;char*l3;char*l4;int l5;short l6;char l7;}l8[];struct Xl1*l9();struct l1*l10();struct l1*l11();struct l1*l12();long l13();char*l14() X;char*l15();char*l16();typedef char*l17;typedef int l18;typedef char l19; Xtypedef char*l20;extern l20 l21();extern long l22();typedef struct l23{int l24 X;struct l23*l25,*l26;}l27;typedef struct l28{int l24;struct l28*l25,*l26;l27* Xl29;}l28;typedef struct l30 l31;struct l30{int l24;l31*l25,*l26;l17 l32;l20 Xl33;};extern l31*l34();extern l31*l35();typedef struct{int l36;l31*l37[1];} Xl38;extern l38*l39();extern l31**l40();extern l41();extern l42();typedef Xunsigned char l43;typedef unsigned short l44;typedef unsigned int l45;typedef Xunsigned long l46;typedef unsigned short l47;typedef struct l48{short l49[1]; X}*l50;typedef struct l51{int l52[15];}l51;typedef struct l53{long l52[2];}l54 X;typedef long l55;typedef char*l56;typedef long*l57;typedef l46 l58;typedef Xlong l59;typedef long l60;typedef long l61;typedef short l62;typedef long l63 X;typedef l44 l64;typedef l44 l65;typedef l46 l66;typedef long l67;typedef Xstruct l68{l67 l69[(((256)+(((sizeof(l67)*8))-1))/((sizeof(l67)*8)))];}l68; Xstruct l70{l62 l71;l58 l72;unsigned short l73;short l74;l64 l75;l65 l76;l62 Xl77;l63 l78;l61 l79;int l80;l61 l81;int l82;l61 l83;int l84;long l85;long l86 X;long l87[2];};extern char l88[];l17 l89[] = {"int","char","float","double", X"struct","union","enum","long","short","unsigned","auto","extern","register", X"typedef","static","goto","return","sizeof","break","continue","if","else", X"for","do","while","switch","case","default","entry","fortran","asm","main", X"void"};int l90 = sizeof l89/sizeof(l17);main(l91,l92)int l91;l17 l92[];{l18 Xl93 = 0,l94 = 0;int l95,l96,l97,l98,l99;l38*l100,*l101;l31*l102;l17*l103,* Xl104,l105;static char l106[1024] = {'\0'};char l107[1024],l108[1024];struct Xl70 l109;struct l1*l110,*l111,*l112,*l12();l62 l113;l58 l114;l17 l115,l116, Xl117,l118();char l119,*l120,l121[1024],*l122,l123;int l124,l125;enum{l126, Xl127,l128,l129,l130}l131,l132;static l17 l133[] = {"none","symbol","string", X"number","other"};l18 l134;l17 l135 = "=!<>&|+-*/%&^";int l136 = 0;static char Xl137[5000][6];for(l95=0;l95<5000/1000;l95++)for(l96=0;l96<=9;l96++)for(l97=0; Xl97<=9;l97++)for(l98=0;l98<=9;l98++){l120 = l137[l136++];*l120++ = 'l';if(l95 X)*l120++ = '0'+l95;if(l95||l96)*l120++ = '0'+l96;if(l95||l96||l97)*l120++ = X'0'+l97;*l120++ = '0'+l98;*l120 = '\0';}l100 = l39(1000);for(l95=0,l103 = l89 X;l95<l90;l95++,l103++)l34(*l103,l100);for(l99=1,l104 = &l92[1],l105 = *l104; Xl99<l91;l99++,l104++,l105 = *l104){if(l105[0]!= '-')break;if(l138(l105,"-d") X== 0){if(++l99>= l91-1)break;l105 = *++l104;if((l110 = l9(l105,"r")) == 0){ Xl16(l107,"opqcp: Can't open dictionary %s\n",l105);l139(l107);l140(1);}while( Xl14(l107,1024,l110)!= 0){l107[l141(l107)-1] = '\0';if((l117 = l118(l107,' ')) X!= 0)*l117++ = '\0';l116 = (char*)l21(l141(l107)+1);l142(l116,l107);l102 = Xl34(l116,l100);if(l117!= 0){l102->l33 = (char*)l21(l141(l117)+1);l142(l102-> Xl33,l117);}}l143(l110);}else if(l144(l105,"-I",2) == 0){l145(l106," ");l145( Xl106,l105);}else if(l138(l105,"-t") == 0){l94 = 1;goto l146;}else if(l138( Xl105,"-f") == 0){l146:l93 = 1;l111 = (&l8[0]);l112 = (&l8[1]);}else break;}if X(l105[0] == '-'||!l93&&l91-l99<2){l147((&l8[2]),"%s\n%s\n", X"usage: opqcp [-d dict]* [-Idir]* [srcfile]+ destdir", X" or opqcp [-d dict]* -f");l140(2);}if(!l93){if(l70(l115 = l92[l91-1],& Xl109) == -1){l16(l107,"opqcp: Can't stat directory %s\n",l115);l139(l107); Xl140(1);}if(!(l109.l73&0040000)){l147((&l8[2]), X"opqcp: %s is not a directory.\n",l115);l140(1);}}for(;l93||l99<l91-1;l99++, Xl104++){if(l93)l105 = "(stdin)";else{l105 = *l104;if(l70(l105,&l109) == -1){ Xl16(l107,"opqcp: Can't stat input file %s\n",l105);l139(l107);continue;}if(!( Xl109.l73&0100000)){l147((&l8[2]),"opqcp: %s is not a plain file.\n",l105); Xcontinue;}l113 = l109.l71;l114 = l109.l72;l16(l107,"%s/%s",l115,l105);if(l70( Xl107,&l109) == 0){if(l109.l71 == l113&&l109.l72 == l114){l147((&l8[2]), X"opqcp: Can't copy file %s to itself.\n",l105);continue;}if(!(l109.l73& X0100000)){l147((&l8[2]),"opqcp: %s is not a plain file.\n",l107);continue;}} Xif((l112 = l9(l107,"w")) == 0){l16(l107,"opqcp: Can't write file %s",l105); Xl139(l107);continue;}l148("/* Licensed material, Copyright ",l112);l148( X"(c) 1985, University of Utah. */\n",l112);l16(l108,"cc -E %s %s",l106,l105); Xif((l111 = l12(l108,"r")) == 0){l16(l108,"opqcp: Couldn't start cpp on %s.", Xl105);l139(l108);l143(l112);l149(l107);continue;}}l101 = l39(1000);l136 = 0; Xl119 = '\n';(l125 = 0);l132 = l126;while(l119!= (-1)){(l122 = l121,*l122 = X'\0');l131 = l126;l134 = 0;while(((l88+1)[l119]&010)){l134 = 1;if(l119!= '\n' X)(l119 = (--(l111)->l2>=0?(int)(*(unsigned char*)(l111)->l3++):l150(l111))); Xelse{(l119 = (--(l111)->l2>=0?(int)(*(unsigned char*)(l111)->l3++):l150(l111) X));if(l119 == '#'){while(l119!= '\n'&&l119!= (-1))(l119 = (--(l111)->l2>=0?( Xint)(*(unsigned char*)(l111)->l3++):l150(l111)));}}}if(((l88+1)[l119]&(01|02) X)||l119 == '_'){l131 = l127;((*l122++ = l119,*l122 = '\0'),(l119 = (--(l111) X->l2>=0?(int)(*(unsigned char*)(l111)->l3++):l150(l111))));while(((l88+1)[ Xl119]&(01|02|04))||l119 == '_')((*l122++ = l119,*l122 = '\0'),(l119 = (--( Xl111)->l2>=0?(int)(*(unsigned char*)(l111)->l3++):l150(l111))));if((l102 = Xl35(l121,l100))!= 0){if(l102->l33!= 0){l142(l121,l102->l33);}}else{if((l102 = Xl35(l121,l101)) == 0){l116 = (char*)l21(l141(l121)+1);l142(l116,l121);l102 = Xl34(l116,l101);l102->l33 = l137[++l136];}l142(l121,l102->l33);}}else if(l119 X== '"'||l119 == '\''){l131 = l128;l123 = l119;((*l122++ = l119,*l122 = '\0'), X(l119 = (--(l111)->l2>=0?(int)(*(unsigned char*)(l111)->l3++):l150(l111)))); Xwhile(l119!= l123){if(l119!= '\\')((*l122++ = l119,*l122 = '\0'),(l119 = (--( Xl111)->l2>=0?(int)(*(unsigned char*)(l111)->l3++):l150(l111))));else{((*l122 X++ = l119,*l122 = '\0'),(l119 = (--(l111)->l2>=0?(int)(*(unsigned char*)(l111 X)->l3++):l150(l111))));if(l123!= '"'||l119!= '\n')((*l122++ = l119,*l122 = X'\0'),(l119 = (--(l111)->l2>=0?(int)(*(unsigned char*)(l111)->l3++):l150(l111 X))));else{((*l122++ = l119,*l122 = '\0'),(l119 = (--(l111)->l2>=0?(int)(*( Xunsigned char*)(l111)->l3++):l150(l111))));if(l141(l121)+l125>77)l148("\n", Xl112);l148(l121,l112);(l125 = 0);(l122 = l121,*l122 = '\0');}}}((*l122++ = Xl119,*l122 = '\0'),(l119 = (--(l111)->l2>=0?(int)(*(unsigned char*)(l111)->l3 X++):l150(l111))));}else if(((l88+1)[l119]&04)){l151:l131 = l129;if(l119 == X'0'){((*l122++ = l119,*l122 = '\0'),(l119 = (--(l111)->l2>=0?(int)(*(unsigned Xchar*)(l111)->l3++):l150(l111))));if(l119 == 'x'||l119 == 'X'){((*l122++ = Xl119,*l122 = '\0'),(l119 = (--(l111)->l2>=0?(int)(*(unsigned char*)(l111)->l3 X++):l150(l111))));while(((l88+1)[l119]&04)||l119>= 'a'&&l119<= 'f'||l119>= X'A'&&l119<= 'F')((*l122++ = l119,*l122 = '\0'),(l119 = (--(l111)->l2>=0?(int) X(*(unsigned char*)(l111)->l3++):l150(l111))));}else while(((l88+1)[l119]&04)) X((*l122++ = l119,*l122 = '\0'),(l119 = (--(l111)->l2>=0?(int)(*(unsigned char X*)(l111)->l3++):l150(l111))));}else while(((l88+1)[l119]&04))((*l122++ = l119 X,*l122 = '\0'),(l119 = (--(l111)->l2>=0?(int)(*(unsigned char*)(l111)->l3++): Xl150(l111))));if(l119 == 'l'||l119 == 'L')((*l122++ = l119,*l122 = '\0'),( Xl119 = (--(l111)->l2>=0?(int)(*(unsigned char*)(l111)->l3++):l150(l111)))); Xelse{if(l119 == '.'){((*l122++ = l119,*l122 = '\0'),(l119 = (--(l111)->l2>=0? X(int)(*(unsigned char*)(l111)->l3++):l150(l111))));while(((l88+1)[l119]&04))( X(*l122++ = l119,*l122 = '\0'),(l119 = (--(l111)->l2>=0?(int)(*(unsigned char* X)(l111)->l3++):l150(l111))));}if(l119 == 'e'||l119 == 'E'){((*l122++ = l119,* Xl122 = '\0'),(l119 = (--(l111)->l2>=0?(int)(*(unsigned char*)(l111)->l3++): Xl150(l111))));if(l119 == '+'||l119 == '-')((*l122++ = l119,*l122 = '\0'),( Xl119 = (--(l111)->l2>=0?(int)(*(unsigned char*)(l111)->l3++):l150(l111)))); Xwhile(((l88+1)[l119]&04))((*l122++ = l119,*l122 = '\0'),(l119 = (--(l111)->l2 X>=0?(int)(*(unsigned char*)(l111)->l3++):l150(l111))));}}}else if(l119!= (-1) X){l131 = l130;if(l119 == '.'){((*l122++ = l119,*l122 = '\0'),(l119 = (--(l111 X)->l2>=0?(int)(*(unsigned char*)(l111)->l3++):l150(l111))));if(((l88+1)[l119] X&04))goto l151;}else{if(l118(l135,l119)!= 0)while(l118(l135,l119)!= 0)((*l122 X++ = l119,*l122 = '\0'),(l119 = (--(l111)->l2>=0?(int)(*(unsigned char*)(l111 X)->l3++):l150(l111))));else((*l122++ = l119,*l122 = '\0'),(l119 = (--(l111)-> Xl2>=0?(int)(*(unsigned char*)(l111)->l3++):l150(l111))));}}if(l94)l147(l112, X"type = %s, token = `",l133[(int)l131]);l124 = l141(l121);if(l124+l125>77){ Xl148("\n",l112);(l125 = 0);}else if((l132==l127||l132==l129)&&(l131==l127|| Xl131==l129)||l121[0] == '='&&l134){l148(" ",l112);l125++;}l148(l121,l112); Xl125+= l124;if(l121[l124-1] == '='&&((l88+1)[l119]&010)){l148(" ",l112);l125 X++;}if(l94)l147(l112,"'\n");l132 = l131;}l148("\n",l112);if(l93)l140(0);else{ Xl152(l111);l143(l112);l42(l101);}}} ________This_Is_The_END________ if test `wc -c < opqcp.opq` -ne 8944; then echo 'shar: opqcp.opq was damaged during transit (should have been 8944 bytes)' fi fi ; : end of overwriting check echo 'x - symtab.c' if test -f symtab.c; then echo 'shar: not overwriting symtab.c'; else sed 's/^X//' << '________This_Is_The_END________' > symtab.c X/* X * symtab.c - Symbol Table package routines. X * ( Descriptions in file symtab.h .) X * X * Author: Russ Fish X * Computer Science Dept. X * University of Utah X * Date: 3 September 1981 X */ X X#include "misc.h" X#include "symtab.h" X X/***************************************************************** X * TAG( new_symbol ) X */ Xid * /* Constructor. */ Xnew_symbol( sym_name, table ) Xstring sym_name; Xhash_table * table; X{ X id * ret, * * slot; X X /* Allocate id node and link into symbol table at hashed location. */ X ret = NEW_1( id ); X slot = hash( sym_name, table ); X ADD( ret, *slot ); X X ret->var_name = sym_name; /* Link to name string from id. */ X ret->var_value = NULL; /* No value cell or fn ptr yet. */ X X return( ret ); X} X X/***************************************************************** X * TAG( find_symbol ) X */ Xid * /* Locator, NULL if not found. */ Xfind_symbol( sym_name, table ) Xstring sym_name; Xhash_table * table; X{ X register id * sym; /* Symbol list traversal ptr. */ X X /* Search list to which symbol hashes. */ X TRACE( sym, *hash( sym_name, table ) ) X { X /* Break out of search loop when matching name is found. */ X if ( strcmp( sym_name, sym->var_name ) == 0 ) break; X } /* sym is NULL if trace loop exits. */ X X return( sym ); X} X X/***************************************************************** X * TAG( new_hash_table ) X */ Xhash_table * /* Constructor. */ Xnew_hash_table( n_entries ) Xint n_entries; X{ X hash_table * ret; X id ** ent; /* Entries of table are bases of id lists. */ X int i; X X ret = NEW( hash_table, sizeof( hash_table ) + n_entries * sizeof( id * ) ); X X ret->hash_size = n_entries; /* Remember the size, for hash comp. */ X X for ( i = 0, ent = & ret->hash_id[0]; /* Clear the entries. */ X i < n_entries; X i++ ) X *ent++ = NULL; /* Empty list pointers. */ X X return( ret ); X} X X/***************************************************************** X * TAG( hash ) X */ Xid * * /* Hashing algorithm, returns ptr to base of an id list in table. */ Xhash( sym_name, table ) Xstring sym_name; Xhash_table * table; X{ X register char * c; X register int i, n, hash_val; X X /* Hash is the total of the character codes, modulo number of entries. */ X for ( i = 0, n = strlen( sym_name ), c = (char *)sym_name, hash_val = 0; X i < n; X i++ ) X hash_val += *c++; X X return( & table->hash_id[ hash_val % table->hash_size ] ); X} X X/***************************************************************** X * TAG( ld_table ) X * X * Links a vector of already initialiazed id's into a hash table. X * NULL var_name terminates the vector. X */ Xld_table( id_vec, table ) Xid id_vec[]; Xhash_table * table; X{ X id * sym; /* Vector traversal ptr. */ X id * * slot; X X for ( sym = & id_vec[0]; sym->var_name != NULL; sym++ ) X { X /* Link id node into symbol table at hashed location. */ X slot = hash( sym->var_name, table ); X ADD( sym, *slot ); X } X} X X/***************************************************************** X * TAG( fr_hash_table ) X * X * Dispose of a hash table. X */ Xfr_hash_table( table ) Xhash_table * table; X{ X id ** ent; /* Entries of table are bases of id lists. */ X id * ids; X int i; X X for ( i = 0, ent = & table->hash_id[0]; /* Clear the entries. */ X i < table->hash_size; X i++, ent++ ) X if ( ids = *ent ) X FREE_LIST( ids ); X X FREE( table ); X} X ________This_Is_The_END________ if test `wc -c < symtab.c` -ne 3411; then echo 'shar: symtab.c was damaged during transit (should have been 3411 bytes)' fi fi ; : end of overwriting check echo 'x - symtab.h' if test -f symtab.h; then echo 'shar: not overwriting symtab.h'; else sed 's/^X//' << '________This_Is_The_END________' > symtab.h X/* X * symtab.h - Declarations for using Symbol Table package. X * X * Author: Russ Fish X * Computer Science Dept. X * University of Utah X * Date: 28 August 1981 X */ X X/***************************************************************** X * TAG( symtab ) X * X * Simple symbol table package. Hash on name string gives buckets within X * hash table, which are bases of lists of id's, rather than reprobing X * within table. Multiple dictionaries are supported. X */ X#ifndef _SYM_TAB /* Only once. */ X#define _SYM_TAB X X#include "list.h" /* Needs list package. */ X X/***************************************************************** X * TAG( id ) X * X * id - Identifier datatype. X */ Xtypedef struct _id id; Xstruct _id X{ X TLISTLINKS(id); /* Linked lists within hash buckets. */ X string var_name; /* Character string name of id. */ X address var_value; /* Ptr to value of variable id. */ X}; X X/***************************************************************** X * TAG( new_symbol find_symbol ) X */ Xextern id * Xnew_symbol(); /* Constructor. */ X/* ( sym_name, table ) X * string sym_name; X * hash_table * table; X */ X Xextern id * Xfind_symbol(); /* Locator, NULL if not found. */ X/* ( sym_name, table ) X * string sym_name; X * hash_table * table; X */ X X/***************************************************************** X * TAG( hash_table new_hash_table hash ) X * X * Datatype for hash dictionaries. X */ Xtypedef struct X{ X int hash_size; /* Number of entries in table. */ X id * hash_id[1]; /* Base of id list on entry. */ X} Xhash_table; X Xextern hash_table * Xnew_hash_table(); /* Constructor, returns cleared table. */ X/* ( n_entries ) X * int n_entries; X */ X Xextern id * * Xhash(); /* Hashing algorithm, returns ptr to base of an id list in table. */ X/* ( sym_name, table ) X * string sym_name; X * hash_table * table; X */ X X/***************************************************************** X * TAG( ld_table ) X * X * Links a vector of already initialiazed id's into a hash table. X * NULL var_name terminates the vector. X */ Xextern Xld_table(); X/* ( id_vec, table ) X * id id_vec[]; X * hash_table * table; X */ X X/***************************************************************** X * TAG( fr_hash_table ) X * X * Dispose of a hash table. X */ Xextern Xfr_hash_table(); X/* ( table ) X * hash_table * table; X */ X X/* Macros to aid in initializing symbol vectors. */ X#define NULLS NULL,NULL X#define VAR_SYM(name_string,var_name) { NULLS, name_string,&var_name, NULL } X#define FN_SYM(name_string,fn_name) { NULLS, name_string, NULL, fn_name } X X#endif _SYM_TAB ________This_Is_The_END________ if test `wc -c < symtab.h` -ne 2547; then echo 'shar: symtab.h was damaged during transit (should have been 2547 bytes)' fi fi ; : end of overwriting check exit 0 ----------------------------------------------------------------------------- That's it. Hope you enjoy it. --- John Gordon Internet: gordon@osiris.cso.uiuc.edu #include <disclaimer.h> gordon@cerl.cecer.army.mil #include <clever_saying.h> GEnie: j.gordon14
chad@anasaz.UUCP (Chad R. Larson) (07/26/90)
davel@cbnewsl.att.com (David Loewenstern) writes +--------------- | I am looking for a program (or emacs macro) which will translate | C code into unreadable but functionally equivalent code. At minimum, | it must replace all variable names with cryptic names such as a1, i23, etc. | Ideally, it should also rename functions. +--------------- One was posted to comp.sources.misc volume 13 issue 68. -- Chad R. Larson ...{mcdphx,asuvax}!anasaz!chad or chad@anasaz.UUCP Anasazi, Inc. - 7500 North Dreamy Draw Drive, Suite 120, Phoenix, Az 85020 (602) 870-3330 "I read the news today, oh boy!" -- John Lennon