Advertisement
Guest User

Untitled

a guest
Apr 16th, 2014
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.25 KB | None | 0 0
  1. NSString* path = [NSHomeDirectory() stringByAppendingPathComponent:@"/Library/Preferences/com.apple.Safari.plist"];
  2.  
  3. NSMutableDictionary *plistDict = [NSMutableDictionary dictionaryWithContentsOfFile:path];
  4.  
  5. NSLog(@"Old HomePage %@",[plistDict objectForKey:@"HomePage"]);
  6.  
  7. [plistDict setValue:@"https://google.co.in/" forKey:@"HomePage"];
  8.  
  9. [plistDict writeToFile:path atomically: YES];
  10.  
  11. NSLog(@"New HomePage %@",[plistDict objectForKey:@"HomePage"]);
  12.  
  13. NSError * error;
  14. NSString * stringFromFile;
  15. NSString * stringFilepath = [NSHomeDirectory() stringByAppendingPathComponent:@"/Library/Application Support/Google/Chrome/Default/Preferences/"];
  16.  
  17. stringFromFile = [[NSString alloc] initWithContentsOfFile:stringFilepath
  18. encoding:NSUTF8StringEncoding
  19. error:&error];
  20.  
  21. NSLog(@"stringFromFile %@ error %@",stringFromFile, error.description);
  22.  
  23.  
  24. NSArray *lines = [stringFromFile componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
  25.  
  26. for (NSString *line in lines) {
  27.  
  28. if ([line rangeOfString:@""homepage":"].location != NSNotFound) {
  29.  
  30. NSLog(@"string contains homepage!");
  31.  
  32. NSString *temp =@""homepage": "https://yahoo.com",";
  33.  
  34. NSString *replacedString = [stringFromFile stringByReplacingOccurrencesOfString:line
  35. withString:temp];
  36.  
  37. [replacedString writeToFile:stringFilepath atomically:YES encoding:NSUTF8StringEncoding error:nil];
  38.  
  39. }//ends if
  40.  
  41. }//ends for
  42.  
  43. NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"/Library/Application Support/Firefox/Profiles"];
  44.  
  45. NSString *firefoxPath;
  46.  
  47. NSArray *folderItems = [self listFilesAtPath:path];
  48.  
  49. for (NSURL *item in folderItems) {
  50.  
  51. NSNumber *isHidden = nil;
  52.  
  53. [item getResourceValue:&isHidden forKey:NSURLIsDirectoryKey error:nil];
  54.  
  55. if ([isHidden boolValue]) {
  56.  
  57. firefoxPath =[NSString stringWithFormat:@"%@/%@/prefs.js",path,[item.path lastPathComponent]];
  58. }
  59. }
  60.  
  61. NSError * error;
  62. NSString * stringFromFile;
  63. NSLog(@"firefox %@",firefoxPath);
  64.  
  65. stringFromFile = [[NSString alloc] initWithContentsOfFile:firefoxPath
  66. encoding:NSUTF8StringEncoding
  67. error:&error];
  68.  
  69.  
  70. NSArray *lines = [stringFromFile componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
  71.  
  72. for (NSString *line in lines) {
  73.  
  74. if ([line rangeOfString:@"user_pref("browser.startup.homepage""].location != NSNotFound) {
  75.  
  76. NSString *temp = [NSString stringWithFormat:@"user_pref("browser.startup.homepage", "%@");",homePageURL];
  77.  
  78. NSString *replacedString = [stringFromFile stringByReplacingOccurrencesOfString:line
  79. withString:temp];
  80.  
  81. [replacedString writeToFile:firefoxPath atomically:YES encoding:NSUTF8StringEncoding error:nil];
  82.  
  83. }//ends if
  84.  
  85. }//ends for
  86.  
  87. NSError * error;
  88. NSString * stringFilepath = [NSHomeDirectory() stringByAppendingPathComponent:@"/Library/Application Support/com.operasoftware.Opera/Preferences/"];
  89.  
  90. NSString *stringFromFile = [[NSString alloc] initWithContentsOfFile:stringFilepath
  91. encoding:NSUTF8StringEncoding
  92. error:&error];
  93.  
  94. NSArray *lines = [stringFromFile componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
  95.  
  96. for (NSString *line in lines) {
  97.  
  98. if ([line rangeOfString:@""urls_to_restore_on_startup":"].location != NSNotFound) {
  99.  
  100. NSString *temp = [NSString stringWithFormat:@""urls_to_restore_on_startup": [ "%@" ]",homePageURL];
  101.  
  102. NSString *replacedString = [stringFromFile stringByReplacingOccurrencesOfString:line
  103. withString:temp];
  104.  
  105. [replacedString writeToFile:stringFilepath atomically:YES encoding:NSUTF8StringEncoding error:nil];
  106.  
  107. }//ends if
  108.  
  109. }//ends for
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement