lundi 18 décembre 2023

Restricted C Struct Randomizer

I am attempting to randomize members of a C struct with a few difficulties:

  1. The randomized struct may not be larger than the original one
  2. Each member has an alignment which has to be respected
  3. Members are of different sizes obviously
  4. Some members are fixed in place
  5. Members may not overlap with respect to their sizes
  6. Each member has a range in which it has to end up [min offset, max offset]

I freestyled a randomizer that respects properties 1 to 5. Also taking into account property 6 greatly complicates things. Is there an algorithm that does this kind of thing or could be abused to do it?

For context:

I have this struct representing the properties of a member of a C struct:

struct Member {
    uint32_t size;
    uint32_t offset;
    uint32_t alignment;
    uint32_t maxadd; // Max increase of offset
    uint32_t maxsub; // Max decrease of offset
};

My randomizer gets a list of objects of this struct, one object per member. It is supposed to find new, randomized offsets for each member, while not having any members overlap in the end and not translating a member by more than maxadd/maxsub.

I am not trying to randomize the strings in a struct definition. I am trying to randomize the memory layout itself. Because it is supposed to work on fully compiled binaries, the resulting layout may not consume more memory than the original struct (e.g. by translating a member by a million bytes). My randomizer also knows the size of the original struct.




Aucun commentaire:

Enregistrer un commentaire