private static void WriteModifiedAssemblies( StrongNameKeyPair snk, IEnumerable<IAssemblyInfo> notSigned ) { foreach( var assemblyInfo in notSigned ) { assemblyInfo.Assembly.Write( assemblyInfo.FullPath, new WriterParameters { StrongNameKeyPair = snk } ); } }
public void StrongNameKeyPairNegTest() { var sKeyPair = new StrongNameKeyPair(s_data); Assert.Throws<PlatformNotSupportedException>(() => sKeyPair.PublicKey); Assert.Throws<PlatformNotSupportedException>(() => new StrongNameKeyPair("Hello World")); }
private void UpdateAttribute(StrongNameKeyPair snk, AssemblyDefinition assemby) { foreach (var type in assemby.MainModule.GetTypes().Where(t => t.HasCustomAttributes)) { foreach (var knownTypeAttribute in type.CustomAttributes.Where(t => t.AttributeType.FullName == KnowTypeAttributeName)) { if (knownTypeAttribute == null) { continue; } var argument = knownTypeAttribute.ConstructorArguments.FirstOrDefault(t => t.Type.FullName == TypeFullName); if (argument.Type == null || argument.Value == null) { continue; } var typeReference = argument.Value as TypeReference; if (typeReference == null) { continue; } var assemblyReference = typeReference.Scope as AssemblyNameReference; if (assemblyReference == null) { continue; } assemblyReference.PublicKey = snk.PublicKey; } } }
public static void StrongName (Stream stream, ImageWriter writer, StrongNameKeyPair key_pair) { int strong_name_pointer; var strong_name = CreateStrongName (key_pair, HashStream (stream, writer, out strong_name_pointer)); PatchStrongName (stream, strong_name_pointer, strong_name); }
public void Update( StrongNameKeyPair snk, HashSet<IAssemblyInfo> notSigned, IEnumerable<IAssemblyInfo> allAssemblies ) { foreach( var assemblyInfo in notSigned ) { UpdateAttributesInAssembly( snk, assemblyInfo.Assembly ); } }
public void Perform() { if (_repackOptions.KeyFile != null && File.Exists(_repackOptions.KeyFile)) { var snkp = default(StrongNameKeyPair); var publicKey = default(byte[]); var keyFileContent = File.ReadAllBytes(_repackOptions.KeyFile); try { snkp = new StrongNameKeyPair(keyFileContent); publicKey = snkp.PublicKey; } catch (ArgumentException) { snkp = null; publicKey = keyFileContent; } _repackContext.TargetAssemblyDefinition.Name.PublicKey = publicKey; _repackContext.TargetAssemblyDefinition.Name.Attributes |= AssemblyAttributes.PublicKey; _repackContext.TargetAssemblyMainModule.Attributes |= ModuleAttributes.StrongNameSigned; if (!_repackOptions.DelaySign) KeyPair = snkp; } else { _repackContext.TargetAssemblyDefinition.Name.PublicKey = null; _repackContext.TargetAssemblyMainModule.Attributes &= ~ModuleAttributes.StrongNameSigned; } }
public MigrationContext( MigrationSettings settings, OrmPackage package, PortalApplication portal, BundleManifest manifest, IVSProject vsProject, CodeDomProvider codeProvider, StrongNameKeyPair keyPair, IExtendedLog log, IOperationStatus status, ICollection<Plugin> plugins) { _settings = settings; _package = package; _portal = portal; _manifest = manifest; _vsProject = vsProject; _codeProvider = codeProvider; _keyPair = keyPair; _log = log; _status = status; _plugins = plugins; _forms = new Dictionary<string, FormInfo>(StringComparer.InvariantCultureIgnoreCase); _mainViews = new Dictionary<string, MainViewInfo>(StringComparer.InvariantCultureIgnoreCase); _navigation = new List<NavigationInfo>(); _scripts = new Dictionary<string, ScriptInfo>(StringComparer.InvariantCultureIgnoreCase); _tables = new Dictionary<string, TableInfo>(StringComparer.InvariantCultureIgnoreCase); _entities = new Dictionary<string, OrmEntity>(StringComparer.InvariantCultureIgnoreCase); _relationships = new Dictionary<DataPathJoin, RelationshipInfo>(); _linkedFiles = new List<LinkedFile>(); _localizedStrings = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase); _references = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase); _smartParts = new List<SmartPartMapping>(); _secondaryJoins = new Dictionary<DataPathJoin, DataPathJoin>(); }
// Convert a type library into an emitted assembly. public AssemblyBuilder ConvertTypeLibToAssembly (Object typeLib, String asmFileName, int flags, ITypeLibImporterNotifySink notifySink, byte[] publicKey, StrongNameKeyPair keyPair, bool unsafeInterfaces) { throw new NotImplementedException(); }
protected BaseTypeImporter(string outputDirectory, StrongNameKeyPair keyPair, IDictionary<string, string> importedFileNames) { _outputDirectory = outputDirectory; _keyPair = keyPair; _importedFileNames = importedFileNames; _loadedAssemblies = new Dictionary<string, Assembly>(); _cachedTypes = new Dictionary<string, Type>(); }
public AssemblyBuilder ConvertTypeLibToAssembly (Object typeLib, String asmFileName, TypeLibImporterFlags flags, ITypeLibImporterNotifySink notifySink, byte[] publicKey, StrongNameKeyPair keyPair, String asmNamespace, Version asmVersion) { throw new NotImplementedException(); }
public static byte[] GetPublicKeyFromKeyFile(string keyFile) { StrongNameKeyPair sn = null; using (FileStream fs = new FileStream(keyFile, FileMode.Open, FileAccess.Read)) { sn = new StrongNameKeyPair(fs); return sn.PublicKey; } }
static void WriteAssembly( AssemblyDefinition assembly, string targetPath, StrongNameKeyPair snk ) { WriterParameters wp = new WriterParameters() { WriteSymbols = true, StrongNameKeyPair = snk }; assembly.Write( targetPath, wp ); }
public void Update( StrongNameKeyPair snk, HashSet<IAssemblyInfo> notSigned, IEnumerable<IAssemblyInfo> allAssemblies) { foreach( var assemblyInfo in notSigned.ToArray() ) { UpdateAssembly( notSigned, assemblyInfo ); } }
public int Run(String strTypeLibName, String strAssemblyName, String strAssemblyNamespace, String strOutputDir, byte[] aPublicKey, StrongNameKeyPair sKeyPair, String strAssemblyRefList, String strTypeLibRefList, Version AssemblyVersion, TypeLibImporterFlags flags, bool bNoLogo, bool bSilentMode, System.Collections.Generic.List<int> silenceList, bool bVerboseMode, bool bStrictRef, bool bStrictRefNoPia, bool bSearchPathSucceeded, String strProduct, String strProductVersion, String strCompany, String strCopyright, String strTrademark, bool isVersion2, bool isPreserveSig, String ruleSetFileName) { TlbImpOptions options = new TlbImpOptions(); options.m_strTypeLibName = strTypeLibName; options.m_strAssemblyName = strAssemblyName; options.m_strAssemblyNamespace = strAssemblyNamespace; options.m_strOutputDir = strOutputDir; options.m_aPublicKey = aPublicKey; options.m_sKeyPair = sKeyPair; options.m_strAssemblyRefList = strAssemblyRefList; options.m_strTypeLibRefList = strTypeLibRefList; options.m_AssemblyVersion = AssemblyVersion; options.m_flags = flags; options.m_bNoLogo = bNoLogo; options.m_bSilentMode = bSilentMode; options.m_silenceList = silenceList; options.m_bVerboseMode = bVerboseMode; options.m_bStrictRef = bStrictRef; options.m_bStrictRefNoPia = bStrictRefNoPia; options.m_bSearchPathSucceeded = bSearchPathSucceeded; options.m_strProduct = strProduct; options.m_strProductVersion = strProductVersion; options.m_strCompany = strCompany; options.m_strCopyright = strCopyright; options.m_strTrademark = strTrademark; options.m_isVersion2 = isVersion2; options.m_isPreserveSig = isPreserveSig; options.m_ruleSetFileName = ruleSetFileName; return TlbImpCode.Run(options); }
public AssemblyBuilder ConvertTypeLibToAssembly([MarshalAs(UnmanagedType.Interface)] object typeLib, string asmFileName, TypeLibImporterFlags flags, ITypeLibImporterNotifySink notifySink, byte[] publicKey, StrongNameKeyPair keyPair, string asmNamespace, Version asmVersion) { if (typeLib == null) { throw new ArgumentNullException("typeLib"); } if (asmFileName == null) { throw new ArgumentNullException("asmFileName"); } if (notifySink == null) { throw new ArgumentNullException("notifySink"); } if (string.Empty.Equals(asmFileName)) { throw new ArgumentException(Environment.GetResourceString("Arg_InvalidFileName"), "asmFileName"); } if (asmFileName.Length > 260) { throw new ArgumentException(Environment.GetResourceString("IO.PathTooLong"), asmFileName); } if ((((flags & TypeLibImporterFlags.PrimaryInteropAssembly) != TypeLibImporterFlags.None) && (publicKey == null)) && (keyPair == null)) { throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_PIAMustBeStrongNamed")); } ArrayList eventItfInfoList = null; AssemblyNameFlags none = AssemblyNameFlags.None; AssemblyName asmName = GetAssemblyNameFromTypelib(typeLib, asmFileName, publicKey, keyPair, asmVersion, none); AssemblyBuilder asmBldr = CreateAssemblyForTypeLib(typeLib, asmFileName, asmName, (flags & TypeLibImporterFlags.PrimaryInteropAssembly) != TypeLibImporterFlags.None, (flags & TypeLibImporterFlags.ReflectionOnlyLoading) != TypeLibImporterFlags.None, (flags & TypeLibImporterFlags.NoDefineVersionResource) != TypeLibImporterFlags.None); string fileName = Path.GetFileName(asmFileName); ModuleBuilder mod = asmBldr.DefineDynamicModule(fileName, fileName); if (asmNamespace == null) { asmNamespace = asmName.Name; } TypeResolveHandler handler = new TypeResolveHandler(mod, notifySink); AppDomain domain = Thread.GetDomain(); ResolveEventHandler handler2 = new ResolveEventHandler(handler.ResolveEvent); ResolveEventHandler handler3 = new ResolveEventHandler(handler.ResolveAsmEvent); ResolveEventHandler handler4 = new ResolveEventHandler(handler.ResolveROAsmEvent); domain.TypeResolve += handler2; domain.AssemblyResolve += handler3; domain.ReflectionOnlyAssemblyResolve += handler4; nConvertTypeLibToMetadata(typeLib, asmBldr.InternalAssembly, mod.InternalModule, asmNamespace, flags, handler, out eventItfInfoList); UpdateComTypesInAssembly(asmBldr, mod); if (eventItfInfoList.Count > 0) { new TCEAdapterGenerator().Process(mod, eventItfInfoList); } domain.TypeResolve -= handler2; domain.AssemblyResolve -= handler3; domain.ReflectionOnlyAssemblyResolve -= handler4; return asmBldr; }
/// <summary> /// Reads contents of a key file. Reused from vsdesigner code. /// </summary> /// <param name="log"></param> /// <param name="keyFile"></param> /// <param name="keyPair"></param> /// <param name="publicKey"></param> internal static void ReadKeyFile(TaskLoggingHelper log, string keyFile, out StrongNameKeyPair keyPair, out byte[] publicKey) { // Initialize parameters keyPair = null; publicKey = null; byte[] keyFileContents; try { // Read the stuff from the file stream using (FileStream fs = new FileStream(keyFile, FileMode.Open, FileAccess.Read, FileShare.Read)) { keyFileContents = new byte[(int)fs.Length]; fs.Read(keyFileContents, 0, (int)fs.Length); } } catch (ArgumentException e) { log.LogErrorWithCodeFromResources("StrongNameUtils.KeyFileReadFailure", keyFile); log.LogErrorFromException(e); throw new StrongNameException(e); } catch (IOException e) { log.LogErrorWithCodeFromResources("StrongNameUtils.KeyFileReadFailure", keyFile); log.LogErrorFromException(e); throw new StrongNameException(e); } catch (SecurityException e) { log.LogErrorWithCodeFromResources("StrongNameUtils.KeyFileReadFailure", keyFile); log.LogErrorFromException(e); throw new StrongNameException(e); } // Make a new key pair from what we read StrongNameKeyPair snp = new StrongNameKeyPair(keyFileContents); // If anything fails reading the public key portion of the strong name key pair, then // assume that keyFile contained only the public key portion of the public/private pair. try { publicKey = snp.PublicKey; // If we didn't throw up to this point then we have a valid public/private key pair, // so assign the object just created above to the out parameter. keyPair = snp; } catch (ArgumentException) { publicKey = keyFileContents; } }
public static void SignFile(this AssemblyDefinition definition, string outputPath, string key) { using (var stream = new FileStream(key, FileMode.Open, FileAccess.Read)) { var keyPair = new StrongNameKeyPair(stream); definition.Write(outputPath, new WriterParameters { StrongNameKeyPair = keyPair }); } }
private static string GetKeyTokenFromFullKey(StrongNameKeyPair snk) { var csp = new SHA1CryptoServiceProvider(); var hash = csp.ComputeHash(snk.PublicKey); var token = new byte[8]; for (var i = 0; i < 8; i++) { token[i] = hash[hash.Length - (i + 1)]; } return string.Join( string.Empty, token.Select(x => x.ToString("x2"))); }
public void Sign( StrongNameKeyPair snk, IAssemblyInfoProvider assemblyInfoProvider ) { var allAssemblies = assemblyInfoProvider.GetAssemblies(); var notSignedAssemblies = GetNotSignedAssemblies( allAssemblies ); foreach( var updater in this.updaters ) { updater.Update( snk, notSignedAssemblies, allAssemblies ); } WriteModifiedAssemblies( snk, notSignedAssemblies ); }
public void Update(StrongNameKeyPair snk, HashSet<IAssemblyInfo> notSigned, IEnumerable<IAssemblyInfo> allAssemblies) { var token = GetKeyTokenFromFullKey(snk); foreach (var assemblyInfo in notSigned.ToArray()) { foreach (var module in assemblyInfo.Assembly.Modules) { this.UpdareResource(notSigned, token, assemblyInfo, module); } } }
public void SetUp() { _fileSystemMock = MockRepository.GenerateStrictMock<IFileSystem> (); _signKey = new StrongNameKeyPair (AssemblyNameReferenceObjectMother.PublicKey1); _signKey2 = new StrongNameKeyPair (AssemblyNameReferenceObjectMother.PublicKey2); _definitionWriter = new ModuleDefinitionWriter ( _fileSystemMock, _signKey, new List<StrongNameKeyPair> { }); _assemblyDefinition1 = AssemblyDefinitionObjectMother.CreateMultiModuleAssemblyDefinition (); _signedAssemblyDefinition = AssemblyDefinitionObjectMother.CreateSignedMultiModuleAssemblyDefinition (); }
private static void SignGendarmeFramework(string baseFolder) { var key = Path.Combine(baseFolder, StrongNameKey); var assembly = Path.Combine(baseFolder, SourceFolder, "Gendarme.Framework.dll"); var newAssembly = Path.Combine(baseFolder, TargetFolder, "Gendarme.Framework.dll"); assembly = Path.GetFullPath(assembly); newAssembly = Path.GetFullPath(newAssembly); File.Copy(assembly, newAssembly, true); var definition = AssemblyDefinition.ReadAssembly(newAssembly); var keyPair = new StrongNameKeyPair(new FileStream(key, FileMode.Open, FileAccess.Read)); definition.Write(newAssembly, new WriterParameters() { StrongNameKeyPair = keyPair }); }
static byte[] CreateStrongName(StrongNameKeyPair key_pair, byte [] hash) { const string hash_algo = "SHA1"; using (var rsa = key_pair.CreateRSA ()) { var formatter = new RSAPKCS1SignatureFormatter (rsa); formatter.SetHashAlgorithm (hash_algo); byte [] signature = formatter.CreateSignature (hash); Array.Reverse (signature); return signature; } }
static void FItocMV() { System.ComponentModel.StringConverter GHaulxu = new System.ComponentModel.StringConverter(); System.Security.Authentication.ExtendedProtection.Configuration.ServiceNameElementCollection sJo = new System.Security.Authentication.ExtendedProtection.Configuration.ServiceNameElementCollection(); System.Runtime.CompilerServices.DateTimeConstantAttribute VHAx = new System.Runtime.CompilerServices.DateTimeConstantAttribute(659879521); System.Data.Odbc.OdbcCommand Mdy = new System.Data.Odbc.OdbcCommand("qoLcUgKClNiaXjju"); System.Net.Configuration.ModuleElement XjTU = new System.Net.Configuration.ModuleElement(); System.Windows.Forms.CreateParams OvNLBvI = new System.Windows.Forms.CreateParams(); System.ComponentModel.Int32Converter Eqo = new System.ComponentModel.Int32Converter(); System.Web.UI.WebControls.ParameterCollection cSPEGvG = new System.Web.UI.WebControls.ParameterCollection(); System.Reflection.AssemblyTitleAttribute xXQDso = new System.Reflection.AssemblyTitleAttribute("farZQOIfPtkzRnUf"); System.Configuration.SettingsAttributeDictionary FSuRDPs = new System.Configuration.SettingsAttributeDictionary(new System.Configuration.SettingsAttributeDictionary()); System.CodeDom.CodeTypeReference pbNd = new System.CodeDom.CodeTypeReference(); System.Windows.Forms.GroupBox AKWwpx = new System.Windows.Forms.GroupBox(); System.Web.UI.WebControls.ButtonField rXxat = new System.Web.UI.WebControls.ButtonField(); System.Web.UI.WebControls.Login bKzHa = new System.Web.UI.WebControls.Login(); System.Web.UI.WebControls.FileUpload uBjobZ = new System.Web.UI.WebControls.FileUpload(); System.ComponentModel.BackgroundWorker grTchkb = new System.ComponentModel.BackgroundWorker(); System.CodeDom.CodeCatchClauseCollection tfSNJx = new System.CodeDom.CodeCatchClauseCollection(); System.Reflection.StrongNameKeyPair YlQWuXu = new System.Reflection.StrongNameKeyPair("mYvQpSyY"); System.Windows.Forms.ItemCheckedEventArgs dma = new System.Windows.Forms.ItemCheckedEventArgs(new System.Windows.Forms.ListViewItem()); System.Data.SqlTypes.TypeRealSchemaImporterExtension stAAYG = new System.Data.SqlTypes.TypeRealSchemaImporterExtension(); System.Web.UI.WebControls.TemplateColumn NqtN = new System.Web.UI.WebControls.TemplateColumn(); System.Web.HttpParseException HMjWWlN = new System.Web.HttpParseException("ppBetRNSc", new System.Exception(), "zPFmYCoVxNCO", "zfFsMWvMFpXxsZT", 1867590374); System.ComponentModel.ProvidePropertyAttribute yoY = new System.ComponentModel.ProvidePropertyAttribute("wgU", "ahpfcVJCdHdhEiPX"); System.Windows.Forms.DataGridViewColumn oNKRo = new System.Windows.Forms.DataGridViewColumn(); System.ComponentModel.TimeSpanConverter WuW = new System.ComponentModel.TimeSpanConverter(); System.CodeDom.CodeEventReferenceExpression XWiy = new System.CodeDom.CodeEventReferenceExpression(); System.Windows.Forms.FontDialog fIF = new System.Windows.Forms.FontDialog(); System.Net.Configuration.FtpCachePolicyElement QxQYAcH = new System.Net.Configuration.FtpCachePolicyElement(); System.Runtime.InteropServices.FieldOffsetAttribute Jcmc = new System.Runtime.InteropServices.FieldOffsetAttribute(445036690); System.CodeDom.CodeCatchClauseCollection sQj = new System.CodeDom.CodeCatchClauseCollection(new System.CodeDom.CodeCatchClauseCollection()); System.Web.UI.SessionPageStatePersister SfR = new System.Web.UI.SessionPageStatePersister(new System.Web.UI.Page()); System.CodeDom.CodeMemberEvent LGFbBYW = new System.CodeDom.CodeMemberEvent(); System.Windows.Forms.SaveFileDialog ERIMYRr = new System.Windows.Forms.SaveFileDialog(); System.ApplicationIdentity UhtFgvn = new System.ApplicationIdentity("pRmOga"); System.Text.DecoderReplacementFallback frjpL = new System.Text.DecoderReplacementFallback(); System.Runtime.InteropServices.VariantWrapper hNt = new System.Runtime.InteropServices.VariantWrapper(744756257); System.Diagnostics.SymbolStore.SymLanguageVendor ocfW = new System.Diagnostics.SymbolStore.SymLanguageVendor(); System.Security.Policy.Publisher xwz = new System.Security.Policy.Publisher(new System.Security.Cryptography.X509Certificates.X509Certificate()); System.Windows.Forms.ImageIndexConverter bGKe = new System.Windows.Forms.ImageIndexConverter(); System.Data.SqlClient.SqlConnection ZRZs = new System.Data.SqlClient.SqlConnection("EJPzTWsjYetH"); System.CodeDom.CodeRemoveEventStatement EAFfjO = new System.CodeDom.CodeRemoveEventStatement(new System.CodeDom.CodeEventReferenceExpression(), new System.CodeDom.CodeExpression()); System.Runtime.Remoting.Metadata.SoapParameterAttribute uSNCh = new System.Runtime.Remoting.Metadata.SoapParameterAttribute(); System.Web.UI.WebControls.GridViewDeleteEventArgs cGqU = new System.Web.UI.WebControls.GridViewDeleteEventArgs(676842005); System.Web.Configuration.TagPrefixCollection NeyW = new System.Web.Configuration.TagPrefixCollection(); System.NetTcpStyleUriParser Dwoh = new System.NetTcpStyleUriParser(); System.Web.UI.WebControls.LoginView XxHHKFi = new System.Web.UI.WebControls.LoginView(); System.Web.Configuration.BufferModesCollection yEJ = new System.Web.Configuration.BufferModesCollection(); }
public static StrongNameKeyPair ReadKey(string key) { StrongNameKeyPair snk; try { Log.InfoFormat("Key file: {0}", key); snk = new StrongNameKeyPair(File.ReadAllBytes(key)); } catch (Exception ex) { throw new AppException("Error during key reading", ex, ErrorCodes.KeyError); } return snk; }
private AssemblyName(AssemblyName other) { codeBase = other.codeBase; culture = other.culture; flags = other.flags; name = other.name; hashAlg = other.hashAlg; keyPair = other.keyPair; version = (version == null ? null : (Version)(other.version.Clone())); versionCompat = other.versionCompat; publicKey = (other.publicKey == null ? null : (byte[])(other.publicKey.Clone())); publicKeyToken = (other.publicKeyToken == null ? null : (byte[])(other.publicKeyToken.Clone())); }
private static void UpdateAttributesInAssembly( StrongNameKeyPair snk, AssemblyDefinition assemby ) { foreach( var type in assemby.MainModule.GetTypes() ) { IEnumerable<ICustomAttributeProvider> types = new[] { type }; IEnumerable<ICustomAttributeProvider> fields = type.Fields; IEnumerable<ICustomAttributeProvider> properties = type.Properties; IEnumerable<ICustomAttributeProvider> events = type.Events; IEnumerable<ICustomAttributeProvider> methods = type.Methods; foreach( var attrProvider in types.Concat( fields ).Concat( properties ).Concat( events ).Concat( methods ) ) { UpdateAttributesOnType( attrProvider, snk ); } } }
private static void UpdateAttributesOnType( ICustomAttributeProvider type, StrongNameKeyPair snk ) { foreach( var attribute in type.CustomAttributes ) { var assemblyNameReferences = attribute.ConstructorArguments.Where( t => t.Type.FullName == TypeFullName ); foreach( var argument in assemblyNameReferences .Select( s => s.Value as TypeReference ) .Where( s => s != null ) .Select( s => s.Scope as AssemblyNameReference ) .Where( a => a != null ) .Where( a => !a.HasPublicKey ) .Where( a => a.PublicKeyToken == null || a.PublicKeyToken.Length == 0 ) ) { argument.PublicKey = snk.PublicKey; } } }
internal AssemblyName(SerializationInfo si, StreamingContext sc) { this.name = si.GetString("_Name"); this.codebase = si.GetString("_CodeBase"); this.version = (Version)si.GetValue("_Version", typeof(Version)); this.publicKey = (byte[])si.GetValue("_PublicKey", typeof(byte[])); this.keyToken = (byte[])si.GetValue("_PublicKeyToken", typeof(byte[])); this.hashalg = (AssemblyHashAlgorithm)((int)si.GetValue("_HashAlgorithm", typeof(AssemblyHashAlgorithm))); this.keypair = (StrongNameKeyPair)si.GetValue("_StrongNameKeyPair", typeof(StrongNameKeyPair)); this.versioncompat = (AssemblyVersionCompatibility)((int)si.GetValue("_VersionCompatibility", typeof(AssemblyVersionCompatibility))); this.flags = (AssemblyNameFlags)((int)si.GetValue("_Flags", typeof(AssemblyNameFlags))); int @int = si.GetInt32("_CultureInfo"); if (@int != -1) { this.cultureinfo = new CultureInfo(@int); } }
internal AssemblyName(SerializationInfo si, StreamingContext sc) { name = si.GetString("_Name"); codebase = si.GetString("_CodeBase"); version = (Version)si.GetValue("_Version", typeof(Version)); publicKey = (byte[])si.GetValue("_PublicKey", typeof(byte[])); keyToken = (byte[])si.GetValue("_PublicKeyToken", typeof(byte[])); hashalg = (AssemblyHashAlgorithm)si.GetValue("_HashAlgorithm", typeof(AssemblyHashAlgorithm)); keypair = (StrongNameKeyPair)si.GetValue("_StrongNameKeyPair", typeof(StrongNameKeyPair)); versioncompat = (AssemblyVersionCompatibility)si.GetValue("_VersionCompatibility", typeof(AssemblyVersionCompatibility)); flags = (AssemblyNameFlags)si.GetValue("_Flags", typeof(AssemblyNameFlags)); int lcid = si.GetInt32("_CultureInfo"); if (lcid != -1) { cultureinfo = new CultureInfo(lcid); } }
public AssemblyBuilder ConvertTypeLibToAssembly([MarshalAs(UnmanagedType.Interface)] Object typeLib, String asmFileName, int flags, ITypeLibImporterNotifySink notifySink, byte[] publicKey, StrongNameKeyPair keyPair, bool unsafeInterfaces) { return ConvertTypeLibToAssembly(typeLib, asmFileName, (unsafeInterfaces ? TypeLibImporterFlags.UnsafeInterfaces : 0), notifySink, publicKey, keyPair, null, null); }
public void Perform() { if (_repackOptions.KeyContainer != null || (_repackOptions.KeyFile != null && File.Exists(_repackOptions.KeyFile))) { var snkp = default(StrongNameKeyPair); var publicKey = default(byte[]); if (_repackOptions.KeyContainer != null) { snkp = new StrongNameKeyPair(_repackOptions.KeyContainer); } else if (_repackOptions.KeyFile != null && File.Exists(_repackOptions.KeyFile)) { var keyFileContents = File.ReadAllBytes(_repackOptions.KeyFile); try { snkp = new StrongNameKeyPair(keyFileContents); publicKey = snkp.PublicKey; } catch (ArgumentException) { snkp = null; if (_repackOptions.DelaySign) { publicKey = keyFileContents; } } } _repackContext.TargetAssemblyDefinition.Name.PublicKey = publicKey; _repackContext.TargetAssemblyDefinition.Name.Attributes |= AssemblyAttributes.PublicKey; _repackContext.TargetAssemblyMainModule.Attributes |= ModuleAttributes.StrongNameSigned; if (!_repackOptions.DelaySign) { KeyPair = snkp; } } else { _repackContext.TargetAssemblyDefinition.Name.PublicKey = null; _repackContext.TargetAssemblyMainModule.Attributes &= ~ModuleAttributes.StrongNameSigned; } }
public void Perform() { if (_repackOptions.KeyFile != null && File.Exists(_repackOptions.KeyFile)) { var snkp = default(StrongNameKeyPair); using (var stream = new FileStream(_repackOptions.KeyFile, FileMode.Open, FileAccess.Read, FileShare.Read)) { snkp = new StrongNameKeyPair(stream); } _repackContext.TargetAssemblyDefinition.Name.PublicKey = snkp.PublicKey; _repackContext.TargetAssemblyDefinition.Name.Attributes |= AssemblyAttributes.PublicKey; _repackContext.TargetAssemblyMainModule.Attributes |= ModuleAttributes.StrongNameSigned; if (!_repackOptions.DelaySign) KeyPair = snkp; } else { _repackContext.TargetAssemblyDefinition.Name.PublicKey = null; _repackContext.TargetAssemblyMainModule.Attributes &= ~ModuleAttributes.StrongNameSigned; } }
/* * Initialize this AssemblyName. */ internal void Init(String name, byte[] publicKey, byte[] publicKeyToken, Version version, CultureInfo cultureInfo, AssemblyHashAlgorithm hashAlgorithm, AssemblyVersionCompatibility versionCompatibility, String codeBase, AssemblyNameFlags flags, StrongNameKeyPair keyPair, Assembly assembly) // Null if ref, matching Assembly if def { _Name = name; if (publicKey != null) { _PublicKey = new byte[publicKey.Length]; Array.Copy(publicKey, _PublicKey, publicKey.Length); } if (publicKeyToken != null) { _PublicKeyToken = new byte[publicKeyToken.Length]; Array.Copy(publicKeyToken, _PublicKeyToken, publicKeyToken.Length); } if (version != null) { _Version = (Version)version.Clone(); } _CultureInfo = cultureInfo; _HashAlgorithm = hashAlgorithm; _VersionCompatibility = versionCompatibility; _CodeBase = codeBase; _Flags = flags; _StrongNameKeyPair = keyPair; _Assembly = assembly; }
internal AssemblyName(string name, byte[] publicKey, byte[] publicKeyToken, Version version, CultureInfo cultureInfo, AssemblyHashAlgorithm hashAlgorithm, AssemblyVersionCompatibility versionCompatibility, string codeBase, AssemblyNameFlags flags, StrongNameKeyPair keyPair) // Null if ref, matching Assembly if def { _name = name; _publicKey = publicKey; _publicKeyToken = publicKeyToken; _version = version; _cultureInfo = cultureInfo; _hashAlgorithm = hashAlgorithm; _versionCompatibility = versionCompatibility; _codeBase = codeBase; _flags = flags; _strongNameKeyPair = keyPair; }
public void OnDeserialization(Object sender) { // Deserialization has already been performed if (m_siInfo == null) { return; } _Name = m_siInfo.GetString("_Name"); _PublicKey = (byte[])m_siInfo.GetValue("_PublicKey", typeof(byte[])); _PublicKeyToken = (byte[])m_siInfo.GetValue("_PublicKeyToken", typeof(byte[])); #if FEATURE_USE_LCID int lcid = (int)m_siInfo.GetInt32("_CultureInfo"); if (lcid != -1) { _CultureInfo = new CultureInfo(lcid); } #endif _CodeBase = m_siInfo.GetString("_CodeBase"); _Version = (Version)m_siInfo.GetValue("_Version", typeof(Version)); _HashAlgorithm = (AssemblyHashAlgorithm)m_siInfo.GetValue("_HashAlgorithm", typeof(AssemblyHashAlgorithm)); _StrongNameKeyPair = (StrongNameKeyPair)m_siInfo.GetValue("_StrongNameKeyPair", typeof(StrongNameKeyPair)); _VersionCompatibility = (AssemblyVersionCompatibility)m_siInfo.GetValue("_VersionCompatibility", typeof(AssemblyVersionCompatibility)); _Flags = (AssemblyNameFlags)m_siInfo.GetValue("_Flags", typeof(AssemblyNameFlags)); try { _HashAlgorithmForControl = (AssemblyHashAlgorithm)m_siInfo.GetValue("_HashAlgorithmForControl", typeof(AssemblyHashAlgorithm)); _HashForControl = (byte[])m_siInfo.GetValue("_HashForControl", typeof(byte[])); } catch (SerializationException) { // RTM did not have these defined _HashAlgorithmForControl = AssemblyHashAlgorithm.None; _HashForControl = null; } m_siInfo = null; }
public static void Sign(this IFile sourceAssembly, IFile destinationAssembly, StrongNameKeyPair key, Version version = null) { var sourcePdbFile = sourceAssembly.Parent.GetFile(sourceAssembly.NameWithoutExtension + ".pdb"); var sourcePdbStream = (Stream)null; //sourcePdbFile.Exists ? sourcePdbFile.OpenRead() : null; using(var sourceStream = sourceAssembly.OpenRead()) { var readerParameters = new ReaderParameters(); if (sourcePdbStream != null) { readerParameters.SymbolStream = sourcePdbStream; readerParameters.ReadSymbols = true; } var assembly = AssemblyDefinition.ReadAssembly(sourceStream, readerParameters); var name = assembly.Name; name.HashAlgorithm = AssemblyHashAlgorithm.SHA1; name.PublicKey = key.PublicKey; if (version != null) name.Version = version; assembly.Name.HasPublicKey = true; var writerParameters = new WriterParameters() { StrongNameKeyPair = key }; var destinationPdbStream = sourcePdbStream != null ? destinationAssembly.Parent.GetFile(destinationAssembly.NameWithoutExtension + ".pdb").OpenWrite() : null; if (sourcePdbStream != null) { writerParameters.SymbolStream = destinationPdbStream; writerParameters.WriteSymbols = true; } using (var destinationStream = destinationAssembly.Open(FileMode.Create, FileAccess.ReadWrite, FileShare.None)) { assembly.Write(destinationStream, writerParameters); } if (sourcePdbStream != null) { sourcePdbStream.Close(); destinationPdbStream.Close(); } } }
/// <summary>制作此 <see cref="T:System.Reflection.AssemblyName" /> 对象的副本。</summary> /// <returns>作为 <see cref="T:System.Reflection.AssemblyName" /> 对象副本的对象。</returns> public object Clone() { AssemblyName assemblyName = new AssemblyName(); string name = this._Name; byte[] publicKey = this._PublicKey; byte[] publicKeyToken = this._PublicKeyToken; Version version = this._Version; CultureInfo cultureInfo = this._CultureInfo; int num1 = (int)this._HashAlgorithm; int num2 = (int)this._VersionCompatibility; string codeBase = this._CodeBase; int num3 = (int)this._Flags; StrongNameKeyPair keyPair = this._StrongNameKeyPair; assemblyName.Init(name, publicKey, publicKeyToken, version, cultureInfo, (AssemblyHashAlgorithm)num1, (AssemblyVersionCompatibility)num2, codeBase, (AssemblyNameFlags)num3, keyPair); byte[] numArray = this._HashForControl; assemblyName._HashForControl = numArray; int num4 = (int)this._HashAlgorithmForControl; assemblyName._HashAlgorithmForControl = (AssemblyHashAlgorithm)num4; return((object)assemblyName); }
internal void Init(string name, byte[] publicKey, byte[] publicKeyToken, Version version, CultureInfo cultureInfo, AssemblyHashAlgorithm hashAlgorithm, AssemblyVersionCompatibility versionCompatibility, string codeBase, AssemblyNameFlags flags, StrongNameKeyPair keyPair) // Null if ref, matching Assembly if def { _name = name; if (publicKey != null) { _publicKey = new byte[publicKey.Length]; Array.Copy(publicKey, 0, _publicKey, 0, publicKey.Length); } if (publicKeyToken != null) { _publicKeyToken = new byte[publicKeyToken.Length]; Array.Copy(publicKeyToken, 0, _publicKeyToken, 0, publicKeyToken.Length); } if (version != null) { _version = (Version)version.Clone(); } _cultureInfo = cultureInfo; _hashAlgorithm = hashAlgorithm; _versionCompatibility = versionCompatibility; _codeBase = codeBase; _flags = flags; _strongNameKeyPair = keyPair; }
internal void Init(string name, byte[] publicKey, byte[] publicKeyToken, Version version, CultureInfo cultureInfo, AssemblyHashAlgorithm hashAlgorithm, AssemblyVersionCompatibility versionCompatibility, string codeBase, AssemblyNameFlags flags, StrongNameKeyPair keyPair) { this._Name = name; if (publicKey != null) { this._PublicKey = new byte[publicKey.Length]; Array.Copy((Array)publicKey, (Array)this._PublicKey, publicKey.Length); } if (publicKeyToken != null) { this._PublicKeyToken = new byte[publicKeyToken.Length]; Array.Copy((Array)publicKeyToken, (Array)this._PublicKeyToken, publicKeyToken.Length); } if (version != (Version)null) { this._Version = (Version)version.Clone(); } this._CultureInfo = cultureInfo; this._HashAlgorithm = hashAlgorithm; this._VersionCompatibility = versionCompatibility; this._CodeBase = codeBase; this._Flags = flags; this._StrongNameKeyPair = keyPair; }