Skip to content

Commit

Permalink
xzre_code: add count_pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
smx-smx committed Aug 3, 2024
1 parent 6a0619f commit eab7ebb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions xzre_code/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
22 changes: 22 additions & 0 deletions xzre_code/count_pointers.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Copyright (C) 2024 Stefano Moioli <[email protected]>
**/
#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;
}

0 comments on commit eab7ebb

Please sign in to comment.