payload_dumper -h >nul || abort payload_dumper 无法在您的系统上运行


:file
    echo - 本功能可以直接选择zip文件，自动提取出payload.bin
    echo - 如果你已经提取出playload.bin也可以直接选择playload.bin文件
    %tishi1% 提取的zip、playload.bin
    set bin_File=
    set /p bin_File=%t1%
    if not defined bin_File ( cls & %error% 未选择文件，提取个鸡儿 & goto file )
    if not exist %bin_File% ( cls &  %error% 选择的文件不存在，提取个鸡儿 & goto file )

    set num=
    %suffix% %bin_File%
    if "%suffix2%"==".zip" (
            for /f "delims=" %%f in ('busybox unzip -l %bin_File% ^| busybox awk "/payload.bin/{print $NF}" ^| busybox tail -1') do set num=%%f
            if defined num (
                echo - 开始解压!num!
                %rdtmp%
                busybox unzip -o %bin_File% !num! -d tmp
                goto next
            ) else (
                abort 未从%bin_File%中找到playload.bin
            )
    )

    if "%suffix2%"==".bin" (
        goto Options
    )

    cls & %error% 未知的文件格式%suffix2% & goto file



:next
       if defined num (
            for /R tmp %%i in (payload.bin) do ( set bin_File=%%i )
       )
            if not exist !bin_File! (
                %error% 提取playload.bin错误，错误详情：
                echo.
                dir tmp
                pause
                abort
            )


:Options
    set gn=
    echo.
    echo - 1      自定义提取
    echo - 2      提取boot
    echo - 3      提取全部镜像
    echo - 4      仅查看有哪些镜像
    echo.
    echo.
    set /p gn=%t2%
    if "%gn%"=="1" ( goto meum1 )
    if "%gn%"=="2" ( goto meum2 )
    if "%gn%"=="3" ( goto meum3 )
    if "%gn%"=="4" ( goto meum4 )
    cls & %error% 输入错误请重新输入 & goto Options


:meum1
    setlocal
    call :name
    call :dir
    payload_dumper -d !name! !bin_File!
    echo - 提取完成，文件已输出到：%cd%\!name!.img
    endlocal
    echo.
    echo.
    echo - 是否还需要提取别的分区镜像？
    set gn=
    set /p gn=- 输入1继续提取        回车和输入任意内容为退出：
    if "%gn%"=="1" ( cd .. & goto meum1 )
    goto end


:meum2
    call :dir
    payload_dumper -d boot !bin_File!
    echo - 解包完成，文件已输出到：%cd%\boot.img
    goto end


:meum3
    call :dir
    payload_dumper !bin_File!
    echo - 解包完成，文件已输出到：%cd%
    goto end


:meum4
    payload_dumper -l !bin_File!
    abort


:name
    set n=0
    set name=
    set option=
    for /f "delims=" %%a in ('payload_dumper -l !bin_File! ^| busybox grep -v "解析"') do (
        set /a n=!n!+1
        echo !n!.%%a
        set "#!n!=%%a"
    )
    
    :c
    echo.
    echo.
    set /p option=%t2%
        if defined #%option% (
            set name=!#%option%!
            echo - 已选择提取!name!
            echo.
        ) else (
            %error% 输入错误请重新输入
            goto c
        )
            exit /B 0


:dir
    for /f "delims=" %%i in ('busybox date "+%%s"') do set d=output-%%i
    md %d%
    cd %d%
    exit /B 0


:end
    cd ..
    abort
