Exemple #1
0
        private static void DoObfuscateByConfig(string[] assemblyPath)
        {
            ObfuscatorConfig obfuscatorConfig = AssetDatabase.LoadAssetAtPath <ObfuscatorConfig>(Const.ConfigAssetPath);

            if (obfuscatorConfig == null)
            {
                Debug.Log(Const.ConfigAssetPath + "不存在");
                return;
            }

            if (!obfuscatorConfig.enableCodeObfuscator)
            {
                return;
            }

            string uselessCodeLibAssemblyPath = obfuscatorConfig.uselessCodeLibPath;

            int randomSeed = obfuscatorConfig.randomSeed;

            if (obfuscatorConfig.useTimeSpan)
            {
                randomSeed = (int)DateTime.Now.Ticks;
            }

            bool              enableNameObfuscate     = obfuscatorConfig.enableNameObfuscate;
            bool              enableCodeInject        = obfuscatorConfig.enableCodeInject;
            ObfuscateType     nameObfuscateType       = obfuscatorConfig.nameObfuscateType;
            ObfuscateType     codeInjectObfuscateType = obfuscatorConfig.codeInjectType;
            ObfuscateNameType obfuscateNameType       = obfuscatorConfig.obfuscateNameType;
            int garbageMethodMultiplePerClass         = obfuscatorConfig.GarbageMethodMultiplePerClass;
            int insertMethodCountPerMethod            = obfuscatorConfig.InsertMethodCountPerMethod;

            DoObfuscate(assemblyPath, uselessCodeLibAssemblyPath, randomSeed, enableNameObfuscate, enableCodeInject, nameObfuscateType, codeInjectObfuscateType, obfuscateNameType, garbageMethodMultiplePerClass, insertMethodCountPerMethod);
        }
Exemple #2
0
 private static void DoObfuscate(string[] assemblyDllPath, string uselessCodeLibAssemblyPath, int randomSeed, bool switchNameObfuscate, bool switchCodeInject,
                                 ObfuscateType nameObfuscateType, ObfuscateType codeInjectObfuscateType, ObfuscateNameType obfuscateNameType,
                                 int garbageMethodMultiplePerClass, int insertMethodCountPerMethod)
 {
     CodeObfuscator.DoObfuscate(assemblyDllPath, uselessCodeLibAssemblyPath, randomSeed, switchNameObfuscate, switchCodeInject,
                                nameObfuscateType, codeInjectObfuscateType, obfuscateNameType, garbageMethodMultiplePerClass, insertMethodCountPerMethod);
 }
        protected virtual IEnumerable SelectOpportunities(List <string> fields)
        {
            ObfuscateType filter = Filter.Current;

            if (filter.MasterEntity != "OP")
            {
                return(new List <PXResult <CRContact, BAccount> >());
            }

            var view = new PXView(this, true, BqlCommand.CreateInstance(
                                      typeof(Select2 <, ,>),
                                      typeof(CRContact),
                                      typeof(LeftJoin <BAccount, On <BAccount.bAccountID, Equal <CRContact.bAccountID> > >),
                                      typeof(Where <, ,>),
                                      typeof(CRContactExt.pseudonymizationStatus), typeof(Equal <>), GetPseudonymizationStatus,
                                      typeof(Or <,>), typeof(CRContactExt.pseudonymizationStatus), typeof(IsNull)));

            List <PXFilterRow> filters = new List <PXFilterRow>();

            foreach (PXFilterRow filterRow in PXView.Filters)
            {
                filters.Add(filterRow);
            }

            if (!String.IsNullOrWhiteSpace(filter.Search))
            {
                for (int i = 0; i < fields.Count; i++)
                {
                    filters.Add(new PXFilterRow()
                    {
                        OrOperator    = true,
                        OpenBrackets  = i == 0 ? 1 : 0,
                        DataField     = fields[i],
                        Condition     = PXCondition.LIKE,
                        Value         = filter.Search,
                        CloseBrackets = i == fields.Count - 1 ? 1 : 0
                    });
                }
            }

            if (filter.ConsentExpired == true)
            {
                view.WhereAnd <Where <CRContact.consentExpirationDate, LessEqual <Now> > >();
            }

            if (filter.NoConsent == true)
            {
                view.WhereAnd <Where <CRContact.consentDate, IsNull> >();
            }

            var startRow  = PXView.StartRow;
            int totalRows = 0;
            var list      = view.Select(PXView.Currents, PXView.Parameters, PXView.Searches, null, null, filters.ToArray(), ref startRow, PXView.MaximumRows, ref totalRows);

            PXView.StartRow = 0;
            return(list);
        }
        public void Init(ObfuscateType obfuscateType, int garbageMethodMultiplePerClass, int insertMethodCountPerMethod)
        {
            Init(obfuscateType);

            if (garbageMethodMultiplePerClass < 0 || insertMethodCountPerMethod < 0)
            {
                Debug.LogError("Insert Garbage Code Param Error");
                return;
            }

            GarbageMethodMultiplePerClass = garbageMethodMultiplePerClass;
            InsertMethodCountPerMethod    = insertMethodCountPerMethod;
        }
        public override void Init(ObfuscateType obfuscateType)
        {
            this.obfuscateType = obfuscateType;

            Dictionary <WhiteListType, string> whiteListPathDic     = new Dictionary <WhiteListType, string>();
            Dictionary <WhiteListType, string> obfuscateListPathDic = new Dictionary <WhiteListType, string>();

            whiteListPathDic.Add(WhiteListType.Namespace, string.Format(Const.WhiteList_NamespacePath, Symbol));
            whiteListPathDic.Add(WhiteListType.Class, string.Format(Const.WhiteList_ClassPath, Symbol));
            whiteListPathDic.Add(WhiteListType.Method, string.Format(Const.WhiteList_MethodPath, Symbol));

            obfuscateListPathDic.Add(WhiteListType.Namespace, string.Format(Const.ObfuscateList_NamespacePath, Symbol));
            obfuscateListPathDic.Add(WhiteListType.Class, string.Format(Const.ObfuscateList_ClassPath, Symbol));
            obfuscateListPathDic.Add(WhiteListType.Method, string.Format(Const.ObfuscateList_MethodPath, Symbol));



            whiteList         = new WhiteList(whiteListPathDic);
            obfuscateList     = new WhiteList(obfuscateListPathDic);
            codeInjectInfoDic = new Dictionary <string, string>();
            injectMethodList  = new List <string>();
        }
Exemple #6
0
        public override void Init(ObfuscateType obfuscateType)
        {
            this.obfuscateType = obfuscateType;

            Dictionary <WhiteListType, string> whiteListPathDic     = new Dictionary <WhiteListType, string>();
            Dictionary <WhiteListType, string> obfuscateListPathDic = new Dictionary <WhiteListType, string>();

            whiteListPathDic.Add(WhiteListType.Namespace, string.Format(Const.WhiteList_NamespacePath, Symbol));
            whiteListPathDic.Add(WhiteListType.NameSpcaceNameOnly, string.Format(Const.WhiteList_NamespaceNameOnlyPath, Symbol));
            whiteListPathDic.Add(WhiteListType.Class, string.Format(Const.WhiteList_ClassPath, Symbol));
            whiteListPathDic.Add(WhiteListType.ClassNameOnly, string.Format(Const.WhiteList_ClassNameOnlyPath, Symbol));
            whiteListPathDic.Add(WhiteListType.Method, string.Format(Const.WhiteList_MethodPath, Symbol));
            whiteListPathDic.Add(WhiteListType.Member, string.Format(Const.WhiteList_MemberPath, Symbol));

            obfuscateListPathDic.Add(WhiteListType.Namespace, string.Format(Const.ObfuscateList_NamespacePath, Symbol));
            obfuscateListPathDic.Add(WhiteListType.NameSpcaceNameOnly, string.Format(Const.ObfuscateList_NamespaceExceptNamespaceNamePath, Symbol));
            obfuscateListPathDic.Add(WhiteListType.Class, string.Format(Const.ObfuscateList_ClassPath, Symbol));
            obfuscateListPathDic.Add(WhiteListType.ClassNameOnly, string.Format(Const.ObfuscateList_ClassExceptClassNamePath, Symbol));
            obfuscateListPathDic.Add(WhiteListType.Method, string.Format(Const.ObfuscateList_MethodPath, Symbol));
            obfuscateListPathDic.Add(WhiteListType.Member, string.Format(Const.ObfuscateList_MemberPath, Symbol));

            whiteList     = new WhiteList(whiteListPathDic);
            obfuscateList = new WhiteList(obfuscateListPathDic);
        }
 public abstract void Init(ObfuscateType obfuscateType);
Exemple #8
0
        public static void DoObfuscate(string[] assemblyPath, string uselessCodeLibAssemblyPath, int randomSeed, bool enableNameObfuscate, bool enableCodeInject,
                                       ObfuscateType nameObfuscateType, ObfuscateType codeInjectObfuscateType, ObfuscateNameType obfuscateNameType, int garbageMethodMultiplePerClass, int insertMethodCountPerMethod)
        {
            if (Application.isPlaying || EditorApplication.isCompiling)
            {
                Debug.Log("You need stop play mode or wait compiling finished");
                return;
            }

            if (assemblyPath.Length <= 0)
            {
                Debug.LogError("Obfuscate dll paths length: 0");
            }

            Debug.Log("Code Obfuscate Start");

            var resolver = new DefaultAssemblyResolver();

            foreach (var item in Const.ResolverSearchDirs)
            {
                resolver.AddSearchDirectory(item);
            }
            var readerParameters = new ReaderParameters {
                AssemblyResolver = resolver, ReadSymbols = true
            };

            AssemblyDefinition[] assemblies = new AssemblyDefinition[assemblyPath.Length];
            for (int i = 0; i < assemblyPath.Length; i++)
            {
                var assembly = AssemblyDefinition.ReadAssembly(assemblyPath[i], readerParameters);

                if (assembly == null)
                {
                    Debug.LogError(string.Format("Code Obfuscate Load assembly failed: {0}", assemblyPath[i]));
                    return;
                }

                assemblies[i] = assembly;
            }

            AssemblyDefinition garbageCodeAssmbly = null;

            if (enableCodeInject)
            {
                garbageCodeAssmbly = AssemblyDefinition.ReadAssembly(uselessCodeLibAssemblyPath, readerParameters);

                if (garbageCodeAssmbly == null)
                {
                    Debug.LogError(string.Format("Code Obfuscate Load assembly failed: {0}", uselessCodeLibAssemblyPath));
                    return;
                }
            }

            try
            {
                //初始化组件
                ObfuscatorHelper.Init(randomSeed);
                NameObfuscate.Instance.Init(nameObfuscateType);
                CodeInject.Instance.Init(codeInjectObfuscateType, garbageMethodMultiplePerClass, insertMethodCountPerMethod);
                NameFactory.Instance.Load(obfuscateNameType);


                //混淆并注入垃圾代码
                for (int i = 0; i < assemblies.Length; i++)
                {
                    var module = assemblies[i].MainModule;

                    if (enableCodeInject)
                    {
                        CodeInject.Instance.DoObfuscate(assemblies[i], garbageCodeAssmbly);
                    }
                    if (enableNameObfuscate)
                    {
                        NameObfuscate.Instance.DoObfuscate(assemblies[i]);
                    }
                }

                //把每个dll对其他被混淆的dll的引用名字修改为混淆后的名字
                if (enableNameObfuscate)
                {
                    foreach (var assembly in assemblies)
                    {
                        foreach (var item in assembly.MainModule.GetMemberReferences())
                        {
                            try
                            {
                                if (item is FieldReference)
                                {
                                    FieldReference fieldReference = item as FieldReference;
                                    Dictionary <BaseObfuscateItem, string> dic = NameFactory.Instance.GetOld_New_NameDic(NameType.Filed);
                                    FieldObfuscateItem fieldObfuscateItem      = new FieldObfuscateItem(fieldReference.DeclaringType.Namespace, fieldReference.DeclaringType.Name, fieldReference.Name);
                                    if (NameFactory.Instance.AlreadyHaveRandomName(NameType.Filed, fieldObfuscateItem))
                                    {
                                        item.Name = NameFactory.Instance.GetRandomName(NameType.Filed, fieldObfuscateItem);
                                    }
                                }
                                else if (item is PropertyReference)
                                {
                                    PropertyReference propertyReference = item as PropertyReference;

                                    PropertyObfuscateItem propertyObfuscateItem = new PropertyObfuscateItem(propertyReference.DeclaringType.Namespace, propertyReference.DeclaringType.Name, propertyReference.Name);

                                    if (NameFactory.Instance.AlreadyHaveRandomName(NameType.Property, propertyObfuscateItem))
                                    {
                                        item.Name = NameFactory.Instance.GetRandomName(NameType.Property, propertyObfuscateItem);
                                    }
                                }
                                else if (item is MethodReference)
                                {
                                    MethodReference methodReference = item as MethodReference;

                                    MethodObfuscateItem methodObfuscateItem = new MethodObfuscateItem(methodReference.DeclaringType.Namespace, methodReference.DeclaringType.Name, methodReference.Name);

                                    if (NameFactory.Instance.AlreadyHaveRandomName(NameType.Method, methodObfuscateItem))
                                    {
                                        item.Name = NameFactory.Instance.GetRandomName(NameType.Method, methodObfuscateItem);
                                    }
                                }
                            }
                            catch
                            {
                                continue;
                            }
                        }

                        foreach (var item in assembly.MainModule.GetTypeReferences())
                        {
                            try
                            {
                                TypeDefinition         typeDefinition         = item.Resolve();
                                TypeObfuscateItem      typeObfuscateItem      = ObfuscateItemFactory.Create(typeDefinition);
                                NamespaceObfuscateItem namespaceObfuscateItem = ObfuscateItemFactory.Create(typeDefinition.Namespace, typeDefinition.Module);

                                if (NameFactory.Instance.AlreadyHaveRandomName(NameType.Class, typeObfuscateItem))
                                {
                                    item.Name = NameFactory.Instance.GetRandomName(NameType.Class, typeObfuscateItem);
                                }
                                if (NameFactory.Instance.AlreadyHaveRandomName(NameType.Namespace, namespaceObfuscateItem))
                                {
                                    item.Namespace = NameFactory.Instance.GetRandomName(NameType.Namespace, namespaceObfuscateItem);
                                }
                            }
                            catch
                            {
                                continue;
                            }
                        }
                    }
                }


                for (int i = 0; i < assemblies.Length; i++)
                {
                    assemblies[i].Write(assemblyPath[i], new WriterParameters {
                        WriteSymbols = true
                    });
                }

                Debug.Log("Code Obfuscate Completed!");
            }
            catch (Exception ex)
            {
                Debug.LogError(string.Format("Code Obfuscate failed: {0}", ex));
            }
            finally
            {
                for (int i = 0; i < assemblies.Length; i++)
                {
                    assemblies[i].MainModule.SymbolReader.Dispose();
                }

                if (garbageCodeAssmbly != null && garbageCodeAssmbly.MainModule.SymbolReader != null)
                {
                    garbageCodeAssmbly.MainModule.SymbolReader.Dispose();
                }

                //输出 名字-混淆后名字 的map
                NameFactory.Instance.OutputNameMap(Const.NameMapPath);
            }
        }