NetworkInterceptor icon indicating copy to clipboard operation
NetworkInterceptor copied to clipboard

Automatic Velocity plugin detection within stack traces

Open mart-r opened this issue 3 years ago • 1 comments

While plugin detection (within stack traces) works for Spigot/Paper and Bungee, there is currently no automatic Plugin detection for Velocity. This is because the class loader does not keep track of the plugin that is responsible for loading a specific class. This is the method that is used to identify plugins for both Spigot/Paper as well as Bungee.

To be clear, plugins that are specified can be identified (https://github.com/SlimeDog/NetworkInterceptor/blob/master/src/main/java/me/lucko/networkinterceptor/velocity/VelocityPluginOptions.java). However, they are not found for detection (https://github.com/SlimeDog/NetworkInterceptor/blob/master/src/main/java/me/lucko/networkinterceptor/InterceptEvent.java#L104).

One way to address this could be to use the manual plugin detection that uses the user-specified (or perhaps even clerly deduced in the future) base package to map certain classes to a plugin. Some of this functionality exists within the plugin (https://github.com/SlimeDog/NetworkInterceptor/blob/master/src/main/java/me/lucko/networkinterceptor/blockers/ManualPluginDetectingBlocker.java).

Another way could be to map (plugin) class loaders to their respective plugins manually. One could then use reflection to find if a class is represented by the specific class loader (the ClassLoader#findLoadedClass method). However, since it would not be clear which class loader a class belongs to, this would include (as a worst case scenario - which also happens if the class is not plugin related) iterating through all plugin's class loaders. There could also be a cache that maps classes (or their names) to the corresponding plugins so that the class-plugin correspondents would only be looked at once. This could/should also identify plugins which have been shown not to be plugin related (otherwise the above worse case scenario of iterating over all the class loaders would be in effect every time).

I've not come to a specific conclusion as to which approach is better nor really on the specifics of the implementation. But I am fairly certain that one (or both) of the above methods could be made to work.

EDIT: Please comment if this is something you would require.

mart-r avatar Jul 31 '21 08:07 mart-r

Plugin identification is not a documented feature of NetworkInterceptor, but it is useful and is available on other platforms, so it would be nice to have.

SlimeDog avatar Jul 31 '21 14:07 SlimeDog