Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

Safe Plugin Architecture [Imports ,Jailed, IO Limited, Plugin Communications]

So i started with some side projects with plugin architecture and decided to write an entire new proper plugin model basis.
This base does all of the former projects (except remote assemblies for the time being) and makes use of jailing (sandboxed),
controlled read/write/ACL (https://msdn.microsoft.com/en-us/library...s.90).aspx),
and being able to import plugin(s) inside the domain from another plugin so they can interact with each other.

[Image: AkOGMQp.png]

In this demo one assembly containing the exported types (can be separate assemblies ofc), the first one tests the read/write on local folder and then on C:\ 
the second one attempts to import the first plugin that has a specific interface on it, and once its imported, invokes a method that is defined from 
this specific interface, this is useful for plugin communications. 

These interfaces don't need to be defined inside the assembly but can also be separate, the loader will load all assemblies found into the domain.
Keep in mind that interfaces work both ways of course.


Importing plugins from and to a plugin

Inside a plugin, one could import plugins with specific interfaces:
Code
Dim plugin As CommunicationTest = Me.Parent.Import(Of CommunicationTest)()

If (plugin IsNot Nothing) Then
   plugin.SayHello(Me.Name)
End If


The interface used in this example
Code
Public Interface CommunicationTest
    Sub SayHello(sender As String)
End Interface


or if more then one is using that particular interface, 
Code
For Each plug In Me.Parent.ImportAll(Of CommunicationTest)()
            '...code....
Next


Setup the base

To setup and load plugins from a folder you would approach it like this
Code
Dim plugins As String = Path.GetFullPath(".\Plugins\")

Using host As New Host("sandboxie", plugins)

            If (host.Load) Then
                Try
                    For Each container As Container(Of IContainer) In host.ImportAll(Of IContainer)()

                        Dim plugin As IContainer = container.RefObject

                        Console.WriteLine("+-----------------------------------------------+")
                        Console.WriteLine("Type: {0} {1}", plugin.Name, plugin.Version)
                        Console.WriteLine(String.Empty)

                        If (plugin.Initialize) Then
                            plugin.Run()
                        End If
                    Next

                Catch ex As Exception
                    Console.WriteLine(ex.Message)
                End Try
            End If

End Using



Plugin Base Structure

The IContainer is the basis for all plugins that want to be able to use the internal functions of the Loader , the base methods include:
Test to see if a plugin can read a specified filename or directory
Code
Public Function CanRead(path As String) As Boolean Implements IContainer.CanRead

Test to see if a plugin can write a specified filename or directory
Code
Public Function CanWrite(path As String) As Boolean Implements IContainer.CanWrite

Test to see if a plugin can do a specified action for that filename or directory
Code
Public Function Access(path As String, rights As FileSystemRights) As Boolean Implements IContainer.Access

Access the parent (loader) that contains the Import/ImportAll methods and Assembly collection
Code
Public ReadOnly Property Parent As ILoader Implements IContainer.Parent

Get the current base directory where the plugin resides in
Code
Public ReadOnly Property BaseDirectory As String Implements IContainer.BaseDirectory
Github: https://github.com/TheBarret/PluginLoader
Changes will be made along the way, for suggestions or questions post them in here.
Not bad! Here is the converted source for CSharp...
Link: anonfile(.)com/dbG0Ufcdb3/CSharp-PluginLoader(.)rar
Password: TheBarret
(Nov 11, 2017 08:21 AM)StaPol Wrote:  Not bad! Here is the converted source for CSharp...
Link: anonfile[dot]com/G0D1U9cfb8/CSharp-PluginLoader[dot]rar
Password: TheBarret

The conversion is nice but it seems the IDE you are using left some personal info in some of the files.
(Nov 11, 2017 08:47 AM)Barret Wrote:  The conversion is nice but it seems the IDE you are using left some personal info in some of the files.

I upload a new archive :)


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C] by lo0srMar 23, 2022 10:40 PM 14 761 Mar 23, 2022 10:40 PM
Last Post: rathvncgod
[Python] by CinderGhoulAug 19, 2021 06:56 AM 2 154 Aug 19, 2021 06:56 AM
Last Post: CinderGhoul
[C] by Tr0jandogSep 10, 2019 11:47 AM 4 262 Sep 10, 2019 11:47 AM
Last Post: Tr0jandog