@echo off
setlocal enabledelayedexpansion
color 0A
cls
echo ################################################################################
echo ##============================================================================##
echo ## CFW 4.xx+ F.A.R. Script v0.5b ##
echo ## by zeroblu3 ##
echo ##============================================================================##
echo ################################################################################
echo.
timeout 3
if %~x1==.BIN (goto eboomenu)
if %~x1==.pkg (goto extract)
else (goto incofile)
:incofile
cls
color 04
echo Incorrect filetype. Prease try another file.
timeout 5
goto exit
:extract
cls
echo ################################################################################
echo ######################## Extracting .pkg please wait ###########################
echo ################################################################################
echo.
echo ####################
echo ## IGNORE WARNING ##
echo ####################
echo.
set PS3_KEYS=%~d0%~p0\ps3keys
%~d0
cd %~p0\extract_here
ungpkg.exe %1 "extract_here\..\%~n1/"
goto moveb1
:moveb1
cd extract_here
DIR /ad /b>dir2.txt
set /p dire=<dir2.txt
move .\"%dire%"\USRDIR\EBOOT.BIN ..
del dir2.txt
cls
timeout 1
goto ebofix
:ebofix
cd ..
if not exist EBOOT.BIN (goto error1)
if not exist EBOOT.ELF (
scetool\scetool.exe --decrypt EBOOT.BIN EBOOT.ELF>DEC.ELF
)
if not exist EBOOT.ELF (goto error2)
set contentid=NONE
scetool\scetool.exe -i EBOOT.BIN>scetool\selfinfo.txt
for /f "skip=3 tokens=1,*" %%i in (scetool\selfinfo.txt) do if "%%i"=="ContentID" set contentid=%%j
if %contentid%==NONE (goto fix4xx)
:fix4xx
scetool\scetool.exe -v --sce-type=SELF --compress-data=TRUE --skip-sections=TRUE --key-revision=10 --self-auth-id=1010000001000003 --self-add-shdrs=TRUE --self-vendor-id=01000002 --self-type=NPDRM --self-app-version=0001000000000000 --self-fw-version=0003006000000000 --np-license-type=FREE --np-content-id=%contentid% --np-app-type=EXEC --np-real-fname=EBOOT.BIN --encrypt EBOOT.ELF EBOOT.BIN
if exist DEC.ELF (del *.ELF)
timeout 1
cls
goto movebo2
:movebo2
move EBOOT.BIN ./extract_here/
cd extract_here
move EBOOT.BIN .\"%dire%"\USRDIR\
del dir3.txt
cls
timeout 1
goto makconf
:makconf
cls
color 0A
copy %1 id.txt
cls
echo ################################################################################
echo ##################### Extracting Content ID please wait ########################
echo ################################################################################
strings.exe -f 48 -n 36 id.txt>idi.txt
set id=NULL
for /f "skip=3 tokens=* delims= " %%i in (idi.txt) do set id=%%i
del idi.txt
del id.txt
echo Content-ID = %id% >package.conf
echo K_licensee = 0x00000000000000000000000000000000 >>package.conf
echo DRM_Type = Free >>package.conf
echo Content_Type = GameExec >>package.conf
echo PackageVersion = 01.05 >>package.conf
goto expid
:expid
set lalala=NONE
for /f "tokens=3 delims=-,_" %%i in (package.conf) do set lalala=%%i
if %lalala%==NONE (for /f %%i in (package.conf) do set lalala=%%i)
goto repack
:repack
cls
color 01
rename "%dire%" "%lalala%"
psn_package_npdrm.exe .\package.conf %lalala%
if not "%ERRORLEVEL%"=="0" (goto error3)
cls
timeout 1
goto cleanexit
:cleanexit
cls
move .\*.pkg ..
cls
color 0A
echo.
echo ===============================================================================
echo ===============================================================================
echo CFW 4.xx .pkg Resigner ScriptFA
echo by zeroblu3
echo ===============================================================================
echo ===============================================================================
echo.
echo.
echo All done. Press any key to exit.
echo.
echo Have fun
pause>nul
rd /s/q %lalala%
del package.conf
cd ..\scetool
del selfinfo.txt
cls
goto exit
:exit
exit
:error1
cls
color 04
echo ##################### WARNING #####################
echo # PKG NOT EXTRACTED #
echo # OR #
echo # EBOOT.BIN MISSING #
echo ###################################################
cd extract_here
rd /s/q %lalala%
timeout 5
exit
:error2
cls
color 04
echo ##################### WARNING #####################
echo # UNABLE TO DECRYPT EBOOT.BIN #
echo ###################################################
cd extract_here
rd /s/q %lalala%
cd ..
del EBOOT.BIN
del DEC.ELF
timeout 5
exit
:error3
cls
color 04
echo ##################### WARNING #####################
echo # UNABLE TO REPACK PKG #
echo # (Check Content ID) #
echo ###################################################
rd /s/q %lalala%
del package.conf
cd ..\scetool
del selfinfo.txt
timeout 5
exit
:eboomenu
cls
color 0A
echo #############################
echo ##### SELECT EBOOT TYPE #####
echo #############################
echo # 1) NPDRM EBOOT #
echo #---------------------------#
echo # 2) DISC EBOOT #
echo #############################
echo.
set select=NONE
set /p select= Select (1 or 2) and press ENTER:
if %select%==1 (goto ebofix2)
if %select%==2 (goto ebofix3) else (goto invalid)
:invalid
cls
color 04
echo Invalid input. Please try again.
timeout 3
goto eboomenu
:ebofix2
%~d0
cd %~dp0
copy /Y "%~f1" "%~dp0EBOOT.BIN"
cls
timeout 1
if not exist EBOOT.ELF (
scetool\scetool.exe --decrypt EBOOT.BIN EBOOT.ELF>DEC.ELF
)
if not exist EBOOT.ELF (goto error5)
scetool\scetool.exe -i EBOOT.BIN>scetool\selfinfo.txt
ren "%~f1" EBOOT.BIN.BAK
del "%~f1"
scetool\scetool.exe -v --sce-type=SELF --compress-data=TRUE --skip-sections=TRUE --key-revision=10 --self-auth-id=1010000001000003 --self-add-shdrs=TRUE --self-vendor-id=01000002 --self-type=NPDRM --self-app-version=0001000000000000 --self-fw-version=0003006000000000 --np-license-type=FREE --np-content-id=%contentid% --np-app-type=EXEC --np-real-fname=EBOOT.BIN --encrypt EBOOT.ELF EBOOT.BIN
if exist DEC.ELF (del *.ELF)
timeout 1
cls
goto cleanexit2
:ebofix3
%~d0
cd %~dp0
copy /Y "%~f1" "%~dp0EBOOT.BIN"
cls
timeout 1
if not exist EBOOT.ELF (
scetool\scetool.exe --decrypt EBOOT.BIN EBOOT.ELF>DEC.ELF
)
if not exist EBOOT.ELF (goto error5)
scetool\scetool.exe -i EBOOT.BIN>"scetool\selfinfo.txt
ren "%~f1" EBOOT.BIN.BAK
del "%~f1"
scetool\scetool.exe scetool.exe -v --sce-type=SELF --compress-data=TRUE --skip-sections=TRUE --key-revision=10 --self-auth-id=1010000001000003 --self-vendor-id=01000002 --self-type=APP --self-app-version=0001000000000000 --self-fw-version=0003006000000000 --encrypt EBOOT.ELF EBOOT.BIN
if exist DEC.ELF (del *.ELF)
timeout 1
cls
goto cleanexit2
:cleanexit2
cd scetool
del selfinfo.txt
cls
color 0A
echo.
echo ===============================================================================
echo ===============================================================================
echo CFW 4.xx+ F.A.R. Script
echo by zeroblu3
echo ===============================================================================
echo ===============================================================================
echo.
echo.
echo All done. Press any key to exit.
echo.
echo Have fun
pause>nul
cls
goto exit
:error5
color 04
echo ##################### WARNING #####################
echo # UNABLE TO DECRYPT EBOOT.BIN #
echo # OR #
echo # EBOOT/TOOL NOT ON SAME PARTITION #
echo ###################################################
del DEC.ELF
timeout 5
exit