简体   繁体   English

从提取的Jar中批量生成要反编译的.Class文件的批处理文件不会保留在原始目录中

[英]Batch File to Mass Decompile .Class Files from Extracted Jar not Leaving in Original Directory

I'm working on a batch file that recurs-es within a directory and called the Java Decompiler in order to decompile .class files. 我正在处理一个在目录中递归的批处理文件,并称为Java Decompiler,以便反编译.class文件。

For some reason or other, the files are decompiled but they don't remain in the original locations but instead the .jad files are in the location that I have called my bat file from. 出于某种原因,这些文件将被反编译,但它们不会保留在原始位置,而是.jad文件位于我从其调用bat文件的位置。

My BAT file code is the following: 我的BAT文件代码如下:

SETLOCAL EnableDelayedExpansion

FOR /D /r %%G in ("*") do (
@echo decompiling
jad -o "%%G/*.class"
@echo decompiled

@echo renaming
ren *.jad *.java
@echo renamed
)

Help would be appreciated. 帮助将不胜感激。

It seems to me you don't understand the concept of the working directory all that well. 在我看来,您不太了解工作目录的概念。

Your batch file is executed from a specific working directory, which than calls JAD continuously from there. 您的批处理文件是从特定的工作目录执行的,该目录随后从那里连续调用JAD。

You need to either change your batch file to CD (Change directory), or to move the resulting decompiled files to the location where the .class was located. 您需要将批处理文件更改为CD(更改目录),或者将生成的反编译文件移动到.class所在的位置。

Something like this should do it: 像这样的东西应该这样做:

move *.java "%%G/"

Give it a try. 试试看。 Additionally, you should consider moving the .class files to another location if your planning on using the source code within a project. 此外,如果计划在项目中使用源代码,则应考虑将.class文件移动到另一个位置。

Update 更新资料

So your whole script for decompiling and keeping the original package structure should be the one below. 因此,用于反编译和保留原始包结构的整个脚本应为以下脚本。 I also took the liberty to add an option to delete the .class files for cleanup. 我还随意添加了一个选项,以删除.class文件进行清理。

SETLOCAL EnableDelayedExpansion

FOR /D /r %%G in ("*") do (
@echo decompiling
jad -o "%%G/*.class"
@echo decompiled

@echo renaming
ren *.jad *.java
@echo renamed

@echo moving...
move *.java "%%G/"
@echo moved...
)

SET /P RESULT=[Delete .class files (y/n)]
IF %RESULT% == yes do (
    FOR /D /r %%G in ("*") do (
    cd "%%G/"
    del *.class
    )
)

In the latest version of Jad (1.5.8g) doesn't pickup filenames with certain characters (like a dollarsign) when using a wildcard. 在最新版本的Jad(1.5.8g)中,使用通配符时不会提取带有某些字符(如dollarign)的文件名。 I've modified the script to decompile files individually to get around this limitation in Jad. 我已经修改了脚本,以分别对文件进行反编译,以解决Jad中的这一限制。

I've also modified it to use the -d option to specify the output folder. 我还修改了它以使用-d选项指定输出文件夹。 This removes the need to performe a move operation. 这消除了执行移动操作的需要。

@echo off

SETLOCAL EnableDelayedExpansion

FOR /D /r %%G in ("*") do (
    FOR %%X in ("%%G\*.class") do (
        jad -o -d "%%G" "%%X"
        ren "%%~dpnX.jad" "%%~nX.java"
    )
)

SET /P RESULT=[Delete .class files (y/n)]
IF %RESULT% == yes do (
    FOR /D /r %%G in ("*") do (
    cd "%%G\"
    del *.class
    )
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM