diff --git a/xzre_code/CMakeLists.txt b/xzre_code/CMakeLists.txt index 6efc00a..cdf97e3 100644 --- a/xzre_code/CMakeLists.txt +++ b/xzre_code/CMakeLists.txt @@ -1,6 +1,7 @@ add_library(xzre_code backdoor_entry.c chacha_decrypt.c + count_pointers.c elf_parse.c elf_symbol_get_addr.c get_lzma_allocator.c diff --git a/xzre_code/count_pointers.c b/xzre_code/count_pointers.c new file mode 100644 index 0000000..080b267 --- /dev/null +++ b/xzre_code/count_pointers.c @@ -0,0 +1,22 @@ +/** + * Copyright (C) 2024 Stefano Moioli + **/ +#include "xzre.h" + +BOOL count_pointers( + void **ptrs, + u64 *count_out, + libc_imports_t *funcs +){ + if(!ptrs) return FALSE; + if(!funcs) return FALSE; + if(!funcs->malloc_usable_size) return FALSE; + size_t blockSize = funcs->malloc_usable_size(ptrs); + if(blockSize - 8 > 127) return FALSE; + size_t nWords = blockSize >> 3; + + size_t i; + for(i=0; i < nWords && ptrs[i]; ++i); + *count_out = i; + return TRUE; +} \ No newline at end of file