diff --git a/xzre.h b/xzre.h index 3634122..7e231d8 100644 --- a/xzre.h +++ b/xzre.h @@ -2859,24 +2859,23 @@ extern void * backdoor_init(elf_entry_ctx_t *state, u64 *caller_frame); * * stores the address of the symbol cpuid_random_symbol in elf_entry_ctx_t::symbol_ptr * stores the return address of the function that called the IFUNC resolver which is a stack address in ld.so - * calls get_got_offset() to update elf_entry_ctx_t::got_offset - * calls get_cpuid_got_index() to update elf_entry_ctx_t::cpuid_fn + * calls update_got_offset() to update elf_entry_ctx_t::got_offset + * calls get_cpuid_got_index() to update @ref elf_entry_ctx_t.got_ctx.cpuid_fn * * @param ctx */ extern void init_elf_entry_ctx(elf_entry_ctx_t *ctx); /** - * @brief get the offset to the GOT + * @brief updates the offset to the GOT * - * the offset is relative to the address of the symbol cpuid_random_symbol - * - * stores the offset in elf_entry_ctx_t::got_offset + * the offset is the distance to the GOT relative to the address of the symbol cpuid_random_symbol + * this value is stored in @ref elf_entry_ctx_t.got_ctx.got_offset * * @param ctx - * @return ptrdiff_t offset to GOT from the symbol cpuid_random_symbol + * @return ptrdiff_t */ -extern ptrdiff_t get_got_offset(elf_entry_ctx_t *ctx); +extern void update_got_offset(elf_entry_ctx_t *ctx); /** * @brief get the cpuid() GOT index @@ -3940,7 +3939,7 @@ static_assert(sizeof(tls_get_addr_random_symbol) == 0x8); * * liblzma_la-crc64-fast.o lists the fields in the relocation table so that the linker fills out the fields with the offsets * - * used by call_backdoor_init_stage2(), get_got_offset() and get_cpuid_got_index() + * used by call_backdoor_init_stage2(), update_got_offset() and get_cpuid_got_index() * */ extern const backdoor_cpuid_reloc_consts_t cpuid_reloc_consts; diff --git a/xzre.lds.in b/xzre.lds.in index d0058ab..a309d5e 100644 --- a/xzre.lds.in +++ b/xzre.lds.in @@ -91,7 +91,7 @@ SECTIONS_BEGIN() /* 0000000000003F50 */ DEFSYM(get_cpuid_got_index, .text.lzma_stream_decoder_inia) /* 0000000000003F70 */ DEFSYM(get_tls_get_addr_random_symbol_got_offset, .text.lzma_stream_flags_compara) /* 0000000000003F90 */ DEFSYM(update_got_address, .text.lzma_stream_header_encoda) - /* 0000000000004000 */ DEFSYM(get_got_offset, .text.parse_delt1) + /* 0000000000004000 */ DEFSYM(update_got_offset, .text.parse_delt1) /* 0000000000004020 */ DEFSYM(init_elf_entry_ctx, .text.read_output_and_waia) /* 0000000000004050 */ DEFSYM(get_lzma_allocator, .text.stream_decoder_memconfia) /* 0000000000004070 */ DEFSYM(find_link_map_l_name, .text.lzma_delta_props_encoda) diff --git a/xzre_code/CMakeLists.txt b/xzre_code/CMakeLists.txt index 09cbb24..343a279 100644 --- a/xzre_code/CMakeLists.txt +++ b/xzre_code/CMakeLists.txt @@ -20,6 +20,7 @@ add_library(xzre_code secret_data_get_decrypted.c sha256.c sshd_patch_variables.c + update_got_offset.c ) target_compile_options(xzre_code PRIVATE -Os -fomit-frame-pointer diff --git a/xzre_code/init_elf_entry_ctx.c b/xzre_code/init_elf_entry_ctx.c index 98cdb7f..bd01121 100644 --- a/xzre_code/init_elf_entry_ctx.c +++ b/xzre_code/init_elf_entry_ctx.c @@ -6,7 +6,7 @@ void init_elf_entry_ctx(elf_entry_ctx_t *ctx){ ctx->symbol_ptr = (void *)&cpuid_random_symbol; ctx->got_ctx.return_address = (void *)ctx->frame_address[3]; - get_got_offset(ctx); + update_got_offset(ctx); get_cpuid_got_index(ctx); ctx->got_ctx.got_ptr = NULL; } diff --git a/xzre_code/update_got_offset.c b/xzre_code/update_got_offset.c new file mode 100644 index 0000000..66358ed --- /dev/null +++ b/xzre_code/update_got_offset.c @@ -0,0 +1,8 @@ +/** + * Copyright (C) 2024 Stefano Moioli + **/ +#include "xzre.h" + +void update_got_offset(elf_entry_ctx_t *ctx){ + ctx->got_ctx.got_offset = cpuid_reloc_consts.cpuid_random_symbol_got_offset; +}