示例#1
0
        public void TestDependencyMissingType()
        {
            PatchInstaller installer = new PatchInstaller(new MockModuleSource(module));
            StandardPatch  patch     = new StandardPatch("TestPatch");

            patch.Module(module.Name, ModificationKind.FailIfMissing, true).Type(MissingNamespace, NormalClass, ModificationKind.FailIfMissing).Attributes = TypeAttributes.BeforeFieldInit;
            installer.Add(patch);
            installer.Install();
        }
示例#2
0
        public void TestDependencyMissingProperty()
        {
            PatchInstaller   installer = new PatchInstaller(new MockModuleSource(module));
            StandardPatch    patch     = new StandardPatch("TestPatch");
            TypeModification type      = patch.Module(module.Name, ModificationKind.FailIfMissing, true).Type(ReadOnlyNamespace, NormalClass, ModificationKind.FailIfMissing);

            type.Attributes = TypeAttributes.BeforeFieldInit;
            type.Property(MissingMember, new PropertySignature(true, new CorLibTypeSignature(new TypeReference(patch.Module("System.Runtime", ModificationKind.FailIfMissing, true), "System", "String", new ModuleReference("System.Runtime")), ElementType.String)), ModificationKind.FailIfMissing);
            installer.Add(patch);
            installer.Install();
        }
示例#3
0
        public void TestDependencyMissingMethod()
        {
            PatchInstaller   installer = new PatchInstaller(new MockModuleSource(module));
            StandardPatch    patch     = new StandardPatch("TestPatch");
            TypeModification type      = patch.Module(module.Name, ModificationKind.FailIfMissing, true).Type(ReadOnlyNamespace, NormalClass, ModificationKind.FailIfMissing);

            type.Attributes = TypeAttributes.BeforeFieldInit;
            type.Method(MissingMember, new MethodSignature(CallingConvention.HasThis, 0u, new CorLibTypeSignature(new TypeReference(patch.Module("System.Runtime", ModificationKind.FailIfMissing, true), "System", "Void", new ModuleReference("System.Runtime")), ElementType.Void)), ModificationKind.FailIfMissing).Attributes = MethodAttributes.HideBySig;
            installer.Add(patch);
            installer.Install();
        }
 private void InstallPatch(string source, params string[] references)
 {
     using (MemoryStream stream = new MemoryStream(4096))
     {
         List <string> paths = Locate(references.Concat(AllReferences)).ToList();
         Compile(source, stream, paths);
         stream.Position = 0L;
         PatchInstaller installer = new PatchInstaller(new MockModuleSource(module, stream, paths.ToDictionary <string, UTF8String, ModuleDef>(p => Path.GetFileNameWithoutExtension(p), p => ModuleDefMD.Load(p))));
         installer.Add(ModuleDefMD.Load(stream).CreatePatch("TestPatch"));
         installer.Install();
     }
 }
示例#5
0
        public void TestDependencyExistingProperty()
        {
            PatchInstaller   installer = new PatchInstaller(new MockModuleSource(module));
            StandardPatch    patch     = new StandardPatch("TestPatch");
            TypeModification type      = patch.Module(module.Name, ModificationKind.FailIfMissing, true).Type(ReadOnlyNamespace, NormalClass, ModificationKind.FailIfMissing);

            type.Attributes = TypeAttributes.BeforeFieldInit;
            MethodModification propertyGet = type.Method("get_" + StringProperty, new MethodSignature(CallingConvention.HasThis, 0u, new CorLibTypeSignature(new TypeReference(patch.Module("System.Runtime", ModificationKind.FailIfMissing, true), "System", "String", new ModuleReference("System.Runtime")), ElementType.String)), ModificationKind.FailIfMissing);

            propertyGet.Attributes = MethodAttributes.HideBySig | MethodAttributes.SpecialName;
            type.Property(StringProperty, new PropertySignature(true, new CorLibTypeSignature(new TypeReference(patch.Module("System.Runtime", ModificationKind.FailIfMissing, true), "System", "String", new ModuleReference("System.Runtime")), ElementType.String)), ModificationKind.FailIfMissing).Get(propertyGet);
            installer.Add(patch);
            installer.Install();
        }
示例#6
0
        public static void Main(string[] args)
        {
            CommandLineApplication app = new CommandLineApplication()
            {
                Name        = Path.GetFileNameWithoutExtension(Environment.GetCommandLineArgs()[0]),
                Description = "Install compiled patches into assemblies."
            };

            app.HelpOption("-?|-h|--help");
            CommandOption patches = app.Option("-p|--patch <file>", "Path to a patch that should be installed", CommandOptionType.MultipleValue);
            CommandOption targets = app.Option("-t|--target <dir>", "Directory to search for the libraries onto which the patches should be installed", CommandOptionType.MultipleValue);
            CommandOption output  = app.Option("-o|--output <dir>", "The directory to which the patched libraries should be written, ignored if --readonly is specified", CommandOptionType.SingleValue);
            CommandOption noWrite = app.Option("-r|--readonly", "Treat libraries as read-only and fail if anything is modified", CommandOptionType.NoValue);

            app.OnExecute(() =>
            {
                if (!patches.HasValue() || !targets.HasValue())
                {
                    Console.WriteLine("Please specify a patch and target directory");
                    app.ShowHint();
                    return(0);
                }
                IEnumerable <IStreamSource> sources = targets.Values.Select <string, IStreamSource>(t => new FileStreamSource(t)).ToList();
                IStreamSource source;
                if (output.HasValue())
                {
                    Directory.CreateDirectory(output.Value());
                    source = new WritableStreamSource(sources, new FileStreamSource(output.Value()));
                }
                else if (noWrite.HasValue())
                {
                    Console.WriteLine("Attempting a read-only install, failing if the patch makes any changes");
                    source = new ReadOnlyStreamSource(sources, true);
                }
                else
                {
                    Console.WriteLine("Output not specified, attempting an install without saving");
                    source = new ReadOnlyStreamSource(sources, false);
                }
                PatchInstaller installer = new PatchInstaller(new StreamModuleSource(source));
                foreach (string patch in patches.Values)
                {
                    installer.Add(ModuleDefMD.Load(patch).CreatePatch());
                }
                installer.Install();
                return(0);
            });
            try
            {
                app.Execute(args);
            }
            catch (CommandParsingException e)
            {
                Console.WriteLine(e.Message);
            }
            catch (Exception e)
            {
                Console.WriteLine("An exception occurred whilst installing");
                Console.WriteLine(e);
            }
        }