public override PatchResult Patch(ICommonAssembly assembly)
        {
            const string constsTypeFullName = "Consts";

            log.Info($"Patching '{constsTypeFullName}' type...");

            var constsType = assembly.GetCommonTypeFromThisAssembly(constsTypeFullName);

            if (constsType == null)
            {
                log.Info($"Not found '{constsTypeFullName}' type");
                return(PatchResult.Continue);
            }

            constsType.Load().GetField("PublicKey").MonoCecil.Constant = applicationPatcherSelfConfiguration.MonoCecilNewPublicKey.ToHexString();

            log.Info($"'{constsTypeFullName}' type was patched");
            return(PatchResult.Continue);
        }
示例#2
0
        public override PatchResult Patch(ICommonAssembly assembly)
        {
            log.Info("Patching selected types...");
            var foundSelectedPatchingTypes = applicationPatcherSelfConfiguration.MonoCecilSelectedPatchingTypeFullNames
                                             .Select(typeFullName => assembly.GetCommonTypeFromThisAssembly(typeFullName))
                                             .Where(type => type != null)
                                             .ToArray();

            if (!foundSelectedPatchingTypes.Any())
            {
                log.Info("Not found selected types");
                return(PatchResult.Continue);
            }

            log.Debug("Selected types found:", foundSelectedPatchingTypes.Select(type => type.FullName).OrderBy(fullName => fullName));

            foreach (var type in foundSelectedPatchingTypes)
            {
                log.Info($"Patching type '{type.FullName}'...");

                log.Info($"Loading type '{type.FullName}'...");
                type.Load();
                log.Info($"Type '{type.FullName}' was loaded");

                type.MonoCecil.IsSealed = false;

                CreateEmptyInternalConstructor(assembly, type);
                SetVirtualOnProperties(type);
                SetVirtualOnMethods(type);

                log.Info($"Type '{type.FullName}' was patched");
            }

            foundSelectedPatchingTypes.ForEach(type => type.MonoCecil.IsSealed = false);
            log.Info("Selected types was patched");
            return(PatchResult.Continue);
        }
 public static ICommonType GetCommonTypeFromThisAssembly(this ICommonAssembly commonAssembly, IHasType hasType, bool throwExceptionIfNotFound = false)
 {
     return(commonAssembly.GetCommonTypeFromThisAssembly(hasType.Type, throwExceptionIfNotFound));
 }
 public static bool TryGetCommonTypeFromThisAssembly(this ICommonAssembly commonAssembly, string typeFullName, out ICommonType foundCommonType)
 {
     return((foundCommonType = commonAssembly.GetCommonTypeFromThisAssembly(typeFullName)) != null);
 }
 public static bool TryGetCommonTypeFromThisAssembly(this ICommonAssembly commonAssembly, IHasType hasType, out ICommonType foundCommonType)
 {
     return((foundCommonType = commonAssembly.GetCommonTypeFromThisAssembly(hasType)) != null);
 }