diff --git a/selfpatch/src/targets.c b/selfpatch/src/targets.c index d0bd662..b6126bb 100644 --- a/selfpatch/src/targets.c +++ b/selfpatch/src/targets.c @@ -2,6 +2,7 @@ #include "spslr_program.h" #include +#include #include static void seed_rand_time() { @@ -160,6 +161,13 @@ static uint32_t target_get_shuffle_options(const struct Target* target, uint32_t const struct ShuffleRegion* origin, uint32_t alignment) { uint32_t count = 0; + /* + TODO + Self overlap... + 1. Can skip swap check for origin field + 2. Origin field can however reduce one side of the origin region if it still overlaps + */ + uint32_t current_field = 0; for (uint32_t offset = 0; offset < target->size; offset += alignment) { // Placing the origin region here or further would exceed struct boundaries @@ -203,8 +211,17 @@ static uint32_t target_get_shuffle_options(const struct Target* target, uint32_t return count; } +static void print_indices(const char* txt, const struct Target* target) { + // TODO + printf("%s\n", txt); + for (uint32_t i = 0; i < target->field_count; i++) { + printf(" %u\n", target->fields[i].initial_idx); + } +} + static void target_swap(struct Target* target, uint32_t origin_idx, const struct ShuffleRegion* origin_region, uint32_t new_offset) { + print_indices("Before swap:", target); int origin_pulled = 0; uint32_t origin_region_ptr = origin_region->begin; uint32_t option_fill_end = new_offset + (origin_region->fill_end - origin_region->fill_begin); @@ -243,10 +260,11 @@ static void target_swap(struct Target* target, uint32_t origin_idx, const struct struct Field tmp = target->fields[it]; for (uint32_t pull_it = it + 1; pull_it <= origin_idx; pull_it++) - target->fields[it - 1] = target->fields[it]; + target->fields[pull_it - 1] = target->fields[pull_it]; target->fields[origin_idx] = tmp; } + print_indices("After swap:", target); } static void target_shuffle_one(struct Target* target) { @@ -308,6 +326,12 @@ int spslr_randomize(uint32_t target) { ff->offset = f->offset; } + printf("Randomization of target %u...\n", target); + for (uint32_t i = 0; i < t->field_count; i++) { + const struct FinalField* ff = &t->final_fields[i]; + printf(" Field %u: %u -> %u\n", i, ff->initial_offset, ff->offset); + } + return 0; }