selfpatch instruction dispatcher
This commit is contained in:
parent
10e56ffd47
commit
98e91d875e
@ -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);
|
||||
|
||||
|
||||
@ -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
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
|
||||
16
selfpatch/src/patcher.c
Normal file
16
selfpatch/src/patcher.c
Normal file
@ -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;
|
||||
}
|
||||
|
||||
10
selfpatch/src/patcher.h
Normal file
10
selfpatch/src/patcher.h
Normal file
@ -0,0 +1,10 @@
|
||||
#ifndef SPSLR_PATCHER_H
|
||||
#define SPSLR_PATCHER_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
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
|
||||
@ -2,17 +2,12 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <spslr_program.h>
|
||||
|
||||
// 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:
|
||||
|
||||
16
selfpatch/src/targets.c
Normal file
16
selfpatch/src/targets.c
Normal file
@ -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;
|
||||
}
|
||||
|
||||
10
selfpatch/src/targets.h
Normal file
10
selfpatch/src/targets.h
Normal file
@ -0,0 +1,10 @@
|
||||
#ifndef SPSLR_TARGETS_H
|
||||
#define SPSLR_TARGETS_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
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
|
||||
Loading…
Reference in New Issue
Block a user