Skip to content

Instantly share code, notes, and snippets.

@projected1
Last active October 6, 2020 09:19
Show Gist options
  • Save projected1/c672dc5848a45a2cb75443c1516a03a0 to your computer and use it in GitHub Desktop.
Save projected1/c672dc5848a45a2cb75443c1516a03a0 to your computer and use it in GitHub Desktop.
Decompiles Java JAR files.
@rem ------------------------------------------------------
@rem Decompiles Java JAR files.
@rem This script depends on the following libraries:
@rem * 7ZIP CLI : https://www.7-zip.org/a/7z1900-extra.7z
@rem * jad decompiler: http://www.kpdus.com/jad/winnt/jadnt158.zip
@rem ------------------------------------------------------
@echo off
setlocal
if "%~1" == "" (
echo Input path argument is missing and it is not optional
echo Usage: %~0 ^<path^>
exit /b 1
)
if not exist "%~1" (
echo Input path not found
exit /b 1
)
set me=%~dp0
set tools=%me%\tools
set z7="%tools%\7z1900\7za.exe"
set jad="%tools%\jad158g.win\jad.exe"
set timestamp=%date:~10,4%%date:~7,2%%date:~4,2%%time:~0,2%%time:~3,2%%time:~6,2%%time:~9,2%
set logfile=runtime_%timestamp%.log
echo. > %logfile%
for /f "usebackq tokens=*" %%f in (`dir /s /b %1\*.jar`) do (
call :decompile %%f
)
endlocal
exit /b %errorlevel%
:decompile
set jar_path=%~1
set jar_name=%~n1
set jar_file=%~nx1
set out_dir=%me%\out\%jar_file%
echo Extracting JAR . . .
echo Extracting JAR . . . >> %logfile%
rem x - extract with full paths
rem -y - assume Yes on all queries
call %z7% x %jar_path% -o%out_dir%\%jar_file%_jar -y >> %logfile%
if not exist %out_dir%\%jar_file%_jar (
echo 7z failed!
echo 7z failed! >> %logfile%
exit /b 1
)
echo Decompiling Java classes . . .
echo Decompiling Java classes >> %logfile%
rem -o - overwrite output files without confirmation
rem -r - restore package directory structure
rem -s <ext> - output file extension (default: .jad)
rem -d <dir> - directory for output files
rem -& - redirect stderr to stdout
call %jad% -o -r -s java -d %out_dir%\%jar_file%_jad %out_dir%\%jar_file%_jar\**\*.class >> %logfile% 2>&1
exit /b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment