1+ using System ;
2+ using System . IO ;
3+ using System . Net ;
4+ using System . Linq ;
5+ using Microsoft . Win32 ;
6+ using OpenQA . Selenium ;
7+ using System . Threading ;
8+ using SmorcIRL . TempMail ;
9+ using System . Diagnostics ;
10+ using System . Threading . Tasks ;
11+ using OpenQA . Selenium . Chrome ;
12+ using SmorcIRL . TempMail . Models ;
13+ using System . Security . Principal ;
14+ using OpenQA . Selenium . Support . UI ;
15+ using System . Security . AccessControl ;
16+ using System . Collections . ObjectModel ;
17+
18+ namespace MathGPTProGenerator
19+ {
20+ static class Chrome
21+ {
22+ public static string version ;
23+ private static string updater ;
24+ private static ChromeDriver driver ;
25+
26+ public static async Task Initialization ( )
27+ {
28+ string uninstallKeyPath = @"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Google Chrome" ;
29+ string updateKeyPath = @"SOFTWARE\WOW6432Node\Google\Update" ;
30+
31+ using ( RegistryKey uninstall = Registry . LocalMachine . OpenSubKey ( uninstallKeyPath ) )
32+ {
33+ if ( uninstall == null )
34+ {
35+ Installing ( ) ;
36+ }
37+ }
38+
39+ while ( Registry . LocalMachine . OpenSubKey ( uninstallKeyPath ) == null || Registry . LocalMachine . OpenSubKey ( updateKeyPath ) == null )
40+ {
41+ await Task . Delay ( 1000 ) ;
42+ }
43+
44+ using ( RegistryKey uninstall = Registry . LocalMachine . OpenSubKey ( uninstallKeyPath ) )
45+ {
46+ if ( uninstall != null )
47+ {
48+ version = uninstall . GetValue ( "Version" ) . ToString ( ) ;
49+ }
50+ }
51+
52+ using ( RegistryKey update = Registry . LocalMachine . OpenSubKey ( updateKeyPath ) )
53+ {
54+ if ( update != null )
55+ {
56+ updater = update . GetValue ( "Path" ) . ToString ( ) ;
57+ }
58+ }
59+ }
60+
61+ public static void CheckUpdateStatus ( )
62+ {
63+ Utils . CheckProcesses ( ) ;
64+ Console . WriteLine ( "Checking status of auto-updates..." ) ;
65+
66+ if ( updater != null && File . Exists ( updater ) )
67+ {
68+ FileSecurity security = File . GetAccessControl ( updater ) ;
69+ AuthorizationRuleCollection rules = security . GetAccessRules ( true , true , typeof ( SecurityIdentifier ) ) ;
70+
71+ if ( rules . Count > 0 )
72+ {
73+ Console . WriteLine ( "Disabling chrome auto-updates..." ) ;
74+
75+ foreach ( FileSystemAccessRule rule in rules )
76+ {
77+ security . RemoveAccessRule ( rule ) ;
78+ }
79+
80+ security . SetAccessRuleProtection ( true , false ) ;
81+ File . SetAccessControl ( updater , security ) ;
82+ }
83+ }
84+ else
85+ {
86+ Console . WriteLine ( "Updater file does not exist!" ) ;
87+ }
88+ }
89+
90+ public static void Installing ( )
91+ {
92+ Console . WriteLine ( "Perform chrome installation..." ) ;
93+
94+ using ( WebClient client = new WebClient ( ) )
95+ {
96+ string [ ] files = { "ChromeSetup.exe" , "ChromeDriver.exe" } ;
97+ string url = "https://github.com/DeniedAccessLife/MathGPTProGenerator/raw/main/MathGPTProGenerator/MathGPTProGenerator/bin/Debug/" ;
98+
99+ foreach ( string file in files )
100+ {
101+ string localPath = Path . Combine ( Directory . GetCurrentDirectory ( ) , file ) ;
102+
103+ if ( File . Exists ( localPath ) )
104+ {
105+ File . Delete ( localPath ) ;
106+ }
107+ client . DownloadFile ( url + file , localPath ) ;
108+ }
109+ }
110+
111+ string installer = Path . Combine ( Directory . GetCurrentDirectory ( ) , "ChromeSetup.exe" ) ;
112+
113+ Process process = new Process ( ) ;
114+ process . StartInfo . FileName = installer ;
115+ process . StartInfo . Arguments = "/silent /install" ;
116+ process . Start ( ) ;
117+
118+ if ( ! process . WaitForExit ( 120000 ) )
119+ {
120+ Utils . KillProcessChildren ( process . Id ) ;
121+ Console . WriteLine ( "The installation process did not complete within the expected time!" ) ;
122+ Console . WriteLine ( "To continue working, try to reboot the system, or start the installation process yourself." ) ;
123+
124+ Console . ReadKey ( ) ;
125+ Environment . Exit ( 1 ) ;
126+ }
127+
128+ process . WaitForExit ( ) ;
129+
130+ try
131+ {
132+ File . Delete ( installer ) ;
133+ }
134+ catch ( UnauthorizedAccessException ex )
135+ {
136+ Console . WriteLine ( $ "Failed to delete file due to access restrictions: { ex . Message } ") ;
137+ }
138+ }
139+
140+ public static async Task Start ( )
141+ {
142+ CheckUpdateStatus ( ) ;
143+
144+ Console . Write ( "Enter the number of accounts to generate: " ) ;
145+ int count = int . Parse ( Console . ReadLine ( ) ) ;
146+
147+ MailClient client = new MailClient ( ) ;
148+ driver = new ChromeDriver ( GetChromeDriverService ( ) , GetChromeOptions ( ) , TimeSpan . FromMinutes ( 2 ) ) ;
149+
150+ for ( int i = 0 ; i < count ; i ++ )
151+ {
152+ driver . Navigate ( ) . GoToUrl ( "https://mathgptpro.com/new" ) ;
153+ driver . Manage ( ) . Timeouts ( ) . ImplicitWait = TimeSpan . FromSeconds ( 45 ) ;
154+ string domain = await client . GetFirstAvailableDomainName ( ) ;
155+
156+ string username = Utils . Random ( 10 ) ;
157+ string password = Utils . Random ( 16 ) ;
158+ string email = $ "{ username } @{ domain } ";
159+
160+ await client . Register ( email , password ) ;
161+
162+ Input ( driver , By . Id ( "input-email" ) , email ) ;
163+ Thread . Sleep ( 500 ) ;
164+ Click ( driver , By . XPath ( "//*[@id='root']/div/div[1]/div/div/div/div/div[4]/button" ) ) ;
165+
166+ MessageInfo [ ] messages = null ;
167+
168+ while ( messages == null || messages . Length == 0 )
169+ {
170+ messages = await client . GetAllMessages ( ) ;
171+ await Task . Delay ( 1000 ) ;
172+ }
173+
174+ MessageSource source = await client . GetMessageSource ( messages [ 0 ] . Id ) ;
175+
176+ string url = Utils . ExtractUrlFromHtml ( source . Data ) ;
177+
178+ if ( ! string . IsNullOrEmpty ( url ) )
179+ {
180+ driver . Navigate ( ) . GoToUrl ( url ) ;
181+
182+ Input ( driver , By . Id ( "input-firstName" ) , Utils . Random ( 5 ) ) ;
183+ Thread . Sleep ( 500 ) ;
184+ Input ( driver , By . Id ( "input-lastName" ) , Utils . Random ( 5 ) ) ;
185+ Thread . Sleep ( 500 ) ;
186+
187+ Click ( driver , By . CssSelector ( ".MuiAutocomplete-popupIndicator" ) ) ;
188+
189+ WebDriverWait wait = new WebDriverWait ( driver , TimeSpan . FromSeconds ( 5 ) ) ;
190+ wait . Until ( ExpectedConditions . VisibilityOfAllElementsLocatedBy ( By . CssSelector ( ".MuiAutocomplete-option" ) ) ) ;
191+
192+ ReadOnlyCollection < IWebElement > options = driver . FindElements ( By . CssSelector ( ".MuiAutocomplete-option" ) ) ;
193+
194+ Random random = new Random ( ) ;
195+ int index = random . Next ( options . Count ) ;
196+ options [ index ] . Click ( ) ;
197+
198+ Input ( driver , By . Id ( "input-password-new" ) , password ) ;
199+ Thread . Sleep ( 500 ) ;
200+ Input ( driver , By . Id ( "input-password-again" ) , password ) ;
201+ Thread . Sleep ( 500 ) ;
202+ Click ( driver , By . XPath ( "//*[@id='root']/div/div[1]/div/div/div/div/div[8]/button" ) ) ;
203+ Thread . Sleep ( 500 ) ;
204+
205+ Console . WriteLine ( $ "{ email } :{ password } ") ;
206+ File . AppendAllText ( "Accounts.txt" , $ "{ email } :{ password } \n ") ;
207+
208+ await client . DeleteMessage ( messages [ 0 ] . Id ) ;
209+ await client . DeleteAccount ( ) ;
210+
211+ driver . Manage ( ) . Cookies . DeleteAllCookies ( ) ;
212+ Thread . Sleep ( 500 ) ;
213+ }
214+ }
215+
216+ driver . Quit ( ) ;
217+ }
218+
219+ private static ChromeDriverService GetChromeDriverService ( )
220+ {
221+ ChromeDriverService service = ChromeDriverService . CreateDefaultService ( ) ;
222+
223+ service . EnableVerboseLogging = false ;
224+ service . SuppressInitialDiagnosticInformation = true ;
225+
226+ return service ;
227+ }
228+
229+ private static ChromeOptions GetChromeOptions ( )
230+ {
231+ ChromeOptions options = new ChromeOptions ( ) ;
232+ options . AddArgument ( "--start-maximized" ) ;
233+ options . AddExcludedArgument ( "--enable-automation" ) ;
234+ options . AddUserProfilePreference ( "credentials_enable_service" , false ) ;
235+ options . AddUserProfilePreference ( "profile.default_content_setting_values.images" , 2 ) ;
236+
237+ //options.AddArgument("--headless");
238+
239+ return options ;
240+ }
241+
242+ public static void Click ( ChromeDriver driver , By by )
243+ {
244+ WebDriverWait wait = new WebDriverWait ( driver , TimeSpan . FromSeconds ( 40 ) ) ;
245+
246+ bool element = wait . Until ( condition =>
247+ {
248+ try
249+ {
250+ IWebElement e = driver . FindElement ( by ) ;
251+
252+ if ( e != null && e . Displayed )
253+ {
254+ e . Click ( ) ;
255+ return true ;
256+ }
257+ else
258+ {
259+ return false ;
260+ }
261+ }
262+ catch ( StaleElementReferenceException )
263+ {
264+ return false ;
265+ }
266+ catch ( NoSuchElementException )
267+ {
268+ return false ;
269+ }
270+ } ) ;
271+ }
272+
273+ public static void Input ( ChromeDriver driver , By by , string text )
274+ {
275+ WebDriverWait wait = new WebDriverWait ( driver , TimeSpan . FromSeconds ( 20 ) ) ;
276+
277+ bool element = wait . Until ( condition =>
278+ {
279+ try
280+ {
281+ IWebElement e = driver . FindElements ( by ) . FirstOrDefault ( ) ;
282+
283+ if ( e != null && e . Displayed )
284+ {
285+ e . SendKeys ( text ) ;
286+ return true ;
287+ }
288+ else
289+ {
290+ return false ;
291+ }
292+ }
293+ catch ( StaleElementReferenceException )
294+ {
295+ return false ;
296+ }
297+ catch ( NoSuchElementException )
298+ {
299+ return false ;
300+ }
301+ } ) ;
302+ }
303+ }
304+ }
0 commit comments