.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 ...
随机推荐
- 自己动手写一个服务网关-java
自己动手写一个服务网关 原文链接:https://www.cnblogs.com/bigben0123/p/9252444.html 引言 什么是网关?为什么需要使用网关? 如图所示,在不使用网关的情 ...
- oracle-function-into时为null报错
oracle-function-into时为null报错 create or replace function P_ADD_CUSTOMER_FOR_CSS_heyt_test(i_cust_name ...
- 什么是大数据计算服务MaxCompute
大数据计算服务(MaxCompute,原名ODPS)是一种快速.完全托管的EB级数据仓库解决方案. 当今社会数据收集手段不断丰富,行业数据大量积累,数据规模已增长到了传统软件行业无法承载的海量数据(百 ...
- 把人都送到房子里的最小花费--最小费用最大流MCMF
题意:http://acm.hdu.edu.cn/showproblem.php?pid=1533 相邻的容量为inf,费用为1,S到m容量为1,费用为0 ,H到T容量为1,费用为0. 建图跑-最小费 ...
- thinkphp5.1中使用Bootstrap4分页样式修改
1.找到thinkphp下的Boorstrap的源码 \thinkphp\library\think\paginator\driver\Bootstrap.php 2丶直接修改源码 <?php ...
- 第十三章 ZYNQ-MIZ701 TIMER定时器中断
上篇文章实现了了PS接受来自PL的中断,本片文章将在ZYNQ的纯PS里实现私有定时器中断.每隔一秒中断一次,在中断函数里计数加1,通过串口打印输出. 本文所使用的开发板是Miz701 PC 开发环 ...
- 以前面试 经常写这种 问掉的 copy 还是 =
get的时候,生成的 那个对象赋值给aa 生成的对象在这条语句完 就析构了: https://blog.csdn.net/qq_31759205/article/details/80544468h ...
- 实例详解jQuery的无new构建
jQuery的无new构建 jQuery框架的核心就是从HTML文档中匹配元素并对其执行操作. 回想一下使用 jQuery 的时候,实例化一个 jQuery 对象的方法: // 无 new 构造 $( ...
- JS执行顺序问题
JavaScript执行引擎并非一行一行地分析和执行程序,而是一段一段地分析执行的.而且在分析执行同一段代码中,定义式的函数语句会被提取出来优先执行.函数定义执行完后,才会按顺序执行其他代码. 先看看 ...
- Java多线程(八):ReentrantReadWriteLock
读写锁ReentrantReadWriteLock概述 读写锁ReentrantReadWriteLock,使用它比ReentrantLock效率更高. 读写锁表示两个锁,一个是读操作相关的锁,称为共 ...