예제 #1
0
        private static void CreateRevertToBackupFallbackScript(AddEventsOptions options)
        {
            var revertToToBackupCommand = $"\"{AppDomain.CurrentDomain.BaseDirectory}{AppDomain.CurrentDomain.FriendlyName}\"" +
                                          $" {RevertToOriginalOptions.RevertToOriginalVerb} -t \"{string.Join(AddEventsOptions.MultipleDelimiter.ToString(), options.TargetDllPaths)}\"";

            File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + "revert-last-weaving.bat", revertToToBackupCommand);
        }
예제 #2
0
        public int Run(AddEventsOptions options)
        {
            foreach (var targetPath in options.TargetDllPaths)
            {
                System.Console.WriteLine($"Processing... {targetPath}");

                if (!CreateCleanCopyFromBackup(targetPath))
                {
                    System.Console.WriteLine($"Unable to {nameof(CreateCleanCopyFromBackup)}, exiting...");
                    return(1);
                }

                CreateRevertToBackupFallbackScript(options);

                using (var assembly = AssemblyDefinition.ReadAssembly(targetPath, new ReaderParameters {
                    ReadWrite = true
                }))
                {
                    _ilEventGenerator = new IlEventGenerator(assembly);
                    _ilEventManager   = new IlEventHookManager(assembly);

                    var assemblyName = assembly.FullName.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries)[0];
                    var targetDefinitionsForAssembly = options.TargetDefinitions.Where(t => string.IsNullOrEmpty(t.DllName) || t.DllName == assemblyName).ToList();
                    foreach (var targetDefinition in targetDefinitionsForAssembly)
                    {
                        var propertyType = ResolveSetterValueArgType(targetDefinition.ObjectTypeName, targetDefinition.PropertyName, assembly.MainModule);
                        CreateEventAndWeaveCallAtSetterStart(targetDefinition.ObjectTypeName, targetDefinition.PropertyName, propertyType);
                    }

                    assembly.Write();
                }

                System.Console.WriteLine($"Processed! {targetPath}\r\n\r\n");
            }

            return(0);
        }