Java是否与`/usr/bin/strip`相对应? [英] Any Java counterpart for `/usr/bin/strip`?

查看:127
本文介绍了Java是否与`/usr/bin/strip`相对应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何工具可以从Java .class文件中删除调试信息,就像/usr/bin/strip可以从Linux上的C/C ++对象文件中删除调试信息一样?

Is there any tool that can remove debug info from Java .class files, just like /usr/bin/strip can from C/C++ object files on Linux?

我都喜欢Thilo和Peter Mmm的回答:Peter很简短,这一点暴露了我对JDK附带的东西的无知.无论如何,我肯定会检查Thilo的ProGuard建议,以了解它似乎提供的所有这些额外功能.谢谢Thilo和Peter!

I liked both Thilo's and Peter Mmm's answers: Peter's was short and to the point exposing my ignorance of what ships with JDK; Thilo's ProGuard suggestion is something I'll definitely be checking out anyway for all those extra features it appears to provide. Thank you Thilo and Peter!

推荐答案

ProGuard (例如,Android SDK附带以减小代码大小),可以进行各种操作来缩小JAR文件:

ProGuard (which the Android SDK for example ships with to reduce code size), can do all kinds of manipulation to shrink JAR files:

  • 计算常量表达式.
  • 删除不必要的字段访问和方法调用.
  • 删除不必要的分支.
  • 删除不必要的比较和测试实例.
  • 删除未使用的代码块.
  • 合并相同的代码块.
  • 减少变量分配.
  • 删除只写字段和未使用的方法参数.
  • 内联常量字段,方法参数和返回值.
  • 短或仅被调用一次的内联方法.
  • 简化尾递归调用.
  • 合并类和接口.
  • 在可能的情况下将方法设置为私有,静态和最终.
  • 在可能的情况下使类成为静态的和最终的.
  • 替换具有单个实现的接口.
  • 执行200多个窥孔优化,例如将... * 2替换为...<<< 1.
  • (可选)删除日志记录代码.
  • Evaluate constant expressions.
  • Remove unnecessary field accesses and method calls.
  • Remove unnecessary branches.
  • Remove unnecessary comparisons and instanceof tests.
  • Remove unused code blocks.
  • Merge identical code blocks.
  • Reduce variable allocation.
  • Remove write-only fields and unused method parameters.
  • Inline constant fields, method parameters, and return values.
  • Inline methods that are short or only called once.
  • Simplify tail recursion calls.
  • Merge classes and interfaces.
  • Make methods private, static, and final when possible.
  • Make classes static and final when possible.
  • Replace interfaces that have single implementations.
  • Perform over 200 peephole optimizations, like replacing ...*2 by ...<<1.
  • Optionally remove logging code.

他们没有提到在该列表中删除调试信息,但是我想他们也可以这样做.

They do not mention removing debug info in that list, but I guess they can also do that.

更新:是的,确实是

默认情况下,已编译的字节码仍然包含许多调试信息:源文件名,行号,字段名,方法名,参数名,变量名等.此信息使直接编译字节码和反向工程变得很简单.整个程序.有时,这是不可取的.诸如ProGuard之类的混淆器可以删除调试信息,并以无意义的字符序列替换所有名称,这使得对代码进行反向工程变得更加困难.它进一步压缩了代码作为奖励.该程序在功能上保持等效,除了在异常堆栈跟踪中给出的类名称,方法名称和行号以外.

By default, compiled bytecode still contains a lot of debugging information: source file names, line numbers, field names, method names, argument names, variable names, etc. This information makes it straightforward to decompile the bytecode and reverse-engineer entire programs. Sometimes, this is not desirable. Obfuscators such as ProGuard can remove the debugging information and replace all names by meaningless character sequences, making it much harder to reverse-engineer the code. It further compacts the code as a bonus. The program remains functionally equivalent, except for the class names, method names, and line numbers given in exception stack traces.

这篇关于Java是否与`/usr/bin/strip`相对应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆