jar로 이미 묶인 패키지를 다시 풀어서 코드를 확인 하고 싶을 때 유용하게 사용할 수 있는 방법입니다.
unzip 으로 jar파일 압축 푼 class파일 javap 디컴파일링 통해 java파일 확인하기
How to decompile java class file from jar file feat. unzip, javap
1. unzip jar file / jar압축 풀기
unzip을 이용해 jar파일 압축을 풀어줍니다. 패키징 구조대로 압축이 풀리며 각 class파일이 생성됩니다.
extract your jar file by using unizp. you can see class file with your code structures.
$ unzip
UnZip 6.00 of 20 April 2009, by Info-ZIP. Maintained by C. Spieler. Send
bug reports using http://www.info-zip.org/zip-bug.html; see README for details.
Usage: unzip [-Z] [-opts[modifiers]] file[.zip] [list] [-x xlist] [-d exdir]
Default action is to extract files in list, except those in xlist, to exdir;
file[.zip] may be a wildcard. -Z => ZipInfo mode ("unzip -Z" for usage).
-p extract files to pipe, no messages -l list files (short format)
-f freshen existing files, create none -t test compressed archive data
-u update files, create if necessary -z display archive comment only
-v list verbosely/show version info -T timestamp archive to latest
-x exclude files that follow (in xlist) -d extract files into exdir
modifiers:
-n never overwrite existing files -q quiet mode (-qq => quieter)
-o overwrite files WITHOUT prompting -a auto-convert any text files
-j junk paths (do not make directories) -aa treat ALL files as text
-U use escapes for all non-ASCII Unicode -UU ignore any Unicode fields
-C match filenames case-insensitively -L make (some) names lowercase
-X restore UID/GID info -V retain VMS version numbers
-K keep setuid/setgid/tacky permissions -M pipe through "more" pager
See "unzip -hh" or unzip.txt for more help. Examples:
unzip data1 -x joe => extract all files except joe from zipfile data1.zip
unzip -p foo | more => send contents of foo.zip via pipe into program more
unzip -fo foo ReadMe => quietly replace existing ReadMe if archive file newer
$ unzip -d your-package.jar
2. decompile by javap / javap를 이용해 디컴파일링
javap 옵션 중 -c를 이용해서 class파일을 지정하면 디컴파일링 된 코드를 볼 수 있습니다. 코드 작성 할 때 처럼 깔끔한 코드모양은 아니지만 주요 메쏘드와 흐름을 볼 수 있으며, -p옵션을 함께 써주면 호출 된 세부 메쏘드 까지 확인 가능합니다.
using javap with -c option will show you simple decompiled code you selected class file. then you can add -p option to see more details with method called in your class. It is enough to check your flow of code.
$ javap
Usage: javap <options> <classes>
where possible options include:
-help --help -? Print this usage message
-version Version information
-v -verbose Print additional information
-l Print line number and local variable tables
-public Show only public classes and members
-protected Show protected/public classes and members
-package Show package/protected/public classes
and members (default)
-p -private Show all classes and members
-c Disassemble the code
-s Print internal type signatures
-sysinfo Show system info (path, size, date, MD5 hash)
of class being processed
-constants Show final constants
-classpath <path> Specify where to find user class files
-cp <path> Specify where to find user class files
-bootclasspath <path> Override location of bootstrap class files
javap -c -p {your_class}.class