Skip to content

Instantly share code, notes, and snippets.

@pandada8
Created September 24, 2016 01:48
Show Gist options
  • Save pandada8/3f6bd6412b1b4c544058d236df72d204 to your computer and use it in GitHub Desktop.
Save pandada8/3f6bd6412b1b4c544058d236df72d204 to your computer and use it in GitHub Desktop.
preload in mac
#include <stdlib.h>
#include <stdio.h>
#include <time.h>

int main() {
	srand(time(NULL));
	int i = 10;
	while (i --) {
		printf("%d\n", rand() * 100);
	}
	return 0;
}

preload.c

int rand() {
	return 42;
}

to run

gcc random_num.c -o random_num
gcc -dynamiclib preload.c -o preload.dylib
DYLD_FORCE_FLAT_NAMESPACE=1 DYLD_INSERT_LIBRARIES=preload.dylib ./random_num
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment