Can we change the order of declaration to C or C ++?

Is there a method / plugin / addon to ignore the following sentence (for some c / C ++ compiler)? Change the order of declaring members in a structure at the same stage as a preprocessor or similar? Perhaps adding a keyword like volatile or something similar to the beginning of a structure declaration.

I thought: a compiler option, an inline keyword, or a programming method.

C99 §6.7.2.1 Clause 13:

Inside an object are structures of members that are not bit fields, and units in which there are bit fields, addresses that increase the order in which they are declared.

C ++ seems to have a similar article, and that interests me too. These sentences indicate a reasonable function that, in terms of later declarations, has a larger memory bias. But I often do not need to know the declaration order of my structure for interface purposes or any other. It would be nice to write code like:

scrambled struct foo {
    int a;
    int bar;
};

or, suppose the order does not matter for this structure.

scrambled struct foo {
    int bar;
    int a;
};

So, declare aand bdeclare randomly every time you compile. I believe this also applies to undoing stack memory.

main() {
    scrambled int a;
    scrambled int foo;
    scrambled int bar;
    ..

Why am I asking?

I was curious to see how the program bots were created. I watched as some people analyzed memory offsets for changes during the launch of a program for which a hack would be created.

, : . .

, , . , , , , .

+4
2

, . a struct , . 1. int

#define foo 0
#define bar 1
#define zee 2

struct abc {
    int scramble [3];
};

...
value = abc.scramble[bar];

2, , , .

int abcindex [3];               // index lookup 
int abcpool  [3];               // index pool for randomise

for (i=0; i<3; i++)             // initialise index pool
    abcpool[i] = i;

srand (time(NULL));
for (i=0; i<3; i++) {           // initialise lookup array
    j = rand()%(3-i);
    abcindex[i] = abcpool[j];   // allocate random index from pool
    abcpool[j] = abcpool[2-i];  // remove index from pool
    }

value = abc.scramble[abcindex[bar]];

, , , - , , . , - , , .

+1

, (). . . , ASLR. , " " " libc, ".

0

All Articles