C# Paste by kerrubin
Description: Sample C# code / MSIL / Decompile
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | **************************************************************************** C# **************************************************************************** using System; using System.Collections.Generic; using System.Linq; using System.Reflection; namespace Samples { public abstract class Transformer<T> where T : class { protected Type CurrentType = typeof(T); /// <summary> /// Commentaire pour le fun /// </summary> /// <param name="transformerType"></param> /// <returns></returns> public Dictionary<String, Object> Transform(String transformerType) { Dictionary<String, Object> returnValues = new Dictionary<String, Object>(); List<String> propWithAttr = new List<string>(); PropertyInfo[] allProps = CurrentType.GetProperties(); if (allProps != null) { allProps.ToList().ForEach(p => { if (p.GetCustomAttributes(true).Any(o => o is TransformerAttribute && ((TransformerAttribute)o).TransformerType == transformerType)) returnValues.Add(p.Name, p.GetValue(this, null)); }); } return returnValues; } } } **************************************************************************** MSIL **************************************************************************** // Microsoft (R) .NET Framework IL Disassembler. Version 3.5.30729.1 // Copyright (c) Microsoft Corporation. Tous droits r?serv?s. // warning : THIS IS A PARTIAL DISASSEMBLY, NOT SUITABLE FOR RE-ASSEMBLING // Metadata version: v4.0.30319 .assembly extern mscorlib { .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } .assembly extern System.Core { .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } .assembly Samples { .custom instance void [mscorlib]System.Reflection.AssemblyProductAttribute::.ctor(string) = ( 01 00 07 53 61 6D 70 6C 65 73 00 00 ) // ...Samples.. .custom instance void [mscorlib]System.Reflection.AssemblyCopyrightAttribute::.ctor(string) = ( 01 00 12 43 6F 70 79 72 69 67 68 74 20 C2 A9 20 // ...Copyright .. 20 32 30 31 32 00 00 ) // 2012.. .custom instance void [mscorlib]System.Reflection.AssemblyTrademarkAttribute::.ctor(string) = ( 01 00 00 00 00 ) .custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78 // ....T..WrapNonEx 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. .custom instance void [mscorlib]System.Reflection.AssemblyDescriptionAttribute::.ctor(string) = ( 01 00 00 00 00 ) .custom instance void [mscorlib]System.Reflection.AssemblyConfigurationAttribute::.ctor(string) = ( 01 00 00 00 00 ) .custom instance void [mscorlib]System.Reflection.AssemblyCompanyAttribute::.ctor(string) = ( 01 00 00 00 00 ) .custom instance void [mscorlib]System.Runtime.InteropServices.GuidAttribute::.ctor(string) = ( 01 00 24 31 31 39 66 37 33 31 61 2D 35 63 62 31 // ..$119f731a-5cb1 2D 34 36 30 32 2D 61 32 34 36 2D 62 32 66 63 61 // -4602-a246-b2fca 63 34 32 30 36 61 33 00 00 ) // c4206a3.. // --- The following custom attribute is added automatically, do not uncomment ------- // .custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggableAttribute/DebuggingModes) = ( 01 00 07 01 00 00 00 00 ) .custom instance void [mscorlib]System.Reflection.AssemblyTitleAttribute::.ctor(string) = ( 01 00 07 53 61 6D 70 6C 65 73 00 00 ) // ...Samples.. .custom instance void [mscorlib]System.Runtime.InteropServices.ComVisibleAttribute::.ctor(bool) = ( 01 00 00 00 00 ) .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) .custom instance void [mscorlib]System.Reflection.AssemblyFileVersionAttribute::.ctor(string) = ( 01 00 07 31 2E 30 2E 30 2E 30 00 00 ) // ...1.0.0.0.. .custom instance void [mscorlib]System.Runtime.Versioning.TargetFrameworkAttribute::.ctor(string) = ( 01 00 1A 2E 4E 45 54 46 72 61 6D 65 77 6F 72 6B // ....NETFramework 2C 56 65 72 73 69 6F 6E 3D 76 34 2E 30 01 00 54 // ,Version=v4.0..T 0E 14 46 72 61 6D 65 77 6F 72 6B 44 69 73 70 6C // ..FrameworkDispl 61 79 4E 61 6D 65 10 2E 4E 45 54 20 46 72 61 6D // ayName..NET Fram 65 77 6F 72 6B 20 34 ) // ework 4 .hash algorithm 0x00008004 .ver 1:0:0:0 } .module Samples.dll // MVID: {4A713B39-50B9-4CA0-8E39-35C0ACCE9FCF} .imagebase 0x00400000 .file alignment 0x00000200 .stackreserve 0x00100000 .subsystem 0x0003 // WINDOWS_CUI .corflags 0x00000001 // ILONLY // Image base: 0x00240000 // =============== CLASS MEMBERS DECLARATION =================== // ============================================================= .custom (method instance string Samples.TransformerAttribute::get_TransformerType()) instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom (UNKNOWN_OWNER) instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom (method instance void Samples.TransformerAttribute::set_TransformerType(string)) instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom (Samples.TransformerAttribute) instance void [mscorlib]System.AttributeUsageAttribute::.ctor(valuetype [mscorlib]System.AttributeTargets) = ( 01 00 80 00 00 00 01 00 54 02 0D 41 6C 6C 6F 77 // ........T..Allow 4D 75 6C 74 69 70 6C 65 01 ) // Multiple. .custom (Samples.Transformer`1/'<>c__DisplayClass3') instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) // *********** DISASSEMBLY COMPLETE *********************** **************************************************************************** Decompilation : http://wiki.sharpdevelop.net/ILSpy.ashx **************************************************************************** using System; using System.Collections.Generic; using System.Linq; using System.Reflection; namespace Samples { public abstract class Transformer<T> where T : class { protected Type CurrentType = typeof(T); public Dictionary<string, object> Transform(string transformerType) { Dictionary<string, object> returnValues = new Dictionary<string, object>(); List<string> propWithAttr = new List<string>(); PropertyInfo[] allProps = this.CurrentType.GetProperties(); if (allProps != null) { allProps.ToList<PropertyInfo>().ForEach(delegate(PropertyInfo p) { if (p.GetCustomAttributes(true).Any((object o) => o is TransformerAttribute && ((TransformerAttribute)o).TransformerType == transformerType)) { returnValues.Add(p.Name, p.GetValue(this, null)); } }); } return returnValues; } } } **************************************************************************** Decompilation après obfuscation (rapide + réglage par défaut) : https://fr.wikipedia.org/wiki/Obfuscateur **************************************************************************** using System; using System.Collections.Generic; using System.Linq; using System.Reflection; namespace Samples { public abstract class Transformer<T> where T : class { protected Type CurrentType = typeof(T); public Dictionary<string, object> Transform(string transformerType) { Action<PropertyInfo> action = null; Transformer<T>.<>c__DisplayClass3 <>c__DisplayClass = new Transformer<T>.<>c__DisplayClass3(); <>c__DisplayClass.c = transformerType; <>c__DisplayClass.b = this; <>c__DisplayClass.a = new Dictionary<string, object>(); List<string> list = new List<string>(); PropertyInfo[] properties = this.CurrentType.GetProperties(); if (properties != null) { List<PropertyInfo> arg_58_0 = properties.ToList<PropertyInfo>(); if (action == null) { action = new Action<PropertyInfo>(<>c__DisplayClass.d); } arg_58_0.ForEach(action); } return <>c__DisplayClass.a; } } } |