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