Last active
September 21, 2023 18:38
-
-
Save 0xilis/bdd684bbda71c4ca94707dc98a6ec6dc to your computer and use it in GitHub Desktop.
shit code (hook_free for auto =NULL, macOS 12.6)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#define CHECK_OFFSET 1 | |
/* Dunno how this works but it does? (At least it seems to on macOS 12.6 :P */ | |
void hook_free(void *pointer) { | |
free(pointer); | |
void **pointerToArg = &pointer; | |
pointerToArg += 1; | |
#if CHECK_OFFSET | |
/* | |
* TODO: How TF does this work? | |
* For cases when the orig pointer of the arg passed into the function is more than 1 above, we loop through each pointer above to check for a value that points to the same memory in the heap. | |
* However, this is *BAD*! First off, obviously bad on performance, cycling through can be quite intensive, and factor in that this will be run every free()... yeah this is not great. PLUS, this opens us up to potential issues in which there are two variables that point to the same address in memory that we freed, and detect the wrong variable and NULL the wrong pointer. | |
* But?? I can't get this to happen???? | |
*/ | |
/* check that pointerToArg points to the same address as the arg */ | |
while (*pointerToArg != pointer) { | |
if (pointerToArg >= 0x7fffffffffff) { | |
printf("EMERGENCY STOP, could not find ptr, not setting NULL...\n"); | |
return; | |
} | |
pointerToArg += 1; | |
} | |
#endif | |
*pointerToArg = NULL; | |
pointerToArg = NULL; | |
pointer = NULL; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment