What's new? | Help | Directory | Sign in
Google
iflickr
iPhone Native App for Flickr
  
  
  
  
    
Search
for
Updated Sep 19, 2007 by pradeepta
Labels: Featured
LocationAwarenessoniPhone  

Hack Cell id location into the iPhone and integrate with Yahoo! Zonetag (http://zonetag.research.yahoo.com//)

Introduction

Zonetag makes it easy to get Location. http://developer.yahoo.com/yrb/zonetag/locatecell.html

Details

Reverse engineer the FieldTest.app to get API calls that we need.

Ok, finally managed to compile not crash after reverse engineering FieldTest.app but what does it do ;-)

include <CoreFoundation/CoreFoundation.h>

#include <stdio.h>
#include <time.h>
#include <dlfcn.h>

typedef struct __CFMachPort *CFMachPortRef;

extern void * _CTServerConnectionCreate(CFAllocatorRef, int (*)(void *, CFStringRef, CFDictionaryRef, void *), int *);
extern int _CTServerConnectionSetVibratorState(int *, void *, int, int, int, int, int);
extern int _CTServerConnectionRegisterForNotification(void*, void*, int*);
extern mach_port_t _CTServerConnectionGetPort(void*);
extern void _CTServerConnectionCellMonitorStart( void*);

int callback(void *connection, CFStringRef string, CFDictionaryRef dictionary, void *data) {
        printf("callback (but it never calls me back :( ))\n");
        CFShow(string);
        CFShow(dictionary);

        return 0;
}

void sourcecallback ( CFMachPortRef port, void *msg, CFIndex size, void *info)
{
        printf("Source called back\n");
}

int main() {
        printf("10 seconds of pleasure!!111!!one!!!!111!!\n");

        int x = 0;

        void *connection = _CTServerConnectionCreate(kCFAllocatorDefault, callback, &x);
        void    *handle;
        handle = dlopen("/System/Library/Frameworks/CoreTelephony.framework/CoreTelephony", RTLD_LOCAL | RTLD_LAZY);
        void* kCTCellMonitorUpdateNotification = dlsym(handle, "kCTCellMonitorUpdateNotification");
        if( kCTCellMonitorUpdateNotification== NULL)
        {
                printf("Could not find kCTCellMonitorUpdateNotification\n");
        }

        _CTServerConnectionRegisterForNotification(connection,kCTCellMonitorUpdateNotification,&x);
        mach_port_t port ;
        printf("%d\n", port);
        port  = _CTServerConnectionGetPort(connection);
        printf("%d\n", port);
        printf("%x\n", connection);
        CFMachPortContext  context = { 0, 0, NULL, NULL, NULL };

        //Boolean shouldFreeInfo = false;
        printf("Done\n");

        CFMachPortRef ref = CFMachPortCreateWithPort(kCFAllocatorDefault,port,NULL,NULL, NULL);

           CFRunLoopSourceRef rlref = CFMachPortCreateRunLoopSource ( kCFAllocatorDefault, ref, 0);
           CFRunLoopRef currentRunLoop = CFRunLoopGetCurrent();
           CFRunLoopAddSource(currentRunLoop, rlref, kCFRunLoopCommonModes);
           _CTServerConnectionCellMonitorStart( connection);

        sleep(15);
        return 0;
}


Comment by pradeepta, Sep 16, 2007

Here is what happens in FieldTest?.app (CoreTelephony?.framework):

  • Call to CTServerConnectionCreate (# params 1, return ?)
  • Call to CTCellMonitorUpdateNotification ??
  • Call to CTServerConnectionRegisterForNotification
  • Call to CTServerConnectionGetPort (to get somekind of Port ?)
  • Call to CFMachPortCreateWithPort from the above portNum to get a source ref
  • Get the current run loop (ususal suspects : CFMachPortCreateRunLoopSource or CFRunLoopGetCurrent)
  • Add the Source ref to main run loop with call to CFRunLoopAddSource
  • Call to CTServerConnectionCellMonitorStart
  • When ready the callbacks will be invoked.
  • CTServerConnectionCellMonitorGetCellCount gets # cells, so that the FieldApp? can create the UI table.
  • CTServerConnectionCellMonitorGetCellInfo is called to get details.
Comment by pradeepta, Sep 16, 2007

I have given up hope of using mach_inject (http://rentzsch.com/mach_inject/), I don't have sufficient low level programming expertise to port it to ARM. It would have been nice though. Could have got what I want on stdout by overriding FieldTestView?:updateCellInfo.

Comment by ste...@sproose.com, Sep 18, 2007

This would be a awesome feature!!!

Comment by soldoutactivist, Sep 19, 2007

I don't like the Big brother implications, but this could be cool with iFlickr and some other stuff.

Comment by allen.porter, Sep 19, 2007

I was looking for some info on doing this and thought I woudl share what I have found:

See http://www.thebends.org/~allen/code/iphone-apps/telephony/

which is based on some work on the iphone-wireless project at: http://iphone-wireless.googlecode.com/svn/trunk/CellStumbler/main.c

I've updated what we have found about CoreTelephony?.h to the trunk of the iphone-binutils project at berlios.de.

Comment by pradeepta, Sep 20, 2007

The reason why your code does not work may be something to do with the variables not being global. I know it sounds wierd, but this time my suspicion is that the toolkit is messing things somehow.

Comment by pradeepta, Sep 21, 2007

GSM location is now integrated with iFlickr, Brave souls may test it http://iflickr.googlecode.com/files/iFlickr-0.0.5_1.tar.gz

Comment by maihill9, Sep 25, 2007

Great app, What happened to the time laps feature? Would a command line version be possible? Would be fun to run from a cron job!

Comment by natatwo, Sep 26, 2007

GSM Location is pretty sweet. Could we integrate that with the machine tags?

Comment by pradeepta, Sep 27, 2007

I took out the time lapse feature, it seems to be causing the app to crash places.

Comment by decaro.mike, Sep 27, 2007

What information were you able to retrieve using the calls you found in FieldTest?.app? Can you get a listing of cell tower id's and signal strength from each?

Comment by subband, Dec 03, 2007

As far as the porting mach_inject - all you have to do is port branch island, which should be just a few calls. Rest calls are the same as OS X.

Comment by d.paolino, Dec 16, 2007

Hello,

I would like to start such an application but for ImageShack?, can you tell me in wich language it is coded and where I can start to read documentation ?

Thanks alot

Comment by namjam105, Feb 09, 2008

Add Source installer : http://iphonebaidu.com/app/ Test iPhone - iPhone Simulator : http://iphonebaidu.com/test/ All Software for Apple MAC : http://iphonebaidu.com/mac-iphone/ All Software for Apple iPhone : http://iphonebaidu.com/mac-iphone/iphone.html

Install iTransformy (.swf) view for iPhone : http://iphonebaidu.com/beta/ Forum, DOwnload Themes, Apps for iPhone. http://iphonebaidu.com/forum/

Copyright © 2008 iPhone Baidu! Inc. All rights reserved


Sign in to add a comment