@@ -100,15 +100,6 @@ namespace {
100
100
typedef struct segment_command macho_segment_command;
101
101
#endif
102
102
103
- struct patch_t {
104
- const char *name;
105
- const void *fn;
106
-
107
- template <typename T>
108
- patch_t (const char *newName, const T *newFn)
109
- : name(newName), fn((const void *)newFn) {
110
- }
111
- };
112
103
} // end anonymous namespace
113
104
114
105
// / Overwrite a cross-image symbol reference by directly editing symbol tables
@@ -121,7 +112,8 @@ namespace {
121
112
// /
122
113
// / Also, if the symbol being patched has references within the image where it
123
114
// / was originaly defined, those references will \e not be patched.
124
- static void patchLazyPointers (const mach_header *mh, patch_t patch) {
115
+ static void patchLazyPointers (const mach_header *mh, const char *symbolName,
116
+ const void *newValue) {
125
117
// Get linkEditBase
126
118
const uint32_t cmd_count = mh->ncmds ;
127
119
const load_command * const cmds =
@@ -205,10 +197,10 @@ static void patchLazyPointers(const mach_header *mh, patch_t patch) {
205
197
// Found symbol for this lazy pointer, now lookup address.
206
198
const char *lazyTargetName =
207
199
&stringTable[symbolTable[symbolIndex].n_un .n_strx ];
208
- if (strcmp (patch. name , lazyTargetName) == 0 ) {
200
+ if (strcmp (symbolName , lazyTargetName) == 0 ) {
209
201
// Can't use the value currently stored here because it may
210
202
// be a dyld stub binder that will undo our patch if called.
211
- symbolPointers[lazyIndex] = (uintptr_t )patch. fn ;
203
+ symbolPointers[lazyIndex] = (uintptr_t )newValue ;
212
204
}
213
205
}
214
206
}
@@ -256,8 +248,9 @@ static const char *patchedGetImageNameFromClassForOldOSs(Class _Nullable cls) {
256
248
static void patchGetImageNameInImage (const struct mach_header *mh,
257
249
intptr_t vmaddr_slide) {
258
250
(void )vmaddr_slide;
259
- patchLazyPointers (mh, patch_t (" _class_getImageName" ,
260
- &patchedGetImageNameFromClassForOldOSs));
251
+ const void *newImplementationAddr =
252
+ reinterpret_cast <const void *>(&patchedGetImageNameFromClassForOldOSs);
253
+ patchLazyPointers (mh, " _class_getImageName" , newImplementationAddr);
261
254
}
262
255
263
256
/* **************************************************************************/
0 commit comments