Plugin Engine

From World Wind Wiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 10:50, 19 May 2005 (edit)
160.62.4.10 (Talk)
(Security Lockdown Fix)
← Previous diff
Revision as of 11:26, 19 May 2005 (edit) (undo)
Mashiharu (Talk | contribs)
m
Next diff →
Line 1: Line 1:
-An experimental C#/VB/JScript.NET '''Script Engine''' has been committed on the WORLDWIND_1_3_MASHI_SCRIPTCOMPILER branch in [[CVS]].+A C#/VB/JScript.NET '''Plugin Compiler''' has been committed to [[CVS]] (HEAD).
==Features== ==Features==
Line 28: Line 28:
*Very fast on-the-fly compilation of the scripts. *Very fast on-the-fly compilation of the scripts.
*Scripts executes with same speed as a precompiled assembly. *Scripts executes with same speed as a precompiled assembly.
 +*Debuggable inside World Wind project
 +*Custom dlls may be dynamically loaded
==Drawbacks== ==Drawbacks==
-*Not very debug-friendly (yet), maybe include a working debug project  
*Security: The script could wipe out the hard drive or worse. But with a script at least the user can verify the intentions by looking at the source. Even current add-ons (layers) are often .exe installers giving the user no way of identifying evil code. *Security: The script could wipe out the hard drive or worse. But with a script at least the user can verify the intentions by looking at the source. Even current add-ons (layers) are often .exe installers giving the user no way of identifying evil code.
*To unload a script's assembly from memory, WW must be restarted (unless we start messing with appdomains) *To unload a script's assembly from memory, WW must be restarted (unless we start messing with appdomains)
-*With no fixed interface into WW the script could break on a new version of WW. But even with an interface the script will break when the interface changes, so in my opinion ([[User:Mashiharu|Mashiharu]]) having fixed interfaces will:+*With no fixed interface into WW the script could stop working on a new version of WW.
-**Give developers a lot of extra work+
-**Limit the scripts flexibility+
-*Currently no way for scripts to reference other assemblies (third party dlls)+
==Security Lockdown Fix== ==Security Lockdown Fix==
Line 54: Line 52:
} }
-From [ http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetsec/html/THCMCh08.asp Code Access Security in Practice - MSDN ]+From [http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetsec/html/THCMCh08.asp Code Access Security in Practice - MSDN]
==Code Translator== ==Code Translator==

Revision as of 11:26, 19 May 2005

A C#/VB/JScript.NET Plugin Compiler has been committed to CVS (HEAD).

Contents

Features

  • Dynamic compilation and execution of script code written in the following languages:
    • C#
    • VB.NET
    • JSCript.net
  • Full access to World Wind internals (same as internal code)
  • Runs at full speed (same as an integral part of World Wind)

Sample scripts

  • Clock (C#): On-screen lower-right corner clock. Simple example of how to implement a RenderableObject.
  • UdpReceiver (C#): Listens for incoming UDP packets and commands ww to go to (lat,lon) location. Feature was requested by Flight Gear developers. They have code in their flight simulator to remote control World Wind so pilots can use it as a moving map display.
  • RangeFog (JScript): Enables Direct3D fog in the scene. This is also a RenderableObject but written in JScript.Net.
  • TrackLog (VB.NET): Draws line on ground as you move over the globe
  • ISS (C#): Loads model of the International Space Station and displays in an approximately corrrect location (Longitude is 20 degrees off for some reason. Please help Mashi debug, it is driving him crazy.)

Engine logic

When World Wind starts the following steps are performed:

  • The ScriptCompiler scans bin\Plugin directory and the 1st level subdirectories of the plugin directory for files ending in any of the supported file extensions.
  • When it finds one it tries to compile the source (to memory) with references to the same assemblies as the app has referenced.
  • It then searches the compiled assembly for an implementation of IScript.
  • If it finds one it executes InitializeScript().

Benefits

  • Since the compiler for C#,VB and JSCript comes with the .Net Framework no additional third party library is required.
    • For other languages (like J#) an install will be needed, and unfortunately I haven't found an easy way of enumerating all available compilers (before .Net 2.0)
  • Very fast on-the-fly compilation of the scripts.
  • Scripts executes with same speed as a precompiled assembly.
  • Debuggable inside World Wind project
  • Custom dlls may be dynamically loaded

Drawbacks

  • Security: The script could wipe out the hard drive or worse. But with a script at least the user can verify the intentions by looking at the source. Even current add-ons (layers) are often .exe installers giving the user no way of identifying evil code.
  • To unload a script's assembly from memory, WW must be restarted (unless we start messing with appdomains)
  • With no fixed interface into WW the script could stop working on a new version of WW.

Security Lockdown Fix

Following this example we should be able to lockdown FileIO to the AppDir

public static string ReadFile(string filename)
{
  string appDir = Directory.GetCurrentDirectory();
  FileIOPermission f = new FileIOPermission(PermissionState.None);
  f.SetPathList(FileIOPermissionAccess.Read, appDir);
  f.SetPathList(FileIOPermissionAccess.PathDiscovery, appDir);
  f.PermitOnly(); 

  // Use Path.GetFilePath() to canonicalize the file name
  // Use FileStream.OpenRead to open the file
  // Use FileStream.Read to access and return the data
}

From Code Access Security in Practice - MSDN

Code Translator

C#<->VB [1] So no one can complain about languages. :)

Personal tools