// Check the signature via the SIP which should never erroneously validate an invalid signature // or altered script. private static Signature GetSignatureWithEncodingRetry(string path, ExternalScriptInfo script) { // Invoke the SIP directly with the most simple method Signature signature = SignatureHelper.GetSignature(path, fileContent: null); if (signature.Status == SignatureStatus.Valid) { return(signature); } // try harder to validate the signature by being explicit about encoding // and providing the script contents string verificationContents = Encoding.Unicode.GetString(script.OriginalEncoding.GetPreamble()) + script.ScriptContents; signature = SignatureHelper.GetSignature(path, verificationContents); // A last ditch effort - // If the file was originally ASCII or UTF8, the SIP may have added the Unicode BOM if (signature.Status != SignatureStatus.Valid && script.OriginalEncoding != Encoding.Unicode) { verificationContents = Encoding.Unicode.GetString(Encoding.Unicode.GetPreamble()) + script.ScriptContents; Signature fallbackSignature = SignatureHelper.GetSignature(path, verificationContents); if (fallbackSignature.Status == SignatureStatus.Valid) { signature = fallbackSignature; } } return(signature); }
public async Task <YuntongxunSmsResult> SendCodeAsync(YuntongxunCode code) { if (code == null) { throw new ArgumentNullException(nameof(code)); } if (string.IsNullOrWhiteSpace(_yuntongxunAccount.AccountSid)) { throw new ArgumentNullException(nameof(_yuntongxunAccount.AccountSid)); } if (string.IsNullOrWhiteSpace(_yuntongxunAccount.AccountToken)) { throw new ArgumentNullException(nameof(_yuntongxunAccount.AccountToken)); } if (string.IsNullOrWhiteSpace(_yuntongxunAccount.AppId)) { throw new ArgumentNullException(nameof(_yuntongxunAccount.AppId)); } code.CheckParameters(); var bizParams = code.ToSendObject(_yuntongxunAccount); var sigTuple = SignatureHelper.GetSignature(_yuntongxunAccount.AccountSid, _yuntongxunAccount.AccountToken); var urlSegment = $"/2013-12-26/Accounts/{_yuntongxunAccount.AccountSid}/SMS/TemplateSMS?sig={sigTuple.sig}"; return(await _proxy.SendAsync(urlSegment, sigTuple.auth, bizParams) .Retry(_config.RetryTimes) .Handle().WhenCatch <Exception>(e => { _exceptionHandler?.Invoke(e); return ReturnAsDefautlResponse(); })); }
/// <summary> /// Compiles a DynamicMethodState and returns a delegate. /// </summary> /// <typeparam name="R">The return type of the expression</typeparam> /// <typeparam name="C">The type of the function class</typeparam> /// <param name="methodState">The serialized version of a method on the functionClass</param> /// <returns>ExecuteExpression<R, C> - a delegate that calls the compiled expression</returns> public ExecuteExpression <R, C> CreateExpressionDelegate <R, C>(DynamicMethodState methodState) { //create a dynamic method var dynamicMethod = new DynamicMethod("_" + Guid.NewGuid().ToString("N"), typeof(R), new[] { typeof(C) }, typeof(C)); //get the IL writer for it DynamicILInfo dynamicInfo = dynamicMethod.GetDynamicILInfo(); //set the properties gathered from the compiled expression dynamicMethod.InitLocals = methodState.InitLocals; //set local variables SignatureHelper locals = SignatureHelper.GetLocalVarSigHelper(); foreach (int localIndex in methodState.LocalVariables.Keys) { LocalVariable localVar = methodState.LocalVariables[localIndex]; locals.AddArgument(Type.GetTypeFromHandle(localVar.LocalType), localVar.IsPinned); } dynamicInfo.SetLocalSignature(locals.GetSignature()); //resolve any metadata tokens var tokenResolver = new IlTokenResolver(methodState.TokenOffset.Fields, methodState.TokenOffset.Methods, methodState.TokenOffset.Types, methodState.TokenOffset.LiteralStrings); methodState.CodeBytes = tokenResolver.ResolveCodeTokens(methodState.CodeBytes, dynamicInfo); //set the IL code for the dynamic method dynamicInfo.SetCode(methodState.CodeBytes, methodState.MaxStackSize); //create a delegate for fast execution var expressionDelegate = (ExecuteExpression <R, C>)dynamicMethod.CreateDelegate(typeof(ExecuteExpression <R, C>)); return(expressionDelegate); }
public void GetTokenFor_String_Success() { DynamicMethod dynamicMethod = new DynamicMethod(nameof(HelloWorld), typeof(string), new Type[] { }, typeof(DynamicILInfoTests), false); DynamicILInfo dynamicILInfo = dynamicMethod.GetDynamicILInfo(); SignatureHelper sigHelper = SignatureHelper.GetLocalVarSigHelper(); sigHelper.AddArgument(typeof(string), false); dynamicILInfo.SetLocalSignature(sigHelper.GetSignature()); byte[] code = { 0x00, 0x72, 0x01, 0x00, 0x00, 0x70, 0x6f, 0x04, 0x00, 0x00, 0x0a, 0x0a, 0x2b, 0x00, 0x06, 0x2a }; int token0 = dynamicILInfo.GetTokenFor("hello, world"); int token1 = dynamicILInfo.GetTokenFor(typeof(string).GetMethod("ToUpper", Type.EmptyTypes).MethodHandle); PutInteger4(token0, 0x0002, code); PutInteger4(token1, 0x0007, code); dynamicILInfo.SetCode(code, 1); string ret = (string)dynamicMethod.Invoke(null, null); Assert.Equal(ret, HelloWorld()); }
public void GetTokenFor_DynamicMethod_Success() { // Calling DynamicMethod recursively DynamicMethod dynamicMethod = new DynamicMethod(nameof(Fib), typeof(long), new Type[] { typeof(long) }, typeof(DynamicILInfoTests), false); DynamicILInfo dynamicILInfo = dynamicMethod.GetDynamicILInfo(); SignatureHelper sigHelper = SignatureHelper.GetLocalVarSigHelper(); sigHelper.AddArgument(typeof(long), false); sigHelper.AddArgument(typeof(bool), false); dynamicILInfo.SetLocalSignature(sigHelper.GetSignature()); byte[] code = { 0x00, 0x02, 0x16, 0x6a, 0x2e, 0x0a, 0x02, 0x17, 0x6a, 0xfe, 0x01, 0x16, 0xfe, 0x01, 0x2b, 0x01, 0x16, 0x0b, 0x07, 0x2d, 0x04, 0x02, 0x0a, 0x2b, 0x16, 0x02, 0x17, 0x6a, 0x59, 0x28, 0x02, 0x00, 0x00, 0x06, 0x02, 0x18, 0x6a, 0x59, 0x28, 0x02, 0x00, 0x00, 0x06, 0x58, 0x0a, 0x2b, 0x00, 0x06, 0x2a }; int token0 = dynamicILInfo.GetTokenFor(dynamicMethod); PutInteger4(token0, 0x001e, code); PutInteger4(token0, 0x0027, code); dynamicILInfo.SetCode(code, 3); long ret = (long)dynamicMethod.Invoke(null, new object[] { 20 }); Assert.Equal(ret, Fib(20)); }
public void GetLocalVarSigHelper_Module_Length_ReturnsTwo() { ModuleBuilder module = Helpers.DynamicModule(); SignatureHelper helper = SignatureHelper.GetLocalVarSigHelper(module); Assert.Equal(2, helper.GetSignature().Length); }
public void GetFieldSigHelper_Length_ReturnsOne() { ModuleBuilder module = Helpers.DynamicModule(); SignatureHelper helper = SignatureHelper.GetFieldSigHelper(module); Assert.Equal(1, helper.GetSignature().Length); }
public void GetTokenFor_StringGenerics_Success() { DynamicMethod dynamicMethod = new DynamicMethod(nameof(ContactString), typeof(string), Type.EmptyTypes, typeof(DynamicILInfoTests), false); DynamicILInfo dynamicILInfo = dynamicMethod.GetDynamicILInfo(); SignatureHelper sigHelper = SignatureHelper.GetLocalVarSigHelper(); sigHelper.AddArgument(typeof(MyList <string>), false); sigHelper.AddArgument(typeof(string), false); sigHelper.AddArgument(typeof(string), false); sigHelper.AddArgument(typeof(string), false); sigHelper.AddArgument(typeof(System.Collections.Generic.IEnumerator <string>), false); sigHelper.AddArgument(typeof(bool), false); dynamicILInfo.SetLocalSignature(sigHelper.GetSignature()); byte[] code = { 0x00, 0x73, 0x26, 0x00, 0x00, 0x0a, 0x0a, 0x06, 0x72, 0x29, 0x01, 0x00, 0x70, 0x6f, 0x27, 0x00, 0x00, 0x0a, 0x00, 0x06, 0x72, 0x37, 0x01, 0x00, 0x70, 0x6f, 0x27, 0x00, 0x00, 0x0a, 0x00, 0x7e, 0x28, 0x00, 0x00, 0x0a, 0x0b, 0x00, 0x06, 0x6f, 0x29, 0x00, 0x00, 0x0a, 0x13, 0x04, 0x2b, 0x12, 0x11, 0x04, 0x6f, 0x2a, 0x00, 0x00, 0x0a, 0x0c, 0x00, 0x07, 0x08, 0x28, 0x2b, 0x00, 0x00, 0x0a, 0x0b, 0x00, 0x11, 0x04, 0x6f, 0x20, 0x00, 0x00, 0x0a, 0x13, 0x05, 0x11, 0x05, 0x2d, 0xe1, 0xde, 0x14, 0x11, 0x04, 0x14, 0xfe, 0x01, 0x13, 0x05, 0x11, 0x05, 0x2d, 0x08, 0x11, 0x04, 0x6f, 0x21, 0x00, 0x00, 0x0a, 0x00, 0xdc, 0x00, 0x07, 0x0d, 0x2b, 0x00, 0x09, 0x2a }; int token0 = dynamicILInfo.GetTokenFor(typeof(MyList <string>).GetConstructor(Type.EmptyTypes).MethodHandle, typeof(MyList <string>).TypeHandle); int token1 = dynamicILInfo.GetTokenFor("Hello~"); int token2 = dynamicILInfo.GetTokenFor(typeof(MyList <string>).GetMethod("Add").MethodHandle, typeof(MyList <string>).TypeHandle); int token3 = dynamicILInfo.GetTokenFor("World!"); int token4 = dynamicILInfo.GetTokenFor(typeof(string).GetField("Empty").FieldHandle); int token5 = dynamicILInfo.GetTokenFor(typeof(MyList <string>).GetMethod("GetEnumerator").MethodHandle, typeof(MyList <string>).TypeHandle); int token6 = dynamicILInfo.GetTokenFor(typeof(System.Collections.Generic.IEnumerator <string>).GetMethod("get_Current").MethodHandle, typeof(System.Collections.Generic.IEnumerator <string>).TypeHandle); int token7 = dynamicILInfo.GetTokenFor(typeof(string).GetMethod("Concat", new Type[] { typeof(string), typeof(string) }).MethodHandle); int token8 = dynamicILInfo.GetTokenFor(typeof(System.Collections.IEnumerator).GetMethod("MoveNext").MethodHandle); int token9 = dynamicILInfo.GetTokenFor(typeof(System.IDisposable).GetMethod("Dispose").MethodHandle); PutInteger4(token0, 0x0002, code); PutInteger4(token1, 0x0009, code); PutInteger4(token2, 0x000e, code); PutInteger4(token3, 0x0015, code); PutInteger4(token2, 0x001a, code); PutInteger4(token4, 0x0020, code); PutInteger4(token5, 0x0028, code); PutInteger4(token6, 0x0033, code); PutInteger4(token7, 0x003c, code); PutInteger4(token8, 0x0045, code); PutInteger4(token9, 0x005f, code); dynamicILInfo.SetCode(code, 2); byte[] exceptions = { 0x41, 0x1c, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x2e, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00, 0x51, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; dynamicILInfo.SetExceptions(exceptions); string ret = (string)dynamicMethod.Invoke(null, null); Assert.Equal(ret, ContactString()); }
public void AddArgument_Type_Bool(bool pinned, int expectedLength) { ModuleBuilder module = Helpers.DynamicModule(); SignatureHelper helper = SignatureHelper.GetFieldSigHelper(module); helper.AddArgument(typeof(string), pinned); Assert.Equal(expectedLength, helper.GetSignature().Length); }
public void AddArgument_Type_TypeArray_TypeArray(Type[] requiredCustomModifiers, Type[] optionalCustomModifiers, int expectedLength) { ModuleBuilder module = Helpers.DynamicModule(); SignatureHelper helper = SignatureHelper.GetFieldSigHelper(module); helper.AddArgument(typeof(string), requiredCustomModifiers, optionalCustomModifiers); Assert.Equal(expectedLength, helper.GetSignature().Length); }
public void AddArgument_Type() { ModuleBuilder module = Helpers.DynamicModule(); SignatureHelper helper = SignatureHelper.GetFieldSigHelper(module); helper.AddArgument(typeof(string)); Assert.Equal(2, helper.GetSignature().Length); }
public void GetProperySigHelper_Module_Type_TypeArray_TypeArray_TypeArrayArray_TypeArrayArray(Type[] types, int expectedLength) { ModuleBuilder module = Helpers.DynamicModule(); Type[][] customModifiers = new Type[][] { types, types }; SignatureHelper helper = SignatureHelper.GetPropertySigHelper(module, typeof(string), types, types, types, customModifiers, customModifiers); Assert.Equal(expectedLength, helper.GetSignature().Length); }
public void PosTest3() { int expectedValue = 5; int actualValue; SignatureHelper sHelper = SignatureHelper.GetPropertySigHelper(null, typeof(string), new Type[] { typeof(string), typeof(int) }); actualValue = sHelper.GetSignature().Length; Assert.Equal(expectedValue, actualValue); }
public static ProtocolMessage Sign(this ProtocolMessage protocolMessage, byte[] signature = default, SigningContext signingContext = default) { var clone = protocolMessage.Clone(); clone.Signature = SignatureHelper.GetSignature(signature, signingContext); return(clone); }
public void AddArguments_SignatureFinished_ThrowsArgumentException() { ModuleBuilder module = Helpers.DynamicModule(); SignatureHelper helper = SignatureHelper.GetFieldSigHelper(module); helper.GetSignature(); AssertExtensions.Throws <ArgumentException>(null, () => helper.AddArguments(new Type[] { typeof(string) }, null, null)); }
private Dictionary <string, string> GetSignedDictionary(BillPayload payload) { var dict = payload.GetDictionary(); var signature = SignatureHelper.GetSignature(_secretKey, dict); dict["signature"] = signature; return(dict); }
/// <summary> /// 登录,获取对象 /// </summary> /// <param name="userName"></param> /// <param name="passWord"></param> /// <returns></returns> public UserInfo Login(string userName, string passWord) { UserInfo info = dal.Login(userName, SignatureHelper.GetSignature(passWord));///PASSWORD加密 if (info == null) { throw new Exception("MC:0x00000129");///登录失败 } return(info); }
public void PosTest5() { int expectedValue = 3; int actualValue; SignatureHelper sHelper = SignatureHelper.GetMethodSigHelper(CallingConventions.VarArgs, typeof(string)); actualValue = sHelper.GetSignature().Length; Assert.Equal(expectedValue, actualValue); }
public void AddArgument_DifferentCountsForCustomModifiers_ThrowsArgumentException() { ModuleBuilder module = Helpers.DynamicModule(); SignatureHelper helper = SignatureHelper.GetFieldSigHelper(module); helper.GetSignature(); AssertExtensions.Throws <ArgumentException>(null, () => helper.AddArgument(typeof(string), new Type[] { typeof(int) }, null)); AssertExtensions.Throws <ArgumentException>(null, () => helper.AddArgument(typeof(string), null, new Type[] { typeof(int) })); }
public void PosTest1() { int expectedValue = 2; int actualValue; SignatureHelper localVarHelper = SignatureHelper.GetLocalVarSigHelper(); actualValue = localVarHelper.GetSignature().Length; Assert.Equal(expectedValue, actualValue); }
private static void SetLocalSignature(MethodBody body, DynamicILInfo ilInfo) { SignatureHelper sig = SignatureHelper.GetLocalVarSigHelper(); foreach (LocalVariableInfo lvi in body.LocalVariables) { sig.AddArgument(lvi.LocalType, lvi.IsPinned); } ilInfo.SetLocalSignature(sig.GetSignature()); }
public void GetTokenFor_Exception_Success() { DynamicMethod dynamicMethod = new DynamicMethod(nameof(ExceptionTest), typeof(int), Type.EmptyTypes, typeof(DynamicILInfoTests), false); DynamicILInfo dynamicILInfo = dynamicMethod.GetDynamicILInfo(); SignatureHelper sigHelper = SignatureHelper.GetLocalVarSigHelper(); sigHelper.AddArgument(typeof(int), false); sigHelper.AddArgument(typeof(int), false); sigHelper.AddArgument(typeof(int), false); sigHelper.AddArgument(typeof(string), false); sigHelper.AddArgument(typeof(int), false); dynamicILInfo.SetLocalSignature(sigHelper.GetSignature()); byte[] code = { 0x00, 0x16, 0x0a, 0x00, 0x00, 0x16, 0x0b, 0x17, 0x07, 0x5b, 0x0c, 0x00, 0xde, 0x09, 0x26, 0x00, 0x06, 0x17, 0x58, 0x0a, 0x00, 0xde, 0x00, 0x00, 0x00, 0x72, 0xed, 0x01, 0x00, 0x70, 0x17, 0x28, 0x32, 0x00, 0x00, 0x0a, 0x26, 0x00, 0xde, 0x09, 0x26, 0x00, 0x06, 0x17, 0x58, 0x0a, 0x00, 0xde, 0x00, 0x00, 0x14, 0x0d, 0x09, 0x6f, 0x05, 0x00, 0x00, 0x0a, 0x26, 0x00, 0xde, 0x09, 0x26, 0x00, 0x06, 0x17, 0x58, 0x0a, 0x00, 0xde, 0x00, 0x00, 0xde, 0x07, 0x00, 0x06, 0x18, 0x58, 0x0a, 0x00, 0xdc, 0x00, 0x06, 0x13, 0x04, 0x2b, 0x00, 0x11, 0x04, 0x2a }; int token0 = dynamicILInfo.GetTokenFor("A.B"); int token1 = dynamicILInfo.GetTokenFor(typeof(System.Type).GetMethod("GetType", new Type[] { typeof(string), typeof(bool) }).MethodHandle); int token2 = dynamicILInfo.GetTokenFor(typeof(string).GetMethod("ToUpper", Type.EmptyTypes).MethodHandle); PutInteger4(token0, 0x001a, code); PutInteger4(token1, 0x0020, code); PutInteger4(token2, 0x0036, code); dynamicILInfo.SetCode(code, 2); int token3 = dynamicILInfo.GetTokenFor(typeof(System.Object).TypeHandle); int token4 = dynamicILInfo.GetTokenFor(typeof(System.Exception).TypeHandle); int token5 = dynamicILInfo.GetTokenFor(typeof(System.NullReferenceException).TypeHandle); byte[] exceptions = { 0x41, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x47, 0x00, 0x00, 0x00, 0x4a, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; PutInteger4(token3, 0x0018, exceptions); PutInteger4(token4, 0x0030, exceptions); PutInteger4(token5, 0x0048, exceptions); dynamicILInfo.SetExceptions(exceptions); int ret = (int)dynamicMethod.Invoke(null, null); Assert.Equal(ret, ExceptionTest()); }
public void GetMethodSigHelper_Module_Type_TypeArray() { ModuleBuilder module = Helpers.DynamicModule(); SignatureHelper helper1 = SignatureHelper.GetMethodSigHelper(module, typeof(string), new Type[] { typeof(char), typeof(int) }); Assert.Equal(5, helper1.GetSignature().Length); SignatureHelper helper2 = SignatureHelper.GetMethodSigHelper(null, typeof(string), new Type[] { typeof(char), typeof(int) }); Assert.Equal(5, helper2.GetSignature().Length); }
public void GetMethodSigHelper_Module_CallingConventions_Type_Length_ReturnsThree(CallingConventions callingConventions, Type type) { ModuleBuilder module = Helpers.DynamicModule(); SignatureHelper helper1 = SignatureHelper.GetMethodSigHelper(module, callingConventions, type); Assert.Equal(3, helper1.GetSignature().Length); SignatureHelper helper2 = SignatureHelper.GetMethodSigHelper(null, callingConventions, type); Assert.Equal(3, helper2.GetSignature().Length); }
private SortedDictionary <String, String> GetRequestParam(SimbossRequest request) { SortedDictionary <String, String> paramDic = request.GetParam(); paramDic.Add("appid", this.config.AppId); paramDic.Add("timestamp", TimeHelper.GetTimeStamp()); String sign = SignatureHelper.GetSignature(paramDic, this.config.AppSecret); paramDic.Add("sign", sign); return(paramDic); }
public void NegTest2() { AssemblyBuilder myAssembly = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("Assembly_SignatureHelperAddArgument"), AssemblyBuilderAccess.Run); ModuleBuilder myModule = TestLibrary.Utilities.GetModuleBuilder(myAssembly, "Module_SignatureHelperAddArgument"); SignatureHelper sHelper = SignatureHelper.GetFieldSigHelper(myModule); byte[] signature = sHelper.GetSignature(); //this action will lead the Signature be finished. Assert.Throws <ArgumentException>(() => { sHelper.AddArgument(typeof(string), null, null); }); }
public ActionResult Detial(string id) { string nonceStr = new CheckCode().CreateVerifyCode(); string timestamp = GetUnixTimeStamp(DateTime.Now); ReturnStr objec = SignatureHelper.GetSignature(timestamp, nonceStr); ViewBag.AppId = System.Configuration.ConfigurationManager.AppSettings["appid"]; ViewBag.NonceStr = objec.nonceStr; ViewBag.TimeStamp = objec.timestamp; ViewBag.Signature = objec.signature; return(View(WebService.Find_Image(id))); }
public void GetTokenFor_IntGenerics_Success() { DynamicMethod dynamicMethod = new DynamicMethod(nameof(SumInteger), typeof(int), new Type[] { }, typeof(DynamicILInfoTests), false); DynamicILInfo dynamicILInfo = dynamicMethod.GetDynamicILInfo(); SignatureHelper sigHelper = SignatureHelper.GetLocalVarSigHelper(); sigHelper.AddArgument(typeof(MyList <int>), false); sigHelper.AddArgument(typeof(int), false); sigHelper.AddArgument(typeof(int), false); sigHelper.AddArgument(typeof(int), false); sigHelper.AddArgument(typeof(System.Collections.Generic.IEnumerator <int>), false); sigHelper.AddArgument(typeof(bool), false); dynamicILInfo.SetLocalSignature(sigHelper.GetSignature()); byte[] code = { 0x00, 0x73, 0x1c, 0x00, 0x00, 0x0a, 0x0a, 0x06, 0x1f, 0x64, 0x6f, 0x1d, 0x00, 0x00, 0x0a, 0x00, 0x06, 0x20, 0xc8, 0x00, 0x00, 0x00, 0x6f, 0x1d, 0x00, 0x00, 0x0a, 0x00, 0x06, 0x20, 0x2c, 0x01, 0x00, 0x00, 0x6f, 0x1d, 0x00, 0x00, 0x0a, 0x00, 0x16, 0x0b, 0x00, 0x06, 0x6f, 0x1e, 0x00, 0x00, 0x0a, 0x13, 0x04, 0x2b, 0x0e, 0x11, 0x04, 0x6f, 0x1f, 0x00, 0x00, 0x0a, 0x0c, 0x00, 0x07, 0x08, 0x58, 0x0b, 0x00, 0x11, 0x04, 0x6f, 0x20, 0x00, 0x00, 0x0a, 0x13, 0x05, 0x11, 0x05, 0x2d, 0xe5, 0xde, 0x14, 0x11, 0x04, 0x14, 0xfe, 0x01, 0x13, 0x05, 0x11, 0x05, 0x2d, 0x08, 0x11, 0x04, 0x6f, 0x21, 0x00, 0x00, 0x0a, 0x00, 0xdc, 0x00, 0x07, 0x0d, 0x2b, 0x00, 0x09, 0x2a }; int token0 = dynamicILInfo.GetTokenFor(typeof(MyList <int>).GetConstructors()[0].MethodHandle, typeof(MyList <int>).TypeHandle); int token1 = dynamicILInfo.GetTokenFor(typeof(MyList <int>).GetMethod("Add").MethodHandle, typeof(MyList <int>).TypeHandle); int token2 = dynamicILInfo.GetTokenFor(typeof(MyList <int>).GetMethod("GetEnumerator").MethodHandle, typeof(MyList <int>).TypeHandle); int token3 = dynamicILInfo.GetTokenFor(typeof(System.Collections.Generic.IEnumerator <int>).GetMethod("get_Current").MethodHandle, typeof(System.Collections.Generic.IEnumerator <int>).TypeHandle); int token4 = dynamicILInfo.GetTokenFor(typeof(System.Collections.IEnumerator).GetMethod("MoveNext").MethodHandle); int token5 = dynamicILInfo.GetTokenFor(typeof(System.IDisposable).GetMethod("Dispose").MethodHandle); PutInteger4(token0, 0x0002, code); PutInteger4(token1, 0x000b, code); PutInteger4(token1, 0x0017, code); PutInteger4(token1, 0x0023, code); PutInteger4(token2, 0x002d, code); PutInteger4(token3, 0x0038, code); PutInteger4(token4, 0x0046, code); PutInteger4(token5, 0x0060, code); dynamicILInfo.SetCode(code, 2); byte[] exceptions = { 0x41, 0x1c, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x33, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x52, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; dynamicILInfo.SetExceptions(exceptions); int ret = (int)dynamicMethod.Invoke(null, null); Assert.Equal(ret, SumInteger()); }
public void PosTest1() { AssemblyBuilder myAssembly = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("Assembly_SignatureHelperAddArgument"), AssemblyBuilderAccess.Run); ModuleBuilder myModule = TestLibrary.Utilities.GetModuleBuilder(myAssembly, "Module_SignatureHelperAddArgument"); SignatureHelper sHelper = SignatureHelper.GetFieldSigHelper(myModule); int expectedValue = 1; int actualValue; actualValue = sHelper.GetSignature().Length; Assert.Equal(expectedValue, actualValue); }
public void PosTest2() { AssemblyBuilder myAssembly = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("Assembly_SignatureHelperAddArgument"), AssemblyBuilderAccess.Run); ModuleBuilder myModule = TestLibrary.Utilities.GetModuleBuilder(myAssembly, "Module_SignatureHelperAddArgument"); int expectedValue = 6; int actualValue; SignatureHelper sHelper = SignatureHelper.GetPropertySigHelper(myModule, typeof(Type), new Type[] { typeof(char), typeof(object) }); actualValue = sHelper.GetSignature().Length; Assert.Equal(expectedValue, actualValue); }