Obtain iPhone call records (jailbreak required)

Source: Internet
Author: User

After the jailbreak, the database file of the mobile phone can be freely accessed. The call record is usually stored in the call_history.db file. As long as you read this file, we can know the current call record of the mobile phone.

The following code checks whether the mobile phone can read call_history.db.

NSFileManager *fileManager = [NSFileManager defaultManager];
NSDirectoryEnumerator *dirnum = [[NSFileManager defaultManager] enumeratorAtPath: @"/private/"];
NSString *nextItem = [NSString string];
while( (nextItem = [dirnum nextObject])) {
if ([[nextItem pathExtension] isEqualToString: @"db"] ||
[[nextItem pathExtension] isEqualToString: @"sqlitedb"]) {
if ([fileManager isReadableFileAtPath:nextItem]) {
NSLog(@"%@", nextItem);
}
}
}

Normally, the file location is var/wireless/library/callhistory/call_history.db. ios3 and 4 may be different. For details, refer to the output of the code above.

The following code can read the content in the database.

- (void)readCallLogs
{
if (_dataArray == nil) {
_dataArray = [[NSMutableArray alloc] init];
}
[_dataArray removeAllObjects];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *callHisoryDatabasePath = @"var/wireless/Library/CallHistory/call_history.db";
BOOL callHistoryFileExist = FALSE;
callHistoryFileExist = [fileManager fileExistsAtPath:callHisoryDatabasePath];
[fileManager release];
//NSMutableArray *callHistory = [[NSMutableArray alloc] init];

if(callHistoryFileExist) {
if ([fileManager isReadableFileAtPath:callHisoryDatabasePath]) {
sqlite3 *database;
if(sqlite3_open([callHisoryDatabasePath UTF8String], &database) == SQLITE_OK) {
sqlite3_stmt *compiledStatement;
NSString *sqlStatement = [NSString stringWithString:@"SELECT * FROM call;"];

int errorCode = sqlite3_prepare_v2(database, [sqlStatement UTF8String], -1,
&compiledStatement, NULL);
if( errorCode == SQLITE_OK) {
int count = 1;

while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
// Read the data from the result row
NSMutableDictionary *callHistoryItem = [[NSMutableDictionary alloc] init];
int numberOfColumns = sqlite3_column_count(compiledStatement);
NSString *data;
NSString *columnName;

for (int i = 0; i < numberOfColumns; i++) {
columnName = [[NSString alloc] initWithUTF8String:
(char *)sqlite3_column_name(compiledStatement, i)];

data = [[NSString alloc] initWithUTF8String:
(char *)sqlite3_column_text(compiledStatement, i)];


}
[callHistoryItem setObject:data forKey:columnName];

[columnName release];
[data release];
}
[_dataArray addObject:callHistoryItem];
[callHistoryItem release];
count++;
}
}
else {
NSLog(@"Failed to retrieve table");
NSLog(@"Error Code: %d", errorCode);
}
sqlite3_finalize(compiledStatement);
}
}
}
NSLog(@"%@",_dataArray);
}

Now you can read all the call records.

By Mac-z

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.