6 @interface One : TestRoot @end
7 @implementation One @end
9 @interface Two : TestRoot @end
10 @implementation Two @end
12 @interface Both : TestRoot @end
13 @implementation Both @end
15 @interface None : TestRoot @end
16 @implementation None @end
19 objc_hook_getImageName OnePreviousHook;
20 BOOL GetImageNameHookOne(Class cls, const char **outName)
22 if (0 == strcmp(class_getName(cls), "One")) {
23 *outName = "Image One";
25 } else if (0 == strcmp(class_getName(cls), "Both")) {
26 *outName = "Image Both via One";
29 return OnePreviousHook(cls, outName);
33 objc_hook_getImageName TwoPreviousHook;
34 BOOL GetImageNameHookTwo(Class cls, const char **outName)
36 if (0 == strcmp(class_getName(cls), "Two")) {
37 *outName = "Image Two";
39 } else if (0 == strcmp(class_getName(cls), "Both")) {
40 *outName = "Image Both via Two";
43 return TwoPreviousHook(cls, outName);
50 // before hooks: main executable is the image name for four classes
51 testassert(strstr(class_getImageName([One class]), "getImageNameHook"));
52 testassert(strstr(class_getImageName([Two class]), "getImageNameHook"));
53 testassert(strstr(class_getImageName([Both class]), "getImageNameHook"));
54 testassert(strstr(class_getImageName([None class]), "getImageNameHook"));
55 testassert(strstr(class_getImageName([NSObject class]), "libobjc"));
58 objc_setHook_getImageName(GetImageNameHookOne, &OnePreviousHook);
60 // two classes are in Image One with hook One in place
61 testassert(strstr(class_getImageName([One class]), "Image One"));
62 testassert(strstr(class_getImageName([Two class]), "getImageNameHook"));
63 testassert(strstr(class_getImageName([Both class]), "Image Both via One"));
64 testassert(strstr(class_getImageName([None class]), "getImageNameHook"));
65 testassert(strstr(class_getImageName([NSObject class]), "libobjc"));
67 // install hook Two which chains to One
68 objc_setHook_getImageName(GetImageNameHookTwo, &TwoPreviousHook);
70 // two classes are in Image Two and one in One with both hooks in place
71 testassert(strstr(class_getImageName([One class]), "Image One"));
72 testassert(strstr(class_getImageName([Two class]), "Image Two"));
73 testassert(strstr(class_getImageName([Both class]), "Image Both via Two"));
74 testassert(strstr(class_getImageName([None class]), "getImageNameHook"));
75 testassert(strstr(class_getImageName([NSObject class]), "libobjc"));