Compile with:
Get a poor version of atos.
gcc testcname.m -framework Cocoa /System/Library/PrivateFrameworks/vmutils.framework/vmutils
Get a poor version of atos.
cristi:~/Programming/test diciu$ cat testcname.m
#import
#import "vmutil.h"
int stringToAddress(char * str, int * result)
{
unsigned int addr;
int allok = 0;
NSScanner * scanner;
if(strlen(str) < 2)
return 0;
scanner = [NSScanner scannerWithString:[NSString stringWithFormat:@"%s", str]];
if((str[0] == '0' && (str[1] == 'X' || str[1] == 'x')) ? [scanner scanHexInt:&addr] : [scanner scanInt:&addr])
allok = 1;
else
fprintf(stdout, "Can't parse address: >%s<\n", str);
*result = addr;
return allok;
}
int main(int argc, char ** argv)
{
char in[100];
task_t port;
if(argc < 2)
{
fprintf(stdout, "pid argument required\n");
exit(1);
}
int pid = atoi(argv[1]);
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
kern_return_t kr = task_for_pid(mach_task_self(), pid, (mach_port_name_t *)&port);
NSMachOTaskImage * mi = [[NSMachOTaskImage alloc] initWithTask:port];
while(1)
{
if(!fgets(in, 99, stdin))
exit(1);
[[mi memoryCache] startPeeking];
int addr;
if(stringToAddress(in, &addr))
fprintf(stdout, "%s\n", [mi cnameOfSymbolWithAddress:addr]);
[[mi memoryCache] stopPeeking];
}
[pool release];
}