I was wondering if there was any way to swizzle a method by a memory address. For example: I have a pointer to a method 0xFFFFFF. I have an method in my application. I want to replace the pointer with the my method. Is there way that I could replace this pointer in Objective-C. Thanks.
Asked
Active
Viewed 221 times
0
-
Did you have a particular language in mind? COBOL? SQL? :-) – paxdiablo Sep 13 '11 at 02:35
-
Can you explain a little more what you mean? Specifically, what is a "pointer to a method"? Are we talking a `struct objc_method *`? How do you come to have one with the value 0xFFFFFF? That's a rather improbable value. And what does it mean to "replace the pointer"? Just assign a new value to the variable or what? – Chuck Sep 13 '11 at 07:14
-
Ok, a pointer to a method is what I find in IDA Pro. It's a memory address associated to a function. I am talking about a '-(void)myMethod:(id)sender'. Memory address was just an example and it's not actually that value. And by replacing the pointer, is there any way that I could replace the memory address of the method with the memory address of my own method in my app. – Jnani Sep 13 '11 at 15:30
3 Answers
0
You're looking for method_setImplementation(Method m, IMP imp)
You have to have resolved the Method for your selector first though, using class_getInstanceMethod
or class_getClasssMethod

JTAS
- 431
- 4
- 6
0
You are talking about injection.
Take a look at mach_inject
also Starruntime
and Application Enhancer.

RLT
- 4,219
- 4
- 37
- 91
-2
You could use "performSelector":
[object performSelector:@selector(doSomething)];
The selector can be stored in a variable.

Kobski
- 1,636
- 15
- 27