使用 ProGuard 混淆代码

发布于 2024-09-24 02:39:17 字数 3161 浏览 6 评论 0原文

我选择了 ProGuard,以下是我为其配置的选项:

收缩

选项:

  • 收缩

保留:

  • 应用程序
  • 小程序

同时保留: >

  • 枚举
  • 数据库驱动程序
  • Swing UI L&F

混淆

选项:

  • 混淆(废话!:P)
  • 积极重载
  • 使用唯一的类成员名称
  • 使用大小写混合的类名
  • 扁平化包层次结构
  • 重新打包类

保留名称:

  • 本机方法名称
  • .class方法名称

优化

选项:

  • 积极优化
  • Merge接口

删除:

  • [全部检查框]

信息

预验证和定位:

  • 预验证

一致性和正确性:

  • 注意配置中的潜在错误
  • 警告可能的错误输入
  • 跳过非公共库类成员

,当我获取 jar 并将其设置为:

启动时出现此小程序错误:

    java.lang.RuntimeException: java.lang.NoClassDefFoundError: b
        at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
        at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
    Caused by: java.lang.NoClassDefFoundError: b
        at java.lang.Class.getDeclaredConstructors0(Native Method)
        at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
        at java.lang.Class.getConstructor0(Unknown Source)
        at java.lang.Class.newInstance0(Unknown Source)
        at java.lang.Class.newInstance(Unknown Source)
        at sun.plugin2.applet.Plugin2Manager$12.run(Unknown Source)
        at java.awt.event.InvocationEvent.dispatch(Unknown Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)
    Caused by: java.lang.ClassNotFoundException: b
        at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 14 more
    Caused by: java.io.IOException: open HTTP connection failed:http://mystikrpg.com/b.class
        at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)
        at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source)
        at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        ... 17 more
    Exception: java.lang.RuntimeException: java.lang.NoClassDefFoundError: b

这是混淆之前 jar 文件内的内容 clientOffline.jar

line_tile/
META-INF/

这是该 jar 文件的内容是在对 newOne.jar 进行混淆之后:

line_tile/
META-INF/
weapon/
me.gif
a.class
b.class

我希望这足以帮助我解决这个问题。我做错了什么?

I chose ProGuard and here's the options I configured it with:

Shrinking

Options:

  • Shrink

Keep:

  • Applications
  • Applets

Also keep:

  • Enumerations
  • Database drivers
  • Swing UI L&F

Obfuscation

Options:

  • Obfuscate (duh! :P)
  • Overload aggressively
  • Use unique class member names
  • Use mixed-casee class names
  • Flatten package hierarchy
  • Repackage classes

Keep names:

  • native method names
  • .class method names

Optimization

Options:

  • Optimize
  • Merge interfaces aggressively

Remove:

  • [All boxes checked]

Information

Preverifiaction and targeting:

  • Preverify

Consistency and correctness:

  • Note potential mistakes in the configuration
  • Warn about possibly errornous input
  • Skip non-public library class members

and when I take the jar and put it as:

I get this applet error upon launch:

    java.lang.RuntimeException: java.lang.NoClassDefFoundError: b
        at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
        at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
    Caused by: java.lang.NoClassDefFoundError: b
        at java.lang.Class.getDeclaredConstructors0(Native Method)
        at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
        at java.lang.Class.getConstructor0(Unknown Source)
        at java.lang.Class.newInstance0(Unknown Source)
        at java.lang.Class.newInstance(Unknown Source)
        at sun.plugin2.applet.Plugin2Manager$12.run(Unknown Source)
        at java.awt.event.InvocationEvent.dispatch(Unknown Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)
    Caused by: java.lang.ClassNotFoundException: b
        at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 14 more
    Caused by: java.io.IOException: open HTTP connection failed:http://mystikrpg.com/b.class
        at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)
        at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source)
        at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        ... 17 more
    Exception: java.lang.RuntimeException: java.lang.NoClassDefFoundError: b

Here is what is INSIDE the jar file BEFORE the obfuscation clientOffline.jar:

line_tile/
META-INF/

and here is what that jar file is AFTER the obfuscation to newOne.jar:

line_tile/
META-INF/
weapon/
me.gif
a.class
b.class

I hope this is good enough to help me solve this. What am I doing wrong?

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

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

发布评论

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

评论(1

滿滿的愛 2024-10-01 02:39:17

我猜 b.class 是从 GamePanel 内部类生成的。所以内部类可能存在问题。 此处在 Stackoverflow Tom 提到他无法正确混淆内部类。这里的建议也适用于这里:尝试使用 verbose=true 进行混淆(或使用 java -jar proguard.jar @myconfig.pro -verbose)。

我还建议对 GamePanel 和/或使用 -keepnames 选项(请参阅 手册) tileOffline 因为它会使这些类因混淆而保持不变(至少对于找到问题的根本原因)。

附注是在 Java 编程时尝试使用 CamelCase 类名。

I guess that b.class is generated from the GamePanel inner class. So there can be a problem with inner classes. Here at Stackoverflow Tom mentioned that he could not obfuscate inner classes correctly. The suggestion there also applies here: try to obfuscate with verbose=true (or with java -jar proguard.jar @myconfig.pro -verbose).

I would also suggest to use -keepnames option (see manual) for GamePanel and/or tileOffline since it will leave these classes unchanged by the obfuscation (at least for finding the root cause of the problem).

A side note is try to use CamelCase class names when programming in Java.

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