@Test public void testJARMagicBytes() throws Exception { final InputStream inputStream = getClass().getClassLoader().getResourceAsStream( "hello.jar" ); final BufferedInputStream in = new BufferedInputStream( inputStream ); final boolean result = PluginManager.validMagicNumbers( in ); assertTrue( result ); }
public static boolean validMagicNumbers( final BufferedInputStream bin ) throws IOException { final List<String> validMagicBytesCollection = JiveGlobals.getListProperty( "plugins.upload.magic-number.values.expected-value", Arrays.asList( "504B0304", "504B0506", "504B0708" ) ); for ( final String entry : validMagicBytesCollection ) { final byte[] validMagicBytes = StringUtils.decodeHex( entry ); bin.mark( validMagicBytes.length ); try { final byte[] magicBytes = new byte[validMagicBytes.length]; final int bytesRead = IOUtils.read( bin, magicBytes ); if ( bytesRead == validMagicBytes.length && Arrays.equals( validMagicBytes, magicBytes ) ) { return true; } } finally { bin.reset(); } } return false; }
PluginManager { public static boolean validMagicNumbers( final BufferedInputStream bin ) throws IOException { final List<String> validMagicBytesCollection = JiveGlobals.getListProperty( "plugins.upload.magic-number.values.expected-value", Arrays.asList( "504B0304", "504B0506", "504B0708" ) ); for ( final String entry : validMagicBytesCollection ) { final byte[] validMagicBytes = StringUtils.decodeHex( entry ); bin.mark( validMagicBytes.length ); try { final byte[] magicBytes = new byte[validMagicBytes.length]; final int bytesRead = IOUtils.read( bin, magicBytes ); if ( bytesRead == validMagicBytes.length && Arrays.equals( validMagicBytes, magicBytes ) ) { return true; } } finally { bin.reset(); } } return false; } }
PluginManager { public static boolean validMagicNumbers( final BufferedInputStream bin ) throws IOException { final List<String> validMagicBytesCollection = JiveGlobals.getListProperty( "plugins.upload.magic-number.values.expected-value", Arrays.asList( "504B0304", "504B0506", "504B0708" ) ); for ( final String entry : validMagicBytesCollection ) { final byte[] validMagicBytes = StringUtils.decodeHex( entry ); bin.mark( validMagicBytes.length ); try { final byte[] magicBytes = new byte[validMagicBytes.length]; final int bytesRead = IOUtils.read( bin, magicBytes ); if ( bytesRead == validMagicBytes.length && Arrays.equals( validMagicBytes, magicBytes ) ) { return true; } } finally { bin.reset(); } } return false; } PluginManager( File pluginDir ); }
PluginManager { public static boolean validMagicNumbers( final BufferedInputStream bin ) throws IOException { final List<String> validMagicBytesCollection = JiveGlobals.getListProperty( "plugins.upload.magic-number.values.expected-value", Arrays.asList( "504B0304", "504B0506", "504B0708" ) ); for ( final String entry : validMagicBytesCollection ) { final byte[] validMagicBytes = StringUtils.decodeHex( entry ); bin.mark( validMagicBytes.length ); try { final byte[] magicBytes = new byte[validMagicBytes.length]; final int bytesRead = IOUtils.read( bin, magicBytes ); if ( bytesRead == validMagicBytes.length && Arrays.equals( validMagicBytes, magicBytes ) ) { return true; } } finally { bin.reset(); } } return false; } PluginManager( File pluginDir ); synchronized void start(); synchronized void shutdown(); Path getPluginsDirectory(); boolean installPlugin( InputStream in, String pluginFilename ); boolean isInstalled( final String canonicalName ); synchronized boolean isExtracted( final String canonicalName ); synchronized boolean isLoaded( final String canonicalName ); synchronized Map<String, PluginMetadata> getMetadataExtractedPlugins(); synchronized PluginMetadata getMetadata( String canonicalName ); Collection<Plugin> getPlugins(); synchronized String getCanonicalName( Plugin plugin ); @Deprecated synchronized Plugin getPlugin( String canonicalName ); synchronized Optional<Plugin> getPluginByName(final String pluginName); @Deprecated File getPluginDirectory( Plugin plugin ); synchronized Path getPluginPath( Plugin plugin ); boolean isExecuted(); void deletePlugin( final String pluginName ); boolean reloadPlugin( String pluginName ); Class loadClass( Plugin plugin, String className ); synchronized PluginDevEnvironment getDevEnvironment( Plugin plugin ); @Deprecated String getName( Plugin plugin ); @Deprecated String getDescription( Plugin plugin ); @Deprecated String getAuthor( Plugin plugin ); @Deprecated String getVersion( Plugin plugin ); @Deprecated String getMinServerVersion( Plugin plugin ); @Deprecated String getDatabaseKey( Plugin plugin ); @Deprecated int getDatabaseVersion( Plugin plugin ); @Deprecated String getLicense( Plugin plugin ); synchronized PluginClassLoader getPluginClassloader( Plugin plugin ); static boolean validMagicNumbers( final BufferedInputStream bin ); void addPluginListener( PluginListener listener ); void removePluginListener( PluginListener listener ); void addPluginManagerListener( PluginManagerListener listener ); void removePluginManagerListener( PluginManagerListener listener ); boolean isMonitorTaskRunning(); }
PluginManager { public static boolean validMagicNumbers( final BufferedInputStream bin ) throws IOException { final List<String> validMagicBytesCollection = JiveGlobals.getListProperty( "plugins.upload.magic-number.values.expected-value", Arrays.asList( "504B0304", "504B0506", "504B0708" ) ); for ( final String entry : validMagicBytesCollection ) { final byte[] validMagicBytes = StringUtils.decodeHex( entry ); bin.mark( validMagicBytes.length ); try { final byte[] magicBytes = new byte[validMagicBytes.length]; final int bytesRead = IOUtils.read( bin, magicBytes ); if ( bytesRead == validMagicBytes.length && Arrays.equals( validMagicBytes, magicBytes ) ) { return true; } } finally { bin.reset(); } } return false; } PluginManager( File pluginDir ); synchronized void start(); synchronized void shutdown(); Path getPluginsDirectory(); boolean installPlugin( InputStream in, String pluginFilename ); boolean isInstalled( final String canonicalName ); synchronized boolean isExtracted( final String canonicalName ); synchronized boolean isLoaded( final String canonicalName ); synchronized Map<String, PluginMetadata> getMetadataExtractedPlugins(); synchronized PluginMetadata getMetadata( String canonicalName ); Collection<Plugin> getPlugins(); synchronized String getCanonicalName( Plugin plugin ); @Deprecated synchronized Plugin getPlugin( String canonicalName ); synchronized Optional<Plugin> getPluginByName(final String pluginName); @Deprecated File getPluginDirectory( Plugin plugin ); synchronized Path getPluginPath( Plugin plugin ); boolean isExecuted(); void deletePlugin( final String pluginName ); boolean reloadPlugin( String pluginName ); Class loadClass( Plugin plugin, String className ); synchronized PluginDevEnvironment getDevEnvironment( Plugin plugin ); @Deprecated String getName( Plugin plugin ); @Deprecated String getDescription( Plugin plugin ); @Deprecated String getAuthor( Plugin plugin ); @Deprecated String getVersion( Plugin plugin ); @Deprecated String getMinServerVersion( Plugin plugin ); @Deprecated String getDatabaseKey( Plugin plugin ); @Deprecated int getDatabaseVersion( Plugin plugin ); @Deprecated String getLicense( Plugin plugin ); synchronized PluginClassLoader getPluginClassloader( Plugin plugin ); static boolean validMagicNumbers( final BufferedInputStream bin ); void addPluginListener( PluginListener listener ); void removePluginListener( PluginListener listener ); void addPluginManagerListener( PluginManagerListener listener ); void removePluginManagerListener( PluginManagerListener listener ); boolean isMonitorTaskRunning();  }