Exemplo n.º 1
0
        /// <summary>
        /// Get TypeDefinition from a runtime Type object.
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static TypeDefinition GetDefinitionByType(Type type)
        {
            TypeInspector inspector = new TypeInspector();

            inspector.ScanAssembly(type.Assembly.Location);
            return(inspector.FindTypeByFullName(type.FullName));
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            AssemblyDefinition targetAsm = AssemblyDefinition.ReadAssembly(File.OpenRead("Target.exe"));

            var inspector = new TypeInspector();

            inspector.ScanAssembly(targetAsm);
            inspector.ScanAssembly(typeof(Program).Assembly.Location);
            inspector.ScanAssembly(typeof(Console).Assembly.Location);

            var targetClass   = TypeInspector.GetDefinitionByType(typeof(Injected));
            var injectedClass = CodeInjector.InjectClass(targetAsm.MainModule, targetClass);

            injectedClass.Namespace = "Target";

            targetAsm.Write(File.OpenWrite("Target.Hooked.exe"));
        }