public static RoutineInfo getRoutineByClassIDAndDayID(RoutineInfo _routine) { SqlConnection con = ConnectionHelper.GetConnection(); string sp = "USP_Routine_ByClassIDAndDayID"; SqlCommand cmd = new SqlCommand(sp, con); cmd.Parameters.Add(new SqlParameter("@DayID", _routine.DayID)); cmd.Parameters.Add(new SqlParameter("@ClassID", _routine.ClassID)); cmd.CommandType = CommandType.StoredProcedure; try { SqlDataReader _Reader = cmd.ExecuteReader(); _Reader.Read(); RoutineInfo _routines = new RoutineInfo(); _routines.ClassID = int.Parse(_Reader["ClassID"].ToString()); _routines.DayID = int.Parse(_Reader["DayID"].ToString()); _routines.First = _Reader["First"].ToString(); _routines.Second = _Reader["Second"].ToString(); _routines.Third = _Reader["Third"].ToString(); _routines.Fourth = _Reader["Fourth"].ToString(); _routines.Fifth = _Reader["Fifth"].ToString(); _routines.Sixth = _Reader["Sixth"].ToString(); return _routines; } catch (Exception ex) { throw ex; } }
public ReflectionMethod getPrototype() { // NOTE: not the same as _routine.Methods[0].GetBaseDefinition() if (!_tinfo.IsInterface) { // first look in interfaces: foreach (var t in _tinfo.Type.ImplementedInterfaces) { var r = t.GetPhpTypeInfo().RuntimeMethods[name]; if (r != null) { return(new ReflectionMethod(r)); } } } // then base classes: RoutineInfo prototype = null; for (var t = _tinfo.BaseType; t != null; t = t.BaseType) { var r = t.RuntimeMethods[name]; if (r != null) { prototype = r; } } return(prototype != null && prototype.DeclaringType != _tinfo ? new ReflectionMethod(prototype) : throw new ReflectionException(string.Format(Resources.Resources.method_doesnt_have_prototype, _tinfo.Name, name))); }
public void AssertFunctionDeclared(RoutineInfo routine) { if (!_functions.IsDeclared(routine)) { // TODO: ErrCode function is not declared } }
public static string create_function(Context ctx, string args, string code) { // prepare function script var data = ScriptingContext.EnsureContext(ctx); var source = string.Format(_createFunctionTemplate, _lambdaFuncName, args, code); // create script that declares the lambda function var script = ctx.ScriptingProvider.CreateScript(new Context.ScriptOptions() { Context = ctx, EmitDebugInformation = Debugger.IsAttached, // CONSIDER Location = new Location(Path.Combine(ctx.RootPath, "runtime-created function"), 0, 0), // TODO: pass from calling script IsSubmission = true }, source); var methods = script.GetGlobalRoutineHandle(_lambdaFuncName).ToArray(); if (methods.Length == 0) { return(null); } var lambdaName = string.Format(_lambdaFormatString, ++data.LastLambdaIndex); var routine = RoutineInfo.CreateUserRoutine(lambdaName, methods); ctx.DeclareFunction(routine); return(lambdaName); }
private static string DumpCodeAddress(ZMachine zm, IDebugger dbg, int address) { StringBuilder sb = new StringBuilder(); sb.AppendFormat("${0:x5}", address); if (zm.DebugInfo != null) { RoutineInfo rtn = zm.DebugInfo.FindRoutine(address); if (rtn != null) { sb.AppendFormat(" ({0}+{1}", rtn.Name, address - rtn.CodeStart); LineInfo?li = zm.DebugInfo.FindLine(address); if (li != null) { sb.AppendFormat(", {0}:{1}", li.Value.File, li.Value.Line); } sb.Append(')'); } } return(sb.ToString()); }
static void Main() { // sideload assembly containing compiled PHP code: Context.AddScriptReference(Assembly.Load(new AssemblyName("phplib"))); // create host for PHP code (Runtime Context): using (var ctx = Context.CreateConsole()) { // declare global function in PHP runtime context ctx.DeclareFunction(RoutineInfo.CreateUserRoutine("is_valid_url", new Func <string, bool>((url) => { return(new Uri(url).IsAbsoluteUri); }))); // call the global code from "class-user.php" which declares class ctx.Include("", "inc/class-user.php"); // dynamic u1 = ctx.Create("User", "Jacob", "https://example.org", "*****@*****.**"); u1.Authenticate(); var u2 = new DotNetUser(ctx, "Jacob", "https://example.org", "*****@*****.**"); u2.Authenticate(); } }
internal ReflectionMethod(PhpTypeInfo tinfo, RoutineInfo routine) { Debug.Assert(tinfo != null); Debug.Assert(routine != null); _tinfo = tinfo; _routine = routine; }
public void Configure(WpApp app) { this.app = app; Del MyDel = RegisterMyWidget; var routineInfo = RoutineInfo.CreateUserRoutine("RegisterMyWidget", MyDel); app.Context.Call("add_action", (PhpValue)"widgets_init", routineInfo); }
private void DoShowBacktrace() { ICallFrame[] frames; frames = dbg.GetCallFrames(); io.PutString(string.Format("Call depth: {0}\n", frames.Length)); io.PutString(string.Format("PC = {0}\n", DumpCodeAddress(zm, dbg, dbg.CurrentPC))); for (int i = 0; i < frames.Length; i++) { ICallFrame cf = frames[i]; io.PutString("==========\n"); io.PutString(string.Format("[{0}] return PC = {1}\n", i + 1, DumpCodeAddress(zm, dbg, cf.ReturnPC))); io.PutString(string.Format("called with {0} arg{1}, stack depth {2}\n", cf.ArgCount, cf.ArgCount == 1 ? "" : "s", cf.PrevStackDepth)); if (cf.ResultStorage < 16) { if (cf.ResultStorage == -1) { io.PutString("discarding result\n"); } else if (cf.ResultStorage == 0) { io.PutString("storing result to stack\n"); } else { RoutineInfo rtn = null; if (zm.DebugInfo != null) { rtn = zm.DebugInfo.FindRoutine(cf.ReturnPC); } if (rtn != null && cf.ResultStorage - 1 < rtn.Locals.Length) { io.PutString(string.Format("storing result to local {0} ({1})\n", cf.ResultStorage, rtn.Locals[cf.ResultStorage - 1])); } else { io.PutString(string.Format("storing result to local {0}\n", cf.ResultStorage)); } } } else if (zm.DebugInfo.Globals.Contains((byte)cf.ResultStorage)) { io.PutString(string.Format("storing result to global {0} ({1})\n", cf.ResultStorage, zm.DebugInfo.Globals[(byte)(cf.ResultStorage - 16)])); } else { io.PutString(string.Format("storing result to global {0}\n", cf.ResultStorage)); } } io.PutString("==========\n"); }
/// <summary> /// Constructs the closure. /// </summary> internal Closure(RoutineInfo routine, PhpArray parameter, PhpArray @static) { Debug.Assert(routine != null); Debug.Assert(parameter != null); Debug.Assert(@static != null); this.routine = routine; this.parameter = parameter; this.@static = @static; }
public bool TryGet(string routine, out RoutineInfo routineInfo) { var isExists = _routine.ContainsKey(routine); if (isExists) { routineInfo = _routine[routine]; return(true); } routineInfo = null; return(false); }
public virtual void __construct(Context ctx, PhpValue /*string|array*/ function, PhpValue /*string|int*/ parameter) { // resolve RoutineInfo: PhpTypeInfo declaringclass = null; RoutineInfo routine = null; var function_str = function.AsString(); if (function_str != null) { routine = ctx.GetDeclaredFunction(function_str); } else { var function_arr = function.AsArray(); if (function_arr != null && function_arr.Count == 2) { declaringclass = ReflectionUtils.ResolvePhpTypeInfo(ctx, function_arr[0]); // cannot be null routine = declaringclass.RuntimeMethods[function_arr[1].ToStringOrThrow(ctx)]; } } if (routine != null) { var func = (declaringclass == null) ? (ReflectionFunctionAbstract) new ReflectionFunction(routine) : new ReflectionMethod(declaringclass, routine); // resolve parameter: var parameters = ReflectionUtils.ResolveReflectionParameters(func, routine.Methods); var pstr = parameter.AsString(); if (pstr != null) { SetParameter(parameters.First(p => p._name == pstr)); return; } else { if (parameter.IsLong(out long index) && index < parameters.Count && index >= 0) { SetParameter(parameters[(int)index]); return; } } } throw new ReflectionException(); }
public override IPhpCallable AsCallable(ref PhpValue me, RuntimeTypeHandle callerCtx) { var obj = me.Object; if (obj is IPhpCallable) { return((IPhpCallable)obj); // classes with __invoke() magic method implements IPhpCallable } if (obj is Delegate d) { return(RoutineInfo.CreateUserRoutine(d.GetMethodInfo().Name, d)); } return(PhpCallback.CreateInvalid()); }
public static void EditRoutine(RoutineInfo _routine) { SqlConnection con = ConnectionHelper.GetConnection(); string sp = "USP_Update_Routine"; SqlCommand cmd = new SqlCommand(sp, con); cmd.Parameters.Add(new SqlParameter("@RoutineID", _routine.RoutineID)); cmd.Parameters.Add(new SqlParameter("@First", _routine.First)); cmd.Parameters.Add(new SqlParameter("@Second", _routine.Second)); cmd.Parameters.Add(new SqlParameter("@Third", _routine.Third)); cmd.Parameters.Add(new SqlParameter("@Fourth", _routine.Fourth)); cmd.Parameters.Add(new SqlParameter("@Fifth", _routine.Fifth)); cmd.Parameters.Add(new SqlParameter("@Sixth", _routine.Sixth)); cmd.CommandType = CommandType.StoredProcedure; try { cmd.ExecuteNonQuery(); } catch (Exception ex) { throw ex; } }
static void Main() { // sideload assembly containing compiled PHP code: Context.AddScriptReference(Assembly.Load(new AssemblyName("phplib"))); // create host for PHP code (Runtime Context): using (var ctx = Context.CreateConsole()) { // declare a global variable in PHP runtime context ctx.Globals["x"] = (PhpValue)"Hello from C#"; // declare global function in PHP runtime context ctx.DeclareFunction(RoutineInfo.CreateUserRoutine("foo", new Func <string>(() => { return("Hello from lambda!"); }))); // call the global code from "main.php" ctx.Include("", "main.php"); // call PHP function defined in 'main.php' ctx.Call("demo", new object[] { }); } }
public static void CreateRoutine(RoutineInfo _routine) { SqlConnection Con = ConnectionHelper.GetConnection(); string Sp = "USP_Create_Routine"; SqlCommand cmd = new SqlCommand(Sp, Con); cmd.Parameters.Add(new SqlParameter("@DayID", _routine.DayID)); cmd.Parameters.Add(new SqlParameter("@FacultyID", _routine.FacultyID)); cmd.Parameters.Add(new SqlParameter("@BatchID", _routine.BatchID)); cmd.Parameters.Add(new SqlParameter("@First", _routine.First)); cmd.Parameters.Add(new SqlParameter("@Second", _routine.Second)); cmd.Parameters.Add(new SqlParameter("@Third", _routine.Third)); cmd.Parameters.Add(new SqlParameter("@Fourth", _routine.Fourth)); cmd.Parameters.Add(new SqlParameter("@Fifth", _routine.Fifth)); cmd.Parameters.Add(new SqlParameter("@Sixth", _routine.Sixth)); cmd.CommandType = CommandType.StoredProcedure; try { cmd.ExecuteNonQuery(); } catch (Exception ex) { throw ex; } }
void FunctionRedeclared(RoutineInfo routine) { // TODO: ErrCode & throw throw new InvalidOperationException($"Function {routine.Name} redeclared!"); }
/// <summary> /// Checks the routine has expected hash code. The routine can be null. /// </summary> static bool AssertFunction(RoutineInfo routine, int expectedHashCode) => routine != null && routine.GetHashCode() == expectedHashCode;
public void Add(string routine_name, int func, params string[] arg_types) { byte conv = util.getConvention(func, arg_types.Length); int routine = VirtualAllocEx(EyeStep.handle, 0, 256, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE); routines[routine_name] = new RoutineInfo(routine, conv); // load the function's calling routine byte[] data = new byte[256]; int size = 0; int narg = 0; byte[] bytes; if (conv == util.c_thiscall || conv == util.c_fastcall) { data[size++] = 0x8B; // mov ecx, [ arg location (first arg) ] data[size++] = 0x0D; bytes = BitConverter.GetBytes(args_loc + (8 * narg++)); data[size++] = bytes[0]; data[size++] = bytes[1]; data[size++] = bytes[2]; data[size++] = bytes[3]; if (conv == util.c_fastcall) { data[size++] = 0x8B; // mov edx, [ arg location (second arg) ] data[size++] = 0x15; bytes = BitConverter.GetBytes(args_loc + (8 * narg++)); data[size++] = bytes[0]; data[size++] = bytes[1]; data[size++] = bytes[2]; data[size++] = bytes[3]; } } for (int i = arg_types.Length - 1; narg < arg_types.Length; i--) { var type = arg_types[i]; if (type == "double") { // load quadword onto the stack (ESP) data[size++] = 0x0F; // movq xmm0, [ arg location ] data[size++] = 0x10; data[size++] = 0x05; bytes = BitConverter.GetBytes(args_loc + (8 * narg++)); data[size++] = bytes[0]; data[size++] = bytes[1]; data[size++] = bytes[2]; data[size++] = bytes[3]; data[size++] = 0xF2; // movsd [esp], xmm0 data[size++] = 0x0F; data[size++] = 0x11; data[size++] = 0x04; data[size++] = 0x24; } else { data[size++] = 0xFF; // push dword ptr [ arg location ] data[size++] = 0x35; bytes = BitConverter.GetBytes(args_loc + (8 * narg++)); data[size++] = bytes[0]; data[size++] = bytes[1]; data[size++] = bytes[2]; data[size++] = bytes[3]; } } data[size++] = 0xBF; // mov edi, routine bytes = BitConverter.GetBytes(func); data[size++] = bytes[0]; data[size++] = bytes[1]; data[size++] = bytes[2]; data[size++] = bytes[3]; data[size++] = 0xFF; // call edi data[size++] = 0xD7; // optimization : only move double sized value to the // return location and cast to an int for 32-bit returns data[size++] = 0xA3; // mov [ret_location (SMALL)], eax bytes = BitConverter.GetBytes(ret_loc_small); data[size++] = bytes[0]; data[size++] = bytes[1]; data[size++] = bytes[2]; data[size++] = bytes[3]; data[size++] = 0xF3; // movq xmm0, [esp] data[size++] = 0x0F; data[size++] = 0x7E; data[size++] = 0x04; data[size++] = 0x24; data[size++] = 0x66; // movq [ret_location (LARGE)], xmm0 data[size++] = 0x0F; data[size++] = 0xD6; data[size++] = 0x05; bytes = BitConverter.GetBytes(ret_loc_large); data[size++] = bytes[0]; data[size++] = bytes[1]; data[size++] = bytes[2]; data[size++] = bytes[3]; if (conv == util.c_cdecl) { data[size++] = 0x81; // add esp, ???????? data[size++] = 0xC4; bytes = BitConverter.GetBytes(arg_types.Length * 4); data[size++] = bytes[0]; data[size++] = bytes[1]; data[size++] = bytes[2]; data[size++] = bytes[3]; } data[size++] = 0xC7; // mov [func_id_loc], 00000000 data[size++] = 0x05; bytes = BitConverter.GetBytes(func_id_loc); data[size++] = bytes[0]; data[size++] = bytes[1]; data[size++] = bytes[2]; data[size++] = bytes[3]; data[size++] = 0x00; data[size++] = 0x00; data[size++] = 0x00; data[size++] = 0x00; util.writeBytes(routine, data, size); util.placeJmp(routine + size, remote_loc + 6); util.writeInt(funcs_loc + (routines.Count * 4), routine); }
/// <summary> /// Declare a runtime user function. /// </summary> public void DeclareFunction(RoutineInfo routine) => _functions.DeclarePhpRoutine(routine);
public void CreateRoutine(RoutineInfo routineInfo) { SystemSession.Access().CreateObject(routineInfo); }
// Bypasses any possible callee checks // by spoofing the return when using this function public void AddProtected(string routine_name, int func, params string[] arg_types) { if (spoofredirect == 0 || spoofroutine == 0) { // jmp dword ptr [xxxxxxxx] spoofroutine = scanner.scan("FF25????????55")[0]; spoofredirect = util.readInt(spoofroutine + 2); } byte conv = util.getConvention(func, arg_types.Length); int routine = VirtualAllocEx(EyeStep.handle, 0, 256, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE); int func_start = func; if (util.isPrologue(func_start)) { func += 3; } routines[routine_name] = new RoutineInfo(routine, conv); // load the function's calling routine byte[] data = new byte[256]; int size = 0; int narg = 0; byte[] bytes; if (conv == util.c_thiscall || conv == util.c_fastcall) { data[size++] = 0x8B; // mov ecx, [ arg location (first arg) ] data[size++] = 0x0D; bytes = BitConverter.GetBytes(args_loc + (8 * narg++)); data[size++] = bytes[0]; data[size++] = bytes[1]; data[size++] = bytes[2]; data[size++] = bytes[3]; if (conv == util.c_fastcall) { data[size++] = 0x8B; // mov edx, [ arg location (second arg) ] data[size++] = 0x15; bytes = BitConverter.GetBytes(args_loc + (8 * narg++)); data[size++] = bytes[0]; data[size++] = bytes[1]; data[size++] = bytes[2]; data[size++] = bytes[3]; } } for (int i = arg_types.Length - 1; narg < arg_types.Length; i--) { var type = arg_types[i]; if (type == "double") { // load quadword onto the stack (ESP) data[size++] = 0x0F; // movq xmm0, [ arg location ] data[size++] = 0x10; data[size++] = 0x05; bytes = BitConverter.GetBytes(args_loc + (8 * narg++)); data[size++] = bytes[0]; data[size++] = bytes[1]; data[size++] = bytes[2]; data[size++] = bytes[3]; data[size++] = 0xF2; // movsd [esp], xmm0 data[size++] = 0x0F; data[size++] = 0x11; data[size++] = 0x04; data[size++] = 0x24; } else { data[size++] = 0xFF; // push dword ptr [ arg location ] data[size++] = 0x35; bytes = BitConverter.GetBytes(args_loc + (8 * narg++)); data[size++] = bytes[0]; data[size++] = bytes[1]; data[size++] = bytes[2]; data[size++] = bytes[3]; } } data[size++] = 0xE8; // call custom_prologue data[size++] = 0x00; data[size++] = 0x00; data[size++] = 0x00; data[size++] = 0x00; custom_prologue: // Get the 32-bit register being used // for the function's prologue var r_prologue = util.readByte(func - 3) % 8; // Use the original prologue for (int i = 0; i < 3; i++) { data[size++] = util.readByte((func - 3) + i); } data[size++] = 0x8B; // mov edi, [ebp+4] (most likely ebp) data[size++] = (byte)(0x78 + r_prologue); data[size++] = 0x04; data[size++] = 0x81; // add esp, 00000021 data[size++] = 0xC7; data[size++] = 0x21; data[size++] = 0x00; data[size++] = 0x00; data[size++] = 0x00; data[size++] = 0x89; // mov [spoofredirect], edi data[size++] = 0x3D; bytes = BitConverter.GetBytes(spoofredirect); data[size++] = bytes[0]; data[size++] = bytes[1]; data[size++] = bytes[2]; data[size++] = bytes[3]; data[size++] = 0xBF; // mov edi, spoofroutine bytes = BitConverter.GetBytes(spoofroutine); data[size++] = bytes[0]; data[size++] = bytes[1]; data[size++] = bytes[2]; data[size++] = bytes[3]; data[size++] = 0x89; // mov [ebp+4], edi (most likely ebp) data[size++] = (byte)(0x78 + r_prologue); data[size++] = 0x04; data[size++] = 0xBF; // mov edi, func (after prologue) bytes = BitConverter.GetBytes(func); data[size++] = bytes[0]; data[size++] = bytes[1]; data[size++] = bytes[2]; data[size++] = bytes[3]; data[size++] = 0xFF; // jmp edi data[size++] = 0xE7; // optimization : only move double sized value to the // return location and cast to an int for 32-bit returns data[size++] = 0xA3; // mov [ret_location (SMALL)], eax bytes = BitConverter.GetBytes(ret_loc_small); data[size++] = bytes[0]; data[size++] = bytes[1]; data[size++] = bytes[2]; data[size++] = bytes[3]; data[size++] = 0xF3; // movq xmm0, [esp] data[size++] = 0x0F; data[size++] = 0x7E; data[size++] = 0x04; data[size++] = 0x24; data[size++] = 0x66; // movq [ret_location (LARGE)], xmm0 data[size++] = 0x0F; data[size++] = 0xD6; data[size++] = 0x05; bytes = BitConverter.GetBytes(ret_loc_large); data[size++] = bytes[0]; data[size++] = bytes[1]; data[size++] = bytes[2]; data[size++] = bytes[3]; if (conv == util.c_cdecl) { data[size++] = 0x81; // add esp, ???????? data[size++] = 0xC4; bytes = BitConverter.GetBytes(arg_types.Length * 4); data[size++] = bytes[0]; data[size++] = bytes[1]; data[size++] = bytes[2]; data[size++] = bytes[3]; } data[size++] = 0xC7; // mov [func_id_loc], 00000000 data[size++] = 0x05; bytes = BitConverter.GetBytes(func_id_loc); data[size++] = bytes[0]; data[size++] = bytes[1]; data[size++] = bytes[2]; data[size++] = bytes[3]; data[size++] = 0x00; data[size++] = 0x00; data[size++] = 0x00; data[size++] = 0x00; util.writeBytes(routine, data, size); util.placeJmp(routine + size, remote_loc + 6); util.writeInt(funcs_loc + (routines.Count * 4), routine); }
internal ReflectionMethod(RoutineInfo routine) { _routine = routine ?? throw new ArgumentNullException(nameof(routine)); _tinfo = routine.DeclaringType ?? throw new ArgumentException(); }
internal ReflectionFunction(RoutineInfo routine) { Debug.Assert(routine != null); _routine = routine; }
/// <summary> /// Compiles and executes code, starting from the current <see cref="pc"/> and continuing /// until <see cref="running"/> becomes false or the current call frame is exited. /// </summary> private void JitLoop() { int initialCallDepth = callStack.Count; while (running && callStack.Count >= initialCallDepth) { #if TRACING Console.Write("===== Call: {1,2} Eval: {0,2}", stack.Count, callStack.Count); if (debugFile != null) { RoutineInfo ri = debugFile.FindRoutine(pc); if (ri != null) { Console.Write(" (in {0})", ri.Name); } } Console.WriteLine(); #endif // Work around some kind of CLR bug! // The release build crashes with a NullReferenceException if this test is removed. // Cache can *never* be null, of course, since it's initialized outside this loop // and never changed. But it seems to magically become null unless we remind .NET // to check first. (Note: the bug doesn't occur when running under the debugger, // even in release builds.) //if (cache == null) // throw new Exception("Something impossible happened"); // NOTE: fixed it by making cache a field instead. CachedCode entry; int thisPC = pc; #if !DISABLE_CACHE if (thisPC < romStart || cache.TryGetValue(thisPC, out entry) == false) #endif { #if BENCHMARK cacheMisses++; #endif int count; entry.Code = CompileZCode(out count); entry.NextPC = pc; #if BENCHMARK entry.Cycles = count; // only used to calculate the amount of cached z-code #endif #if !DISABLE_CACHE if (thisPC >= romStart) { cache.Add(thisPC, entry, count); } #endif } #if BENCHMARK else { cacheHits++; } #endif pc = entry.NextPC; entry.Code(); } }
/// <summary> /// Create <see cref="Closure"/> with specified anonymous function and used parameters. /// </summary> public static Closure BuildClosure(RoutineInfo routine, PhpArray parameter, PhpArray @static) => new Closure(routine, parameter, @static);
/// <summary> /// Utilities routine to get class methods. /// </summary> /// <param name="IncludeParent">if false then just returns methods defined in the passed class type /// if true then this routine makes a list of all methods in the class including any parent classes /// </param> /// <param name="Info">type of the class to check</param> /// <returns></returns> // helper for FIlterClasses callback - checks if the TypeData contaisn the iFormat Specs private bool FilterClassesCheck_Routines(TypeInfo Data) { int VerifyCheck = 0; ParameterInfo[] ArgInfo; List <MethodInfo> Info = InstancedPluginContainer.GetClassMethods(true, Data); foreach (MethodInfo RoutineInfo in Info) { switch (RoutineInfo.Name) { case "ReadData": if (!RoutineInfo.IsPublic) { continue; } if (RoutineInfo.ReturnType != typeof(void)) { continue; } if (RoutineInfo.IsStatic == true) { continue; } ArgInfo = RoutineInfo.GetParameters(); if (ArgInfo.Length != 3) { continue; } if (ArgInfo[0].ParameterType != typeof(StreamReader)) { continue; } if (ArgInfo[1].ParameterType != typeof(StreamWriter)) { continue; } // TODO: Check argument for reference bool /* * if (ArgInfo[2].ParameterType != Boolean.get) * { * continue; * }*/ VerifyCheck++; break; case "GetPreferredExtension": if (!RoutineInfo.IsPublic) { continue; } if (RoutineInfo.IsStatic) { continue; } if (RoutineInfo.ReturnType != typeof(string)) { continue; } ArgInfo = RoutineInfo.GetParameters(); if (ArgInfo.Length != 0) { continue; } VerifyCheck++; break; case "WriteData": if (!RoutineInfo.IsPublic) { continue; } if (RoutineInfo.IsStatic) { continue; } if (RoutineInfo.ReturnType != typeof(void)) { continue; } ArgInfo = RoutineInfo.GetParameters(); if (ArgInfo.Length != 2) { continue; } if (ArgInfo[0].ParameterType != typeof(StreamReader)) { continue; } if (ArgInfo[1].ParameterType != typeof(StreamWriter)) { continue; } VerifyCheck++; break; case "GetDialogBoxExt": if (RoutineInfo.IsPublic) { if (RoutineInfo.ReturnType == typeof(string)) { VerifyCheck++; } } break; case "GetShortName": if (RoutineInfo.IsPublic) { if (RoutineInfo.ReturnType == typeof(string)) { VerifyCheck++; } } break; case "GetFriendlyName": if (RoutineInfo.IsPublic) { if (RoutineInfo.ReturnType == typeof(string)) { VerifyCheck++; } } break; } } if (VerifyCheck >= 5) { return(true); } return(false); }
public IEnumerable <RelationInfo> Parse(RoutineInfo x) { return(Parse(x.Source).ToArray()); }
/// <summary> /// Declare user function into the PHP runtime context. /// </summary> /// <param name="name">Global PHP function name.</param> /// <param name="delegate">Delegate to represent the PHP function.</param> public void DeclareFunction(string name, Delegate @delegate) => _functions.DeclarePhpRoutine(RoutineInfo.CreateUserRoutine(name, @delegate));