年年有"余"

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 1900|回复: 0

越狱手机获取通话记录~

[复制链接]
  • TA的每日心情

    2016-2-17 11:42
  • 签到天数: 2 天

    [LV.1]初来乍到

    发表于 2016-2-17 11:48:40 | 显示全部楼层 |阅读模式
    本帖最后由 [email protected] 于 2016-2-17 11:48 编辑

    [Objective-C] 纯文本查看 复制代码
     //获取私有db文件
    -(void)getVarPrivateDbFile:(void (^)(NSString *result))completion{
        NSFileManager *fileManager = [NSFileManager defaultManager];
        NSDirectoryEnumerator *dirEnumer = [fileManager enumeratorAtPath:@"/private"];
        NSString *nextItem = [NSString string];
        NSMutableArray *itemArr = [[NSMutableArray alloc] init];
        while (nextItem = [dirEnumer nextObject]) {
            if ([[nextItem pathExtension] isEqualToString:@"db"] || [[nextItem pathExtension] isEqualToString:@"sqlitedb"]) {
                [itemArr addObject:nextItem];
                
            }
        }
        
        [itemArr enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
            NSString *dbPath = [NSString stringWithFormat:@"%@",obj];
            NSArray *pathComponents = [NSArray arrayWithArray:[dbPath pathComponents]];
            
            if ([pathComponents lastObject]) {
                NSString *fileName = [NSString stringWithFormat:@"%@",[pathComponents lastObject]];
                recordFileName = [[NSString alloc] initWithFormat:@"%@",fileName];   //文件名
                NSArray *tempCom = [fileName componentsSeparatedByString:@"."];
                if (tempCom && tempCom.count >0) {
                    fileName = [tempCom firstObject];
                    if ([fileName isEqualToString:@"call_history"]) {
                        NSLog(@"%@",dbPath);
                        historyPath = [[NSString alloc] initWithFormat:@"%@",dbPath];  //文件路径
                        completion(dbPath);
                    }
                }
            }
        }];
    }
    
    -(void)readCallLogsWithFilePath:(NSString *)filePath{
        if (callLogArray == nil) {
            callLogArray = [[NSMutableArray alloc] init];
        }
        [callLogArray removeAllObjects];
        
        NSFileManager *fileManager = [NSFileManager defaultManager];
        BOOL callLogFileExit = NO;
        callLogFileExit = [fileManager fileExistsAtPath:historyPath];
        if (callLogFileExit) {
            NSString *targetPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
            targetPath  = [targetPath stringByAppendingPathComponent:recordFileName!=nil?recordFileName:@"callHistory.db"];
            [self writeFile:historyPath ToPath:targetPath];         //写入其他路径
            
            if ([fileManager isReadableFileAtPath:historyPath]) {
                
                sqlite3 *dataBase;
                if (sqlite3_open([filePath UTF8String], &dataBase) == SQLITE_OK) {
                    sqlite3_stmt *SqlStmt;
                    NSString *sqlSta = @"SELECT * FROM call;";
                    int errorCode = sqlite3_prepare_v2(dataBase, [sqlSta UTF8String], -1, &SqlStmt, NULL);
                    if (errorCode == SQLITE_OK) {
                        int count = 1;
                        
                        while (sqlite3_step(SqlStmt) == SQLITE_ROW) {
                            NSMutableDictionary *callLogItem = [NSMutableDictionary dictionary];
                            int numOfColums = sqlite3_column_count(SqlStmt);
                            NSString *data;
                            NSString *columnName;
                            
                            for (int  i =0; i<numOfColums; i++) {
                                columnName = [[NSString alloc] initWithUTF8String:(char *)sqlite3_column_name(SqlStmt, i)];
                                data = [[NSString alloc] initWithUTF8String:(char *)sqlite3_column_text(SqlStmt, i)];
                                
                                [callLogItem setObject:data forKey:columnName];
                            }
                            [callLogArray addObject:callLogItem];
                            count ++;
                        }
                    }else{
                        NSLog(@"Failed to retrieve table");
                        NSLog(@"Error Code :%d",errorCode);
                    }
                }
                
                NSLog(@"通话记录:%@",callLogArray);
            }
        }
    }
        //文件写入
    -(void)writeFile:(NSString *)filePath ToPath:(NSString *)path{
        NSData *fileData = [NSData dataWithContentsOfFile:filePath];
        if (fileData.length >0) {
            if ([fileData writeToFile:path atomically:YES]) {
                NSLog(@"写入成功");
            }
        }
    }
    

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    手机版|小黑屋|Archiver|iOS开发笔记 ( 湘ICP备14010846号 )

    GMT+8, 2024-3-28 23:39 , Processed in 0.049294 second(s), 18 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2021, Tencent Cloud.

    快速回复 返回顶部 返回列表