473,382 Members | 1,369 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Obfuscated c using #include

Hi,
I know you shouldn't do this, but I just thought of a really nasty way to
obfuscate c code. I am however not sure if this is correct c at all. What
I did was this:

file obfuscate.c:
#include <stdio.h>

int main(int argc, char* argv[]){
#include "obfuscate.h"
}

file obfuscate.h:
printf("hello world\n");

I also tried some variations on this scheme, and my compiler accepted all
of them. But does it have to, or is this not valid c?

Till
--
Please add "Salt and Peper" to the subject line to bypass my spam filter

Nov 14 '05 #1
6 1756
Till Crueger <Ti****@gmx.net> wrote:
Hi,
I know you shouldn't do this, but I just thought of a really nasty way to
obfuscate c code. I am however not sure if this is correct c at all. What
I did was this: file obfuscate.c:
#include <stdio.h> int main(int argc, char* argv[]){
#include "obfuscate.h"
} file obfuscate.h:
printf("hello world\n"); I also tried some variations on this scheme, and my compiler accepted all
of them. But does it have to, or is this not valid c?

It is legal and sometimes useful to import source code from
another file. Traditionally, the source include file should still
have a '.c' extension.

i.e.

#ifdef IPV6
#include "ipv6code.c"
#else
#include "ipv4code.c"
#endif

--
Alex Monjushko (mo*******@hotmail.com)
Nov 14 '05 #2
Till Crueger wrote:
I know you shouldn't do this,
but I just thought of a really nasty way to obfuscate C code.
I am however not sure if this is correct C at all.
What I did was this:

//file obfuscate.c:
#include <stdio.h>

int main(int argc, char* argv[]){
#include "obfuscate.h" return 0; }

//file obfuscate.h:
printf("hello world\n");

I also tried some variations on this scheme,
and my compiler accepted all of them.
But does it have to?
Yes.
Or is this not valid C?


It *is* valid C.

Note that obfuscate.h is *not* a header file
because it in not included at the *head*
of your obfuscate.c source file.

It is perfectly OK to include code like this
but you should probably use a file extension
different from ".h" to avoid confusing other programmers
who may need to read, understand and maintain your code.
Nov 14 '05 #3

On Thu, 3 Jun 2004, Till Crueger wrote:

file obfuscate.c:
#include <stdio.h>

int main(int argc, char* argv[]){
#include "obfuscate.h"
}

file obfuscate.h:
printf("hello world\n");

I also tried some variations on this scheme, and my compiler accepted all
of them. But does it have to, or is this not valid c?


It has to. #include just includes some source text; it doesn't
care what it is. As others have pointed out, this is sometimes
even useful.
What is *not* generally useful, but *is* obfuscated a little bit,
is when a file #includes itself one or more times:

file obfuscate.c:
#ifdef FOO
puts("Hello world!");
#undef FOO
#define FOO return 0;}
#else
#include <stdio.h>
#define FOO {
int main(void)
FOO
#include "obfuscate.c"
FOO
#endif

-Arthur,
corrupting
Nov 14 '05 #4
Till Crueger wrote:
I know you shouldn't do this, but I just thought of a really nasty way to
Yes, you should do it! Be bold and push C to its limits;
figure out why things are the way they are. This is IMO
what could make the difference between being/becomming a
regular programmer and an expert.
obfuscate c code. I am however not sure if this is correct c at all. What
I did was this:

file obfuscate.c:
#include <stdio.h>

int main(int argc, char* argv[]){
#include "obfuscate.h"
}

file obfuscate.h:
printf("hello world\n");

I also tried some variations on this scheme, and my compiler accepted all
of them. But does it have to, or is this not valid c?


See the C preprocessor as a simple text-processor with a
limited set of #-operations. The #include simply and only
replaces itself by the literal contents of the named
file. Many compilers allow you to see the code that is
actually (i.e., after all text #-operations have been
replaced by code) using a command line option (some compiler
have -E). During preprocessing there is no notion of C
grammar/syntax. (So, you could (mis)use the C preprocessor
for other purposes.)

<OT>
An obfuscated program that does nice in this context is:

#include </dev/tty> /* /dev/tty is the 'command tool' device */

Which at least works on UNIX machines. When running the
compiler on this program, the compiler connects its input
to the command tool from which you just invoked the compiler.
So, you can start typing the actual program. When done, you
can close the input using ^D, and of the compiler goes finishing
it's job.
</OT>

Good luck!

Kees

Nov 14 '05 #5
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

In comp.lang.c, E. (E.**************@jpl.nasa.gov) wrote:
It is perfectly OK to include code like this
but you should probably use a file extension
different from ".h" to avoid confusing other programmers
who may need to read, understand and maintain your code.


I thought obfuscating code was made with the purpose of
confusing the next code maintainer.

Regards.

- --
My real e-mail address: chema (AT) chema.homelinux.org
http://EuropeSwPatentFree.hispalinux.es - EuropeSwPatentFree
I don't read HTML posts / No leo mensajes en HTML
Blog Overflow: http://chema.homelinux.org
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFAwNkw9P6GbSlI+hkRAjXuAJ40jnSiF6U5Y19JEQ7tGI NAvOGpygCgpn4X
EEtQymUGWtRFXLPa0ozCszs=
=xQ6D
-----END PGP SIGNATURE-----
Nov 14 '05 #6
On Thu, 3 Jun 2004 17:20:36 -0400 (EDT), "Arthur J. O'Dwyer"
<aj*@nospam.andrew.cmu.edu> wrote:

On Thu, 3 Jun 2004, Till Crueger wrote:

file obfuscate.c:
#include <stdio.h>

int main(int argc, char* argv[]){
#include "obfuscate.h"
}

file obfuscate.h:
printf("hello world\n");

I also tried some variations on this scheme, and my compiler accepted all
of them. But does it have to, or is this not valid c?


It has to. #include just includes some source text; it doesn't
care what it is. As others have pointed out, this is sometimes
even useful.
What is *not* generally useful, but *is* obfuscated a little bit,
is when a file #includes itself one or more times:

/* file obfuscate.c: */
#ifdef FOO
puts("Hello world!");
#undef FOO
#define FOO return 0;}
#else
#include <stdio.h>
#define FOO {
int main(void)
FOO
#include "obfuscate.c"
FOO
#endif
Nov 14 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: fix | last post by:
Hello, i need to protect my xsl file. In my xsl i have a mechanism for defining a personal stylesheet, what i want to do is, if it possible, find a mechanism for Obfuscated the xsl source code ....
1
by: Wibo | last post by:
Hello, we have a large application, that gave weird behavior. On W2K we're suffering from instable program ececution from time to time, untill now we managed to workaround these problems. On...
1
by: assaf | last post by:
hi all i am using PreEmptive Solutions dotfuscator (community edition). and i am getting 'TypeLoadException' for a simple interface that i defined. how can i debug an obfuscated application? ...
0
by: Steve Covert | last post by:
Has anyone encountered problems with building an installer for a Windows app using Wise? In my case, the installation fails due an obfuscated dll. Instructions are provided for remedying this from...
7
by: tgh003 | last post by:
I would be interested to hear how others are managing their javascript (.js) files from the original code vs the obfuscated version they publish to their site/webapp. I currently manage 2 files,...
4
by: Paul E Collins | last post by:
For those who appreciate such things, here's a bit of obfuscated C# I knocked up in a spare moment at work. http://CL4.org/comp/jabberwocky.txt P. -- www.CL4.org
35
by: +-={K-SoL}=-+ | last post by:
when I try to reference 2 obfuscated libraries at the same time visual studio gives me a compilation error since the obfuscator has converted some name spaces to a and b in both libraries, now I...
4
by: Bry | last post by:
I'm trying Obfuscation for the first time using the community edition of dotfuscator that ships with vs .net 2005. After building my code, I load the compiled .exe into dotfuscator and let it...
3
by: c.lang.myself | last post by:
I just came across following obfuscated code which prints map of a asian country India...... Can any body help me in understanding what is happening in this program..........
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.