2

我有以下java代码片段

while (condition1){
    switch (someinteger){
        case 1:
            if(condition2) continue;
            // other stuff here
            break;
        // other cases here
    }
}

一切皆好。当我生成一个类文件,然后使用免费工具 (JD-gui) 对其进行反编译时,我得到以下代码。

while (condition1){
    switch (someinteger){
        case 1:
            if(!condition2);
            // other stuff here
            break;
        // other cases here
    }
}

所以它变成if(condition2) continue;if(!condition2); 我在另一个 if 语句(没有大括号)上找不到任何信息。谁能解释这里的逻辑?提前致谢。

编辑:我做了更多测试,反编译器无法正常工作。

这是之前的代码:

public void strip(InputStreamReader f1, OutputStreamWriter f2) throws IOException{
    int commentON=0, quoteON=0;
    int b1;
    while ((b1 = f1.read()) != -1){
        switch ((char) b1){
            case '\\':
                    if (commentON==0){
                            quoteON = 1;
                            break;
                    }
                    continue;
            case '\n':
                    if (commentON>0){ commentON=0; continue; }
                    break;
            case '%':
                    if (commentON>0) continue;
                    if (quoteON>0) { quoteON=0; break; }
                    commentON=2;
                    continue;
            default:
                    if (commentON>0) continue;
                    if (quoteON>0) quoteON=0;
                    break;
        }
        f2.write(b1);
    }
}

这是反编译的代码

public void strip(InputStreamReader f1, OutputStreamWriter f2) throws IOException
{
int commentON = 0; int quoteON = 0;

while ((b1 = f1.read()) != -1)
{
  int b1;
  switch ((char)b1)
  {
  case '\\':
    if (commentON == 0);
    quoteON = 1;
    break;
  case '\n':
    if (commentON <= 0) break label109; commentON = 0; break;
  case '%':
    if (commentON <= 0);
    if (quoteON > 0) { quoteON = 0; break label109: }
    commentON = 2;
    break;
  }
  if (commentON <= 0);
  if (quoteON > 0) quoteON = 0;

  label109: f2.write(b1);
}
}

很抱歉打扰大家。:P 如果可以的话,我会尝试删除这个问题。

4

3 回答 3

4

反编译器几乎不可能重建您的原始语法,因为它们正在处理编译器对您代码的解释。

你编写java代码,java编译器将其编译为字节码。

然后反编译器尝试从字节码创建 java 代码。

由于这两个代码片段在逻辑上是相同的,反编译器已经完成了它的工作。

编辑(看到你的评论):

实际上,反编译器很可能(这很常见)出错了。

该语句if(!condition2);基本上没有任何效果(前提是 condition2 确实是布尔值而不是伪代码)。

因此//other stuff here,无论condition2在反编译版本中,您的第一个都将被处理。

你确定反编译的代码可以正常工作吗?

于 2010-01-14T00:44:44.373 回答
1

没有主体的 if 语句(“没有花括号”)只是一个不执行任何代码的空 if 语句。

于 2010-01-14T00:46:01.300 回答
0

它是相同逻辑的替代/规范表示。反编译器不保留代码。

于 2010-01-14T00:47:41.830 回答