Beispiel #1
0
        public static Stream GetTransformedStream(string filePath, CMS_HASH_TRANSFORM transform)
        {
            Stream stream = (Stream)null;

            if (transform == CMS_HASH_TRANSFORM.CMS_HASH_TRANSFORM_MANIFESTINVARIANT)
            {
                PEStream peStream = (PEStream)null;
                try
                {
                    peStream = new PEStream(filePath, true);
                    peStream.ZeroOutOptionalHeaderCheckSum();
                    peStream.ZeroOutDefaultId1ManifestResource();
                    stream = (Stream)peStream;
                    return(stream);
                }
                finally
                {
                    if (peStream != stream && peStream != null)
                    {
                        peStream.Close();
                    }
                }
            }
            else
            {
                if (transform == CMS_HASH_TRANSFORM.CMS_HASH_TRANSFORM_IDENTITY)
                {
                    return((Stream) new FileStream(filePath, FileMode.Open, FileAccess.Read));
                }
                throw new NotSupportedException(string.Format((IFormatProvider)CultureInfo.CurrentUICulture, Resources.GetString("Ex_TransformAlgorithmNotSupported"), new object[1]
                {
                    (object)transform.ToString()
                }));
            }
        }
        public static Stream GetTransformedStream(string filePath, System.Deployment.Internal.Isolation.Manifest.CMS_HASH_TRANSFORM transform)
        {
            Stream stream = null;

            if (transform == System.Deployment.Internal.Isolation.Manifest.CMS_HASH_TRANSFORM.CMS_HASH_TRANSFORM_MANIFESTINVARIANT)
            {
                PEStream stream2 = null;
                try
                {
                    stream2 = new PEStream(filePath, true);
                    stream2.ZeroOutOptionalHeaderCheckSum();
                    stream2.ZeroOutDefaultId1ManifestResource();
                    return(stream2);
                }
                finally
                {
                    if ((stream2 != stream) && (stream2 != null))
                    {
                        stream2.Close();
                    }
                }
            }
            if (transform != System.Deployment.Internal.Isolation.Manifest.CMS_HASH_TRANSFORM.CMS_HASH_TRANSFORM_IDENTITY)
            {
                throw new NotSupportedException(string.Format(CultureInfo.CurrentUICulture, Resources.GetString("Ex_TransformAlgorithmNotSupported"), new object[] { transform.ToString() }));
            }
            return(new FileStream(filePath, FileMode.Open, FileAccess.Read));
        }
 public static Stream GetTransformedStream(string filePath, System.Deployment.Internal.Isolation.Manifest.CMS_HASH_TRANSFORM transform)
 {
     Stream stream = null;
     if (transform == System.Deployment.Internal.Isolation.Manifest.CMS_HASH_TRANSFORM.CMS_HASH_TRANSFORM_MANIFESTINVARIANT)
     {
         PEStream stream2 = null;
         try
         {
             stream2 = new PEStream(filePath, true);
             stream2.ZeroOutOptionalHeaderCheckSum();
             stream2.ZeroOutDefaultId1ManifestResource();
             return stream2;
         }
         finally
         {
             if ((stream2 != stream) && (stream2 != null))
             {
                 stream2.Close();
             }
         }
     }
     if (transform != System.Deployment.Internal.Isolation.Manifest.CMS_HASH_TRANSFORM.CMS_HASH_TRANSFORM_IDENTITY)
     {
         throw new NotSupportedException(string.Format(CultureInfo.CurrentUICulture, Resources.GetString("Ex_TransformAlgorithmNotSupported"), new object[] { transform.ToString() }));
     }
     return new FileStream(filePath, FileMode.Open, FileAccess.Read);
 }