//Дорівнює protected void ButtonResult_Click(object sender, EventArgs e) { try { a = (double)ViewState["a"]; b = Convert.ToDouble(TextBox1.Text); action = (int)ViewState["action"]; switch (action) { case 1: TextBox1.Text = Convert.ToString(SCClass.Addition(a, b)); ViewState["b"] = TextBox1.Text; break; case 2: TextBox1.Text = Convert.ToString(SCClass.Subtraction(a, b)); ViewState["b"] = TextBox1.Text; break; case 3: TextBox1.Text = Convert.ToString(SCClass.Multiplication(a, b)); ViewState["b"] = TextBox1.Text; break; case 4: TextBox1.Text = Convert.ToString(SCClass.Division(a, b)); ViewState["b"] = TextBox1.Text; break; } } catch { ERROR(); } }
static void ArraysCreatedByCriticalCaller() { // Critical creating an array of a Critical type CClass[] c_array = new CClass [0]; // Critical creating an array of a SafeCritical type SCClass[] sc_array = new SCClass [0]; // Critical creating a multidimentional array of a Critical type CClass[,] c_multi = new CClass [0, 0]; // Critical creating a multidimentional array of a SafeCritical type SCClass[,] sc_multi = new SCClass [0, 0]; // Critical creating a jagged array of a Critical type CClass[][] c_jagged = new CClass [0][]; // Critical creating a jagged array of a Critical type SCClass[][] sc_jagged = new SCClass [0][]; }
//Операції public void ActionControl(int act) { try { if (ViewState["b"] != null) { a = (double)ViewState["b"]; action = (int)ViewState["action"]; b = Convert.ToDouble(TextBox1.Text); switch (action) { case 1: result = (SCClass.Addition(a, b)); ViewState["b"] = result; break; case 2: result = (SCClass.Subtraction(a, b)); ViewState["b"] = result; break; case 3: result = (SCClass.Multiplication(a, b)); ViewState["b"] = result; break; case 4: result = (SCClass.Division(a, b)); ViewState["b"] = result; break; } ViewState["a"] = result; ViewState["action"] = act; TextBox1.Text = null; } else { a = Convert.ToDouble(TextBox1.Text); ViewState["a"] = a; ViewState["b"] = a; ViewState["action"] = act; TextBox1.Text = null; } } catch { ERROR(); } }
static void ArraysCreatedByTransparentCaller() { // Transparent creating an array of a Critical type // using Class[] (rank == 1) throws a TypeLoadException on SL2 - but that looks like a bug // reported as https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=490406 CClass[] c_array = new CClass [0]; // Transparent creating an array of a SafeCritical type SCClass[] sc_array = new SCClass [0]; // Transparent creating a multidimentional array of a Critical type CClass[,] c_multi = new CClass [0, 0]; // Transparent creating a multidimentional array of a SafeCritical type SCClass[,] sc_multi = new SCClass [0, 0]; // Transparent creating a jagged array of a Critical type CClass[][] c_jagged = new CClass [0][]; // Transparent creating a jagged array of a Critical type SCClass[][] sc_jagged = new SCClass [0][]; }
static void ArraysCreatedBySafeCriticalCaller() { // SafeCritical creating an array of a Critical type CClass[] c_array = new CClass [0]; // SafeCritical creating an array of a SafeCritical type SCClass[] sc_array = new SCClass [0]; // SafeCritical creating a multidimentional array of a Critical type CClass[,] c_multi = new CClass [0, 0]; // SafeCritical creating a multidimentional array of a SafeCritical type SCClass[,] sc_multi = new SCClass [0, 0]; // SafeCritical creating a jagged array of a Critical type CClass[][] c_jagged = new CClass [0][]; // SafeCritical creating a jagged array of a Critical type SCClass[][] sc_jagged = new SCClass [0][]; // Transparent Main could not call a critical method by itself ArraysCreatedByCriticalCaller(); }
public static int Main() { SCMethod (); try { CMethod (); error ("static critical method called"); } catch (MethodAccessException) { } SCClass sc = new SCClass (); sc.Method (); try { CClass c = new CClass (); // Illegal error ("critical object instantiated"); c.Method (); // Illegal error ("critical method called"); } catch (MethodAccessException) { } try { doSCDev (); error ("security-critical-derived class error"); } catch (TypeLoadException) { } try { doCMethodDev (); } catch (TypeLoadException) { } try { getpid (); error ("pinvoke called"); } catch (MethodAccessException) { } try { MethodDelegate md = new MethodDelegate (CClass.StaticMethod); md (); error ("critical method called via delegate"); } catch (MethodAccessException) { } try { CriticalClass.NestedClassInsideCritical.Method (); } catch (MethodAccessException) { } try { doSCInterfaceDev (); } catch (TypeLoadException) { } /* try { unsafeMethod (); } catch (VerificationException) { } */ try { Type type = Type.GetType ("Test"); MethodInfo method = type.GetMethod ("TransparentReflectionCMethod"); method.Invoke(null, null); } catch (MethodAccessException) { error ("transparent method not called via reflection"); } try { Type type = Type.GetType ("Test"); MethodInfo method = type.GetMethod ("ReflectionCMethod"); method.Invoke(null, null); } catch (MethodAccessException) { } try { Type type = Type.GetType ("Test"); MethodInfo method = type.GetMethod ("TransparentReflectionCMethod"); InvokeDelegate id = new InvokeDelegate (method.Invoke); id (null, null); } catch (MethodAccessException) { error ("transparent method not called via reflection delegate"); } try { Type type = Type.GetType ("Test"); MethodInfo method = type.GetMethod ("ReflectionCMethod"); InvokeDelegate id = new InvokeDelegate (method.Invoke); id (null, null); } catch (MethodAccessException) { } //Console.WriteLine ("ok"); if (haveError) return 1; return 0; }
public static int Main () { SCMethod (); try { CMethod (); error ("static critical method called"); } catch (MethodAccessException) { } SCClass sc = new SCClass (); sc.Method (); try { CClass c = new CClass (); // Illegal error ("critical object instantiated"); c.Method (); // Illegal error ("critical method called"); } catch (MethodAccessException) { } try { doSCDev (); error ("security-critical-derived class error"); } catch (TypeLoadException) { } try { doCMethodDev (); } catch (TypeLoadException) { } try { getpid (); error ("pinvoke called"); } catch (MethodAccessException) { } try { MethodDelegate md = new MethodDelegate (CClass.StaticMethod); md (); error ("critical method called via delegate"); } catch (MethodAccessException) { } try { CriticalClass.NestedClassInsideCritical.Method (); } catch (MethodAccessException) { } try { doSCInterfaceDev (); } catch (TypeLoadException) { } /* try { unsafeMethod (); } catch (VerificationException) { } */ try { Type type = Type.GetType ("Test"); MethodInfo method = type.GetMethod ("TransparentReflectionCMethod"); method.Invoke(null, null); } catch (MethodAccessException) { error ("transparent method not called via reflection"); } try { Type type = Type.GetType ("Test"); MethodInfo method = type.GetMethod ("ReflectionCMethod"); method.Invoke(null, null); } catch (MethodAccessException) { } try { Type type = Type.GetType ("Test"); MethodInfo method = type.GetMethod ("TransparentReflectionCMethod"); InvokeDelegate id = new InvokeDelegate (method.Invoke); id (null, null); } catch (MethodAccessException) { error ("transparent method not called via reflection delegate"); } try { Type type = Type.GetType ("Test"); MethodInfo method = type.GetMethod ("ReflectionCMethod"); InvokeDelegate id = new InvokeDelegate (method.Invoke); id (null, null); } catch (MethodAccessException) { } // wrapper 7 try { CallStringTest (); } catch (MethodAccessException) { error ("string test failed"); } try { doBadTransparentOverrideClass (); error ("BadTransparentOverrideClass error"); } catch (TypeLoadException) { } try { doBadSafeCriticalOverrideClass (); error ("BadSafeCriticalOverrideClass error"); } catch (TypeLoadException) { } try { doBadCriticalOverrideClass (); error ("BadCriticalOverrideClass error"); } catch (TypeLoadException) { } new TransparentClassWithSafeCriticalDefaultConstructor (); try { new TransparentInheritFromSafeCriticalDefaultConstructor (); } catch (TypeLoadException) { } new SafeInheritFromSafeCriticalDefaultConstructor (); // arrays creation tests ArraysCreatedByTransparentCaller (); ArraysCreatedBySafeCriticalCaller (); // the above also calls ArraysCreatedBySafeCriticalCaller since (Transparent) Main cannot call it directly if (haveError) return 1; // Console.WriteLine ("ok"); return 0; }
static void ArraysCreatedByCriticalCaller () { // Critical creating an array of a Critical type CClass[] c_array = new CClass [0]; // Critical creating an array of a SafeCritical type SCClass[] sc_array = new SCClass [0]; // Critical creating a multidimentional array of a Critical type CClass[,] c_multi = new CClass [0,0]; // Critical creating a multidimentional array of a SafeCritical type SCClass[,] sc_multi = new SCClass [0,0]; // Critical creating a jagged array of a Critical type CClass[][] c_jagged = new CClass [0][]; // Critical creating a jagged array of a Critical type SCClass[][] sc_jagged = new SCClass [0][]; }
static void ArraysCreatedBySafeCriticalCaller () { // SafeCritical creating an array of a Critical type CClass[] c_array = new CClass [0]; // SafeCritical creating an array of a SafeCritical type SCClass[] sc_array = new SCClass [0]; // SafeCritical creating a multidimentional array of a Critical type CClass[,] c_multi = new CClass [0,0]; // SafeCritical creating a multidimentional array of a SafeCritical type SCClass[,] sc_multi = new SCClass [0,0]; // SafeCritical creating a jagged array of a Critical type CClass[][] c_jagged = new CClass [0][]; // SafeCritical creating a jagged array of a Critical type SCClass[][] sc_jagged = new SCClass [0][]; // Transparent Main could not call a critical method by itself ArraysCreatedByCriticalCaller (); }
static void ArraysCreatedByTransparentCaller () { // Transparent creating an array of a Critical type // using Class[] (rank == 1) throws a TypeLoadException on SL2 - but that looks like a bug // reported as https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=490406 CClass[] c_array = new CClass [0]; // Transparent creating an array of a SafeCritical type SCClass[] sc_array = new SCClass [0]; // Transparent creating a multidimentional array of a Critical type CClass[,] c_multi = new CClass [0,0]; // Transparent creating a multidimentional array of a SafeCritical type SCClass[,] sc_multi = new SCClass [0,0]; // Transparent creating a jagged array of a Critical type CClass[][] c_jagged = new CClass [0][]; // Transparent creating a jagged array of a Critical type SCClass[][] sc_jagged = new SCClass [0][]; }