예제 #1
0
 public IRyuFacade Create(RyuConfiguration configuration)
 {
     IAssemblyLoader assemblyLoader = new AssemblyLoader(logger);
      IModuleLoader moduleLoader = new ModuleLoader();
      IActivator activator = new Activator();
      IModuleSorter moduleSorter = new ModuleSorter();
      IModuleImporter moduleImporter = new ModuleImporter(moduleSorter);
      var bootstrapper = new Bootstrapper(assemblyLoader, moduleLoader, activator, moduleImporter);
      var container = bootstrapper.Bootstrap(configuration);
      var facade = new RyuFacade(container, activator);
      facade.Initialize();
      return facade;
 }
예제 #2
0
		public AddUpdatedNodesHelper(Lazy<IMethodAnnotations> methodAnnotations, Lazy<IResourceNodeFactory> resourceNodeFactory, IDocumentTreeView documentTreeView, ModuleDocumentNode modNode, ModuleImporter importer) {
			this.modNode = modNode;
			var dict = new Dictionary<string, List<TypeDef>>(StringComparer.Ordinal);
			foreach (var t in importer.NewNonNestedTypes) {
				List<TypeDef> list;
				var ns = (t.TargetType.Namespace ?? UTF8String.Empty).String;
				if (!dict.TryGetValue(ns, out list))
					dict[ns] = list = new List<TypeDef>();
				list.Add(t.TargetType);
			}
			newTypeNodeCreators = dict.Values.Select(a => new TypeNodeCreator(modNode, a)).ToArray();
			existingTypeNodeUpdaters = importer.MergedNonNestedTypes.Select(a => new ExistingTypeNodeUpdater(methodAnnotations, modNode, a)).ToArray();
			if (!importer.MergedNonNestedTypes.All(a => a.TargetType.Module == modNode.Document.ModuleDef))
				throw new InvalidOperationException();
			newAssemblyDeclSecurities = importer.NewAssemblyDeclSecurities;
			newAssemblyCustomAttributes = importer.NewAssemblyCustomAttributes;
			newModuleCustomAttributes = importer.NewModuleCustomAttributes;
			if (newAssemblyDeclSecurities != null)
				origAssemblyDeclSecurities = modNode.Document.AssemblyDef?.DeclSecurities.ToArray();
			if (newAssemblyCustomAttributes != null)
				origAssemblyCustomAttributes = modNode.Document.AssemblyDef?.CustomAttributes.ToArray();
			if (newModuleCustomAttributes != null)
				origModuleCustomAttributes = modNode.Document.ModuleDef.CustomAttributes.ToArray();

			if (importer.NewResources.Length != 0) {
				var module = modNode.Document.ModuleDef;
				var rsrcListNode = GetResourceListTreeNode(modNode);
				Debug.Assert(rsrcListNode != null);
				if (rsrcListNode != null) {
					var newNodes = new ResourceNode[importer.NewResources.Length];
					var treeNodeGroup = documentTreeView.DocumentTreeNodeGroups.GetGroup(DocumentTreeNodeGroupType.ResourceTreeNodeGroup);
					for (int i = 0; i < newNodes.Length; i++)
						newNodes[i] = (ResourceNode)documentTreeView.TreeView.Create(resourceNodeFactory.Value.Create(module, importer.NewResources[i], treeNodeGroup)).Data;
					resourceNodeCreator = new ResourceNodeCreator(rsrcListNode, newNodes);
				}
			}
		}
예제 #3
0
 protected abstract void Import(ModuleImporter importer, CompilationResult result);
예제 #4
0
 protected override void Import(ModuleImporter importer, CompilationResult result) =>
 importer.Import(result.RawFile, result.DebugFile, ModuleImporterOptions.ReplaceModuleAssemblyAttributes | ModuleImporterOptions.ReplaceAssemblyDeclSecurities);
예제 #5
0
 public UnionClassFormatterAllConsequentImplementor(ModuleDefinition module, SystemObjectHelper objectHelper, InterfaceMessagePackFormatterHelper interfaceMessagePackFormatterHelper, SystemInvalidOperationExceptionHelper invalidOperationExceptionHelper, ModuleImporter importer, MessagePackSecurityHelper securityHelper, MessagePackSerializerOptionsHelper messagePackSerializerOptionsHelper, MessagePackWriterHelper writerHelper, MessagePackReaderHelper readerHelper, FormatterResolverExtensionHelper formatterResolverExtensionHelper, FixedTypeKeyInt32ValueHashtableGenerator generator)
 {
     this.module       = module;
     this.objectHelper = objectHelper;
     this.interfaceMessagePackFormatterHelper = interfaceMessagePackFormatterHelper;
     this.invalidOperationExceptionHelper     = invalidOperationExceptionHelper;
     this.importer       = importer;
     this.securityHelper = securityHelper;
     this.messagePackSerializerOptionsHelper = messagePackSerializerOptionsHelper;
     this.writerHelper = writerHelper;
     this.readerHelper = readerHelper;
     this.formatterResolverExtensionHelper = formatterResolverExtensionHelper;
     this.generator = generator;
 }
예제 #6
0
 public AddUpdatedNodesHelper(Lazy <IMethodAnnotations> methodAnnotations, ModuleDocumentNode modNode, ModuleImporter importer)
 {
     this.modNode                  = modNode;
     this.newTypeNodeCreators      = importer.NewNonNestedTypes.Select(a => new TypeNodeCreator(modNode, a.TargetType)).ToArray();
     this.existingTypeNodeUpdaters = importer.MergedNonNestedTypes.Select(a => new ExistingTypeNodeUpdater(methodAnnotations, modNode, a)).ToArray();
     if (!importer.MergedNonNestedTypes.All(a => a.TargetType.Module == modNode.Document.ModuleDef))
     {
         throw new InvalidOperationException();
     }
     this.newAssemblyCustomAttributes = importer.NewAssemblyCustomAttributes;
     this.newModuleCustomAttributes   = importer.NewModuleCustomAttributes;
     if (newAssemblyCustomAttributes != null)
     {
         origAssemblyCustomAttributes = modNode.Document.AssemblyDef?.CustomAttributes.ToArray();
     }
     if (newModuleCustomAttributes != null)
     {
         origModuleCustomAttributes = modNode.Document.ModuleDef.CustomAttributes.ToArray();
     }
 }
예제 #7
0
        public AddUpdatedNodesHelper(Lazy <IMethodAnnotations> methodAnnotations, Lazy <IResourceNodeFactory> resourceNodeFactory, IDocumentTreeView documentTreeView, ModuleDocumentNode modNode, ModuleImporter importer)
        {
            asmNode      = modNode.TreeNode.Parent?.Data as AssemblyDocumentNode;
            this.modNode = modNode;
            var dict = new Dictionary <string, List <TypeDef> >(StringComparer.Ordinal);

            foreach (var t in importer.NewNonNestedTypes)
            {
                var ns = (t.TargetType.Namespace ?? UTF8String.Empty).String;
                if (!dict.TryGetValue(ns, out var list))
                {
                    dict[ns] = list = new List <TypeDef>();
                }
                list.Add(t.TargetType);
            }
            newTypeNodeCreators      = dict.Values.Select(a => new TypeNodeCreator(modNode, a)).ToArray();
            existingTypeNodeUpdaters = importer.MergedNonNestedTypes.Select(a => new ExistingTypeNodeUpdater(methodAnnotations, modNode, a)).ToArray();
            if (!importer.MergedNonNestedTypes.All(a => a.TargetType.Module == modNode.Document.ModuleDef))
            {
                throw new InvalidOperationException();
            }
            newAssemblyDeclSecurities   = importer.NewAssemblyDeclSecurities;
            newAssemblyCustomAttributes = importer.NewAssemblyCustomAttributes;
            newModuleCustomAttributes   = importer.NewModuleCustomAttributes;
            newExportedTypes            = importer.NewExportedTypes;
            newAssemblyVersion          = importer.NewAssemblyVersion;
            if (newAssemblyDeclSecurities != null)
            {
                origAssemblyDeclSecurities = modNode.Document.AssemblyDef?.DeclSecurities.ToArray();
            }
            if (newAssemblyCustomAttributes != null)
            {
                origAssemblyCustomAttributes = modNode.Document.AssemblyDef?.CustomAttributes.ToArray();
            }
            if (newModuleCustomAttributes != null)
            {
                origModuleCustomAttributes = modNode.Document.ModuleDef.CustomAttributes.ToArray();
            }
            if (newExportedTypes != null)
            {
                origExportedTypes = modNode.Document.ModuleDef.ExportedTypes.ToArray();
            }
            if (newAssemblyVersion != null)
            {
                origAssemblyVersion = modNode.Document.AssemblyDef?.Version;
            }

            if (importer.NewResources.Length != 0)
            {
                var module       = modNode.Document.ModuleDef;
                var rsrcListNode = GetResourceListTreeNode(modNode);
                Debug.Assert(rsrcListNode != null);
                if (rsrcListNode != null)
                {
                    var newNodes      = new ResourceNode[importer.NewResources.Length];
                    var treeNodeGroup = documentTreeView.DocumentTreeNodeGroups.GetGroup(DocumentTreeNodeGroupType.ResourceTreeNodeGroup);
                    for (int i = 0; i < newNodes.Length; i++)
                    {
                        newNodes[i] = (ResourceNode)documentTreeView.TreeView.Create(resourceNodeFactory.Value.Create(module, importer.NewResources[i], treeNodeGroup)).Data;
                    }
                    resourceNodeCreator = new ResourceNodeCreator(rsrcListNode, newNodes);
                }
            }
        }
예제 #8
0
		protected EditCodeCommandBase(Lazy<IAddUpdatedNodesHelperProvider> addUpdatedNodesHelperProvider, ModuleDocumentNode modNode, ModuleImporter importer) {
			addUpdatedNodesHelper = addUpdatedNodesHelperProvider.Value.Create(modNode, importer);
		}
예제 #9
0
 protected override void Import(ModuleImporter importer, CompilationResult result) =>
 importer.Import(result.RawFile, result.DebugFile, methodToEdit);
예제 #10
0
        public static FieldReference Transplant(FieldReference reference, GenericInstanceType targetType, ModuleImporter importer)
        {
            var importedFieldType     = importer.Import(reference.FieldType).Reference;
            var importedDeclaringType = importer.Import(targetType).Reference;
            var transplant            = new FieldReference(reference.Name, importedFieldType, importedDeclaringType);

            return(transplant);
        }
예제 #11
0
        /// <summary>
        /// Transplants generic parameters from serialize target type to formatter type.
        /// </summary>
        /// <param name="formatterTypeDefinition">Destination formatter type.</param>
        /// <param name="serializeTargetTypeDefinition">Source serializable type.</param>
        /// <param name="importer">Module importer.</param>
        /// <param name="genericInstanceFormatter">Generic instance of formatter type.</param>
        /// <param name="genericInstanceSerializeTarget">Generic instance of serializable type.</param>
        public static void TransplantGenericParameters(TypeDefinition formatterTypeDefinition, TypeDefinition serializeTargetTypeDefinition, ModuleImporter importer, out GenericInstanceType genericInstanceFormatter, out GenericInstanceType genericInstanceSerializeTarget)
        {
            var baseGenericParameters = serializeTargetTypeDefinition.GenericParameters;

            FirstAddGenericParameters(formatterTypeDefinition, baseGenericParameters);

            var targetTypeGenericParameters = formatterTypeDefinition.GenericParameters;

            for (var index = 0; index < targetTypeGenericParameters.Count; index++)
            {
                var formatterGenericParameter = targetTypeGenericParameters[index];
                var baseGenericParameter      = baseGenericParameters[index];
                TransplantCustomAttributes(formatterGenericParameter, baseGenericParameter, importer);
                TransplantConstraints(formatterGenericParameter, targetTypeGenericParameters, baseGenericParameter, importer);
            }

            genericInstanceFormatter       = new GenericInstanceType(formatterTypeDefinition);
            genericInstanceSerializeTarget = new GenericInstanceType(importer.Import(serializeTargetTypeDefinition).Reference);
            foreach (var parameter in formatterTypeDefinition.GenericParameters)
            {
                genericInstanceFormatter.GenericArguments.Add(parameter);
                genericInstanceSerializeTarget.GenericArguments.Add(parameter);
            }
        }
예제 #12
0
 EditAssemblyCommand(Lazy <IMethodAnnotations> methodAnnotations, ModuleDocumentNode modNode, ModuleImporter importer)
     : base(methodAnnotations, modNode, importer)
 {
 }
예제 #13
0
        public static MethodReference Transplant(MethodReference reference, GenericInstanceType targetType, ModuleImporter importer)
        {
            var answer = new MethodReference(reference.Name, importer.Import(reference.ReturnType).Reference, targetType)
            {
                HasThis = reference.HasThis,
            };

            for (var index = 0; index < reference.Parameters.Count; index++)
            {
                var parameter = reference.Parameters[index];
                var item      = new ParameterDefinition(parameter.Name, parameter.Attributes, importer.Import(parameter.ParameterType).Reference);
                answer.Parameters.Add(item);
                foreach (var attribute in parameter.CustomAttributes)
                {
                    item.CustomAttributes.Add(new CustomAttribute(importer.Import(attribute.Constructor), attribute.GetBlob()));
                }
            }

            return(answer);
        }
예제 #14
0
 public EmptyEmitter(MethodDefinition method, ModuleImporter importer)
 {
     _method   = method;
     _importer = importer;
 }
예제 #15
0
        public void Finish(ModuleDef module, ModuleImporter importer)
        {
            var dict = new Dictionary <string, List <TypeDef> >(StringComparer.Ordinal);

            foreach (var type in importer.NewNonNestedTypes)
            {
                module.Types.Add(type.TargetType);
            }

            var newAssemblyDeclSecurities   = importer.NewAssemblyDeclSecurities;
            var newAssemblyCustomAttributes = importer.NewAssemblyCustomAttributes;
            var newModuleCustomAttributes   = importer.NewModuleCustomAttributes;

            DeclSecurity[]    origAssemblyDeclSecurities   = null;
            CustomAttribute[] origAssemblyCustomAttributes = null;
            CustomAttribute[] origModuleCustomAttributes   = null;

            if (newAssemblyDeclSecurities != null)
            {
                origAssemblyDeclSecurities = module.Assembly.DeclSecurities.ToArray();
            }
            if (newAssemblyCustomAttributes != null)
            {
                origAssemblyCustomAttributes = module.Assembly.CustomAttributes.ToArray();
            }
            if (newModuleCustomAttributes != null)
            {
                origModuleCustomAttributes = module.Assembly.CustomAttributes.ToArray();
            }

            if (origAssemblyDeclSecurities != null && newAssemblyDeclSecurities != null)
            {
                module.Assembly.DeclSecurities.Clear();
                foreach (var ds in newAssemblyDeclSecurities)
                {
                    module.Assembly.DeclSecurities.Add(ds);
                }
            }
            if (origAssemblyCustomAttributes != null && newAssemblyCustomAttributes != null)
            {
                module.Assembly.CustomAttributes.Clear();
                foreach (var ca in newAssemblyCustomAttributes)
                {
                    module.Assembly.CustomAttributes.Add(ca);
                }
            }
            if (origModuleCustomAttributes != null && newModuleCustomAttributes != null)
            {
                module.CustomAttributes.Clear();
                foreach (var ca in newModuleCustomAttributes)
                {
                    module.CustomAttributes.Add(ca);
                }
            }
            if (importer.NewResources.Length != 0)
            {
                foreach (Resource res in importer.NewResources)
                {
                    module.Resources.Add(res);
                }
            }
        }
예제 #16
0
 protected override void Import(ModuleImporter importer, CompilationResult result) =>
 importer.ImportAssembly(result.RawFile, result.DebugFile);
예제 #17
0
 protected override void Import(ModuleImporter importer, in CompilationResult result) =>
예제 #18
0
        private static void TransplantConstraints(GenericParameter formatterGenericParameter, Collection <GenericParameter> formatterGenericParameters, GenericParameter baseGenericParameter, ModuleImporter importer)
        {
            for (var index = 0; index < baseGenericParameter.Constraints.Count; index++)
            {
#if UNITY_2018_4_OR_NEWER
                var baseConstraintType = baseGenericParameter.Constraints[index];
                if (baseConstraintType is GenericInstanceType genericInstanceType)
                {
                    var transplanted = TransplantInternal(genericInstanceType, formatterGenericParameters, importer);
                    formatterGenericParameter.Constraints.Add(transplanted);
                }
                else
                {
                    formatterGenericParameter.Constraints.Add(importer.Import(baseConstraintType).Reference);
                }
#else
                var baseConstraint     = baseGenericParameter.Constraints[index];
                var baseConstraintType = baseConstraint.ConstraintType;
                if (baseConstraintType is GenericInstanceType genericInstanceType)
                {
                    var transplanted = TransplantInternal(genericInstanceType, formatterGenericParameters, importer);
                    formatterGenericParameter.Constraints.Add(new GenericParameterConstraint(transplanted));
                }
                else
                {
                    formatterGenericParameter.Constraints.Add(new GenericParameterConstraint(importer.Import(baseConstraintType).Reference));
                }
#endif
            }
        }
예제 #19
0
파일: Commands.cs 프로젝트: KernelBK/dnSpy
 EditMethodBodyCodeCommand(Lazy <IAddUpdatedNodesHelperProvider> addUpdatedNodesHelperProvider, ModuleDocumentNode modNode, ModuleImporter importer)
     : base(addUpdatedNodesHelperProvider, modNode, importer)
 {
 }
예제 #20
0
        private static GenericInstanceType TransplantInternal(GenericInstanceType genericInstanceType, Collection <GenericParameter> formatterGenericParameters, ModuleImporter importer)
        {
            var element = importer.Import(genericInstanceType.ElementType);
            var answer  = new GenericInstanceType(element.Reference);

            foreach (var argument in genericInstanceType.GenericArguments)
            {
                if (argument is GenericInstanceType genericInstanceArgument)
                {
                    answer.GenericArguments.Add(TransplantInternal(genericInstanceArgument, formatterGenericParameters, importer));
                }
                else if (argument is GenericParameter genericParameter)
                {
                    answer.GenericArguments.Add(formatterGenericParameters[genericParameter.Position]);
                }
                else
                {
                    answer.GenericArguments.Add(importer.Import(argument).Reference);
                }
            }

            return(answer);
        }
예제 #21
0
 public EmptyEmitter(MethodDefinition method, ModuleImporter importer)
 {
     _method = method;
     _importer = importer;
 }
예제 #22
0
 private static void TransplantCustomAttributes(GenericParameter formatterGenericParameter, GenericParameter baseGenericParameter, ModuleImporter importer)
 {
     for (var index = 0; index < baseGenericParameter.CustomAttributes.Count; index++)
     {
         var baseAttribute = baseGenericParameter.CustomAttributes[index];
         var transplant    = importer.Import(baseAttribute);
         formatterGenericParameter.CustomAttributes.Add(transplant);
     }
 }
예제 #23
0
 public GenericStructIntKeyFormatterImplementor(ModuleDefinition module, TypeProvider provider, ModuleImporter importer)
 {
     this.module   = module;
     this.provider = provider;
     this.importer = importer;
 }
예제 #24
0
 protected override void Import(ModuleImporter importer, CompilationResult result) =>
 importer.Import(result.RawFile, result.DebugFile, ModuleImporterOptions.None);
예제 #25
0
 public AddUpdatedNodesHelper Create(ModuleDocumentNode modNode, ModuleImporter importer) =>
 new AddUpdatedNodesHelper(methodAnnotations, resourceNodeFactory, documentTreeView, modNode, importer);
예제 #26
0
 public AddUpdatedNodesHelper(Lazy <IMethodAnnotations> methodAnnotations, IModuleFileNode modNode, ModuleImporter importer)
 {
     this.modNode                  = modNode;
     this.newTypeNodeCreators      = importer.NewNonNestedTypes.Select(a => new TypeNodeCreator(modNode, a.TargetType)).ToArray();
     this.existingTypeNodeUpdaters = importer.MergedNonNestedTypes.Select(a => new ExistingTypeNodeUpdater(methodAnnotations, modNode, a)).ToArray();
     if (!importer.MergedNonNestedTypes.All(a => a.TargetType.Module == modNode.DnSpyFile.ModuleDef))
     {
         throw new InvalidOperationException();
     }
 }
예제 #27
0
파일: Commands.cs 프로젝트: jy4618272/dnSpy
 EditMethodBodyCodeCommand(Lazy <IMethodAnnotations> methodAnnotations, IModuleFileNode modNode, ModuleImporter importer)
 {
     this.addUpdatedNodesHelper = new AddUpdatedNodesHelper(methodAnnotations, modNode, importer);
 }
예제 #28
0
		static void Execute(IPickFilename pickFilename, Lazy<IAddUpdatedNodesHelperProvider> addUpdatedNodesHelperProvider, Lazy<IUndoCommandService> undoCommandService, IAppService appService, DocumentTreeNodeData[] nodes) {
			if (!CanExecute(nodes))
				return;

			var asmNode = nodes[0] as AssemblyDocumentNode;
			ModuleDocumentNode modNode;
			if (asmNode != null) {
				asmNode.TreeNode.EnsureChildrenLoaded();
				modNode = asmNode.TreeNode.DataChildren.FirstOrDefault() as ModuleDocumentNode;
			}
			else
				modNode = nodes[0].GetModuleNode();
			Debug.Assert(modNode != null);
			if (modNode == null)
				return;
			var module = modNode.Document.ModuleDef;
			Debug.Assert(module != null);
			if (module == null)
				throw new InvalidOperationException();

			var filename = pickFilename.GetFilename(null, "dll", PickFilenameConstants.DotNetAssemblyOrModuleFilter);
			var result = GetModuleBytes(filename);
			if (result == null)
				return;

			// This is a basic assembly merger, we don't support merging dependencies. It would require
			// fixing all refs to the dep and redirect them to the new defs that now exist in 'module'.
			var asm = module.Assembly;
			if (asm != null && result.Value.Assembly != null) {
				if (IsNonSupportedAssembly(module, asm, result.Value.Assembly)) {
					Contracts.App.MsgBox.Instance.Show($"Can't merge with {result.Value.Assembly} because it's a dependency");
					return;
				}
			}

			var importer = new ModuleImporter(module, EditCodeVM.makeEverythingPublic);
			try {
				importer.Import(result.Value.RawBytes, result.Value.DebugFile, ModuleImporterOptions.None);
			}
			catch (Exception ex) {
				Contracts.App.MsgBox.Instance.Show(ex);
				return;
			}

			undoCommandService.Value.Add(new MergeWithAssemblyCommand(addUpdatedNodesHelperProvider, modNode, importer));
		}
예제 #29
0
 protected override void Import(ModuleImporter importer, CompilationResult result) =>
 importer.ImportNewMembers(result.RawFile !, result.DebugFile, nonNestedType);
예제 #30
0
		MergeWithAssemblyCommand(Lazy<IAddUpdatedNodesHelperProvider> addUpdatedNodesHelperProvider, ModuleDocumentNode modNode, ModuleImporter importer)
			: base(addUpdatedNodesHelperProvider, modNode, importer) {
		}
예제 #31
0
 protected EditCodeCommandBase(Lazy <IAddUpdatedNodesHelperProvider> addUpdatedNodesHelperProvider, ModuleDocumentNode modNode, ModuleImporter importer)
 {
     addUpdatedNodesHelper = addUpdatedNodesHelperProvider.Value.Create(modNode, importer);
 }
예제 #32
0
        public static Instruction[] DeserializeFixedSizeBuffer(VariableDefinition targetVariable, FieldDefinition fixedField, ModuleDefinition module, MessagePackReaderHelper reader, ModuleImporter importer, SystemInvalidOperationExceptionHelper invalidOperationExceptionHelper, FixedSizeBufferElementType elementType, int count)
        {
            var same   = Instruction.Create(OpCodes.Ldloca_S, targetVariable);
            var read   = reader.ReadMessagePackPrimitive(GetType(module, elementType));
            var stride = SizeOf(elementType);

            switch (count)
            {
            case 1:
                return(new[]
                {
                    Instruction.Create(OpCodes.Ldarg_1),
                    Instruction.Create(OpCodes.Call, reader.ReadArrayHeader),
                    InstructionUtility.LdcI4(count),
                    Instruction.Create(OpCodes.Beq_S, same),
                    Instruction.Create(OpCodes.Ldstr, "Fixed size buffer field should have " + count.ToString(CultureInfo.InvariantCulture) + " element(s)."),
                    Instruction.Create(OpCodes.Newobj, invalidOperationExceptionHelper.Ctor),
                    Instruction.Create(OpCodes.Throw),
                    same,
                    Instruction.Create(OpCodes.Ldflda, importer.Import(fixedField)),
                    Instruction.Create(OpCodes.Ldarg_1),
                    Instruction.Create(OpCodes.Call, read),
                    Instruction.Create(StInd(elementType)),
                });

            case 2:
                return(new[]
                {
                    Instruction.Create(OpCodes.Ldarg_1),
                    Instruction.Create(OpCodes.Call, reader.ReadArrayHeader),
                    InstructionUtility.LdcI4(count),
                    Instruction.Create(OpCodes.Beq_S, same),
                    Instruction.Create(OpCodes.Ldstr, "Fixed size buffer field should have " + count.ToString(CultureInfo.InvariantCulture) + " element(s)."),
                    Instruction.Create(OpCodes.Newobj, invalidOperationExceptionHelper.Ctor),
                    Instruction.Create(OpCodes.Throw),
                    same,
                    Instruction.Create(OpCodes.Ldflda, importer.Import(fixedField)),
                    Instruction.Create(OpCodes.Dup),
                    Instruction.Create(OpCodes.Ldarg_1),
                    Instruction.Create(OpCodes.Call, read),
                    Instruction.Create(StInd(elementType)),
                    InstructionUtility.LdcI4(stride),
                    Instruction.Create(OpCodes.Add),
                    Instruction.Create(OpCodes.Ldarg_1),
                    Instruction.Create(OpCodes.Call, read),
                    Instruction.Create(StInd(elementType)),
                });

            default:
            {
                var answer = new Instruction[6 + (6 * count)];
                answer[0] = Instruction.Create(OpCodes.Ldarg_1);
                answer[1] = Instruction.Create(OpCodes.Call, reader.ReadArrayHeader);
                answer[2] = InstructionUtility.LdcI4(count);
                answer[3] = Instruction.Create(OpCodes.Beq_S, same);
                answer[4] = Instruction.Create(OpCodes.Ldstr, "Fixed size buffer field should have " + count.ToString(CultureInfo.InvariantCulture) + " element(s). field : " + fixedField.FullName);
                answer[5] = Instruction.Create(OpCodes.Newobj, invalidOperationExceptionHelper.Ctor);
                answer[6] = Instruction.Create(OpCodes.Throw);
                answer[7] = same;
                answer[8] = Instruction.Create(OpCodes.Ldflda, importer.Import(fixedField));

                answer[9]  = Instruction.Create(OpCodes.Dup);
                answer[10] = Instruction.Create(OpCodes.Ldarg_1);
                answer[11] = Instruction.Create(OpCodes.Call, read);
                answer[12] = Instruction.Create(StInd(elementType));

                for (var i = 1; i < count - 1; i++)
                {
                    var start = 7 + (i * 6);
                    answer[start++] = Instruction.Create(OpCodes.Dup);
                    answer[start++] = InstructionUtility.LdcI4(stride);
                    answer[start++] = Instruction.Create(OpCodes.Add);
                    answer[start++] = Instruction.Create(OpCodes.Ldarg_1);
                    answer[start++] = Instruction.Create(OpCodes.Call, read);
                    answer[start]   = Instruction.Create(StInd(elementType));
                }

                answer[1 + (6 * count)] = InstructionUtility.LdcI4(stride);
                answer[2 + (6 * count)] = Instruction.Create(OpCodes.Add);
                answer[3 + (6 * count)] = Instruction.Create(OpCodes.Ldarg_1);
                answer[4 + (6 * count)] = Instruction.Create(OpCodes.Call, read);
                answer[5 + (6 * count)] = Instruction.Create(StInd(elementType));

                return(answer);
            }
            }
        }
예제 #33
0
        async Task StartCompileAsync()
        {
            Result = null;
            SetDiagnostics(Array.Empty <CompilerDiagnostic>());

            bool              canceled        = false;
            Exception         caughtException = null;
            CompilationResult?result          = null;

            try {
                result = await CompileAsync();
            }
            catch (OperationCanceledException) {
                canceled = true;
            }
            catch (Exception ex) {
                caughtException = ex;
            }

            ModuleImporter moduleImporterResult = null;
            var            compilerDiagnostics  = result?.Diagnostics ?? Array.Empty <CompilerDiagnostic>();

            if (canceled)
            {
                // It gets canceled when the dialog box gets closed, or when Roslyn cancels the task
                // for some unknown reason.
                compilerDiagnostics = new CompilerDiagnostic[] {
                    new CompilerDiagnostic(CompilerDiagnosticSeverity.Error, "The task was canceled", "DSWTF!", null, null),
                };
            }
            else if (caughtException != null)
            {
                compilerDiagnostics = new CompilerDiagnostic[] { ToCompilerDiagnostic(caughtException) };
            }
            else if (result?.Success == true)
            {
                try {
                    moduleImporterResult = new ModuleImporter(methodToEdit.Module);
                    moduleImporterResult.Import(result.Value.RawFile, result.Value.DebugFile, methodToEdit);
                    compilerDiagnostics = moduleImporterResult.Diagnostics;
                    if (compilerDiagnostics.Any(a => a.Severity == CompilerDiagnosticSeverity.Error))
                    {
                        moduleImporterResult = null;
                    }
                }
                catch (ModuleImporterAbortedException) {
                    compilerDiagnostics = moduleImporterResult.Diagnostics;
                    Debug.Assert(compilerDiagnostics.Length != 0);
                    moduleImporterResult = null;
                }
                catch (Exception ex) {
                    compilerDiagnostics  = new CompilerDiagnostic[] { ToCompilerDiagnostic(ex) };
                    moduleImporterResult = null;
                }
            }

            SetDiagnostics(compilerDiagnostics);

            compileCodeState?.Dispose();
            compileCodeState = null;
            CanCompile       = true;

            if (moduleImporterResult != null)
            {
                Result = moduleImporterResult;
                CodeCompiled?.Invoke(this, EventArgs.Empty);
            }

            // The compile button sometimes doesn't get enabled again
            CommandManager.InvalidateRequerySuggested();
        }
예제 #34
0
 public SystemArrayHelper(ModuleDefinition module, ModuleImporter importer)
 {
     this.module   = module;
     this.importer = importer;
     Array         = new TypeReference("System", nameof(Array), module, module.TypeSystem.CoreLibrary, false);
 }
예제 #35
0
 AddClassMembersCommand(Lazy <IAddUpdatedNodesHelperProvider> addUpdatedNodesHelperProvider, ModuleDocumentNode modNode, ModuleImporter importer)
     : base(addUpdatedNodesHelperProvider, modNode, importer)
 {
 }
예제 #36
0
		protected override void Import(ModuleImporter importer, CompilationResult result) =>
			importer.Import(result.RawFile, result.DebugFile, ModuleImporterOptions.None);
예제 #37
0
		AddClassCommand(Lazy<IAddUpdatedNodesHelperProvider> addUpdatedNodesHelperProvider, ModuleDocumentNode modNode, ModuleImporter importer)
			: base(addUpdatedNodesHelperProvider, modNode, importer) {
		}
예제 #38
0
		protected override void Import(ModuleImporter importer, CompilationResult result) =>
			importer.Import(result.RawFile, result.DebugFile, ModuleImporterOptions.ReplaceModuleAssemblyAttributes | ModuleImporterOptions.ReplaceAssemblyDeclSecurities);
예제 #39
0
		public AddUpdatedNodesHelper Create(ModuleDocumentNode modNode, ModuleImporter importer) =>
			new AddUpdatedNodesHelper(methodAnnotations, resourceNodeFactory, documentTreeView, modNode, importer);
예제 #40
0
 public GenericClassStringKeyFormatterImplementor(ModuleDefinition module, TypeProvider provider, DataHelper dataHelper, ModuleImporter importer, AutomataEmbeddingHelper automataHelper)
 {
     this.module         = module;
     this.provider       = provider;
     this.dataHelper     = dataHelper;
     this.importer       = importer;
     this.automataHelper = automataHelper;
 }
예제 #41
0
		protected override void Import(ModuleImporter importer, CompilationResult result) =>
			importer.Import(result.RawFile, result.DebugFile, nonNestedTypeToEdit);
예제 #42
0
		EditMethodBodyCodeCommand(Lazy<IAddUpdatedNodesHelperProvider> addUpdatedNodesHelperProvider, ModuleDocumentNode modNode, ModuleImporter importer)
			: base(addUpdatedNodesHelperProvider, modNode, importer) {
		}