Identified selfpatch randomizer issues
This commit is contained in:
parent
527db5ce1f
commit
b5cc83537d
@ -2,6 +2,7 @@
|
|||||||
#include "spslr_program.h"
|
#include "spslr_program.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
static void seed_rand_time() {
|
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) {
|
const struct ShuffleRegion* origin, uint32_t alignment) {
|
||||||
uint32_t count = 0;
|
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;
|
uint32_t current_field = 0;
|
||||||
for (uint32_t offset = 0; offset < target->size; offset += alignment) {
|
for (uint32_t offset = 0; offset < target->size; offset += alignment) {
|
||||||
// Placing the origin region here or further would exceed struct boundaries
|
// 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;
|
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,
|
static void target_swap(struct Target* target, uint32_t origin_idx, const struct ShuffleRegion* origin_region,
|
||||||
uint32_t new_offset) {
|
uint32_t new_offset) {
|
||||||
|
print_indices("Before swap:", target);
|
||||||
int origin_pulled = 0;
|
int origin_pulled = 0;
|
||||||
uint32_t origin_region_ptr = origin_region->begin;
|
uint32_t origin_region_ptr = origin_region->begin;
|
||||||
uint32_t option_fill_end = new_offset + (origin_region->fill_end - origin_region->fill_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];
|
struct Field tmp = target->fields[it];
|
||||||
|
|
||||||
for (uint32_t pull_it = it + 1; pull_it <= origin_idx; pull_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;
|
target->fields[origin_idx] = tmp;
|
||||||
}
|
}
|
||||||
|
print_indices("After swap:", target);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void target_shuffle_one(struct Target* target) {
|
static void target_shuffle_one(struct Target* target) {
|
||||||
@ -308,6 +326,12 @@ int spslr_randomize(uint32_t target) {
|
|||||||
ff->offset = f->offset;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user