当前位置: 首页>>代码示例>>C#>>正文


C# EmbeddedResource.GetResourceStream方法代码示例

本文整理汇总了C#中Mono.Cecil.EmbeddedResource.GetResourceStream方法的典型用法代码示例。如果您正苦于以下问题:C# EmbeddedResource.GetResourceStream方法的具体用法?C# EmbeddedResource.GetResourceStream怎么用?C# EmbeddedResource.GetResourceStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mono.Cecil.EmbeddedResource的用法示例。


在下文中一共展示了EmbeddedResource.GetResourceStream方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ReadToken

 static string ReadToken(EmbeddedResource resources, string token)
 {
     using (var resourceStream = resources.GetResourceStream())
     using (var resourceSet = new ResourceSet(resourceStream))
         return resourceSet.GetString(token, true);
 }
开发者ID:nuxleus,项目名称:openwrap,代码行数:6,代码来源:CommandDocumentation.cs

示例2: InitResourceGridRows

        private bool InitResourceGridRows(EmbeddedResource er)
        {
            ResourceReader rr;
            try
            {
                rr = new ResourceReader(er.GetResourceStream());
            }
            catch
            {
                rr = null;
            }

            if (rr == null)
                return false;

            DataRow dr;
            IDictionaryEnumerator de = rr.GetEnumerator();
            int count = 0;
            while (de.MoveNext())
            {
                dr = _dtResource.NewRow();
                string name = de.Key as string;
                dr["no"] = count.ToString();
                count++;
                dr["name"] = name;
                object value = de.Value;
                dr["type"] = value == null ? null : value.GetType().FullName;
                try
                {
                    DataGridViewTextAndImageCellValue cv = new DataGridViewTextAndImageCellValue(name, value);
                    cv.Image = ConvertToImage(name, value);
                    dr["value"] = cv;
                }
                catch //(Exception ex)
                {
                    dr["value"] = new DataGridViewTextAndImageCellValue(String.Empty, value);
                    //dr["value"] = new DataGridViewTextAndImageCellValue(String.Empty, String.Format("Error: {0}", ex.Message));
                    //dr["type"] = "System.String";
                }
                _dtResource.Rows.Add(dr);
            }

            rr.Close();
            return true;
        }
开发者ID:adisik,项目名称:simple-assembly-explorer,代码行数:45,代码来源:ClassEditResourceHandler.cs

示例3: CheckSatelliteResource

		private void CheckSatelliteResource (EmbeddedResource mainResource, EmbeddedResource satelliteResource, IMetadataTokenProvider satelliteAssembly)
		{
			using (Stream resourceStream = satelliteResource.GetResourceStream ())
			using (ResourceSet resourceSet = new ResourceSet (resourceStream)) {
				foreach (DictionaryEntry entry in resourceSet) {
					string resourceName = (string) entry.Key;
					object satelliteValue = entry.Value;
					object mainValue;
					if (!mainAssemblyResourceCache.TryGetMainResource (mainResource, resourceName, out mainValue)) {
						Runner.Report (satelliteAssembly, Severity.Low, Confidence.High,
							String.Format ("The resource {0} in the file {1} exist in the satellite assembly but not in the main assembly", resourceName, satelliteResource.Name));
						continue;
					}

					Type satelliteType = satelliteValue.GetType ();
					Type mainType = mainValue.GetType ();
					if (!satelliteType.Equals (mainType)) {
						Runner.Report (satelliteAssembly, Severity.High, Confidence.High,
							String.Format ("The resource {0} in the file {1} is of type {2} in the satellite assembly but of type {3} in the main assembly", resourceName, satelliteResource.Name, satelliteType, mainType));
						continue;
					}

					if (satelliteType.Equals (typeof (string))) {
						Bitmask<int> mainParameters = GetStringFormatExpectedParameters ((string) mainValue);
						Bitmask<int> satelliteParameters = GetStringFormatExpectedParameters ((string) satelliteValue);

						if (!mainParameters.Equals (satelliteParameters))
							Runner.Report (satelliteAssembly, Severity.High, Confidence.Normal,
								String.Format ("The string resource {0} in the file {1} does not use the same string format parameters in the satellite and main assemblies", resourceName, satelliteResource.Name));
					}
				}
			}
		}
开发者ID:boothead,项目名称:mono-tools,代码行数:33,代码来源:SatelliteResourceMismatchRule.cs

示例4: GetRepackListFromResource

 private static string[] GetRepackListFromResource(EmbeddedResource resource)
 {
     return (string[])new BinaryFormatter().Deserialize(resource.GetResourceStream());
 }
开发者ID:jinjingcai2014,项目名称:il-repack,代码行数:4,代码来源:ResourcesRepackStep.cs

示例5: decryptResource

 byte[] decryptResource(EmbeddedResource resource)
 {
     using (var rsrcStream = resource.GetResourceStream()) {
         using (var reader = new BinaryReader(rsrcStream)) {
             var key = reader.ReadString();
             var data = reader.ReadBytes((int)(rsrcStream.Length - rsrcStream.Position));
             var cryptoTransform = new DESCryptoServiceProvider {
                 Key = Encoding.ASCII.GetBytes(key),
                 IV = Encoding.ASCII.GetBytes(key),
             }.CreateDecryptor();
             var memStream = new MemoryStream(data);
             using (var reader2 = new BinaryReader(new CryptoStream(memStream, cryptoTransform, CryptoStreamMode.Read))) {
                 return reader2.ReadBytes((int)memStream.Length);
             }
         }
     }
 }
开发者ID:ldh0227,项目名称:de4dot,代码行数:17,代码来源:ResourceDecrypter.cs

示例6: AddResource

        private void AddResource (EmbeddedResource resource)
        {
            if (embedded_resource_parser == null) {
                return;
            }

            if (Path.GetExtension (resource.Name) == ".resources") {
                using (var reader = new ResourceReader (resource.GetResourceStream ())) {
                    foreach (DictionaryEntry re in reader) {
                        if (embedded_resource_parser.SupportedFileExtensions.Contains (Path.GetExtension (re.Key as string))) {
                            embedded_resource_parser.Add (re.Value as Stream, re.Key as string);
                        }
                    }        
                }
            } else if (embedded_resource_parser.SupportedFileExtensions.Contains (Path.GetExtension(resource.Name))) {			
                embedded_resource_parser.Add (resource.GetResourceStream (), resource.Name);
            }
        }
开发者ID:lothrop,项目名称:vernacular,代码行数:18,代码来源:AssemblyParser.cs

示例7: ProcessXamlResources

        private void ProcessXamlResources(EmbeddedResource resource, ModuleDefinition module)
        {
            string targetDir = Path.GetDirectoryName(TargetPath);
            using (ResourceReader resourceReader = new ResourceReader(resource.GetResourceStream()))
            {
                foreach (System.Collections.DictionaryEntry resourceEntry in resourceReader)
                {
                    string xamlResourceKey = Utilities.GetXamlResourceKey(resourceEntry, module);

					bool isBamlResource = ((string)resourceEntry.Key).EndsWith(".baml", StringComparison.OrdinalIgnoreCase);

                    string xamlResourceRelativePath = xamlResourcesToPathsMap[xamlResourceKey];
                    string fullPath = Path.Combine(targetDir, xamlResourceRelativePath);

                    string fullClassName = TryWriteBamlResource(fullPath, isBamlResource, resourceEntry.Value as UnmanagedMemoryStream);
                    if (fullClassName != null)
                    {
                        fileGenContext.XamlFullNameToRelativePathMap.Add(fullClassName, xamlResourceRelativePath);
                    }
                    else
                    {
                        fileGenContext.OtherXamlResources.Add(new ProjectItemGroupResource() { Include = xamlResourceRelativePath });
                    }

					IFileGeneratedInfo args = new FileGeneratedInfo(fullPath, false);
                    OnProjectFileCreated(args);
                }
            }
        }
开发者ID:besturn,项目名称:JustDecompileEngine,代码行数:29,代码来源:MSBuildProjectBuilder.cs

示例8: ShowResource

        private void ShowResource(EmbeddedResource er)
        {
            if (PathUtils.IsResourceExt(er.Name))
            {
                if (InitResourceGridRows(er))
                {
                    //ShowDetailsControl(DetailTypes.Resources);
                    if (_dtResource.Rows.Count == 0)
                    {
                        ShowText(String.Empty);
                    }
                    else
                    {
                        ShowText((string)null);
                    }
                }
                else
                {
                    ShowBinary(er, false);
                }
            }
            else if (ResourceFile.Default.IsTextResource(er.Name))
            {
                ShowText(er.GetResourceStream(), null, false);
            }
            else if (PathUtils.IsIconExt(er.Name))
            {
                Icon ico = new Icon(er.GetResourceStream());
                pbResource.Image = ico.ToBitmap();
                ShowDetailsControl(DetailTypes.ImageResource);
            }
            else if (PathUtils.IsCursorExt(er.Name))
            {
                Cursor c = LoadCursor(er.GetResourceStream());
                Bitmap bmp = ConvertToBitmap(c);
                pbResource.Image = bmp;
                ShowDetailsControl(DetailTypes.ImageResource);
            }
            else if (ResourceFile.Default.IsImageResource(er.Name))
            {
                //wmf size is wrong with Image.FromStream
                //pbResource.Image = new Bitmap(er.GetResourceStream());

                Bitmap bmp = new Bitmap(er.GetResourceStream());
                pbResource.Image = bmp;
                //if (!ImageAnimator.CanAnimate(bmp))
                //{
                //    pbResource.Image = bmp;
                //}
                //else
                //{
                //    pbResource.Image = new Bitmap(bmp.Width, bmp.Height);
                //}
                ShowDetailsControl(DetailTypes.ImageResource);
            }
            else
            {
                //always try to parse as .resources
                if (InitResourceGridRows(er))
                {
                    //ShowDetailsControl(DetailTypes.Resources);
                    if (_dtResource.Rows.Count == 0)
                    {
                        ShowText(String.Empty);
                    }
                    else
                    {
                        ShowText((string)null);
                    }
                }
                else
                {
                    ShowBinary(er, false);
                }
            }
        }
开发者ID:adisik,项目名称:simple-assembly-explorer,代码行数:76,代码来源:ClassEditResourceHandler.cs

示例9: TryLoadAssembly

		/// <summary>Tries to load assembly for other assembly resources.</summary>
		/// <param name="resource">The resource.</param>
		/// <param name="guid">The GUID.</param>
		/// <returns>Loaded assembly image.</returns>
		private static byte[] TryLoadAssembly(EmbeddedResource resource, string guid)
		{
			var match = ResourceNameRx.Match(resource.Name);
			if (!match.Success || match.Groups["guid"].Value != guid)
				return null;

			try
			{
				var flags = match.Groups["flags"].Value;
				var size = int.Parse(match.Groups["size"].Value);
				var compressed = flags.Contains("z");

				var buffer = new byte[size];

				using (var rstream = resource.GetResourceStream())
				{
					if (rstream == null)
						return null;
					using (var zstream = compressed ? new DeflateStream(rstream, CompressionMode.Decompress) : rstream)
					{
						zstream.Read(buffer, 0, size);
					}
				}

				return buffer;
			}
			catch
			{
				return null;
			}
		}
开发者ID:jinjingcai2014,项目名称:LibZ,代码行数:35,代码来源:InstrumentLibZTask.cs

示例10: TryCreateResXFile

        private bool TryCreateResXFile(EmbeddedResource embeddedResource, string resourceFilePath)
        {
            List<System.Collections.DictionaryEntry> resourceEntries = new List<System.Collections.DictionaryEntry>();

            using (ResourceReader resourceReader = new ResourceReader(embeddedResource.GetResourceStream()))
            {
                IDictionaryEnumerator enumerator = resourceReader.GetEnumerator();

                while (enumerator.MoveNext())
                {
                    try
                    {
                        resourceEntries.Add(enumerator.Entry);
                    }
                    catch (Exception ex)
                    {
                        if (ResourceWritingFailure != null)
                        {
                            ResourceWritingFailure(this, embeddedResource.Name, ex);
                        }

						if (this.projectNotifier != null)
						{
							this.projectNotifier.OnResourceWritingFailure(embeddedResource.Name, ex);
						}
                    }
                }
            }

            string dirPath = Path.GetDirectoryName(resourceFilePath);
            if (!Directory.Exists(dirPath))
            {
                Directory.CreateDirectory(dirPath);
            }

#if !NET35
            using (ResXResourceWriter resXWriter = new ResXResourceWriter(resourceFilePath, ResourceTypeNameConverter))
#else
            using (ResXResourceWriter resXWriter = new ResXResourceWriter(resourceFilePath))
#endif
            {
                foreach (System.Collections.DictionaryEntry resourceEntry in resourceEntries)
                {
                    resXWriter.AddResource((string)resourceEntry.Key, resourceEntry.Value);
                }
            }

            return true;
        }
开发者ID:besturn,项目名称:JustDecompileEngine,代码行数:49,代码来源:MSBuildProjectBuilder.cs

示例11: init

        public void init(ResourceDecrypter resourceDecrypter)
        {
            if (decrypterType == null)
                return;

            encryptedResource = CoUtils.getResource(module, DotNetUtils.getCodeStrings(DotNetUtils.getMethod(decrypterType, ".cctor")));
            constantsData = resourceDecrypter.decrypt(encryptedResource.GetResourceStream());
        }
开发者ID:Joelone,项目名称:de4dot,代码行数:8,代码来源:ConstantsDecrypter.cs

示例12: decrypt

        public void decrypt(ResourceDecrypter resourceDecrypter)
        {
            if (decryptMethod == null)
                return;

            resource = CoUtils.getResource(module, decrypterCctor);
            if (resource == null)
                return;
            var decrypted = resourceDecrypter.decrypt(resource.GetResourceStream());
            var reader = new BinaryReader(new MemoryStream(decrypted));
            int numEncrypted = reader.ReadInt32();
            Log.v("Restoring {0} encrypted methods", numEncrypted);
            Log.indent();
            for (int i = 0; i < numEncrypted; i++) {
                int delegateTypeToken = reader.ReadInt32();
                uint codeOffset = reader.ReadUInt32();
                var origOffset = reader.BaseStream.Position;
                reader.BaseStream.Position = codeOffset;
                decrypt(reader, delegateTypeToken);
                reader.BaseStream.Position = origOffset;
            }
            Log.deIndent();
        }
开发者ID:Joelone,项目名称:de4dot,代码行数:23,代码来源:MethodsDecrypter.cs

示例13: getMethodsData

 byte[] getMethodsData(EmbeddedResource resource)
 {
     var reader = new BinaryReader(resource.GetResourceStream());
     reader.BaseStream.Position = startOffset;
     if ((reader.ReadInt32() & 1) != 0)
         return decompress(reader);
     else
         return reader.ReadBytes((int)(reader.BaseStream.Length - reader.BaseStream.Position));
 }
开发者ID:KenMacD,项目名称:de4dot,代码行数:9,代码来源:MethodsDecrypter.cs

示例14: RemoveResource

        public EmbeddedResource RemoveResource(EmbeddedResource er, string[] keys)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;

                var rr = new ResourceReader(er.GetResourceStream());
                var ms = new MemoryStream();
                var rw = new ResourceWriter(ms);

                var de = rr.GetEnumerator();
                while (de.MoveNext())
                {
                    string deKey = de.Key as string;
                    bool toBeDeleted = false;
                    foreach (string key in keys)
                    {
                        if (key == deKey)
                        {
                            toBeDeleted = true;
                            break;
                        }
                    }
                    if (toBeDeleted) continue;
                    rw.AddResource(deKey, de.Value);
                }

                rw.Generate();
                rw.Close();
                rr.Close();
                var newEr = new EmbeddedResource(er.Name, er.Attributes, ms.ToArray());
                ms.Close();
                return newEr;
            }
            catch
            {
                throw;
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
开发者ID:adisik,项目名称:simple-assembly-explorer,代码行数:43,代码来源:ClassEditResourceHandler.cs

示例15: GetExternalDescriptor

		static XPathDocument GetExternalDescriptor (EmbeddedResource resource)
		{
			using (var sr = new StreamReader (resource.GetResourceStream ())) {
				return new XPathDocument (new StringReader (sr.ReadToEnd ()));
			}
		}
开发者ID:RavuAlHemio,项目名称:mono,代码行数:6,代码来源:BlacklistStep.cs


注:本文中的Mono.Cecil.EmbeddedResource.GetResourceStream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。