【问题标题】:Why does JD-GUI prefix every line with a comment and line number?为什么 JD-GUI 在每一行都加上注释和行号?
【发布时间】:2014-09-28 20:14:48
【问题描述】:

我已经多次遇到这个问题。每当我使用 JD-GUI 反编译某些东西并保存所有源代码时,它都会在每一行前面加上一个块注释,并在方法体中插入代码的行号。这是我刚刚反编译的 jar 中的一个示例:

/*    */   public void onEnable()
/*    */   {
/* 25 */     List DropList = new ArrayList();
/* 26 */     DropList.add(Integer.valueOf(264));
/* 27 */     DropList.add(Integer.valueOf(57));
/* 28 */     DropList.add(Integer.valueOf(278));
/*    */ 
/* 30 */     this.config = getConfig();
/*    */ 
/* 32 */     this.config.addDefault("GiftDrops", DropList);
/* 33 */     this.config.addDefault("DropRate", Integer.valueOf(0));
/* 34 */     this.config.addDefault("GiftBoxPlayerSkin", "lol768");
/* 35 */     this.config.addDefault("CraftingRecipe.LineOne", "339,339,339");
/* 36 */     this.config.addDefault("CraftingRecipe.LineTwo", "339,264,339");
/* 37 */     this.config.addDefault("CraftingRecipe.LineThree", "339,339,339");
/*    */ 
/* 39 */     this.config.options().copyDefaults(true);
/* 40 */     saveConfig();
/*    */ 
/* 43 */     SkullMeta giftboxskull = (SkullMeta)this.giftbox.getItemMeta();
/*    */ 
/* 45 */     giftboxskull.setOwner(this.config.getString("GiftBoxPlayerSkin"));
/* 46 */     giftboxskull.setDisplayName(ChatColor.GREEN + "Gift Box");
/* 47 */     this.giftbox.setItemMeta(giftboxskull);
/*    */ 
/* 49 */     this.giftboxrecipe = new ShapedRecipe(this.giftbox);
/* 50 */     this.giftboxrecipe.shape(new String[] { "123", "456", "789" });
/*    */ 
/* 52 */     String[] LineOne = getConfig().getString("CraftingRecipe.LineOne").split(",");
/* 53 */     String[] LineTwo = getConfig().getString("CraftingRecipe.LineTwo").split(",");
/* 54 */     String[] LineThree = getConfig().getString("CraftingRecipe.LineThree").split(",");
/*    */ 
/* 56 */     this.giftboxrecipe.setIngredient('1', new ItemStack(Integer.parseInt(LineOne[0])).getData());
/* 57 */     this.giftboxrecipe.setIngredient('2', new ItemStack(Integer.parseInt(LineOne[1])).getData());
/* 58 */     this.giftboxrecipe.setIngredient('3', new ItemStack(Integer.parseInt(LineOne[2])).getData());
/* 59 */     this.giftboxrecipe.setIngredient('4', new ItemStack(Integer.parseInt(LineTwo[0])).getData());
/* 60 */     this.giftboxrecipe.setIngredient('5', new ItemStack(Integer.parseInt(LineTwo[1])).getData());
/* 61 */     this.giftboxrecipe.setIngredient('6', new ItemStack(Integer.parseInt(LineTwo[2])).getData());
/* 62 */     this.giftboxrecipe.setIngredient('7', new ItemStack(Integer.parseInt(LineThree[0])).getData());
/* 63 */     this.giftboxrecipe.setIngredient('8', new ItemStack(Integer.parseInt(LineThree[1])).getData());
/* 64 */     this.giftboxrecipe.setIngredient('9', new ItemStack(Integer.parseInt(LineThree[2])).getData());
/*    */ 
/* 66 */     getServer().addRecipe(this.giftboxrecipe);
/*    */ 
/* 68 */     getServer().getPluginManager().registerEvents(new GiftBoxEventListener(this), this);
/*    */   }

这似乎是 JD-GUI 必须阻止人们使用他们通过编译获得的源文件的功能。我可以使用 bash 命令相当轻松地删除所有这些 cmets,但这仍然很烦人。有没有办法禁用此功能?

【问题讨论】:

  • 我很好奇:你为什么称它为“问题”并跳出如此无情的结论?首先:它不会阻止您编译文件;即使有 cmets,它们也能很好地编译。为什么 JD-GUI 会关心你是否编译它创建的源代码?他们不是他们的来源。我很清楚它为什么这样做:因为它很方便,特别是对于调试。堆栈跟踪和调试信息包含行号,了解第三方代码的哪一行行发生异常或调试期间程序指针所在位置非常有用...
  • 我同意这有时很烦人。例如,如果您想反编译同一个 jar 的 2 个版本并使用合并工具进行比较。一个类文件中的单个额外行将导致文件中的每一行显示为不同。祖富留的回答对我很有帮助!

标签: java decompiling jad jd-gui


【解决方案1】:

在“帮助”->“首选项”中,在“源保存”组下,取消选中“显示行号”

【讨论】:

  • 谢谢,这行得通。我之前看到过这个选项,但认为它是显示在 GUI 中代码旁边的行号,而不是保存的源代码中的行号。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-11-18
  • 2013-10-05
  • 1970-01-01
  • 1970-01-01
  • 2018-06-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多