-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathblueStackRoot.cmd
More file actions
487 lines (417 loc) · 22.7 KB
/
blueStackRoot.cmd
File metadata and controls
487 lines (417 loc) · 22.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
@echo off
setlocal enabledelayedexpansion
:: Check for administrative privileges
net session >nul 2>&1
if '%errorlevel%' NEQ '0' (
echo Requesting administrative privileges...
echo If the script does not work, please manually run it as an administrator.
pause
goto UACPrompt
) else ( goto gotAdmin )
:UACPrompt
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
exit /B
:gotAdmin
if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
pushd "%CD%"
CD /D "%~dp0"
:: Get the installation path of BlueStacks from the registry
for /f "tokens=2*" %%a in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\BlueStacks_nxt" /v "UserDefinedDir"') do set "defaultDirectory=%%b"
:: Check if the BlueStacks path was found in the registry
if not defined defaultDirectory (
echo BlueStacks installation path not found in registry. Using hardcoded path which could be wrong.
powershell -Command "Write-Host 'Please use option 5 to set the correct path.' -ForegroundColor Red"
set "defaultDirectory=%ProgramData%\BlueStacks_nxt"
)
:: Rest of the script
if exist "%~dp0bluestacksconfig.txt" (
set /p customDirectory=<bluestacksconfig.txt
if not defined customDirectory (
set "customDirectory=%defaultDirectory%"
)
) else (
set "customDirectory=%defaultDirectory%"
)
rem remove spaces from the custom directory
set "customDirectory=%customDirectory: =%"
:: Ascii art for the program :D
:: Presenting all options at the beginning
:start_options
powershell -Command "Write-Host ' ____ _ _ _ ____ _ _____ _ ' -ForegroundColor Blue; Write-Host ' | __ )| |_ _ ___ ___| |_ __ _ ___| | _____ | _ \ ___ ___ | |_ |_ _|__ ___ | |' -ForegroundColor Blue; Write-Host ' | _ \| | | | |/ _ \/ __| __/ _` |/ __| |/ / __| | |_) / _ \ / _ \| __| | |/ _ \ / _ \| |' -ForegroundColor Blue; Write-Host ' | |_) | | |_| | __/\__ \ || (_| | (__| <\__ \ | _ < (_) | (_) | |_ | | (_) | (_) | |' -ForegroundColor Blue; Write-Host ' |____/|_|\__,_|\___||___/\__\__,_|\___|_|\_\___/ |_| \_\___/ \___/ \__| |_|\___/ \___/|_|' -ForegroundColor Blue; Write-Host ''; Write-Host ('{0,-30} | {1,-30} | {2,-30}' -f 'Root Options:', 'Unroot Options:', 'Other Options:'); Write-Host ('{0,-30} | {1,-30} | {2,-30}' -f '1. Apply BlueStacks Android 7', '4. Undo BlueStacks Android 7', '8. Force Custom BlueStacks Path'); Write-Host ('{0,-30} | {1,-30} | {2,-30}' -f '2. Apply BlueStacks Android 9', '5. Undo BlueStacks Android 9', 'Current Path: %customDirectory%'); Write-Host ('{0,-30} | {1,-30} | {2,-30}' -f '3. Apply BlueStacks Android 11', '6. Undo BlueStacks Android 11', ''); Write-Host ('{0,-30} | {1,-30} | {2,-30}' -f '', '7. FinalUndoRoot All Versions', ''); Write-Host '';"
set /p choice=Enter option number:
if %choice%=="" (
echo Invalid option. Please enter a number between 1 and 8.
pause
goto start_options
) else if "%choice%"=="1" (
powershell -Command "Write-Host 'You chose to root Android 7 (Nougat32)' -ForegroundColor Red -NoNewline; Write-Host ' Please edit the bat file and replace Nougat32 with Nougat64 if you are using 64-bit version of BlueStacks Android 7' -ForegroundColor Red; Start-Sleep -Seconds 3"
set "version=Nougat32"
set "clonedVersion=Nougat32"
goto apply_changes
) else if "%choice%"=="2" (
set "version=Pie64"
set "clonedVersion=Pie64"
goto apply_changes
) else if "%choice%"=="3" (
set "version=Rvc64"
set "clonedVersion=Rvc64"
goto apply_changes
) else if "%choice%"=="4" (
set "version=Nougat32"
set "clonedVersion=Nougat32"
goto undo_both_changes
) else if "%choice%"=="5" (
set "version=Pie64"
set "clonedVersion=Pie64"
goto undo_both_changes
) else if "%choice%"=="6" (
set "version=Rvc64"
set "clonedVersion=Rvc64"
goto undo_both_changes
) else if "%choice%"=="7" (
goto undo_all_changes_final
) else if "%choice%"=="8" (
echo The default directory is C:\ProgramData\BlueStacks_nxt
set /p "customDirectory=Please enter your Bluestacks_nxt directory: "
if "!customDirectory:~-1!"=="\" (
set "customDirectory=!customDirectory:~0,-1!"
)
if "!customDirectory:~-1!"=="/" (
set "customDirectory=!customDirectory:~0,-1!"
)
echo You entered: !customDirectory!
echo !customDirectory! > bluestacksconfig.txt
powershell -Command "Write-Host 'The path you entered has been saved to bluestacksconfig.txt for future rooting if this script''s location does not change' -ForegroundColor Green"
pause
powershell -Command "Clear-Host"
goto start_options
) else (
echo Invalid option. Please enter a number between 1 and 8.
pause
goto start_options
)
:apply_changes
taskkill /IM "HD-MultiInstanceManager.exe" /F 2>NUL
taskkill /IM "HD-Player.exe" /F 2>NUL
taskkill /IM "BlueStacksHelper.exe" /F 2>NUL
taskkill /IM "BstkSVC.exe" /F 2>NUL
set "XML_FILE=%customDirectory%\Engine\%clonedVersion%\%clonedVersion%.bstk"
set "CONF_FILE=%customDirectory%\bluestacks.conf"
attrib -R "!XML_FILE!"
attrib -R "!CONF_FILE!"
set "TEMP_FILE=!CONF_FILE!.tmp"
attrib -R "!TEMP_FILE!"
:check_file
if not exist "!CONF_FILE!" (
powershell -Command "Write-Host 'Configuration file not found. If you are here please rerun script and choose option 5' -ForegroundColor Red"
echo The default path is C:\ProgramData\BlueStacks_nxt
set /p "BLUESTACKS_PATH=Please enter the path to your BlueStacks_nxt directory choose a different directory if it include spaces, special characters or other unreasonable file paths: "
echo BLUESTACKS_PATH is set to: !BLUESTACKS_PATH!
set "XML_FILE=!BLUESTACKS_PATH!\Engine\%clonedVersion%\%clonedVersion%.bstk"
echo XML_FILE is set to: !XML_FILE!
set "CONF_FILE=!BLUESTACKS_PATH!\bluestacks.conf"
echo CONF_FILE is set to: !CONF_FILE!
set "TEMP_FILE=!CONF_FILE!.tmp"
attrib -R "!XML_FILE!"
attrib -R "!CONF_FILE!"
attrib -R "!TEMP_FILE!"
goto check_file
)
if not exist "!XML_FILE!" (
powershell -Command "Write-Host 'Android emulator not installed or not run at least once and closed or wrong instance chosen.' -ForegroundColor Red"
pause
exit /B
)
:: Set the ENGINE_PATH variable to the hardcoded path
set "ENGINE_PATH=%customDirectory%\Engine"
if exist "!BLUESTACKS_PATH!" (
echo alternate path discovered
set "ENGINE_PATH=!BLUESTACKS_PATH!\Engine"
)
echo Automatically detecting... please run the cloned instance you wish to root and close it before proceeding
echo.
echo.
echo Detecting the cloned instance to root...
echo --------------------------------------------------------------------------
:: Call PowerShell to check the file size and delete the file if it's too large
powershell -Command "$enginePath = '!ENGINE_PATH!'; $enginePath = $enginePath -replace '\\Engine$'; $fileSize = (Get-Item $enginePath\Logs\Player.log).Length / 1MB; if ($fileSize -gt 10) { Remove-Item $enginePath\Logs\Player.log -Force; Write-Host 'The log file was too large and has been deleted. Please rerun your cloned instance you wish to root and close the script'; exit 1 } else { exit 0 }" || (pause && exit /b)
:: Call PowerShell to read the log file in reverse order and search for the pattern to get cloned instance #
if "%clonedVersion%"=="Rvc64" (
for /f "delims=" %%i in ('powershell -Command "$enginePath = '!ENGINE_PATH!'; $enginePath = $enginePath -replace '\\Engine$'; $logContent = Get-Content $enginePath\Logs\Player.log -ReadCount 0; $instanceNumber = $logContent | Select-String 'Rvc64(_\d+)?' -AllMatches | ForEach-Object { $_.Matches } | ForEach-Object { $_.Value } | Select-Object -Last 1; $instanceNumber"') do (
powershell -Command "Write-Host 'The program detected %%i ' -ForegroundColor Green"
set "tempVar=%%i"
)
set "version=!tempVar!"
echo.
) else if "%clonedVersion%"=="Pie64" (
for /f "delims=" %%i in ('powershell -Command "$enginePath = '!ENGINE_PATH!'; $enginePath = $enginePath -replace '\\Engine$'; $logContent = Get-Content $enginePath\Logs\Player.log -ReadCount 0; $instanceNumber = $logContent | Select-String 'Pie64(_\d+)?' -AllMatches | ForEach-Object { $_.Matches } | ForEach-Object { $_.Value } | Select-Object -Last 1; $instanceNumber"') do (
powershell -Command "Write-Host 'The program detected %%i ' -ForegroundColor Green"
set "tempVar=%%i"
)
set "version=!tempVar!"
echo.
)
echo The program will root: !version!
:: Rest of your script...
for %%i in ("%CONF_FILE%") do set "BLUESTACKS_PATH=%%~dpi"
echo BLUESTACKS_PATH is set to: %BLUESTACKS_PATH%
powershell -Command "Add-MpPreference -ExclusionPath '%BLUESTACKS_PATH%' 2>$null; Add-MpPreference -ExclusionPath '%~dp0' 2>$null" && (
echo Excluded path: %BLUESTACKS_PATH%
echo Excluded path: %~dp0
) || (
echo No Windows antivirus detected.
)
rem Define search and replace strings
set "search_str1=type=\"ReadOnly\""
set "replace_str1=type=\"Normal\""
set "search_str2=type=\"ReadOnly\""
set "replace_str2=type=\"Normal\""
rem Create a backup of the original XML file
attrib -R "%XML_FILE%.bak"
copy "%XML_FILE%" "%XML_FILE%.bak" /Y > nul
rem Make changes to the XML file
copy "%XML_FILE%" "%TEMP_FILE%" /Y > nul
powershell -Command "(Get-Content '%TEMP_FILE%') | ForEach-Object { $_ -replace '%search_str1%', '%replace_str1%' } | Set-Content '%TEMP_FILE%'"
move /Y "%TEMP_FILE%" "%XML_FILE%" > nul
rem Create a backup of the original bluestacks.conf file
attrib -R "%CONF_FILE%.bak"
copy "%CONF_FILE%" "%CONF_FILE%.bak" /Y > nul
rem Make changes to the temporary bluestacks.conf file using PowerShell
copy "%CONF_FILE%" "%TEMP_FILE%" /Y > nul
powershell -Command "Get-Content '%TEMP_FILE%' | ForEach-Object { $_ -replace 'enable_root_access=\"0\"', 'enable_root_access=\"1\"' -replace 'bst.feature.rooting=\"0\"', 'bst.feature.rooting=\"1\"' } | Set-Content '%TEMP_FILE%.tmp'; Remove-Item -Path '%TEMP_FILE%'; Rename-Item -Path '%TEMP_FILE%.tmp' -NewName '%TEMP_FILE%'"
rem Replace the original bluestacks.conf file with the modified temporary bluestacks.conf file
move /Y "%TEMP_FILE%" "%CONF_FILE%" > nul
powershell -Command "Write-Host 'Changes applied successfully.' -ForegroundColor Green"
echo If you suspect bluestacks.conf file was corrupted, please choose undo both writable and root immediately
powershell -Command "Remove-MpPreference -ExclusionPath '%~dp0' 2>$null" && (
echo Exclusion removed for path: %~dp0
)
pause
powershell -Command "Clear-Host"
goto start_options
:undo_both_changes
taskkill /IM "HD-MultiInstanceManager.exe" /F 2>NUL
taskkill /IM "HD-Player.exe" /F 2>NUL
taskkill /IM "BlueStacksHelper.exe" /F 2>NUL
taskkill /IM "BstkSVC.exe" /F 2>NUL
set "XML_FILE=%customDirectory%\Engine\%clonedVersion%\%clonedVersion%.bstk"
set "CONF_FILE=%customDirectory%\bluestacks.conf"
attrib -R "!XML_FILE!"
attrib -R "!CONF_FILE!"
set "TEMP_FILE=!CONF_FILE!.tmp"
attrib -R "!TEMP_FILE!"
:check_file_undo
if not exist "!CONF_FILE!" (
echo Configuration file not found.
echo The default path is C:\ProgramData\BlueStacks_nxt
set /p "BLUESTACKS_PATH=Please enter the path to your BlueStacks_nxt directory choose a different directory if it include spaces, special characters or other unreasonable file paths: "
echo BLUESTACKS_PATH is set to: !BLUESTACKS_PATH!
set "XML_FILE=!BLUESTACKS_PATH!\Engine\%clonedVersion%\%clonedVersion%.bstk"
echo XML_FILE is set to: !XML_FILE!
set "CONF_FILE=!BLUESTACKS_PATH!\bluestacks.conf"
echo CONF_FILE is set to: !CONF_FILE!
set "TEMP_FILE=!CONF_FILE!.tmp"
attrib -R "!XML_FILE!"
attrib -R "!CONF_FILE!"
attrib -R "!TEMP_FILE!"
goto check_file_undo
)
if not exist "!XML_FILE!" (
echo Android emulator not installed or not run at least once and closed or wrong instance chosen.
pause
exit /B
)
:: Set the ENGINE_PATH variable to the hardcoded path
set "ENGINE_PATH=%ProgramData%\BlueStacks_nxt\Engine"
if exist "!BLUESTACKS_PATH!" (
echo alternate path discovered
set "ENGINE_PATH=!BLUESTACKS_PATH!\Engine"
)
echo Automatically detecting... please run the cloned instance you wish to undo root and close it before proceeding
echo.
echo.
echo Detecting the cloned instance to undo root...
echo --------------------------------------------------------------------------
:: Call PowerShell to check the file size and delete the file if it's too large
powershell -Command "$enginePath = '!ENGINE_PATH!'; $enginePath = $enginePath -replace '\\Engine$'; $fileSize = (Get-Item $enginePath\Logs\Player.log).Length / 1MB; if ($fileSize -gt 10) { Remove-Item $enginePath\Logs\Player.log -Force; Write-Host 'The log file was too large and has been deleted. Please rerun your cloned instance you wish to undo root and close the script'; exit 1 } else { exit 0 }" || (pause && exit /b)
:: Call PowerShell to read the log file in reverse order and search for the pattern to get cloned instance #
if "%clonedVersion%"=="Rvc64" (
for /f "delims=" %%i in ('powershell -Command "$enginePath = '!ENGINE_PATH!'; $enginePath = $enginePath -replace '\\Engine$'; $logContent = Get-Content $enginePath\Logs\Player.log -ReadCount 0; $instanceNumber = $logContent | Select-String 'Rvc64(_\d+)?' -AllMatches | ForEach-Object { $_.Matches } | ForEach-Object { $_.Value } | Select-Object -Last 1; $instanceNumber"') do (
powershell -Command "Write-Host 'The program detected %%i ' -ForegroundColor Green"
set "tempVar=%%i"
)
set "version=!tempVar!"
echo.
) else if "%clonedVersion%"=="Pie64" (
for /f "delims=" %%i in ('powershell -Command "$enginePath = '!ENGINE_PATH!'; $enginePath = $enginePath -replace '\\Engine$'; $logContent = Get-Content $enginePath\Logs\Player.log -ReadCount 0; $instanceNumber = $logContent | Select-String 'Pie64(_\d+)?' -AllMatches | ForEach-Object { $_.Matches } | ForEach-Object { $_.Value } | Select-Object -Last 1; $instanceNumber"') do (
powershell -Command "Write-Host 'The program detected %%i ' -ForegroundColor Green"
set "tempVar=%%i"
)
set "version=!tempVar!"
echo.
)
echo The program will undo root for: !version!
:: Rest of your script...
for %%i in ("%CONF_FILE%") do set "BLUESTACKS_PATH=%%~dpi"
echo BLUESTACKS_PATH is set to: %BLUESTACKS_PATH%
powershell -Command "Add-MpPreference -ExclusionPath '%BLUESTACKS_PATH%' 2>$null; Add-MpPreference -ExclusionPath '%~dp0' 2>$null" && (
echo Excluded paths: %BLUESTACKS_PATH%, %~dp0
) || (
echo No Windows antivirus detected.
)
rem Define search and replace strings
set "search_str1=type=\"Normal\""
set "replace_str1=type=\"ReadOnly\""
set "search_str2=type=\"Normal\""
set "replace_str2=type=\"ReadOnly\""
rem Revert changes in the XML file
echo Reverting changes in XML file...
powershell -Command "$count = 0; (Get-Content '%XML_FILE%') | ForEach-Object { if ($count -lt 2 -and $_ -match '%search_str1%') { $count++; $_ -replace '%search_str1%', '%replace_str1%' } else { $_ } } | Set-Content '%XML_FILE%'"
rem Check if the PowerShell command executed successfully
if %errorlevel% neq 0 (
echo Failed to revert changes in XML file. Restoring from backup...
copy "%XML_FILE%.bak" "%XML_FILE%" /Y > nul
pause
exit /b 1
)
rem Make changes to the temporary bluestacks.conf file using PowerShell
copy "%CONF_FILE%" "%TEMP_FILE%" /Y > nul
rem powershell -Command "(Get-Content '%TEMP_FILE%') -replace 'bst.instance.%version%.enable_root_access=\"1\"', 'bst.instance.%version%.enable_root_access=\"0\"' | Set-Content '%TEMP_FILE%'; (Get-Content '%TEMP_FILE%') -replace 'bst.feature.rooting=\"1\"', 'bst.feature.rooting=\"0\"' | Set-Content '%TEMP_FILE%'"
rem Check if the PowerShell command executed successfully
if %errorlevel% neq 0 (
echo Failed to revert changes in bluestacks.conf file. Restoring from backup...
copy "%CONF_FILE%.bak" "%CONF_FILE%" /Y > nul
pause
exit /b 1
)
rem Replace the original bluestacks.conf file with the modified temporary bluestacks.conf file
move /Y "%TEMP_FILE%" "%CONF_FILE%" > nul
powershell -Command "Write-Host 'Changes undone successfully.' -ForegroundColor Green"
powershell -Command "Remove-MpPreference -ExclusionPath '%~dp0' 2>$null" && (
echo Exclusion removed for path: %~dp0
)
pause
exit /b 0
:undo_all_changes_final
taskkill /IM "HD-MultiInstanceManager.exe" /F 2>NUL
taskkill /IM "HD-Player.exe" /F 2>NUL
taskkill /IM "BlueStacksHelper.exe" /F 2>NUL
taskkill /IM "BstkSVC.exe" /F 2>NUL
echo Please choose the Android version:
echo 1. Android 7 (Nougat32)
echo 2. Android 9 (Pie)
echo 3. Android 11
set /p "version_choice=Enter option number: "
:undo_all_changes_finalCheckVersion
if "!version_choice!"=="1" (
set "version=Nougat32"
set "clonedVersion=Nougat32"
) else if "!version_choice!"=="2" (
set "version=Pie64"
set "clonedVersion=Pie64"
) else if "!version_choice!"=="3" (
set "version=Rvc64"
set "clonedVersion=Rvc64"
) else (
echo Invalid option. Please enter a number between 1 and 3.
pause
goto undo_all_changes_finalCheckVersion
)
set "XML_FILE=%customDirectory%\Engine\%clonedVersion%\%clonedVersion%.bstk"
set "CONF_FILE=%customDirectory%\bluestacks.conf"
attrib -R "!XML_FILE!"
attrib -R "!CONF_FILE!"
set "TEMP_FILE=!CONF_FILE!.tmp"
attrib -R "!TEMP_FILE!"
:check_file_undo
if not exist "!CONF_FILE!" (
echo Configuration file not found.
echo The default path is C:\ProgramData\BlueStacks_nxt
set /p "BLUESTACKS_PATH=Please enter the path to your BlueStacks_nxt directory choose a different directory if it include spaces, special characters or other unreasonable file paths: "
echo BLUESTACKS_PATH is set to: !BLUESTACKS_PATH!
set "XML_FILE=!BLUESTACKS_PATH!\Engine\%clonedVersion%\%clonedVersion%.bstk"
echo XML_FILE is set to: !XML_FILE!
set "CONF_FILE=!BLUESTACKS_PATH!\bluestacks.conf"
echo CONF_FILE is set to: !CONF_FILE!
set "TEMP_FILE=!CONF_FILE!.tmp"
attrib -R "!XML_FILE!"
attrib -R "!CONF_FILE!"
attrib -R "!TEMP_FILE!"
goto check_file_undo
)
if not exist "!XML_FILE!" (
echo Android emulator not installed or not run at least once and closed or wrong instance chosen.
pause
exit /B
)
:: Set the ENGINE_PATH variable to the hardcoded path
set "ENGINE_PATH=%ProgramData%\BlueStacks_nxt\Engine"
if exist "!BLUESTACKS_PATH!" (
echo alternate path discovered
set "ENGINE_PATH=!BLUESTACKS_PATH!\Engine"
)
echo Automatically detecting... please run the cloned instance you wish to undo root and close it before proceeding
echo.
echo.
echo Detecting the cloned instance to undo root...
echo --------------------------------------------------------------------------
:: Call PowerShell to check the file size and delete the file if it's too large
powershell -Command "$enginePath = '!ENGINE_PATH!'; $enginePath = $enginePath -replace '\\Engine$'; $fileSize = (Get-Item $enginePath\Logs\Player.log).Length / 1MB; if ($fileSize -gt 10) { Remove-Item $enginePath\Logs\Player.log -Force; Write-Host 'The log file was too large and has been deleted. Please rerun your cloned instance you wish to undo root and close the script'; exit 1 } else { exit 0 }" || (pause && exit /b)
:: Call PowerShell to read the log file in reverse order and search for the pattern to get cloned instance #
if "%clonedVersion%"=="Rvc64" (
for /f "delims=" %%i in ('powershell -Command "$enginePath = '!ENGINE_PATH!'; $enginePath = $enginePath -replace '\\Engine$'; $logContent = Get-Content $enginePath\Logs\Player.log -ReadCount 0; $instanceNumber = $logContent | Select-String 'Rvc64(_\d+)?' -AllMatches | ForEach-Object { $_.Matches } | ForEach-Object { $_.Value } | Select-Object -Last 1; $instanceNumber"') do (
powershell -Command "Write-Host 'The program detected %%i ' -ForegroundColor Green"
set "tempVar=%%i"
)
set "version=!tempVar!"
echo.
) else if "%clonedVersion%"=="Pie64" (
for /f "delims=" %%i in ('powershell -Command "$enginePath = '!ENGINE_PATH!'; $enginePath = $enginePath -replace '\\Engine$'; $logContent = Get-Content $enginePath\Logs\Player.log -ReadCount 0; $instanceNumber = $logContent | Select-String 'Pie64(_\d+)?' -AllMatches | ForEach-Object { $_.Matches } | ForEach-Object { $_.Value } | Select-Object -Last 1; $instanceNumber"') do (
powershell -Command "Write-Host 'The program detected %%i ' -ForegroundColor Green"
set "tempVar=%%i"
)
set "version=!tempVar!"
echo.
)
echo The program will undo root for: !version!
:: Rest of your script...
for %%i in ("%CONF_FILE%") do set "BLUESTACKS_PATH=%%~dpi"
echo BLUESTACKS_PATH is set to: %BLUESTACKS_PATH%
powershell -Command "Add-MpPreference -ExclusionPath '%BLUESTACKS_PATH%' 2>$null; Add-MpPreference -ExclusionPath '%~dp0' 2>$null" && (
echo Excluded paths: %BLUESTACKS_PATH%, %~dp0
) || (
echo No Windows antivirus detected.
)
rem Define search and replace strings
set "search_str1=type=\"Normal\""
set "replace_str1=type=\"ReadOnly\""
rem Revert changes in the XML file
echo Reverting changes in XML file...
powershell -Command "$count = 0; (Get-Content '%XML_FILE%') | ForEach-Object { if ($count -lt 2 -and $_ -match '%search_str1%') { $count++; $_ -replace '%search_str1%', '%replace_str1%' } else { $_ } } | Set-Content '%XML_FILE%'"
rem Check if the PowerShell command executed successfully
if %errorlevel% neq 0 (
echo Failed to revert changes in XML file. Restoring from backup...
copy "%XML_FILE%.bak" "%XML_FILE%" /Y > nul
pause
exit /b 1
)
rem Make changes to the temporary bluestacks.conf file using PowerShell
copy "%CONF_FILE%" "%TEMP_FILE%" /Y > nul
powershell -Command "Get-Content '%TEMP_FILE%' | ForEach-Object { $_ -replace 'enable_root_access=\"1\"', 'enable_root_access=\"0\"' -replace 'bst.feature.rooting=\"1\"', 'bst.feature.rooting=\"0\"' } | Set-Content '%TEMP_FILE%.tmp'; Remove-Item -Path '%TEMP_FILE%'; Rename-Item -Path '%TEMP_FILE%.tmp' -NewName '%TEMP_FILE%'"
rem Check if the PowerShell command executed successfully
if %errorlevel% neq 0 (
echo Failed to revert changes in bluestacks.conf file. Restoring from backup...
copy "%CONF_FILE%.bak" "%CONF_FILE%" /Y > nul
pause
exit /b 1
)
rem Replace the original bluestacks.conf file with the modified temporary bluestacks.conf file
move /Y "%TEMP_FILE%" "%CONF_FILE%" > nul
powershell -Command "Write-Host 'Changes undone successfully.' -ForegroundColor Green"
powershell -Command "Remove-MpPreference -ExclusionPath '%~dp0' 2>$null" && (
echo Exclusion removed for path: %~dp0
)
pause
exit /b 0