lundi 17 juin 2019

Randomize a #define at program start

I have an application which has a strict separation between user and the backend. The only way the user can interact with my backend is via one function. To specify what the user wants the first argument of this fucntion is the instruction the user wants the backend to execute (for example getData). This looks something like this

backendcall(getData, arg1, arg2, arg3, arg4)

The names of the services that my backend provides are saved in a .h file (called definitions.h). This file only contains #defines.

#define getData 1
#define setData 2
...

This way the user it is easier for the user. For security reasons I would like to randomize the value of the #defines at the start.

I am aware that it is possible to call functions in a define like this #define var foo()

My problem is that this does not work for me since I can not use a function to define the random value. Even if I add an integer like this

int asdfqweryxcv = 20;

I get an error message on compilation that this value has multiple definitions. I can change the name to whatever I want the result is always the same.

The Error message looks like this:

../../lib.a(userfile1.c.o):/home/../../../definitions.h:8: multiple definition ofasdfqweryxcv' CMakeFiles/mult.c.o:/home/../../../definitions.h:8: first defined here

../../lib.a(userfile2.c.o):/home/../../../definitions.h:8: multiple definition of `asdfqweryxcv' CMakeFiles/mult.c.o:/home/../../../definitions.h:8: first defined here

... ...`

I would like to randomize these defines and have a unique number for every define.




Aucun commentaire:

Enregistrer un commentaire