

set AAPT=_data\aapt.exe

rd /s /q %1\META-INF
set "cd_=%1"
:loop
set cd_=%cd_:*\=%
set cd_tmp=%cd_:\=%
if not %cd_tmp%==%cd_% goto loop

set route=%cd_%
set num=0
set layers_discard=1
call :antitone "%route%"
call :intercept "%str%"
call :antitone "%route%"

set appname=%cd_%

rd %temp%\apkbuilder /s /q
md %temp%\apkbuilder
xcopy /e /c /i /g /h /r /k /y %1 %temp%\apkbuilder
cd /d %temp%\apkbuilder
del /f /s /q *.ttt
del /f /s /q *.bak

cd /d %1\..
:loop1
set "cdd_=%cdd_:*\=%"
set "cdd_tmp=%cdd_:\=%"
if not "%cdd_tmp%"=="%cdd_%" goto loop1
set SUBDIR=%2\..
md %SUBDIR%

"%AAPT%" p -f -F %SUBDIR%\%appname%.apk "%temp%\apkbuilder"

java -jar "_data\SignAPK.jar" %SUBDIR%\%appname%.apk

:intercept
set "route=%~1"
:loopp2
set "route=%route:*_=%"
set /a num+=1
if %num% lss %layers_discard% goto loopp2
goto :eof
