#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Location
    Gloucester, Glos
    Posts
    9
    Rep 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:p--;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++]);

    }
  2. #2
  3. *bounce*
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2002
    Location
    Delft, The Netherlands
    Posts
    514
    Rep Power
    42
    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/
  4. #3
  5. No Profile Picture
    .
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Posts
    296
    Rep Power
    12
    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.

IMN logo majestic logo threadwatch logo seochat tools logo