Created
April 8, 2012 21:44
-
-
Save einarwh/2339957 to your computer and use it in GitHub Desktop.
Iterate over types in an assembly, looking for types to tamper with.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class NotificationTamperer : ITamperer | |
| { | |
| private readonly string _assemblyOutputFileName; | |
| public NotificationTamperer() : this("default_tampered.dll") {} | |
| public NotificationTamperer(string assemblyOutputFileName) | |
| { | |
| _assemblyOutputFileName = assemblyOutputFileName; | |
| } | |
| private static AssemblyDefinition ReadSilverlightAssembly( | |
| string assemblyPath) | |
| { | |
| var resolver = new DefaultAssemblyResolver(); | |
| resolver.AddSearchDirectory(@"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\Silverlight\v4.0"); | |
| var assembly = AssemblyDefinition.ReadAssembly( | |
| assemblyPath, | |
| new ReaderParameters { AssemblyResolver = resolver }); | |
| return assembly; | |
| } | |
| public bool TamperWith(string assemblyPath) | |
| { | |
| var assembly = ReadSilverlightAssembly(assemblyPath); | |
| bool result = TamperWith(assembly); | |
| if (result) | |
| { | |
| assembly.Write(_assemblyOutputFileName); | |
| } | |
| return result; | |
| } | |
| private bool TamperWith(AssemblyDefinition assembly) | |
| { | |
| bool result = false; | |
| foreach (TypeDefinition type in assembly.MainModule.Types) | |
| { | |
| result = new TypeTamperer(type).MaybeTamperWith() || result; | |
| } | |
| return result; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment