public bool BindLibrary(MISP.Engine engine) { var database = new DatabaseService(); engine.AddFunction("osm-query-id", "Query an entry from the OSM database.", (context, arguments) => { var r = database.Query(Convert.ToInt64(arguments[0])); database.CommitChanges(); return r; }, Arguments.Arg("id")); engine.AddFunction("osm-query-name", "Query an entry from the OSM database.", (context, arguments) => { var r = database.Query(Convert.ToString(arguments[0])); database.CommitChanges(); return r; }, Arguments.Arg("name")); var geoMath = AutoBind.GenerateLazyBindingObjectForStaticLibrary(typeof(GeographicMath)); engine.AddGlobalVariable("geo", c => geoMath); return true; }
public static void Deserialize(MISP.GenericScriptObject into, ReadOnlyDatagram from, Database database) { var state = new SerializerState(); state.referencedObjects.Add(0, into); while (from.More) impleDeserialize(from, state, database); }
public static void DecodeMessage(byte[] bytes, out String ID, out MISP.ScriptList Data) { Initialize(); var datagram = new ReadOnlyDatagram(bytes); datagram.ReadString(out ID); Data = DecodeList(datagram); }
public static byte[] EncodeMessage(String ID, MISP.ScriptList Data) { Initialize(); var datagram = new WriteOnlyDatagram(); datagram.WriteString(ID); EncodeList(Data, datagram); return datagram.BufferAsArray; }
public static String Preprocess(String text, MISP.Environment ScriptEngine) { var state = new ParseState { start = 0, end = text.Length, source = text }; var output = new StringBuilder(); var preprocessContext = new PreprocessContext(); preprocessContext.builder = output; var preprocessGlobals = new MISP.ScriptObject(); while (!state.AtEnd()) { while (!state.AtEnd() && !state.MatchNext("<<")) { if (state.MatchNext("\\<<")) //Skip escaped open brackets { output.Append("<<"); state.Advance(3); } else { output.Append(state.Next()); state.Advance(); } } if (!state.AtEnd()) { state.Advance(2); //skip << var script = new StringBuilder(); while (!state.AtEnd() && !state.MatchNext(">>")) { if (state.MatchNext("\\>>")) { script.Append(">>"); state.Advance(3); } else { script.Append(state.Next()); state.Advance(); } } if (!state.AtEnd()) state.Advance(2); //skip >> var scriptContext = ScriptEngine.CompileScript(script.ToString()); scriptContext.Tag = preprocessContext; ScriptEngine.RunScript(scriptContext); if (scriptContext.ExecutionState == MISP.ExecutionState.Error) { Console.WriteLine("Error in preprocessing"); Console.WriteLine(scriptContext.ErrorMessage); } } } return output.ToString(); }
public static WriteOnlyDatagram Serialize(MISP.ScriptObject obj) { var r = new WriteOnlyDatagram(); var state = new SerializerState(); state.referencedObjects.Add(obj); state.referencedObjectsIDs.Add(obj, 0); for (int i = 0; i < state.referencedObjects.Count; ++i) impleSerialize(state.referencedObjects[i], i, r, state); return r; }
public void BindScript(MISP.Engine scriptEngine) { scriptEngine.AddFunction("model", "Create a model component.", (context, arguments) => { var model = GeometryGeneration.MispBinding.ModelArgument(arguments[0]); return new ModelComponent(GeometryGeneration.CompiledModel.CompileModel(model, device)); }, MISP.Arguments.Arg("model")); var meshFunction = GeometryGeneration.MispBinding.GenerateBindingObject(); scriptEngine.AddGlobalVariable("mesh", (context) => { return meshFunction; }); scriptEngine.AddGlobalVariable("camera", (context) => { return Camera; }); }
internal static void impleSerialize(MISP.ScriptObject obj, int index, WriteOnlyDatagram datagram, SerializerState state) { datagram.WriteUInt((uint)index, 16); var propList = obj.ListProperties(); var filteredList = new List<Object>( propList.Where((o) => { return IsSerializableType(obj.GetLocalProperty(o as String)); })); datagram.WriteUInt((uint)filteredList.Count, 16); foreach (var item in filteredList) { datagram.WriteString(item as String); SerializeObject(obj.GetLocalProperty(item as String), datagram, state); } }
void IModule.BindScript(MISP.Engine scriptEngine) { //scriptEngine.AddGlobalVariable("ui-root", c => uiRoot); var guiBinding = Gem.Gui.MispBinding.GenerateBinding(); scriptEngine.AddGlobalVariable("ui", c => guiBinding); scriptEngine.AddFunction("create-ui-scene-node", "", (context, arguments) => { var r = new GuiSceneNode(MISP.AutoBind.IntArgument(arguments[0]), MISP.AutoBind.IntArgument(arguments[1]), this); activeGuis.Add(r); return r; }, MISP.Arguments.Arg("width"), MISP.Arguments.Arg("height")); }
public static void SetupScriptEngine(MISP.Environment ScriptEngine) { ScriptEngine.AddNativeFunction("import", (context, args) => { var filename = args[0].ToString(); var file = System.IO.File.ReadAllText(filename); (context.Tag as PreprocessContext).Append(Preprocess(file, ScriptEngine)); return null; }); ScriptEngine.AddNativeFunction("preprocess", (context, args) => { var text = args[0].ToString(); return Preprocess(text, ScriptEngine); }); ScriptEngine.AddNativeFunction("write", (context, args) => { var str = args[0].ToString(); (context.Tag as PreprocessContext).Append(UnescapeString(str)); return null; }); ScriptEngine.AddNativeFunction("capture", (context, args) => { var pcontext = context.Tag as PreprocessContext; var oldBuilder = pcontext.builder; pcontext.builder = new StringBuilder(); ScriptEngine.RunScript(args[0].ToString()); var r = pcontext.builder.ToString(); pcontext.builder = oldBuilder; return r; }); }
void IModule.BindScript(MISP.Engine scriptEngine) { }
void IModule.BindScript(MISP.Engine scriptEngine) { scriptEngine.AddFunction("get-client", "Retreive a client object.", (context, arguments) => { var n = MISP.AutoBind.IntArgument(arguments[0]); return netSession.getPeer(n); }, MISP.Arguments.Arg("client")); scriptEngine.AddFunction("client-count", "Get the number of connected clients.", (context, arguments) => { return netSession.clientCount; }); }
private static void EncodeList(MISP.ScriptList data, WriteOnlyDatagram datagram) { datagram.WriteUInt((uint)data.Count, 8); foreach (var item in data) { if (item == null) { datagram.WriteUInt((uint)ScriptTypes.Bool, 8); datagram.WriteUInt(0u, 8); continue; } var type = item.GetType(); if (typeCodes.ContainsKey(type)) { var typeCode = typeCodes[type]; datagram.WriteUInt((uint)typeCode, 8); switch (typeCode) { case ScriptTypes.List: EncodeList(item as MISP.ScriptList, datagram); break; case ScriptTypes.String: datagram.WriteString(item as String); break; case ScriptTypes.Int32: datagram.WriteBytes(BitConverter.GetBytes(MISP.AutoBind.IntArgument(item))); break; case ScriptTypes.UInt32: datagram.WriteBytes(BitConverter.GetBytes(MISP.AutoBind.UIntArgument(item))); break; case ScriptTypes.Single: datagram.WriteBytes(BitConverter.GetBytes(MISP.AutoBind.NumericArgument(item))); break; case ScriptTypes.Bool: datagram.WriteUInt(MISP.AutoBind.BooleanArgument(item) ? 1u : 0u, 8); break; default: throw new MISP.ScriptError("Error encoding message", null); } } else { throw new MISP.ScriptError("Type " + type.Name + " cannot be serialized to a network message.", null); } } }
public bool BindLibrary(MISP.Engine engine) { engine.AddFunction("open-database", "Opens a database service object connected to the local adjuster database.", (context, arguments) => { return new DatabaseService(); }); return true; }
void IModule.BindScript(MISP.Engine scriptEngine) { var renderer = new MISP.GenericScriptObject(); renderer.AddFunction("create-scene-leaf", "Create a scene leaf.", (context, arguments) => { var model = GeometryGeneration.MispBinding.ModelArgument(arguments[0]); return new SceneNode { leaf = GeometryGeneration.CompiledModel.CompileModel(model, device) }; }, MISP.Arguments.Arg("model")); renderer.AddFunction("create-scene-component", "Create a scene component.", (context, arguments) => { var r = new SceneGraphRoot(); foreach (var arg in arguments) if (arg is SceneNode) r.rootNode.Add(arg as SceneNode); return r; }, MISP.Arguments.Arg("leaf")); renderer.AddFunction("query", "Query for a specific renderable.", (context, arguments) => { var key = MISP.AutoBind.UIntArgument(arguments[0]); if (this.renderables.ContainsKey(key)) return this.renderables[key]; return null; }, MISP.Arguments.Arg("key")); scriptEngine.AddGlobalVariable("renderer", context => renderer); var meshFunction = GeometryGeneration.MispBinding.GenerateBindingObject(); scriptEngine.AddGlobalVariable("mesh", (context) => { return meshFunction; }); scriptEngine.AddGlobalVariable("camera", (context) => { return Camera; }); }
internal void WriteObject(MISP.ScriptObject obj, WriteOnlyDatagram datagram) { var path = obj.GetProperty("@path"); //If it has a path attribute, it's a named object and should not be saved. if (path != null && path is String) { datagram.WriteUInt((uint)SerializedTypeCode.NamedObject, 8); datagram.WriteString(path as String); } else { datagram.WriteUInt((uint)SerializedTypeCode.InternalObject, 8); if (referencedObjectsIDs.ContainsKey(obj)) datagram.WriteUInt(referencedObjectsIDs[obj], 16); else { referencedObjectsIDs.Add(obj, (uint)referencedObjects.Count); referencedObjects.Add(obj); datagram.WriteUInt((uint)(referencedObjects.Count - 1), 16); } } }
internal DisconnectAction(MISP.ScriptObject player) : base(0) { this.player = player; }