关于检测应用安装和流量信息研究

1. 关于检测应用安装情况研究--- 

(1).利用URL scheme,看对于某一应用特有的url scheme,有没有响应。如果有响应,就说明安装了这个特定的app。

http://developer.apple.com/library/ios/#featuredarticles/iPhoneURLScheme_Reference/Introduction/Introduction.html

对于URL Scheme的使用请参看我之前的文章。 

市场上有一部分应用检测安装是利用第三方ihasapp的接口获取的,目前ihasapp接口可以返回5000多个应用的URL Scheme。https://ihasapp.herokuapp.com/api/schemeApps.json 遍历列表,里面提供了每个应用的URL Scheme,客户端利用application的openurl函数,一个一个在iphone上尝试打开这些app,不过这种实现方式会很快把你的iphone变成暖手宝. 

(2)利用一些方法获得当前正在运行的进程信息,从进程信息中获得安装的app信息。

代码请参看http://forrst.com/posts/UIDevice_Category_For_Processes-h1H

缺点是打印输出的应用名称:让你找不到北,最熟悉的是找到tmall.

(3)破解手机的私有API可参看

http://stackoverflow.com/questions/3878197/is-it-possible-to-get-information-about-all-apps-installed-on-iphone/3878220#3878220

http://www.iphonedevsdk.com/forum/iphone-sdk-development/22289-possible-retrieve-these-information.html

关于越狱情况获取iphone用户安装的app列表:(这是从一篇讨论 360因为侵犯用户隐私被苹果下架 的文章中看来的)

  • 已安装app列表 /private/var/mobile/Library/Caches/com.apple.mobile.installation.plist
  • 用户相片 /var/mobile/Media/DCIM/100APPLE/
  • 音乐目录 /var/mobile/Media/iTunes_Control/Music/

 /private/ ,/var/都是合法app不能访问的目录,但是你的iphone一旦越狱,app就可以为所欲为。

 

 2.关于流量检测研究-----

 (1) 通过读取系统网络接口信息,可以获取当前iphone设备的流量相关信息, 但统计的是上次开机至今的流量信息。代码如下:

-(void)checkNetworkflow {

    struct ifaddrs *ifa_list = 0, *ifa;

    if (getifaddrs(&ifa_list) == -1){

        return;

    }

    uint32_t iBytes = 0;

    uint32_t oBytes = 0;

    uint32_t allFlow = 0;

    uint32_t wifiIBytes = 0;

    uint32_t wifiOBytes = 0;

    uint32_t wifiFlow = 0;

    uint32_t wwanIBytes = 0;

    uint32_t wwanOBytes = 0;

    uint32_t wwanFlow = 0;

    struct timeval time ;

    for (ifa = ifa_list; ifa; ifa = ifa->ifa_next){

        if (AF_LINK != ifa->ifa_addr->sa_family)

            continue;

        if (!(ifa->ifa_flags & IFF_UP) && !(ifa->ifa_flags & IFF_RUNNING))

            continue;

        if (ifa->ifa_data == 0)

            continue;

        // Not a loopback device.

        // network flow

        if (strncmp(ifa->ifa_name"lo"2)){

            struct if_data *if_data = (struct if_data *)ifa->ifa_data;

            iBytes += if_data->ifi_ibytes;

            oBytes += if_data->ifi_obytes;

            allFlow = iBytes + oBytes;

            time = if_data->ifi_lastchange;

            // NSLog(@"1111===%s :iBytes is %d, oBytes is %d", ifa->ifa_name, iBytes, oBytes);

        }

        //<span style="font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; ">WIFI流量统计功能</span>

        if (!strcmp(ifa->ifa_name"en0")){

            struct if_data *if_data = (struct if_data *)ifa->ifa_data;

            wifiIBytes += if_data->ifi_ibytes;

            wifiOBytes += if_data->ifi_obytes;

            wifiFlow = wifiIBytes + wifiOBytes;

        }

        //<span style="font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; ">3GGPRS流量统计</span>

        if (!strcmp(ifa->ifa_name"pdp_ip0")){

            struct if_data *if_data = (struct if_data *)ifa->ifa_data;

            wwanIBytes += if_data->ifi_ibytes;

            wwanOBytes += if_data->ifi_obytes;

            wwanFlow = wwanIBytes + wwanOBytes;

            //NSLog(@"111122===%s :iBytes is %d, oBytes is %d", ifa->ifa_name, iBytes, oBytes);

        }  

    }

    freeifaddrs(ifa_list);

    //    NSString *changeTime=[NSString stringWithFormat:@"%s",ctime(&time)];

    //    NSLog(@"changeTime==%@",changeTime);

    NSString *receivedBytes= [self bytesToAvaiUnit:iBytes];

    NSLog(@"receivedBytes==%@",receivedBytes);

    NSString *sentBytes = [self bytesToAvaiUnit:oBytes];

    NSLog(@"sentBytes==%@",sentBytes);

    NSString *networkFlow = [self bytesToAvaiUnit:allFlow];

    NSLog(@"networkFlow==%@",networkFlow);

    NSString *wifiReceived = [self bytesToAvaiUnit:wifiIBytes];

    NSLog(@"wifiReceived==%@",wifiReceived);

    NSString *wifiSent = [self bytesToAvaiUnit: wifiOBytes];

    NSLog(@"wifiSent==%@",wifiSent);

    NSString *wifiBytes = [self bytesToAvaiUnit:wifiFlow];

    NSLog(@"wifiBytes==%@",wifiBytes);

    NSString *wwanReceived = [self bytesToAvaiUnit:wwanIBytes];

    NSLog(@"wwanReceived==%@",wwanReceived);

    NSString *wwanSent = [self bytesToAvaiUnit:wwanOBytes];

    NSLog(@"wwanSent==%@",wwanSent);

    NSString *wwanBytes = [self bytesToAvaiUnit:wwanFlow];

    NSLog(@"wwanBytes==%@",wwanBytes);

    NSString * alltext = [NSStringstringWithFormat:@" receivedBytes: %@\n sentBytes: %@\n networkFlow: %@\n wifiReceived: %@\n wifiSent: %@\n wifiBytes: %@\n wwanReceived: %@\n wwanSent: %@\n wwanBytes: %@",receivedBytes,sentBytes,networkFlow,wifiReceived,wifiSent,wifiBytes,wwanReceived,wwanSent,wwanBytes];

    //self.textView.text = alltext;

    int i = [selfgetGprs3GFlowIOBytes];

    NSLog(@"3G 流量-----%d",i);

    int j = [selfgetInterfaceBytes];

    NSLog(@"wifi 流量-----%d",j);

}

-(NSString *)bytesToAvaiUnit:(int)bytes {

    if(bytes < 1024) // B        

    {

        return [NSString stringWithFormat:@"%dB", bytes];

    }

    else if(bytes >= 1024 && bytes < 1024 * 1024) // KB

    {

        return [NSString stringWithFormat:@"%.1fKB", (double)bytes / 1024];        

    } else if(bytes >= 1024 * 1024 && bytes < 1024 * 1024 * 1024) // MB

    {

        return [NSString stringWithFormat:@"%.2fMB", (double)bytes / (1024 * 1024)];

    } else // GB

    {

        return [NSString stringWithFormat:@"%.3fGB", (double)bytes / (1024 * 1024 * 1024)];

    }

}

 

//--- 3G/GPRS流量统计

-(int) getGprs3GFlowIOBytes

{

    struct ifaddrs *ifa_list = 0, *ifa;

    if (getifaddrs(&ifa_list) == -1)

    {

        return 0;

    }

    uint32_t iBytes = 0;

    uint32_t oBytes = 0;

    

    for (ifa = ifa_list; ifa; ifa = ifa->ifa_next)

    {

        if (AF_LINK != ifa->ifa_addr->sa_family)

            continue;

        

        if (!(ifa->ifa_flags & IFF_UP) && !(ifa->ifa_flags & IFF_RUNNING))

            continue;

        

        if (ifa->ifa_data == 0)

            continue;

        if (!strcmp(ifa->ifa_name, "pdp_ip0"))

        {

            struct if_data *if_data = (struct if_data *)ifa->ifa_data;

            

            iBytes += if_data->ifi_ibytes;

            oBytes += if_data->ifi_obytes;

NSLog(@"%s :iBytes is %d, oBytes is %d",

  ifa->ifa_name, iBytes, oBytes);

        }

    }

    freeifaddrs(ifa_list);    

return iBytes + oBytes;

//WIFI流量统计功能

- (long long int)getInterfaceBytes

{

    struct ifaddrs *ifa_list = 0, *ifa;

    if (getifaddrs(&ifa_list) == -1)

    {

        return 0;

    }

    uint32_t iBytes = 0;

    uint32_t oBytes = 0;

    for (ifa = ifa_list; ifa; ifa = ifa->ifa_next)

    {

        if (AF_LINK != ifa->ifa_addr->sa_family)

            continue;        

        if (!(ifa->ifa_flags & IFF_UP) && !(ifa->ifa_flags & IFF_RUNNING))

            continue;        

        if (ifa->ifa_data == 0)

            continue;

        /* Not a loopback device. */

        if (strncmp(ifa->ifa_name, "lo", 2))

        {

            struct if_data *if_data = (struct if_data *)ifa->ifa_data;            

            iBytes += if_data->ifi_ibytes;

            oBytes += if_data->ifi_obytes;

            //            NSLog(@"%s :iBytes is %d, oBytes is %d",

            //                  ifa->ifa_name, iBytes, oBytes);

        }

    }

    freeifaddrs(ifa_list);

    return iBytes+oBytes;

}

  可以获取内容有:

  WIFI接收数据流量,WIFI发送数据流量;

  3G和GPRS接收数据流量,3G和GPRS发送数据流量;

 通过查看其他流量软件具体到每日每月总流量,越狱情况下应该可以实现这每日每月总流量检测, 但我还未找到获取单个应用的流量信息私有API,大家有知道怎么获取的,也分享下,呵呵。

 

 

 

 

 

 

 

 

 

 

 

 

 

posted on 2013-06-25 14:06  一梦浮生2012  阅读(968)  评论(1编辑  收藏  举报