Re: Finding the selector used in calls objc_msgSend in otool output...
Re: Finding the selector used in calls objc_msgSend in otool output...
- Subject: Re: Finding the selector used in calls objc_msgSend in otool output...
- From: Shawn Erickson <email@hidden>
- Date: Mon, 10 Jan 2005 18:15:51 -0800
So I came up with a hackish but simple script that will take an
message reference and find the related selector (assuming it is in the
same file).
-----
#!/bin/sh
FILE=$1
MSGREF=$2
SELECTOR=`otool -s __OBJC __message_refs "$FILE" | grep ^[0-9a-f] |
awk '{
b=substr($1,1,7);
print b"0", $2 "\n" b"4" , $3 "\n" b"8", $4 "\n" b"c", $5
}' | grep $MSGREF | awk '{print $2}'`
otool -oV "$FILE" | grep -A 2 $SELECTOR
-----
For example (assume the above is in a file called "lookup_selector")
then looking at the following code you can find the address of the
selector you need to look up.
- (void)changeState:(int)newState
{
state = newState;
[self advanceState];
}
-[PGAppDelegate changeState:]:
0000a85c mfspr r0,lr
0000a860 stmw r30,0xfff8(r1)
0000a864 or r31,r12,r12 << loads r31 with address of this function
(0xa85c)
0000a868 stw r0,0x8(r1)
0000a86c stwu r1,_authPackGAME_CAPACITY(r1)
0000a870 or r30,r1,r1
0000a874 stw r3,0x68(r30)
0000a878 stw r4,0x6c(r30)
0000a87c stw r5,0x70(r30)
0000a880 lwz r2,0x68(r30)
0000a884 lwz r0,0x70(r30)
0000a888 stw r0,0x4c(r2)
0000a88c addis r2,r31,0x9 << sets r2 to 0x9a85c (0x9000 + 0xa85c)
0000a890 addi r2,r2,0x7e4 << sets r2 to 0x9b040 (0x9a85c + 0x7e4)
0000a894 lwz r3,0x68(r30) << isa pointer, in this case self
0000a898 lwz r4,0x0(r2) << message ref in r2 (selector string in r4)
0000a89c bl 0x26368 ; symbol stub for: _objc_msgSend
0000a8a0 lwz r1,0x0(r1)
0000a8a4 lwz r0,0x8(r1)
0000a8a8 mtspr lr,r0
0000a8ac lmw r30,0xfff8(r1)
0000a8b0 blr
G5:~ crs$ ./lookup_selector <path to executable> 0009b040
method_name 0x000221ec advanceState
method_types 0x00022d58 v8@0:4
method_imp 0x0000a8b4 -[PGAppDelegate
advanceState]
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden