Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Variable declaration between function name and first curly brace

Tags:

I am reading an article about code obfuscation in C, and one of the examples declares the main function as:

int main(c,v) char *v; int c;{...}

I've never saw something like this, v and c are global variables?

The full example is this:

#include <stdio.h>

#define THIS printf(
#define IS "%s\n"
#define OBFUSCATION ,v);

int main(c, v) char *v; int c; {
   int a = 0; char f[32];
   switch (c) {
      case 0:
         THIS IS OBFUSCATION
         break;
      case 34123:
         for (a = 0; a < 13; a++) { f[a] = v[a*2+1];};
         main(0,f);
         break;
      default:
         main(34123,"@h3eglhl1o. >w%o#rtlwdl!S\0m");
         break;
      }
}

The article: brandonparker.net (No longer works), but can be found in web.archive.org

like image 562
Alejandro Alcalde Avatar asked Dec 09 '12 16:12

Alejandro Alcalde


People also ask

What is the use of curly brackets in the `Var { …} = …`?

- GeeksforGeeks What is the use of curly brackets in the `var { … } = …` statements ? Destructuring assignment allows us to assign the properties of an array or object to a bunch of variables that are sometimes very convenient and short.

What are curly brackets used for in JavaScript?

Note: Curly brackets ‘ { }’ are used to destructure the JavaScript Object properties. If we want the variables defined in the object should be assigned to the variables with other names then we can set it using a colon.

What is the variable declaration in C?

The variable declaration indicates that the operating system is going to reserve a piece of memory with that variable name. The syntax for variable declaration is as follows − Here, a, b, c, d are variables. The int, float, double are the data types.

What is the syntax for variable initialization in C?

The syntax for variable initialization is as follows − A variable assignment is a process of assigning a value to a variable. A variable may be alphabets, digits, and underscore. A variable name can start with an alphabet, and an underscore but, can’t start with a digit.


1 Answers

It's the old style function definition

void foo(a,b)
int a;
float b;
{
// body
}

is same as

void foo(int a, float b)
{
// body
}

Your case is same as int main(int c,char *v){...} But it's not correct.

The correct syntax is : int main(int c, char **v){...}

Or, int main(int c, char *v[]){...}

EDIT : Remember in main() , v should be char** not the char* as you have written.

I think it's K & R C style.

like image 157
Omkant Avatar answered Oct 05 '22 19:10

Omkant