Really Guava? Sealed jar?

Discussion in 'Plugin Development' started by xTrollxDudex, Aug 11, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    xTrollxDudex

    This has never happened before. Today, I added an "extracted file" (as in extracted Google Guava jarfile) to my jar output on IntelliJ IDEA and when I run it, I get ExceptionInInitalizerError, saying that a SecurityException was thrown because the com.google.commons package is sealed by the jar.

    It errors when I try to use the ClassPath class and get the list of TopLevelClasses.
     
  2. Offline

    1Rogue

    Use maven.
     
  3. Offline

    xTrollxDudex

    I did that as well, the same thing happens.
     
  4. Offline

    RawCode

    modify manifest files at play or modify classloader.

    with complete trace i probably can assemble classloader that will ignore security rules.
     
  5. Offline

    xTrollxDudex

    There was nothing about sealing in the manifest, and I couldn't locate a manifest file in any Guava directories. I even went as far as to explicitly put Sealed: false in the root manifest.

    I think the modifying the class loader is a bit toi extreme, I will resort to it when I have no options left.

    I will examine the other files in the jar tomorrow, I skimmed over the Guava pom and the pom.properties.
     
  6. Offline

    xTrollxDudex

    Code:
    .______    __    __  .___  ___. .______   
    |   _  \  |  |  |  | |   \/   | |   _  \  
    |  |_)  | |  |  |  | |  \  /  | |  |_)  | 
    |   _  <  |  |  |  | |  |\/|  | |   ___/  
    |  |_)  | |  `--'  | |  |  |  | |  |      
    |______/   \______/  |__|  |__| | _|
     
    skyrimfan1 and Rocoty like this.
  7. Offline

    Cirno

    You can create a ClassLoader that has it's own defineClass method. As the current code stands:
    PluginClassLoader extends URLClassLoader (not new news or anything)
    URLClassLoader does its sealed jar check inside of defineClass (http://grepcode.com/file/repository...dk/openjdk/6-b14/java/net/URLClassLoader.java line 224)

    You can use Package.getPackage() and try to set field "sealBase" to null. Note that sealBase is final.
    Here's some spoonfeed that I did off the top of my head:
    Code:java
    1.  
    2. Field sB_f = Package.class.getDeclaredField("sealBase");
    3. sB_f.setAccessible(true);
    4.  
    5. {
    6. Field m_f = Field.class.getDeclaredField("modifiers");
    7. m_f.setAccessible(true);
    8. m_f.set(sB_f, m_f.get() & ~Modifiers.FINAL);
    9. }
    10.  
    11. sB_f.set(Package.getPackage("com.google.commons"), null);
    12.  
     
    xTrollxDudex likes this.
  8. Offline

    ZodiacTheories

    xTrollxDudex and Drew1080 like this.
  9. Offline

    xTrollxDudex

    Cirno
    I will definately try the second method when I get the time.
     
  10. Offline

    fireblast709

    xTrollxDudex Might it be caused by CraftBukkit sealing their jar and shading guava?

    [addition] To elaborate: CB loads Guava, ClassLoader reads the CB manifest, notices the Sealed: true, seals the package.
     
  11. Offline

    xTrollxDudex

    It's extracted into my jar, it used the manifest of my jar as well afaik.
     
  12. Offline

    fireblast709

    xTrollxDudex Still, the packages are the same, and CB is loaded first :p. Hence the idea that the sealing came through CB.
     
  13. Offline

    xTrollxDudex

    Ah, I see now... Well that's some whack dookie (as my friend used to say) -_-

    Cirno
    Nope, fails with this error:
    Code:
    java.lang.NullPointerException
        at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:54) ~[?:1.7.0_65]
        at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:75) ~[?:1.7.0_65]
        at java.lang.reflect.Field.set(Field.java:741) ~[?:1.7.0_65]
        at com.gmail.woodyc40.commons.reflection.impl.SafeField.set(SafeField.java:61) ~[?:?]
        at com.gmail.woodyc40.commons.Commons.disableClassLoaderSealing(Commons.java:112) ~[?:?]
        at com.gmail.woodyc40.commons.Commons.onEnable(Commons.java:82) ~[?:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:316) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-18-ga04b586-b3107jnks]
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:324) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-18-ga04b586-b3107jnks]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:404) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-18-ga04b586-b3107jnks]
        at org.bukkit.craftbukkit.v1_7_R4.CraftServer.loadPlugin(CraftServer.java:455) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-18-ga04b586-b3107jnks]
        at org.bukkit.craftbukkit.v1_7_R4.CraftServer.enablePlugins(CraftServer.java:389) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-18-ga04b586-b3107jnks]
        at net.minecraft.server.v1_7_R4.MinecraftServer.n(MinecraftServer.java:352) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-18-ga04b586-b3107jnks]
        at net.minecraft.server.v1_7_R4.MinecraftServer.g(MinecraftServer.java:326) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-18-ga04b586-b3107jnks]
        at net.minecraft.server.v1_7_R4.MinecraftServer.a(MinecraftServer.java:282) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-18-ga04b586-b3107jnks]
        at net.minecraft.server.v1_7_R4.DedicatedServer.init(DedicatedServer.java:189) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-18-ga04b586-b3107jnks]
        at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:436) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-18-ga04b586-b3107jnks]
        at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-18-ga04b586-b3107jnks]
    Here is the code commit: https://github.com/AgentTroll/BukkitCommons/commit/4389841b020a859301919d534bb76fe442e7d5aa

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
Thread Status:
Not open for further replies.

Share This Page