[英]Why my compiled class has it's methods local variables renamed?
I have a Kitchen.jar
file. 我有一个
Kitchen.jar
文件。 I need to modify a class inside it. 我需要修改它里面的一个类。 I decompile it with JD .
我用JD反编译它。 Then I modify the
Toster.java
file and compile it with: 然后我修改
Toster.java
文件并使用以下命令编译它:
javac -classpath . Toster.java
And then I take it back into the Kitchen.jar
with: 然后我把它带回到
Kitchen.jar
:
jar -uf Kitchen.jar Toster.class
All works except for one problem. 所有工作除了一个问题。 When I open updated
Kitchen.jar
in JD I see that local variables inside all methods are renamed to something like localLongVar
. 当我在JD中打开更新的
Kitchen.jar
,我发现所有方法中的局部变量都被重命名为localLongVar
。 Why? 为什么?
The reason I ask is because Kitchen.jar
refuses to work after the modification. 我问的原因是因为
Kitchen.jar
在修改后拒绝工作。 And I suspect it has to be the compilation problem. 我怀疑它必须是编译问题。 Maybe I've misused some flags or anything.
也许我误用了一些旗帜或任何东西。 Not sure.
不确定。 I have no knowledge of Java whatsoever, except for the basic syntax.
除了基本语法之外,我对Java一无所知。
My guess is that I compile it with latest 1.7 version and original jar is compiled with older JDK. 我的猜测是我使用最新的1.7版本编译它,原始jar用较旧的JDK编译。 That may explain failure of operation, but that doesn't explain the renaming of locals.
这可能解释了操作失败,但这并不能解释当地人的重命名。
The random line from the original jar: 来自原始jar的随机行:
BigInteger[] result = new BigInteger[bis.length / 2];
And the very same line of my class: 同班同学:
BigInteger[] arrayOfBigInteger1 = new BigInteger[paramArrayOfBigInteger.length * 2];
So its result
vs arrayOfBigInteger1
. 所以它的
result
与arrayOfBigInteger1
。
By default javac removes debugging information other than source file and line number. 默认情况下,javac会删除源文件和行号以外的调试信息。 Compile with
javac -g
or javac -g:vars
. 使用
javac -g
或javac -g:vars
。
From the documentation of javac 来自javac的文档
-g
Generate all debugging information, including local variables.-g
生成所有调试信息,包括局部变量。 By default, only line number and source file information is generated.默认情况下,仅生成行号和源文件信息。
-g:none
Do not generate any debugging information.-g:none
不生成任何调试信息。
-g:{keyword list}
Generate only some kinds of debugging information, specified by a comma separated list of keywords.-g:{keyword list}
仅生成某些类型的调试信息,由逗号分隔的关键字列表指定。 Valid keywords are:有效关键字是:
source
Source file debugging informationsource
文件调试信息
lines
Line number debugging informationlines
号行调试信息
vars
Local variable debugging informationvars
局部变量调试信息
The names of the variables are not preserved in compiled code. 变量的名称不会保留在已编译的代码中。 Most obvious to reduce the size of the compiled class.
最明显的是减少编译类的大小。 The compiler will replace them by shorter names.
编译器将用更短的名称替换它们。 Doing this is also good for obfuscating the code so that someone who decompiles the code has problems to understand the logic.
这样做也有助于混淆代码,以便反编译代码的人有理解逻辑的问题。 The
localLongVar
you see in JD is what the compiler makes of the replaced variable names. 您在JD中看到的
localLongVar
是编译器对替换的变量名称所做的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.