Use BAT to decompile the jar package to generate the source code jar package

Source: Internet
Author: User

The tool used for decompilation is jad.exe. The test version of the author is 1.5.8e, and WinRAR is used for compression and decompression.

Jad.exe can decompile a class file as a java file. The author's BAT can decompile a jar package into a complete source code jar package through this tool, and the generated directory can also be used in eclipse

Jad.exe Official Website: http://www.kpdus.com/jad.html)

BAT script

The installation method is as follows:

Copy and paste the logs as a battery, and then place them in the same directory as jad.exe (WinRAR needs to be correctly installed)

The method is as follows: (there are three ways to use either of them, and the results are the same)

1. Double-click BAT and prompt to enter the jar package to be decompiled. Enter the complete jar path.

2. Drag and Drop the jar package on bat.

3. Right-click the jar package, select the open method, and then select use this BAT to execute

The running result is as follows:

Under the same directory of the jar package, a directory is generated. One jar directory contains two subdirectories, one directory stores all the decompressed classes, A directory stores decompiled java files. jar packages are generated by source code compression.

Notes:

1. The WinRAR used in the tool automatically identifies the installation path. Please install WinRAR correctly

2. jad.exe used by the tool must be in the same directory as BAT or a PATH that can be searched.

3. Non-class files in the jar package will also be completely copied to the source code directory to facilitate source code generation.

4. the generated directory name is the same as that of the original jar package. The file name of the generated source jar package is generated by adding-src to the original name. For example, the original jar package is jdbc. jar, the generated directory name is jdbc, And the generated source jar package name is jdbc-src.jar

5. eclipse Method 1: place the directory generated by BAT in the workspace, and then create a project with the same name

6. eclipse Method 2: Create a project of the same name in eclipse, use src as the source file directory, bin as the class file directory, and copy the directory generated by BAT to the eclipse workspace.

 

The BAT is original to blog.csdn.net/seavers. The BAT source code is only for personal learning, use, research, and cannot be used for commercial purposes without my consent.

 

 

The BAT source code is as follows: (copy it directly to the BAT file)

 

: Function: decompile the jar package to generate the corresponding source code jar package. For details, please log on to my blog

: Enable/disable command line display
@ Echo OFF

:::::::: ::::::::::

: Find the PATH of the jad file. Here, jad.exe is used to find the PATH. If you want to manually specify the PATH, modify it here.
Set jad_path1_jad.exe

: Set the location of the decompressed class file (relative path)
Set CLASS_PATH = bin

: Set the location of the decompiled java file (relative path)
Set JAVA_PATH = src

: Check whether the JAD file exists in the directory where bat is located,
If exist "% ~ Dp0jad.exe "set JAD_PATH = % ~ Dp0jad.exe

: Determines the number of parameters. If there is no file parameter, an error is returned. You can also use % ~ here ~ F1, you can also use % 1, it does not matter, then remove the quotation marks
If "% 1" "=" (set/P JAR_PATH = enter the path of the JAR package to be decompiled...) else (set JAR_PATH = % ~ F1)
If '% JAR_PATH :~ 0, 1% % JAR_PATH :~ 0, 1% '=' "'set JAR_PATH = % JAR_PATH :~ 1.-1%

: Obtain the path where the source code is stored. Here, take the path where the JAR package is located, and remove ". jar" as the folder path. The LOCATION here cannot be enclosed by quotation marks because additional characters are required below)
If "% 2" "=" (set LOCATION = % JAR_PATH :~ 0,-4%) else (set LOCATION = % ~ F2)

::::::::::::::::: ::::::::::::::

: The path of winrar.exe is obtained and set in the Temporary Variable rarpath.
For/F "usebackq delims =" % I in ('ftype WinRAR ') do set rarpath = % I

: Parse the rarpath. Remove the first seven characters and the last five characters to obtain the WinRAR execution path.
: The path is roughly in the form of WinRAR = "C:/program files/WinRAR/winrar.exe" "% 1"
Set rarexe = % rarpath :~ 7,-5%

: Call the WinRAR command to decompress the file to the bin directory of the specified directory.
% Rarexe % x "% jar_path %" "% LOCATION %/% class_path % /"

: Repeat all bindirectories, fetch all classfiles, and call jad.exe to decompile the source code. Copy non-class files to the src directory.
: Enable the variable delay function.
Setlocal enabledelayedexpansion
For/R "% LOCATION %/bin" % I in (*. *) do if '% ~ Xi '= '. class '("% jad_path %"-o-r-sjava-FF-B-nonlb-space-T-8-d "% LOCATION %/% java_path %" "% ~ Si ") else (set temp_path = % I & Echo f | xcopy" % I ""! Temp_path: % LOCATION %/bin = % LOCATION %/src! ")
Endlocal enabledelayedexpansion

: Compress the generated Java file into the source code file.
% Rarexe % A-EP1-R "location%-src.zip" "% LOCATION %/% java_path % /*.*"

:::::::::::::::: ::::::
Echo *************************************** ******
Echo program running ended
The path of the jar package parsed by ECHO is % jar_path %.
Echo decompressed tool winrar.exe path: % rarexe %
The path of ECHO decompilation tool jad.exe is % jad_path %
The root path of the file parsed by echo is % LOCATION %
The class file parsed by echo is stored in % LOCATION %/% CLASS_PATH %
The java file parsed by echo is stored in % LOCATION %/% JAVA_PATH %
The java files compressed by echo are stored in %locationation-src.zip.
Echo *************************************** ******
Pause

Source:Http://www.diybl.com/course/3_program/java/javajs/2008116/96535_2.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.