开发者

iPhone, C/objC: getting hostname (not by resolving from IP) by hooking into system wide functions?

I'm currently writing an MobileSubstrate plugin (c开发者_运维知识库ode injection for iPhone). It gets the hostname by hooking into connect() and this piece of code:

#ifndef   NI_MAXHOST
#define   NI_MAXHOST 1025
#endif

int error;

 char hostname[NI_MAXHOST] = "";


 error = getnameinfo(serv_addr, addrlen, hostname, NI_MAXHOST, NULL, 0, 0);

 if (error !=0) {
  ALogTCP(@"coudldn't resolve hostname or internal connect");

  return orig__connect(sockfd, serv_addr, addrlen);
  }


 if (error == 0) {
  ALogTCP(@"hostname: %s", hostname);
  NSString *hostFirst = [NSString stringWithCString:hostname];
}

Now I've noticed that some hostnames won't get resolved properly (wrong host: like connect.xyz.com instead of irc.xyz.com) (depending on the DNS Server).

I'm not very used to all the networking functions and an extensive search didn't turn up any solution.: I'm thinking about hooking into a function which is responsible for all hostname->IP "conversions", getting the hostname and use it later in the above code. Is there such a function? and how is it called?

Thank you very much in advance.


this is how I finally did it, took me only about 7 hours to figure it out :D

  1. hooking into CFHostCreateWithName(CFAllocatorRef *allocator, CFStringRef *hostname)

  2. after that I use gethostbyname to get the IP.

now I can compare that information with the one I retrieve by hooking into connect()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜