Autofill/Autologin for the Blackboard iOS app
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

91 lines
4.2KB

  1. NSString *username, *password;
  2. // Hook into the main view controller
  3. %hook BBLFTWViewController
  4. // Hook into when the login page finishes loading
  5. - (void)webViewDidFinishLoad:(UIWebView *)webView {
  6. // The javascript that we're gonna execute, which will set the username & password to what we've stored
  7. NSString *inject = [NSString stringWithFormat:@"document.getElementById('username').value = '%@';document.getElementById('password').value = '%@';", username, password];
  8. // Inject the JS
  9. [webView stringByEvaluatingJavaScriptFromString:inject];
  10. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void)
  11. {
  12. // Submit the form by pressing the button.
  13. [webView stringByEvaluatingJavaScriptFromString:@"document.forms[\"fm1\"].submit.click();"];
  14. });
  15. %orig;
  16. }
  17. %end
  18. // Interface so we can call our custom method
  19. @interface BBLFTWViewController : UIViewController
  20. -(void)getAutofillInfo;
  21. @end
  22. // Hook into the login view controller
  23. %hook BBLoginViewController
  24. // Hook into when the login button is pressed
  25. -(void)loginBtnTapped {
  26. // Grab your username and password from the userdefaults
  27. username = [[NSUserDefaults standardUserDefaults] objectForKey:@"USERNAME"];
  28. password = [[NSUserDefaults standardUserDefaults] objectForKey:@"PASSWORD"];
  29. // If you don't have an username & password setup
  30. if(!(username && password) || ([username isEqualToString:@""] || [password isEqualToString:@""])) {
  31. // Setup your username & password
  32. [self getAutofillInfo];
  33. } else {
  34. // Otherwise, load up the webview
  35. %orig;
  36. }
  37. }
  38. // Hook into when the help button is tapped
  39. -(void)helpBtnTapped {
  40. // Ask the user if they want to change their information
  41. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Auto-Login" message:@"Would you like to change your login information?" preferredStyle:UIAlertControllerStyleAlert];
  42. UIAlertAction *confirmAction = [UIAlertAction actionWithTitle:@"Change" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  43. // If so, setup their username and pass
  44. [self getAutofillInfo];
  45. }];
  46. [alertController addAction:confirmAction];
  47. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  48. // Otherwise, use the normal function for the help button
  49. %orig;
  50. }];
  51. [alertController addAction:cancelAction];
  52. // Present the alert
  53. [self presentViewController:alertController animated:YES completion:nil];
  54. }
  55. // New function to get the login info
  56. %new
  57. -(void)getAutofillInfo {
  58. // Ask the user to enter their input
  59. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Auto-Login" message:@"Enter your username & password\n(Note: Information stored plaintext in the standard app defaults. To change the information, press the help button)" preferredStyle:UIAlertControllerStyleAlert];
  60. [alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
  61. textField.placeholder = @"Username";
  62. }];
  63. [alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
  64. textField.placeholder = @"Password";
  65. textField.secureTextEntry = YES;
  66. }];
  67. UIAlertAction *confirmAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  68. //Store the information
  69. [[NSUserDefaults standardUserDefaults] setObject:[[alertController textFields][0] text] forKey:@"USERNAME"];
  70. [[NSUserDefaults standardUserDefaults] setObject:[[alertController textFields][1] text] forKey:@"PASSWORD"];
  71. [[NSUserDefaults standardUserDefaults] synchronize];
  72. }];
  73. [alertController addAction:confirmAction];
  74. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  75. }];
  76. [alertController addAction:cancelAction];
  77. // Show the alert
  78. [self presentViewController:alertController animated:YES completion:nil];
  79. }
  80. %end