C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 26th, 2003, 05:12 AM
djwilliams37 djwilliams37 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Gloucester, Glos
Posts: 9 djwilliams37 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
recursive Macros

does anyone know how to decifer this macro, I know what it basically does but want to convert it to a standard function. The code is from Deep Sea secrets and is a BASIC interpreter from the Ofuscated code copetition. The macro O() is called by means of its
b parameter. It looks like some deep nested recursion is going on here. Any one got any ideas.
Thanks
Dave.

define O(b,f,u,s,c,a)b(){\
int o=f();\
switch(*p++){\
case u:return o s b();\
case c :return o a b()\
default--;return o;}\
}


//Macro calls
O(S,J,'=',==,'#',!=);
O(J,K,'<',<,'>',>);
O(K,V,'$',<=,'!',>=);
O(V,W,'+',+,'-',-);
O(W,Y,'*',*,'/',/)Y()
{

int o;

return(*p=='-')? (p++,-Y()) //recursive call of Y() here
*p>='0'&&*p<='9')? (strtol(p,&p,0))
: (*p=='(')?(p++,o=S(),p++,o): (P[*p++]);

}

Reply With Quote
  #2  
Old June 26th, 2003, 07:32 AM
Analyser's Avatar
Analyser Analyser is offline
*bounce*
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2002
Location: Delft, The Netherlands
Posts: 510 Analyser User rank is Corporal (100 - 500 Reputation Level)Analyser User rank is Corporal (100 - 500 Reputation Level)Analyser User rank is Corporal (100 - 500 Reputation Level)Analyser User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Days 20 h 44 m 4 sec
Reputation Power: 9
Send a message via ICQ to Analyser
Try running it through the preprocessor only. If you're using GCC, something like the following may do the trick:

Code:
gcc -E obfuscated.c > nomacros.c


With obfuscated.c being the source you just posted, and nomacros.c being the file containing the "de-obfuscated" code.

Good luck
__________________
"A poor programmer is he who blames his tools."
http://analyser.oli.tudelft.nl/

Reply With Quote
  #3  
Old June 26th, 2003, 09:15 AM
balance balance is offline
.
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 296 balance User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
i just got hold of some obfuscated code. it draws a maze. what gets me is that there's a rand in there but the maze, i think, is the same every time - seems a bit strange.

here it is with some returns and tabs in (it was one big block) :

Code:
#define P(X)j=write(1,X,1)
#define C 39

int M[5000] = {2}, *u = M, N[5000], R = 22, a[4], l[] = {0,-1,C-1,-1}, m[] = {1,-C,-1,C}, *b = N, *d = N, c, e, f, g, i, j, k, s;

main()
{
	for(M[i = C*R - 1] = 24; f|d >= b; ) {
		c = M[g = i];
		i = e;
		for( s=f=0; s < 4; s++)
			if((k = m[s] + g) >= 0 && k < C *R && l [s] != k % C && (!M[k] || !j && c >= 16 != M[k] >= 16))
				a[f++] = s;
				if(f) {
					f = M[e = m[s = a[rand() / (1 + 2147483647 / f)]] + g];
					j = j < f ? f : j;
					f += c & -16 * !j;
					M[g] = c | 1 << s;
					M[*d++ = e] = f | 1 << (s + 2) % 4;
				} else
					e = d > b++ ? b[-1] : e;
			}
		P(" ");
		for(s = C; --s; P("_")) P(" ")
			;
		for( ; P("\n"), R--; P("|"))
			for(e = C; e--; P("_ "+(*u++ / 8) % 2)) P("| "+(*u/4) % 2)
				;
}

Code:
  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
|_   _ _|     |_  |_ _ _  |  _  |  _  |   |  _ _ _  |_ _ _ _ _ _   _ _ _|  _  |
|  _ _ _ _| |_ _ _|  _ _ _ _|_ _|_  |_ _|_ _|_    |_ _  | |  _ _ _ _ _  | |  _|
|   |  _  |  _ _  | |_ _   _|  _  | |  _   _ _ _| | |   |_ _|   |_    |_ _| | |
| |_ _|   |  _  |_ _|  _ _  |_  | | | |   |_ _   _|_ _|_ _|  _|_  | |_  |  _| |
|_ _ _| | | |  _ _ _ _|_  | |  _|_  |_| |_|   | |   |  _  | |_ _ _|_ _| | |   |
|   |  _|_| | |    _ _ _ _|_| |  _ _|   |  _| | | |_ _| |_ _|  _ _  |  _|_ _| |
| |_ _|_ _ _| | |_ _ _  |  _ _| | |  _|_| |_ _|_  |   |   |_ _ _  | |_ _ _    |
| |  _  |  _ _| |   |_ _|_ _ _| |_ _|_  | |  _ _  | | | |_|  _|  _|_ _ _ _  | |
| |_  |_  |   |_ _|_ _   _ _|  _|   |  _| | |   |_| | |_  | |  _|  _ _ _  | | |
| |  _| | | |_ _ _ _ _ _|  _ _|_ _| | | |  _| |_ _ _|_    | |_ _|_ _|  _ _| | |
| |   |_ _|  _|  _ _  |  _|   |  _ _|  _ _|  _|  _   _ _| |  _  |  _ _| |  _| |
| | |_ _ _ _ _ _|_  |_ _| | | | |   | |_  |_ _| |  _| |  _| | | | |    _| |  _|
| |_  |  _ _   _  |  _  |_ _| |_ _| |_  |_ _ _ _| |  _|_  | | |_ _| |_ _ _|_  |
| |_ _| |  _ _ _| |   |_ _ _  |  _ _| |_  |  _ _ _| | |  _| | |   | | | |   | |
|    _ _|_  |   | |_|_ _  | | |  _ _  | | |_ _  |  _|  _|  _| | |_|  _| | |_ _|
| | |_  | |   | |_  |   |_ _| | |_  | |  _|  _  |_  | |_  |  _ _|  _ _ _|_ _ _|
| |_ _ _| |_| |_  |_ _|_ _ _| | |  _| | |   |_ _|  _|_  | | |  _ _|  _   _ _  |
|    _  |_  |_  |     |  _ _   _| |  _| | | |   |_ _   _|   |_ _  | |   | |  _|
| |_  |   | |_ _| | |  _|   |_ _  |_ _ _| | | |_ _  | |   |_  |   |_|_|_ _|_  |
|_  |_| | |_  | | | |_ _ _| |  _ _ _ _  | |_|_ _ _| |_ _|_  | | | |     |  _| |
| |_  | |_ _|_  | | |   |_ _|_|   |_  | |_  |  _ _ _ _ _ _ _|_ _| |_| | |    _|
|_ _ _|_ _ _ _ _|_|_ _|_ _ _ _ _|_ _ _|_ _ _|_ _ _ _ _ _ _ _ _ _|_ _ _|_ _|_  |

god knows how it works really. i haven't tried that pre-processor thing on it though. will do though.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > recursive Macros


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway