Finalizer__spslr_program pointer patch
This commit is contained in:
parent
9c1769549c
commit
527db5ce1f
@ -178,7 +178,26 @@ int main(int argc, char** argv) {
|
||||
bin->add(new_seg);
|
||||
|
||||
// Set __spslr_program to (new_vaddr - &__spslr_program)
|
||||
// TODO
|
||||
for (Segment& seg : bin->segments()) {
|
||||
uint64_t start = seg.virtual_address();
|
||||
uint64_t end_mem = start + seg.virtual_size();
|
||||
|
||||
if (spslr_program_ptr_address >= start && spslr_program_ptr_address < end_mem) {
|
||||
uint64_t offset_within_seg = spslr_program_ptr_address - start;
|
||||
uint64_t min_needed = offset_within_seg + sizeof(uint64_t);
|
||||
|
||||
if (min_needed > seg.physical_size())
|
||||
seg.physical_size(min_needed);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t relative_new_vaddr = new_vaddr - spslr_program_ptr_address;
|
||||
std::vector<uint8_t> program_ptr_bytes;
|
||||
program_ptr_bytes.resize(8);
|
||||
std::memcpy(program_ptr_bytes.data(), &relative_new_vaddr, 8);
|
||||
bin->patch_address(spslr_program_ptr_address, program_ptr_bytes);
|
||||
|
||||
// Output final program
|
||||
Builder builder{ *bin };
|
||||
|
||||
@ -6,13 +6,6 @@
|
||||
#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)
|
||||
2. __spslr_program = spslr_ptr_absolute((uint64_t)__spslr_program) and postprocessor inserts relative value (kinda weird)
|
||||
*/
|
||||
const uint8_t* __spslr_program = NULL;
|
||||
|
||||
static void* spslr_ptr_absolute(uint64_t relative) {
|
||||
@ -20,6 +13,12 @@ static void* spslr_ptr_absolute(uint64_t relative) {
|
||||
return ((uint8_t*)&__spslr_program) + relative;
|
||||
}
|
||||
|
||||
static void spslr_init_program_ptr() {
|
||||
// Finalizer patches __spslr_program to be the relative offset from &__spslr_program to the program
|
||||
uint64_t relative = (uint64_t)__spslr_program;
|
||||
__spslr_program = (const uint8_t*)spslr_ptr_absolute(relative);
|
||||
}
|
||||
|
||||
static int spslr_do(const struct SPSLR_INST* inst) {
|
||||
if (!inst)
|
||||
return -1;
|
||||
@ -65,6 +64,8 @@ void spslr_selfpatch() {
|
||||
return;
|
||||
}
|
||||
|
||||
spslr_init_program_ptr();
|
||||
|
||||
int sz;
|
||||
struct SPSLR_INST inst;
|
||||
while ((sz = spslr_inst_load(&inst, __spslr_program)) > 0) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user