Esempio n. 1
0
        /// <summary>
        /// Executes the roles mutations with the supplied parameters.
        /// </summary>
        /// <param name="parameters">Parameters for the roles mutations.</param>
        /// <returns>The result of the roles mutations, with a success indication and any possible messages.</returns>
        public RoleEngineResult Execute(RoleEngineParameters parameters)
        {
            parameters.Validate();

              var assembly = ReadAssembly(parameters);

              var result = Mutate(assembly, parameters);

              if (result.Success && result.AssemblyChanged) {
            WriteAssembly(parameters, assembly);
              }

              return result;
        }
Esempio n. 2
0
        /// <summary>
        /// Performs the roles mutations on the supplied assembly.
        /// </summary>
        /// <param name="assembly">Assembly to perform the roles mutation on.</param>
        /// <param name="parameters">Parameters for the roles mutations.</param>
        /// <returns>The result of the roles mutation.</returns>
        public RoleEngineResult Mutate(AssemblyDefinition assembly, RoleEngineParameters parameters)
        {
            var result = new RoleEngineResult();

              // checks if the assembly should not be mutated
              if (!ShouldMutate(assembly)) {
            result.AddMessage(Warning.AssemblyMarkedWithDontMutate(assembly.Name));
            return result;
              }

              var runner = new MutationRunner(assembly);

              // Phase 0: Global checks

              var globalChecksResult = runner.Run(new GlobalRoleChecks());
              result.AddResult(globalChecksResult);
              if (!result.Success) return result;

              // Phase 1: Mutate Roles

              var rolesResult = runner.Run(new MorphIntoRoleMutator());
              result.AddResult(rolesResult);
              if (!result.Success) return result;

              // Phase 2: Compose Roles

              var compositionsResult = runner.Run(new RoleComposerAssemblyMutator());
              result.AddResult(compositionsResult);
              if (!result.Success) return result;

              // treat warnings as errors
              if (parameters.TreatWarningsAsErrors && result.Messages.Any(message => message.Type == MessageType.Warning)) {
            result.AddMessage(Error.ErrorFromWarnings());
            return result;
              }

              // marks the assembly as processed
              MarkAsMutated(assembly);

              if (parameters.RunPEVerify) {
            var assemblyVerificationResult = VerifyAssembly(assembly, parameters.PEVerifyPath, parameters.PEVerifyTimeout);
            result.AddResult(assemblyVerificationResult);
            if (!assemblyVerificationResult.Success) return result;
              }

              result.AssemblyChanged = true;
              return result;
        }
Esempio n. 3
0
 void WriteAssembly(RoleEngineParameters parameters, AssemblyDefinition assembly)
 {
     var assemblyPath = parameters.AssemblyPath;
       var writerParameters = new WriterParameters();
       var pdbPath = Path.ChangeExtension(assemblyPath, "pdb");
       if (File.Exists(pdbPath)) {
     writerParameters.WriteSymbols = true;
       }
       else {
     var mdbPath = assemblyPath + ".mdb";
     if (File.Exists(mdbPath)) {
       writerParameters.WriteSymbols = true;
     }
       }
       assembly.Write(parameters.OutputAssemblyPath, writerParameters);
 }
Esempio n. 4
0
 AssemblyDefinition ReadAssembly(RoleEngineParameters parameters)
 {
     var assemblyPath = parameters.AssemblyPath;
       var readerParameters = new ReaderParameters();
       if (parameters.References != null) {
     readerParameters.AssemblyResolver = new AssemblyListAssemblyResolver(parameters.References);
       }
       else {
     var resolver = new DefaultAssemblyResolver();
     resolver.AddSearchDirectory(Path.GetDirectoryName(assemblyPath));
     readerParameters.AssemblyResolver = resolver;
       }
       var pdbPath = Path.ChangeExtension(assemblyPath, "pdb");
       if (File.Exists(pdbPath)) {
     readerParameters.SymbolReaderProvider = new PdbReaderProvider();
     readerParameters.ReadSymbols = true;
       }
       else {
     var mdbPath = assemblyPath + ".mdb";
     if (File.Exists(mdbPath)) {
       readerParameters.SymbolReaderProvider = new MdbReaderProvider();
       readerParameters.ReadSymbols = true;
     }
       }
       var assembly = AssemblyDefinition.ReadAssembly(assemblyPath, readerParameters);
       return assembly;
 }