Autofill/Autologin for the Blackboard iOS app
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
4.3KB

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