diff --git a/pinpoint/final/on_finish_unit.cpp b/pinpoint/final/on_finish_unit.cpp index b01144f..c408673 100644 --- a/pinpoint/final/on_finish_unit.cpp +++ b/pinpoint/final/on_finish_unit.cpp @@ -112,11 +112,7 @@ void on_finish_unit(void* plugin_data, void* user_data) { std::filesystem::path infile = relative_src_path(); std::filesystem::path outfile = spslr_output_file(infile); - std::cout << "Finishing unit " << infile << " ..." << std::endl; - std::cout << " Dumping SPSLR data accumulation to " << outfile << std::endl; - std::string cu_uid = calculate_cu_uid(infile); - std::cout << " Unit UID is 0x" << cu_uid << std::endl; emit_cu_uid_label(cu_uid); diff --git a/selfpatch/CMakeLists.txt b/selfpatch/CMakeLists.txt index 3bfe872..51ec1cf 100644 --- a/selfpatch/CMakeLists.txt +++ b/selfpatch/CMakeLists.txt @@ -1,4 +1,4 @@ -add_library(spslr_selfpatch STATIC src/selfpatch.c) +add_library(spslr_selfpatch STATIC src/selfpatch.c src/targets.c src/patcher.c) target_include_directories(spslr_selfpatch PUBLIC $ diff --git a/selfpatch/src/patcher.c b/selfpatch/src/patcher.c new file mode 100644 index 0000000..e8e952a --- /dev/null +++ b/selfpatch/src/patcher.c @@ -0,0 +1,16 @@ +#include "patcher.h" + +// TODO + +int spslr_mprot(void* base, uint32_t pagecnt, uint8_t perm) { + return 0; +} + +int spslr_ipatch(void* ptr, uint32_t target, uint32_t field) { + return 0; +} + +int spslr_dpatch(void* ptr, uint32_t target) { + return 0; +} + diff --git a/selfpatch/src/patcher.h b/selfpatch/src/patcher.h new file mode 100644 index 0000000..27c8b28 --- /dev/null +++ b/selfpatch/src/patcher.h @@ -0,0 +1,10 @@ +#ifndef SPSLR_PATCHER_H +#define SPSLR_PATCHER_H + +#include + +int spslr_mprot(void* base, uint32_t pagecnt, uint8_t perm); +int spslr_ipatch(void* ptr, uint32_t target, uint32_t field); +int spslr_dpatch(void* ptr, uint32_t target); + +#endif diff --git a/selfpatch/src/selfpatch.c b/selfpatch/src/selfpatch.c index 2aa307c..f6a0bd0 100644 --- a/selfpatch/src/selfpatch.c +++ b/selfpatch/src/selfpatch.c @@ -2,17 +2,12 @@ #include #include -#include - -// TODO -static int spslr_target(uint32_t uid, uint32_t size, uint32_t fieldcnt) { return 0; } -static int spslr_field(uint32_t offset, uint32_t size, uint32_t flags) { return 0; } -static int spslr_randomize(uint32_t target) { return 0; } -static int spslr_mprot(void* base, uint32_t pagecnt, uint8_t perm) { return 0; } -static int spslr_ipatch(void* ptr, uint32_t target, uint32_t field) { return 0; } -static int spslr_dpatch(void* ptr, uint32_t target) { return 0; } +#include "spslr_program.h" +#include "targets.h" +#include "patcher.h" /* +TODO Postprocessing tool patches the value of __spslr_program to point to the SPSLR program section. With ASLR, there are 2 options to make it function correctly: 1. Make sure __spslr_program is relocated with program image shift (preferred) @@ -30,6 +25,7 @@ static int spslr_do(const struct SPSLR_INST* inst) { return -1; static uint32_t pending_fields = 0; + static uint32_t pending_fields_target = 0; if (pending_fields) { if (inst->opcode != SPSLR_FIELD) { @@ -38,14 +34,18 @@ static int spslr_do(const struct SPSLR_INST* inst) { } pending_fields--; + } else if (inst->opcode == SPSLR_FIELD) { + fprintf(stderr, "spslr_do encountered field instruction where none was expected\n"); + return -1; } switch (inst->opcode) { case SPSLR_TARGET: pending_fields = inst->op2.target_fieldcnt; + pending_fields_target = inst->op0.target_uid; return spslr_target(inst->op0.target_uid, inst->op1.target_size, inst->op2.target_fieldcnt); case SPSLR_FIELD: - return spslr_field(inst->op0.field_offset, inst->op1.field_size, inst->op2.field_flags); + return spslr_field(pending_fields_target, inst->op0.field_offset, inst->op1.field_size, inst->op2.field_flags); case SPSLR_RANDOMIZE: return spslr_randomize(inst->op0.randomize_target); case SPSLR_MPROT: diff --git a/selfpatch/include/spslr_program.h b/selfpatch/src/spslr_program.h similarity index 100% rename from selfpatch/include/spslr_program.h rename to selfpatch/src/spslr_program.h diff --git a/selfpatch/src/targets.c b/selfpatch/src/targets.c new file mode 100644 index 0000000..6e761dd --- /dev/null +++ b/selfpatch/src/targets.c @@ -0,0 +1,16 @@ +#include "targets.h" + +// TODO + +int spslr_target(uint32_t uid, uint32_t size, uint32_t fieldcnt) { + return 0; +} + +int spslr_field(uint32_t target, uint32_t offset, uint32_t size, uint32_t flags) { + return 0; +} + +int spslr_randomize(uint32_t target) { + return 0; +} + diff --git a/selfpatch/src/targets.h b/selfpatch/src/targets.h new file mode 100644 index 0000000..6cef7bc --- /dev/null +++ b/selfpatch/src/targets.h @@ -0,0 +1,10 @@ +#ifndef SPSLR_TARGETS_H +#define SPSLR_TARGETS_H + +#include + +int spslr_target(uint32_t uid, uint32_t size, uint32_t fieldcnt); +int spslr_field(uint32_t target, uint32_t offset, uint32_t size, uint32_t flags); +int spslr_randomize(uint32_t target); + +#endif