@ECHO OFF

CLS

TITLE Malware Zero Anti Black Screen

SET LANGCODE=%1
SET UNIQ=%2

REM * Check - Compression
IF NOT EXIST "DB\CHECK\MZK" (
	IF "%LANGCODE%" == "GLOBAL" (
		ECHO Please extract the compressed file correctly before running.
	)
	IF "%LANGCODE%" == "KOREAN" (
		ECHO 압축 파일을 올바르게 해제 후 실행해주세요.
	)
	ECHO.
	PAUSE
	EXIT /B
)

REM * Check - Start
IF NOT "%LANGCODE%" == "GLOBAL" (
	IF NOT "%LANGCODE%" == "KOREAN" (
		ECHO 잘못된 접근입니다. START.BAT 파일로 실행해주세요.
		ECHO.
		ECHO The wrong approach. Please run as START.BAT file.
		ECHO.
		PAUSE
		EXIT /B
	)
)

REM * Setup - Path
IF DEFINED SYSTEMROOT (
	SET "PATH=%CD%;%SYSTEMROOT%\System32\wbem;%SYSTEMROOT%;%SYSTEMROOT%\System32"
) ELSE (
	IF DEFINED WINDIR (
		SET "PATH=%CD%;%WINDIR%\System32\wbem;%WINDIR%;%WINDIR%\System32"
	) ELSE (
		IF "%LANGCODE%" == "GLOBAL" (
			ECHO The environment variable settings are incorrect.
		)
		IF "%LANGCODE%" == "KOREAN" (
			ECHO 환경 변수 설정이 올바르지 않습니다.
		)
		ECHO.
		PAUSE
		EXIT /B
	)
)

REM * Setup - Window Size
MODE.COM CON COLS=98 LINES=8 >Nul 2>Nul

REM * Check - Supported Language
CHCP.COM 949 >Nul 2>Nul

REM * Setup - Architecture
IF /I "%PROCESSOR_ARCHITECTURE%" == "AMD64" (
	SET ARCHITECTURE=x64
) ELSE (
	SET ARCHITECTURE=x86
)

SET "EXEGREP=TOOLS\GREP\%ARCHITECTURE%\GREP.EXE"
SET "EXESETACL=TOOLS\SETACL\%ARCHITECTURE%\SETACL.EXE"

ECHO Malware Zero Anti Black Screen is Running . . .
ECHO.
ECHO This script solves an issue where File Explorer does not launch
ECHO when the Malware Zero window closes.
ECHO.
ECHO Do not force quit . . .

SET A=0
SET B=0

:CHECK
TOOLS\TASKS\TASKLIST.EXE /FI "IMAGENAME eq explorer.exe" 2>Nul|%EXEGREP% -Fi "explorer.exe" >Nul 2>Nul
SET A=%ERRORLEVEL%

TOOLS\TASKS\TASKLIST.EXE /V /FO CSV /NH /FI "IMAGENAME eq cmd.exe" 2>Nul|%EXEGREP% -Ev "^$|Malware Zero Anti Black Screen|N/A" >Nul 2>Nul
SET B=%ERRORLEVEL%

IF %A% NEQ 0 (
	IF %B% EQU 0 (
		PING.EXE -n 1 0 >Nul 2>Nul
		GOTO CHECK
	) ELSE (
		%EXESETACL% -on "HKCU\Software\Microsoft\Internet Explorer\Approved Extensions" -ot reg -actn ace -ace "n:%USERNAME%;p:KEY_SET_VALUE;m:revoke;i:so" -ace "n:%USERNAME%;p:KEY_SET_VALUE;m:deny;i:so" -silent >Nul 2>Nul
		%EXESETACL% -on "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Schedule\CompatibilityAdapter\Signatures" -ot reg -actn setowner -ownr "n:SYSTEM" -rec yes -silent >Nul 2>Nul
		%EXESETACL% -on "HKLM\Software\Wow6432Node\Microsoft\Windows NT\CurrentVersion\Schedule\CompatibilityAdapter\Signatures" -ot reg -actn setowner -ownr "n:SYSTEM" -rec yes -silent >Nul 2>Nul

		TOOLS\TASKS\TASKKILL.EXE /F /IM "NOSLEEP.EXE" >Nul 2>Nul

		DEL /F /Q /A DB_ACTIVE\*.DB >Nul 2>Nul
		DEL /F /Q /S /A DB_EXEC\*.DB >Nul 2>Nul
		DEL /F /Q /S /A VARIABLE\*.V >Nul 2>Nul
		DEL /F /A REGTOOL.EXE.STACKDUMP >Nul 2>Nul

		ATTRIB.EXE -R -H -S "DB_EXEC\*" /S /D >Nul 2>Nul

		SETLOCAL ENABLEDELAYEDEXPANSION
		SCHTASKS.EXE /Run /TN "MalwareZeroRestartExplorerTemporaryTasks_%UNIQ%" /I >Nul 2>Nul
		IF !ERRORLEVEL! NEQ 0 (
			IF NOT DEFINED SAFEBOOT_OPTION (
				TOOLS\MESSAGEBOX\MESSAGEBOX.EXE /C:Malware Zero /T:4160 /M:파일 탐색기가 관리자 권한으로 실행되었습니다.\n\n작업 표시줄이 보이지 않거나 권한 오류가 발생할 경우\n키보드 ^<CTRL ^+ ALT ^+ DEL^> 키를 동시에\n누르신 후 로그아웃 또는 종료 메뉴를 통해 재부팅 해주세요. >Nul 2>Nul
			)
			>Nul 2>Nul START "EXPLORER" /D "!SYSTEMROOT!" /B "EXPLORER.EXE"
			ENDLOCAL
		) ELSE (
			ENDLOCAL
		)

		PING.EXE -n 3 0 >Nul 2>Nul

		SCHTASKS.EXE /End /TN "MalwareZeroRestartExplorerTemporaryTasks_%UNIQ%" >Nul 2>Nul
		SCHTASKS.EXE /Delete /TN "MalwareZeroRestartExplorerTemporaryTasks_%UNIQ%" /F >Nul 2>Nul

		FOR /F "DELIMS=," %%A IN ('SCHTASKS.EXE /Query /FO CSV 2^>Nul^|%EXEGREP% -i MalwareZero 2^>Nul') DO (
			SCHTASKS.EXE /End /TN "%%~nxA" >Nul 2>Nul
			SCHTASKS.EXE /Delete /TN "%%~nxA" /F >Nul 2>Nul
		)
	)
)

SET ARCHITECTURE=
SET EXEGREP=
SET EXESETACL=
SET LANGCODE=
SET UNIQ=