.net core 反编译一小段
public static class A
{ private static readonly MethodInfo GetServiceInfo; public static IApplicationBuilder My_UseStaticFiles(this IApplicationBuilder app, StaticFileOptions options)
{
//检查参数
if (app == null)
{
throw new ArgumentNullException("app");
}
if (options == null)
{
throw new ArgumentNullException("options");
} var t = Microsoft.Extensions.Options.Options.Create<StaticFileOptions>(options); object[] args = new object[] {
t
};
//执行该方法 会自动注入 该类中所需要的对象 RequestDelegate next
//return builder.UseMiddleware<RequestCultureMiddleware>(); return app.UseMiddleware<StaticFileMiddleware>(args);
} public static IApplicationBuilder My_UseMiddleware<T>(this IApplicationBuilder app, params object[] args)
{
return app.My_UseMiddleware(typeof(T), args);
}
public static IApplicationBuilder My_UseMiddleware(this IApplicationBuilder app, Type middleware, params object[] args)
{
if (typeof(IMiddleware).GetTypeInfo().IsAssignableFrom(middleware.GetTypeInfo()))
{
if (args.Length != )
{
throw new NotSupportedException(My_Resources.FormatException_UseMiddlewareExplicitArgumentsNotSupported(typeof(IMiddleware)));
}
return My_UseMiddlewareInterface(app, middleware);
}
IServiceProvider applicationServices = app.ApplicationServices;
return app.Use
(
delegate (RequestDelegate next)
{
MethodInfo[] array = (from m in middleware.GetMethods(BindingFlags.Instance | BindingFlags.Public)
where string.Equals(m.Name, "Invoke", StringComparison.Ordinal) || string.Equals(m.Name, "InvokeAsync", StringComparison.Ordinal)
select m).ToArray();
if (array.Length > )
{
throw new InvalidOperationException(My_Resources.FormatException_UseMiddleMutlipleInvokes("Invoke", "InvokeAsync"));
}
if (array.Length == )
{
throw new InvalidOperationException(My_Resources.FormatException_UseMiddlewareNoInvokeMethod("Invoke", "InvokeAsync", middleware));
}
MethodInfo methodInfo = array[];
if (!typeof(Task).IsAssignableFrom(methodInfo.ReturnType))
{
throw new InvalidOperationException(My_Resources.FormatException_UseMiddlewareNonTaskReturnType("Invoke", "InvokeAsync", "Task"));
}
ParameterInfo[] parameters = methodInfo.GetParameters();
if (parameters.Length == || parameters[].ParameterType != typeof(HttpContext))
{
throw new InvalidOperationException(My_Resources.FormatException_UseMiddlewareNoParameters("Invoke", "InvokeAsync", "HttpContext"));
}
object[] array2 = new object[args.Length + ];
array2[] = next;
Array.Copy(args, , array2, , args.Length);
object instance = ActivatorUtilities.CreateInstance(app.ApplicationServices, middleware, array2);
if (parameters.Length == )
{
return (RequestDelegate)methodInfo.CreateDelegate(typeof(RequestDelegate), instance);
}
Func<object, HttpContext, IServiceProvider, Task> factory = My_Compile<object>(methodInfo, parameters);
return delegate (HttpContext context)
{
IServiceProvider serviceProvider = context.RequestServices ?? applicationServices;
if (serviceProvider == null)
{
throw new InvalidOperationException(My_Resources.FormatException_UseMiddlewareIServiceProviderNotAvailable("IServiceProvider"));
}
return factory(instance, context, serviceProvider);
};
} );
} private static Func<T, HttpContext, IServiceProvider, Task> My_Compile<T>(MethodInfo methodInfo, ParameterInfo[] parameters)
{
ParameterExpression expression = Expression.Parameter((Type)typeof(HttpContext), "httpContext");
ParameterExpression expression2 = Expression.Parameter((Type)typeof(IServiceProvider), "serviceProvider");
ParameterExpression expression3 = Expression.Parameter((Type)typeof(T), "middleware");
Expression[] expressionArray = new Expression[] { expression };
for (int i = ; i < parameters.Length; i++)
{
Type type = parameters[i].ParameterType;
if (type.IsByRef)
{
throw new NotSupportedException(My_Resources.FormatException_InvokeDoesNotSupportRefOrOutParams("Invoke"));
}
Expression[] expressionArray2 = new Expression[] { (Expression)expression2, (Expression)Expression.Constant(type, (Type)typeof(Type)), (Expression)Expression.Constant(methodInfo.DeclaringType, (Type)typeof(Type)) };
expressionArray[i] = (Expression)Expression.Convert((Expression)Expression.Call(GetServiceInfo, expressionArray2), type);
}
Expression expression4 = (Expression)expression3;
if (methodInfo.DeclaringType != typeof(T))
{
expression4 = (Expression)Expression.Convert(expression4, methodInfo.DeclaringType);
}
ParameterExpression[] expressionArray3 = new ParameterExpression[] { expression3, expression, expression2 };
return Expression.Lambda<Func<T, HttpContext, IServiceProvider, Task>>((Expression)Expression.Call(expression4, methodInfo, expressionArray), expressionArray3).Compile();
} private static IApplicationBuilder My_UseMiddlewareInterface(IApplicationBuilder app, Type middlewareType)
{
return app.Use
(
(RequestDelegate next)
=>
async delegate
(HttpContext context)
{
IMiddlewareFactory middlewareFactory = (IMiddlewareFactory)context.RequestServices.GetService(typeof(IMiddlewareFactory));
if (middlewareFactory == null)
{
throw new InvalidOperationException(My_Resources.FormatException_UseMiddlewareNoMiddlewareFactory(typeof(IMiddlewareFactory)));
}
IMiddleware middleware = middlewareFactory.Create(middlewareType);
if (middleware == null)
{
throw new InvalidOperationException(My_Resources.FormatException_UseMiddlewareUnableToCreateMiddleware(middlewareFactory.GetType(), middlewareType));
}
try
{
await middleware.InvokeAsync(context, next);
}
finally
{
middlewareFactory.Release(middleware);
}
}
);
} } internal static class My_Resources
{
// Fields
private static readonly ResourceManager _resourceManager; internal static string FormatException_UseMiddlewareNoMiddlewareFactory(object p0)
{
return string.Format(CultureInfo.CurrentCulture, GetString("Exception_UseMiddlewareNoMiddlewareFactory"), p0);
} internal static string FormatException_UseMiddlewareUnableToCreateMiddleware(object p0, object p1)
{
return string.Format(CultureInfo.CurrentCulture, GetString("Exception_UseMiddlewareUnableToCreateMiddleware"), p0, p1);
} // Methods
static My_Resources()
{
_resourceManager = new ResourceManager(
"Microsoft.AspNetCore.Http.Abstractions.Resources",
IntrospectionExtensions.GetTypeInfo((Type)typeof(My_Resources)).Assembly);
}
private static string GetString(string name, params string[] formatterNames)
{
string str = _resourceManager.GetString(name);
if (formatterNames != null)
{
for (int i = ; i < formatterNames.Length; i++)
{
str = str.Replace("{" + formatterNames[i] + "}", "{" + ((int)i) + "}");
}
}
return str;
}
internal static string FormatException_UseMiddleMutlipleInvokes(object p0, object p1) =>
string.Format((IFormatProvider)CultureInfo.CurrentCulture, GetString("Exception_UseMiddleMutlipleInvokes", Array.Empty<string>()), p0, p1); internal static string FormatException_UseMiddlewareNoInvokeMethod(object p0, object p1, object p2) =>
string.Format((IFormatProvider)CultureInfo.CurrentCulture, GetString("Exception_UseMiddlewareNoInvokeMethod", Array.Empty<string>()), p0, p1, p2); internal static string FormatException_UseMiddlewareNonTaskReturnType(object p0, object p1, object p2) =>
string.Format((IFormatProvider)CultureInfo.CurrentCulture, GetString("Exception_UseMiddlewareNonTaskReturnType", Array.Empty<string>()), p0, p1, p2); internal static string FormatException_UseMiddlewareNoParameters(object p0, object p1, object p2) =>
string.Format((IFormatProvider)CultureInfo.CurrentCulture, GetString("Exception_UseMiddlewareNoParameters", Array.Empty<string>()), p0, p1, p2); internal static string FormatException_UseMiddlewareIServiceProviderNotAvailable(object p0) =>
string.Format((IFormatProvider)CultureInfo.CurrentCulture, GetString("Exception_UseMiddlewareIServiceProviderNotAvailable", Array.Empty<string>()), p0); internal static string FormatException_UseMiddlewareExplicitArgumentsNotSupported(object p0) =>
string.Format((IFormatProvider)CultureInfo.CurrentCulture, GetString("Exception_UseMiddlewareExplicitArgumentsNotSupported", Array.Empty<string>()), p0); //--
internal static string FormatException_InvokeDoesNotSupportRefOrOutParams(object p0) =>
string.Format((IFormatProvider)CultureInfo.CurrentCulture, GetString("Exception_InvokeDoesNotSupportRefOrOutParams", Array.Empty<string>()), p0);
}
.net core 反编译一小段的更多相关文章
- .NET Core 反编译dll源码查看
一.可以通过JetBrains dotPeek进行反编译 二.可以通过.NET Reflector和VS自带的反编译工具查看
- odex反编译dex异常 Cannot locate boot class path file /system/framework/core.odex
为了将ROM中system/app下的CertInstaller.odex反编译为CertInstaller.dex,输入命令: "java -jar baksmali.jar -x C ...
- 嗅探、中间人sql注入、反编译--例说桌面软件安全性问题
嗅探.中间人sql注入.反编译--例说桌面软件安全性问题 今天这篇文章不准备讲太多理论,讲我最近遇到的一个案例.从技术上讲,这个例子没什么高深的,还有一点狗屎运的成分,但是它又足够典型,典型到我可以讲 ...
- 反编译pyinstaller打包的exe安装包
PyInstaller将Python文件打包为exe后如何反编译(破解源码)以及防止反编译 在这里分享一些技巧和经验给大家.辛苦撰文分享,转载或引用请保留本文作者信息及文章链接. 作者的环境: win ...
- aardio + .NET 快速开发独立 EXE 程序,可防 ILSpy 反编译
简介 aardio 可以非常方便地调用 .NET( 不需要任何复杂的步骤 ). .NET 在 aardio 中很好用,系统自带 .NET 组件以及各种开源 .NET 组件在 aardio 用户中也很受 ...
- Android安全攻防战,反编译与混淆技术完全解析(下)
在上一篇文章当中,我们学习了Android程序反编译方面的知识,包括反编译代码.反编译资源.以及重新打包等内容.通过这些内容我们也能看出来,其实我们的程序并没有那么的安全.可能资源被反编译影响还不是很 ...
- Android安全攻防战,反编译与混淆技术完全解析(上)
转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/49738023 之前一直有犹豫过要不要写这篇文章,毕竟去反编译人家的程序并不是什么值 ...
- javap反编译解释外部类直接使用内部类private字段的原理
2016-07-04 15:56:39 我们都知道: 1.内部类可以直接访问外部类的private字段和方法: 2.非静态内部类持有外部类的引用: 3.外部类可以直接访问内部类的private字段和方 ...
- C#防止反编译
http://blog.csdn.net/wangpei421/article/details/42393095 http://www.cnblogs.com/tianguook/archive/20 ...
随机推荐
- hdu 6319 逆序建单调队列
题目传送门//res tp hdu 维护递增单调队列 根据数据范围推测应为O(n)的. 我们需要维护一个区间的信息,区间内信息是"有序"的,同时需要在O(1)的时间进行相邻区间的信 ...
- 剑指offer43:左旋转字符串(字符串):对于一个给定的字符序列S,请你把其循环左移K位后的序列输出。
1 题目描述 汇编语言中有一种移位指令叫做循环左移(ROL),现在有个简单的任务,就是用字符串模拟这个指令的运算结果.对于一个给定的字符序列S,请你把其循环左移K位后的序列输出.例如,字符序列S=”a ...
- jemeter鬓发压力测试包
使用: 为子线程添加响应时间:https://www.cnblogs.com/duanxz/p/5464993.html 结果查看分析:聚合报告在监听器里面: https://wenku.baidu. ...
- 安装 node.js npm,cnpm
参考:https://blog.csdn.net/suiyuehuimou/article/details/74143436 https://www.liaoxuefeng.com/wiki/0014 ...
- c++11 用户定义字面量
c++11 用户定义字面量 #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <string> #inc ...
- 事件处理程序EventUtil
/**********事件处理程序***********EventUtil.js*浏览器兼容,<高三>13章 P354*2014-12-8************************* ...
- html中正则匹配img
1.正则匹配html中的img标签,取出img的url并进行图片文件下载: /// <summary> /// 将image标签的src属性的url替换为base64 /// </s ...
- CSS用户界面样式之cursor/outline/resize
1. 鼠标样式cursor 检测鼠标指针在对象上移动的鼠标指针采用何种系统预定于的光标形状 常用属性: default 小白 hands小手 /pointer move移动 text文本 2. 轮廓 ...
- canvas-绘制矩形-读书笔记
使用<canvas>元素,必须先设置其width和height属性,指定可以绘图的区域大小. 要在画布上绘图,需要取得绘图上下文,也就是要调用getContext()方法并传入上下文的名字 ...
- K2 BPM_携手东航物流,领跑全球航空物流业_全球领先的工作流引擎
现代物流产业正在世界范围内广泛兴起,物流产业已成为各个国家国民经济发展的动脉和基础产业.随着物流新格局的加速形成,商业竞争的核心要素已经从传统的对资产资源的占有,演化为对资本.人才与技术的争夺,流量. ...