.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 ...
随机推荐
- HashMap集合-遍历方法
# HashMap集合-遍历方法 先定义好集合: public static void main(String[] args) { Map<String,String> onemap=ne ...
- Chrome浏览器控制台报 POST http://*** net::ERR_BLOCKED_BY_CLIENT
开发项目广告模块时,遇到前端提交的请求后台拿不到,好像被什么拦截了,查看了过滤器,拦截器都无错误,且请求也到不了拦截器,chrome浏览器报:ERR_BLOCKED_BY_CLIENT错误 搞腾一半天 ...
- 【转载】java8 自定义TemporalAdjuster
有的时候,你需要进行一些更加复杂的操作,比如,将日期调整到下个周日.下个工作日,或者是本月的最后一天.这时,你可以使用重载版本的with方法,向其传递一个提供了更多定制化选择的TemporalAdju ...
- linux 对外开放端口
查看守护进程端口 netstat -ntpl 查看开放的端口 iptables -nvL 查看端口是否可访问:telnet ip 端口号 (如本机的35465:telnet localhost 354 ...
- Scala学习十四——模式匹配和样例类
一.本章要点 match表达式是更好的switch,不会有意外调入下一个分支 如果没有模式能够匹配,会抛出MatchError,可以用case _模式避免 模式可以包含一个随意定义的条件,称做守卫 你 ...
- javascript数字格式化通用类——accounting.js使用
简介 accounting.js 是一个非常小的JavaScript方法库用于对数字,金额和货币进行格式化.并提供可选的Excel风格列渲染.它没有依赖任何JS框架.货币符号等可以按需求进行定制. 代 ...
- Image 对象事件
以前没怎么注意image上的事件 Image 对象事件 事件 描述 W3C onabort 当用户放弃图像的装载时调用的事件句柄. Yes onerror 在装载图像的过程中发生错误时调用的事件句柄. ...
- IE各版本处理XML的方式
一.支持DOM2级的方式我们知道,现阶段支持DOM2的主流浏览器有IE9+.Firefox.Opera.Chrome和Safari.1.1.创建XML//实际上,DOM2级在document.impl ...
- web储存的初级运用
<html> <head> <meta charset="utf-8"> <title>web存储</title>< ...
- javascript字符串机油
1.创建字符串和数组的方法 1.1创建字符串的方法 a.直接数量:var str=“: b.字符串对象创建:新字符串(“): 1.2创建阵列的方法 a.var.arr=要素…. b.var arr=n ...