ProGuard 破坏了 Java 应用程序 - 没有文本,没有图像

发布于 2024-10-17 04:50:18 字数 321 浏览 1 评论 0原文

我正在尝试使用 ProGuard 来混淆 Java 应用程序。我遇到一个问题,所有文本和图像都从 GUI (Swing) 表单中消失。我尝试过禁用优化并包含更多库,但似乎没有任何效果。

我已经使用反编译器检查了混淆器生成的输出,并且我的资源路径似乎仍然正确。

  1. 我是否需要在 jre/lib/rt.jar 之外包含更多核心 Java 库?
  2. 还有更多我应该禁用的设置吗?
  3. ...其他建议?

谢谢。

I'm trying to use ProGuard to obfuscate a Java application. I'm experiencing a problem where all of my text and images disappear from the GUI (Swing) forms. I've tried disabling optimizations and including more libraries, but nothing seems to be working.

I've inspected the output generated by the obfuscator with a decompiler, and my resource paths seem to still be correct.

  1. Do I need to be including more core Java libraries outside of jre/lib/rt.jar?
  2. Are there more settings I should disable?
  3. ...other suggestions?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

葬﹪忆之殇 2024-10-24 04:50:18

您的资源很可能是 (a) 通过混淆包含资源的包时 ProGuard 正在更改的路径来访问,或者 (b) 因为它们没有复制到输出 JAR 中而被删除。

您不需要在配置中显式包含 Java 运行时类。

您可能需要查看以下选项:

-adaptclassstrings [class_filter] 指定与类名对应的字符串常量也应该被混淆。如果没有过滤器,所有与类名相对应的字符串常量都会被调整。使用过滤器时,只会调整与过滤器匹配的类中的字符串常量。例如,如果您的代码包含大量引用类的硬编码字符串,并且您不想保留它们的名称,则可能需要使用此选项。主要适用于混淆时,尽管相应的类也会自动保留在收缩步骤中。

-adaptresourcefilenames [file_filter] 根据相应类文件(如果有)的模糊名称指定要重命名的资源文件。如果没有过滤器,则与类文件对应的所有资源文件都会被重命名。使用过滤器,仅重命名匹配的文件。例如,请参阅处理资源文件。仅在混淆时适用。

-adaptresourcefilecontents [file_filter] 指定要更新其内容的资源文件。资源文件中提到的任何类名都会根据相应类(如果有)的混淆名称进行重命名。如果没有过滤器,所有资源文件的内容都会更新。使用过滤器,仅更新匹配的文件。资源文件使用平台的默认字符集进行解析和写入。您可以通过设置环境变量 LANG 或 Java 系统属性 file.encoding 来更改此默认字符集。有关示例,请参阅处理资源文件。仅在混淆时适用。

并参见http://proguard.sourceforge.net/manual/examples.html#resourcefiles< /a> 了解更多详细信息。

Most likely your resources are either (a) being accessed via a path which ProGuard is changing when the package containing the resource is obfuscated, or (b) being dropped because they are not copied to the output JAR.

You should not need to be explicitly including the Java runtime classes in your configuration.

You might want to look at the following options:

-adaptclassstrings [class_filter] Specifies that string constants that correspond to class names should be obfuscated as well. Without a filter, all string constants that correspond to class names are adapted. With a filter, only string constants in classes that match the filter are adapted. For example, if your code contains a large number of hard-coded strings that refer to classes, and you prefer not to keep their names, you may want to use this option. Primarily applicable when obfuscating, although corresponding classes are automatically kept in the shrinking step too.

-adaptresourcefilenames [file_filter] Specifies the resource files to be renamed, based on the obfuscated names of the corresponding class files (if any). Without a filter, all resource files that correspond to class files are renamed. With a filter, only matching files are renamed. For example, see processing resource files. Only applicable when obfuscating.

-adaptresourcefilecontents [file_filter] Specifies the resource files whose contents are to be updated. Any class names mentioned in the resource files are renamed, based on the obfuscated names of the corresponding classes (if any). Without a filter, the contents of all resource files updated. With a filter, only matching files are updated. The resource files are parsed and written using the platform's default character set. You can change this default character set by setting the environment variable LANG or the Java system property file.encoding. For an example, see processing resource files. Only applicable when obfuscating.

And see http://proguard.sourceforge.net/manual/examples.html#resourcefiles for more detail.

梦过后 2024-10-24 04:50:18
  1. 不可能。奥托,你什么意思? “jre/lib/rt.jar 核心 Java 库外部”不是矛盾吗?

  2. 因为我也遇到过类似的问题。我一开始让 PG 什么都不做,然后允许对我的部分类进行混淆等等,这是对问题的一种二分搜索。最后我找到了罪魁祸首,并且可以混淆几乎所有内容。

  3. 确保您不会接受任何异常。尝试使用 Class.getResource 访问图像,以便了解它是否有效。禁用所有内容。

  1. Improbable. OTOH, what do you mean? Isn't "core Java libraries outside of jre/lib/rt.jar" an oxymoron?

  2. As I had a similar problem,. I started with letting PG do nothing at all, then allowed obfuscation of a part of my classes, etc., a sort of binary search for the problem. At the end I found the culprit and could let obfuscate nearly everything.

  3. Make sure you don't swallow any exception. Try to access the images using Class.getResource, so you find out if it works. Disable everything.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文