public GeneratedCodeObfuscator(BuildModule module, MemberNameGenerator nameGenerator)
        {
            if (module == null)
            {
                throw new ArgumentNullException("module");
            }

            if (nameGenerator == null)
            {
                throw new ArgumentNullException("nameGenerator");
            }

            _module            = module;
            _nameGenerator     = nameGenerator;
            _mainType          = _module.MainType;
            _mainTypeNamespace = _module.MainTypeNamespace;

            if (_mainType != null)
            {
                _callProxyBuilder = new MainTypeCallProxyBuilder(_module);

                if (_module.IsPrimeModule)
                {
                    _functionPointerBuilder = new MainTypeFunctionPointerBuilder(_module);
                }
            }
        }
 public static void Build(BuildModule module)
 {
     foreach (BuildType type in module.Types)
     {
         Build(type);
     }
 }
 public static void Obfuscate(BuildModule module, bool ignoreEncryptIL = false)
 {
     foreach (BuildType type in module.Types)
     {
         Obfuscate(type, ignoreEncryptIL);
     }
 }
 public static void Unmark(BuildModule module)
 {
     foreach (BuildType type in module.Types)
     {
         Unmark(type);
     }
 }
Exemple #5
0
 private void Analyze(BuildModule module)
 {
     foreach (BuildType type in module.Types)
     {
         Analyze(type);
     }
 }
Exemple #6
0
 public static void Analyze(BuildModule module)
 {
     foreach (BuildType type in module.Types)
     {
         Analyze(type);
     }
 }
Exemple #7
0
 public static void Devirtualize(BuildModule module)
 {
     foreach (BuildType type in module.Types)
     {
         Devirtualize(type);
     }
 }
Exemple #8
0
 public static void Seal(BuildModule module)
 {
     foreach (BuildType type in module.Types)
     {
         Seal(type);
     }
 }
		private bool Build(ref ModuleReference moduleRef, BuildModule module)
		{
			if (!module.NameChanged)
				return false;

			moduleRef = new ModuleReference(module.NewName);
			return true;
		}
 internal void Close()
 {
     _buffer     = null;
     _blobs      = null;
     _strings    = null;
     _signatures = null;
     _module     = null;
 }
        private void Analyze(BuildModule module)
        {
            Process(module.CustomAttributes, module);

            foreach (BuildType type in module.Types)
            {
                Analyze(type);
            }
        }
Exemple #12
0
        public DelegateTypeGenerator(BuildModule module)
        {
            if (module == null)
            {
                throw new ArgumentNullException("module");
            }

            _module = module;
        }
        public ILCryptoMethodBuilder(BuildAssembly assembly)
        {
            if (assembly == null)
            {
                throw new ArgumentNullException("assembly");
            }

            _module = (BuildModule)assembly.Module;
        }
        public AssemblyMergeGenerator(BuildModule module, string[] assemblyNames)
        {
            if (module == null)
            {
                throw new ArgumentNullException("module");
            }

            _module        = module;
            _assemblyNames = assemblyNames;
        }
        public ILCryptoMapper(BuildModule module)
        {
            if (module == null)
            {
                throw new ArgumentNullException("module");
            }

            _module            = module;
            _mainTypeNamespace = _module.MainTypeNamespace;
        }
        public DelegateTypeBuilder(BuildModule module)
        {
            if (module == null)
            {
                throw new ArgumentNullException("module");
            }

            _module = module;
            Load();
        }
        public AssemblyEmbedder(BuildModule module)
        {
            if (module == null)
            {
                throw new ArgumentNullException("module");
            }

            _module  = module;
            _storage = module.ResourceStorage;
        }
Exemple #18
0
        private void Load(BuildModule module)
        {
            foreach (BuildType type in module.Types)
            {
                Load(type);
            }

            foreach (var exportedType in module.ExportedTypes)
            {
                _existingStrings.TryAdd(exportedType.GetOutermostType().Name);
            }
        }
        internal void Load(BuildModule module)
        {
            if (_module != null)
            {
                throw new InvalidOperationException();
            }

            _module = module;

            if (_isNew)
            {
                if (_bufferLength == 0)
                {
                    var image = _module.Image;

                    _moduleTableOffset   = BuildAssembly.RowSize * image.GetAssemblyCount();
                    _typeTableOffset     = _moduleTableOffset + BuildModule.RowSize;
                    _methodTableOffset   = _typeTableOffset + (BuildType.RowSize * image.GetTypeDefCount());
                    _fieldTableOffset    = _methodTableOffset + (BuildMethod.RowSize * image.GetMethodCount());
                    _propertyTableOffset = _fieldTableOffset + (BuildField.RowSize * image.GetFieldCount());
                    _eventTableOffset    = _propertyTableOffset + (BuildProperty.RowSize * image.GetPropertyCount());
                    _resourceTableOffset = _eventTableOffset + (BuildEvent.RowSize * image.GetEventCount());
                    _bufferLength        = _resourceTableOffset + (BuildResource.RowSize * image.GetManifestResourceCount());
                }

                _buffer     = new byte[_bufferLength];
                _blobs      = new BlobList();
                _strings    = new StringSerializer();
                _signatures = new SignatureList(_strings);
                _objects    = new ModuleObjectState(this);
            }
            else
            {
                using (var accessor = new StreamAccessor(new FileStream(_stateFilePath, FileMode.Open, FileAccess.Read, FileShare.None)))
                {
                    _bufferLength = accessor.Read7BitEncodedInt();
                    _buffer       = accessor.ReadBytes(_bufferLength);

                    _objects = new ModuleObjectState(this, accessor);

                    _blobs = new BlobList(accessor);

                    var stringBlob = new Blob(accessor.ReadBytes(accessor.Read7BitEncodedInt()));
                    StrongCryptoUtils.Decrypt(stringBlob.GetBuffer(), 0, stringBlob.Length);
                    _strings = new StringSerializer(new BlobAccessor(stringBlob));

                    _signatures = new SignatureList(accessor, _strings);
                }
            }

            _strings.DelayWrite    = true;
            _signatures.DelayWrite = true;
        }
Exemple #20
0
        public static void Change(BuildModule module)
        {
            if (module.NameChanged)
            {
                module.Name = module.NewName;
            }

            foreach (BuildType type in module.Types)
            {
                Change(type);
            }
        }
        public static void Strip(BuildModule module)
        {
            if (module.StripObfuscationAttribute)
            {
                CA.ObfuscationAttribute.RemoveMarkedAsStrip(module.CustomAttributes);
            }

            foreach (BuildType type in module.Types)
            {
                Strip(type);
            }
        }
        public ILCryptoBlobBuilder(BuildAssembly assembly, HashList <string> strings)
        {
            if (assembly == null)
            {
                throw new ArgumentNullException("assembly");
            }

            if (strings == null)
            {
                throw new ArgumentNullException("strings");
            }

            _module  = (BuildModule)assembly.Module;
            _strings = strings;
            _storage = assembly.ResourceStorage;
        }
Exemple #23
0
        public StringLoaderGenerator(BuildAssembly assembly, IReadOnlyList <string> strings)
        {
            if (assembly == null)
            {
                throw new ArgumentNullException("assembly");
            }

            if (strings == null)
            {
                throw new ArgumentNullException("strings");
            }

            _assembly = assembly;
            _module   = (BuildModule)assembly.Module;
            _strings  = strings;
        }
        public StringObfuscator(BuildAssembly assembly, HashList <string> strings)
        {
            if (assembly == null)
            {
                throw new ArgumentNullException("assembly");
            }

            if (strings == null)
            {
                throw new ArgumentNullException("strings");
            }

            _module  = (BuildModule)assembly.Module;
            _strings = strings;

            var mainType = _module.MainType;

            _stringFieldRef =
                new FieldReference(
                    "Strings",
                    new ArrayType(
                        TypeReference.GetPrimitiveType(PrimitiveTypeCode.String, _module.Assembly)),
                    new TypeReference(mainType.Name, mainType.Namespace, false));
        }
Exemple #25
0
 internal MainTypeCallProxyBuilder(BuildModule module)
 {
     _module   = module;
     _mainType = module.MainType;
     _random   = module.RandomGenerator;
 }
Exemple #26
0
 protected internal BuildMethod(BuildModule module, int rid, int typeRID)
     : base(module, rid, typeRID)
 {
     _state       = module.State;
     _stateOffset = _state.GetMethodOffset(rid);
 }
Exemple #27
0
 protected internal BuildType(BuildModule module, int rid, int enclosingTypeRID)
     : base(module, rid, enclosingTypeRID)
 {
     _state       = module.State;
     _stateOffset = _state.GetTypeOffset(rid);
 }
        public static void Generate(BuildModule module, string[] assemblyNames)
        {
            var generator = new AssemblyMergeGenerator(module, assemblyNames);

            generator.Generate();
        }
        public static void Obfuscate(BuildModule module, MemberNameGenerator nameGenerator)
        {
            var obfuscator = new GeneratedCodeObfuscator(module, nameGenerator);

            obfuscator.Obfuscate();
        }
 protected internal BuildProperty(BuildModule module, int rid, int typeRID)
     : base(module, rid, typeRID)
 {
     _state       = module.State;
     _stateOffset = _state.GetPropertyOffset(rid);
 }