aboutsummaryrefslogtreecommitdiff
path: root/test/test-substrate.cpp
blob: 9cf50e845f04c6dfb7c592f9976a857f3177c766 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <substrate.h>
#include <stdio.h>
#include <assert.h>
#include <dlfcn.h>
#include <time.h>

int main() {
	const char *foundation = "/System/Library/Frameworks/Foundation.framework/Foundation";
	dlopen(foundation, RTLD_LAZY);

    MSImageRef im = MSGetImageByName(foundation);
	assert(im);

    int (*f)(int);
    clock_t a = clock();
    MSHookSymbol(f, "_absolute_from_gregorian", im);
    clock_t b = clock();
    printf("init: %ld\n", (long) (b - a));
    a = clock();
    MSHookSymbol(f, "_absolute_from_gregorian", im);
    b = clock();
    printf("spec: %ld\n", (long) (b - a));
	assert(f(12345) < 0);
    a = clock();
    MSHookSymbol(f, "_absolute_from_gregorian");
    b = clock();
    printf("gen: %ld\n", (long) (b - a));
	assert(f(12345) < 0);
}