Esempio n. 1
0
 private void lblSecurity_Click(object sender, EventArgs e)
 {
     this.pnlMain.Controls.Clear();
     this.pnlMain.Controls.Add(_tabSecurity);
     _mainTabType = MainType.Security;
     localization();
 }
Esempio n. 2
0
		public PeHeader(MainType mainType, MyPEImage peImage) {
			uint headerOffset;
			version = GetHeaderOffsetAndVersion(peImage, out headerOffset);
			headerData = peImage.OffsetReadBytes(headerOffset, 0x1000);

			switch (version) {
			case EncryptionVersion.V1:
			case EncryptionVersion.V2:
			case EncryptionVersion.V3:
			case EncryptionVersion.V4:
			case EncryptionVersion.V5:
			default:
				xorKey = 0x7ABF931;
				break;

			case EncryptionVersion.V6:
				xorKey = 0x7ABA931;
				break;

			case EncryptionVersion.V7:
				xorKey = 0x8ABA931;
				break;

			case EncryptionVersion.V8:
				if (CheckMcKeyRva(peImage, 0x99BA9A13))
					break;
				if (CheckMcKeyRva(peImage, 0x18ABA931))
					break;
				if (CheckMcKeyRva(peImage, 0x18ABA933))
					break;
				break;
			}
		}
        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 void Generate()
        {
            if (_assemblyNames.Length == 0)
            {
                return;
            }

            BuildData();

            _mainType = _module.MainType;

            // Methods
            var methods    = _mainType.Methods;
            var initMethod = (BuildMethod)methods.Add();

            MergeInitialize(initMethod);
            OnMergedAssemblyResolve(methods.Add());
            GetMergedAssemblyNames(methods.Add());

            _mainType.AddStartupMethod(initMethod);

            // Fields
            GenerateFields();
            _mainType.AddLockObjectField("_mergeLockObject");

            // Dependencies
            _mainType.GenerateGetAssemblyName();
            _mainType.GenerateReadString();
            _mainType.GenerateRead7BitEncodedInt();
        }
Esempio n. 5
0
        public ViewResult UpdateMainType(MainType _mtype)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    MainType m = Services.MainType.GetLambda(x => x.MainTypeName == _mtype.MainTypeName).FirstOrDefault();
                    if (m != null)
                    {
                        ViewBag.NameError = true;
                    }
                    else
                    {
                        Services.MainType.Update(_mtype);
                        ViewBag.Error = false;
                    }
                }
                catch (Exception)
                {
                    ViewBag.NameError = true;
                }

                ModelState.Clear();
                return(View());
            }
            else
            {
                ViewBag.NameError = true;
                return(View());
            }
        }
		public DecrypterInfo(MainType mainType, byte[] fileData) {
			this.mainType = mainType;
			this.peImage = new MyPEImage(fileData);
			this.peHeader = new PeHeader(mainType, peImage);
			this.mcKey = new McKey(peImage, peHeader);
			this.fileData = fileData;
		}
 /// <summary>
 /// 执行mainclass中的方法
 /// </summary>
 /// <param name="functionname"></param>
 /// <param name=""></param>
 /// <param name=""></param>
 public void DoFunctionFromMainClass(string functionname, params object [] param)
 {
     if (MainClass == null)
     {
         throw new Exception("mainclass 为null");
     }
     MainType.GetMethod(functionname).Invoke(this.MainClass, param.ToArray());
 }
Esempio n. 8
0
        public void TestMethod2()
        {
            MainType t = new MainType();

            Func <MainType, object> ex = GetPropertyFunc <MainType>("REFTYPE.VALUETYPE");
            object val = ex(t);

            Assert.AreEqual(default(Guid), val);
        }
Esempio n. 9
0
        public void TestMethod6()
        {
            MainType t = new MainType();

            Func <MainType, object> ex = GetPropertyFunc <MainType>("REFTYPE.REFTYPE");
            object val = ex(t);

            Assert.AreEqual(default(TestRefType2), val);
        }
Esempio n. 10
0
 private void lblConfig_Click(object sender, EventArgs e)
 {
     this.pnlMain.Controls.Clear();
     //_tabConfig.Dock = DockStyle.Fill;
     _tabConfig.Main = _main;
     this.pnlMain.Controls.Add(_tabConfig);
     _mainTabType = MainType.Config;
     localization();
 }
Esempio n. 11
0
        private void lblEnegry_Click(object sender, EventArgs e)
        {
            this.pnlMain.Controls.Clear();
            //UC_TestControl con = new UC_TestControl();
            //_tabEnergy.Dock = DockStyle.Fill;
            this.pnlMain.Controls.Add(_tabEnergy);
            _mainTabType = MainType.Energy;

            localization();
        }
Esempio n. 12
0
        internal void RemoveMainType()
        {
            if (_mainType == null)
            {
                return;
            }

            Types.Remove(_mainType);
            _mainType = null;
        }
Esempio n. 13
0
        /// <summary>
        /// Creates the entry point for an assembly if it is supposed to be saved.
        /// The entry point method basically calls the Run method and discards the result.
        /// </summary>
        private void createEntryPoint()
        {
            var ep = MainType.CreateMethod(EntityNames.EntryPointMethodName, "Void", args: null, isStatic: true);

            ep.Kind = TypeContentsKind.AutoGenerated;
            ep.Body = Expr.Block(
                Expr.Invoke(Expr.New(EntityNames.MainTypeName), "Run"),
                Expr.Unit()
                );
        }
        public static string GetContentTypeFromPath(this string path)
        {
            var ext = Path.GetExtension(path).ToLowerInvariant();

            if (MainType.ContainsKey(ext))
            {
                return(MainType[ext]);
            }
            return("text/plain");
        }
Esempio n. 15
0
		public ProxyCallFixer(ModuleDefMD module, MainType mainType, ProxyCallFixer oldOne)
			: base(module, oldOne) {
			this.mainType = mainType;
			info.proxyType = Lookup(oldOne.info.proxyType, "Could not find proxyType");
			info.initMethod = Lookup(oldOne.info.initMethod, "Could not find initMethod");
			info.dataField = Lookup(oldOne.info.dataField, "Could not find dataField");
			info.ilgeneratorType = Lookup(oldOne.info.ilgeneratorType, "Could not find ilgeneratorType");
			info.fieldInfoType = Lookup(oldOne.info.fieldInfoType, "Could not find fieldInfoType");
			info.methodInfoType = Lookup(oldOne.info.methodInfoType, "Could not find methodInfoType");
		}
Esempio n. 16
0
 public static IViewModel CreateCardViewModel(MainType selectedType)
 {
     switch (selectedType)
     {
         case MainType.Creature:
             return new CreatureCard().GetViewModel();
         case MainType.Instant:
             return new CreatureCard().GetViewModel();
         default:
             return new Card().GetViewModel();
     }
 }
Esempio n. 17
0
 public ActionResult AddMonster(MainType mainType, int MonsterId)
 {
     if (MonsterId != 0)
     {
         _db.MonsterMainTypes.Add(new MonsterMainType()
         {
             MonsterId = MonsterId, MainTypeId = mainType.MainTypeId
         });
     }
     _db.SaveChanges();
     return(RedirectToAction("Details", new { id = mainType.MainTypeId }));
 }
Esempio n. 18
0
        public ActionResult Edit(FormCollection form)
        {
            int      id   = Convert.ToInt32(form["id"]);
            string   name = form["Name"].ToString();
            MainType type = new MainType()
            {
                ID = id, Name = name
            };

            db.Entry(type).State = EntityState.Modified;
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 19
0
        /// <summary>
        /// Declares a new function.
        /// </summary>
        private void declareFunction(FunctionNode node)
        {
            if (node.Name == "_")
            {
                Error(CompilerMessages.UnderscoreName);
            }

            var isVariadic = false;

            // validation
            if (node.Arguments.Count > 0)
            {
                for (var idx = 0; idx < node.Arguments.Count; idx++)
                {
                    var curr = node.Arguments[idx];
                    if (curr.Name == "_")
                    {
                        curr.Name = Unique.AnonymousArgName();
                    }

                    if (curr.Type == typeof(UnspecifiedType))
                    {
                        Error(CompilerMessages.LambdaArgTypeUnknown);
                    }

                    if (curr.IsVariadic)
                    {
                        if (idx < node.Arguments.Count - 1)
                        {
                            Error(CompilerMessages.VariadicArgumentNotLast);
                        }

                        isVariadic = true;
                    }
                }
            }
            else
            {
                if (node.Name == EntityNames.RunMethodName || node.Name == EntityNames.EntryPointMethodName)
                {
                    Error(CompilerMessages.ReservedFunctionRedefinition, node.Name);
                }
            }

            var method = MainType.CreateMethod(node.Name, node.ReturnTypeSignature, node.Arguments, true, prepare: false);

            method.Kind       = TypeContentsKind.UserDefined;
            method.IsPure     = node.IsPure;
            method.IsVariadic = isVariadic;
            method.Body       = node.Body;
        }
Esempio n. 20
0
        public void TestMethod7()
        {
            MainType t = new MainType();

            t.REFTYPE = new TestRefType1();
            var reftype2 = new TestRefType2();

            t.REFTYPE.REFTYPE = reftype2;

            Func <MainType, object> ex = GetPropertyFunc <MainType>("REFTYPE.REFTYPE");
            object val = ex(t);

            Assert.AreEqual(reftype2, val);
        }
Esempio n. 21
0
        public void TestMethod3()
        {
            MainType t = new MainType();

            t.REFTYPE = new TestRefType1();
            var guid = Guid.NewGuid();

            t.REFTYPE.VALUETYPE = guid;

            Func <MainType, object> ex = GetPropertyFunc <MainType>("REFTYPE.VALUETYPE");
            object val = ex(t);

            Assert.AreEqual(guid, val);
        }
			public MethodInfos(ModuleDef module, MainType mainType, MyPEImage peImage, PeHeader peHeader, McKey mcKey) {
				this.module = module;
				this.mainType = mainType;
				this.peImage = peImage;
				this.peHeader = peHeader;
				this.mcKey = mcKey;

				structSize = GetStructSize(mcKey);

				uint methodInfosRva = peHeader.GetRva(0x0FF8, mcKey.ReadUInt32(0x005A));
				uint encryptedDataRva = peHeader.GetRva(0x0FF0, mcKey.ReadUInt32(0x0046));

				methodInfosOffset = peImage.RvaToOffset(methodInfosRva);
				encryptedDataOffset = peImage.RvaToOffset(encryptedDataRva);
			}
Esempio n. 23
0
 private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (!IsLoaded)
     {
         return;
     }
     if (MainType.Equals("CAST"))
     {
         cbSecondType.Visibility = Visibility.Visible;
         Appear(cbSecondType);
     }
     else if (cbSecondType.Visibility == Visibility.Visible)
     {
         cbSecondType.Visibility = Visibility.Hidden;
         Disappear(cbSecondType);
     }
     TypeChanged?.Invoke(this, e);
 }
Esempio n. 24
0
        /// <summary>
        /// Declares a new type.
        /// </summary>
        private void declareType(TypeDefinitionNode node)
        {
            if (node.Name == "_")
            {
                Error(CompilerMessages.UnderscoreName);
            }

            var mainType = CreateType(node.Name, prepare: false);

            mainType.Kind = TypeEntityKind.Type;

            foreach (var curr in node.Entries)
            {
                var tagName   = curr.Name;
                var labelType = CreateType(tagName, node.Name, isSealed: true, defaultCtor: false, prepare: false);
                labelType.Kind = TypeEntityKind.TypeLabel;

                var ctor = labelType.CreateConstructor(prepare: false);
                ctor.Kind = TypeContentsKind.AutoGenerated;
                if (curr.IsTagged)
                {
                    var tagField = labelType.CreateField("Tag", curr.TagType, prepare: false);
                    tagField.Kind = TypeContentsKind.UserDefined;

                    var args = new HashList <FunctionArgument> {
                        { "value", new FunctionArgument("value", curr.TagType) }
                    };

                    var staticCtor = MainType.CreateMethod(tagName, tagName, new string[0], isStatic: true, prepare: false);
                    staticCtor.Kind = TypeContentsKind.AutoGenerated;

                    ctor.Arguments = staticCtor.Arguments = args;
                    ctor.Body.Add(
                        Expr.SetMember(Expr.This(), "Tag", Expr.Get("value"))
                        );

                    staticCtor.Body.Add(
                        Expr.New(tagName, Expr.Get("value"))
                        );
                }
            }
        }
        public ControlFlowObfuscator(ILBody body, BuildMethod method)
        {
            if (body == null)
            {
                throw new ArgumentNullException("body");
            }

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

            _body   = body;
            _method = method;

            var module = (BuildModule)method.Module;

            _mainType = module.MainType;
            _random   = module.RandomGenerator;
        }
Esempio n. 26
0
        public void Generate()
        {
            if (_strings.Count == 0)
            {
                return;
            }

            BuildData();

            _mainType = _module.MainType;

            // Methods
            var initMethod = (BuildMethod)_mainType.Methods.Add();

            LoadStrings(initMethod);
            _mainType.AddStartupMethod(initMethod);

            // Fields
            GenerateFields();

            // Dependencies
            _mainType.GenerateReadStringIntern();
        }
Esempio n. 27
0
        private Encoding GetEncoding()
        {
            Encoding encoding;
            var      charset = GetParameter(PARAM_CHARSET);

            if (charset != null)
            {
                try {
                    encoding = Encoding.GetEncoding(charset.Trim('"'));
                } catch (ArgumentException ex) {
                    _log.Debug(string.Format("Unsupported Character Set: '{0}'. Defaulting to UTF8 encoding.", charset), ex);
                    encoding = Encoding.UTF8;
                }
            }
            else if (MainType.EqualsInvariant("text"))
            {
                encoding = Encoding.ASCII;
            }
            else
            {
                encoding = Encoding.UTF8;
            }
            return(encoding);
        }
Esempio n. 28
0
        public ViewResult AddMainType(MainType _mtype)
        {
            if (ModelState.IsValid)
            {
                if (!Services.MainType.MainTypeNameControl(_mtype.MainTypeName))
                {
                    _mtype.IsActive = true;
                    Services.MainType.Insert(_mtype);
                    ViewBag.Error = false;
                }
                else
                {
                    ViewBag.NameError = true;
                }

                ModelState.Clear();
                return(View());
            }
            else
            {
                ViewBag.Error = true;
                return(View());
            }
        }
Esempio n. 29
0
		public ProxyCallFixer(ModuleDefMD module, MainType mainType)
			: base(module) {
			this.mainType = mainType;
		}
Esempio n. 30
0
 public FileDecrypter(MainType mainType)
 {
     this.mainType = mainType;
 }
Esempio n. 31
0
		protected override void ScanForObfuscator() {
			FindKillType();
			mainType = new MainType(module);
			mainType.Find();
			proxyCallFixer = new ProxyCallFixer(module, mainType);
			proxyCallFixer.FindDelegateCreator();
			methodsDecrypter = new MethodsDecrypter(mainType);
			methodsDecrypter.Find();
			stringDecrypter = new StringDecrypter(module, mainType);
			stringDecrypter.Find();
			var version = DetectVersion();
			if (!string.IsNullOrEmpty(version))
				obfuscatorName = obfuscatorName + " " + version;
		}
Esempio n. 32
0
 public MethodsDecrypter(MainType mainType, MethodsDecrypter oldOne)
 {
     this.mainType = mainType;
 }
Esempio n. 33
0
            public PeHeader(MainType mainType, PeImage peImage)
            {
                headerData = getPeHeaderData(peImage);

                if (!mainType.IsOld && peImage.readUInt32(0x2008) != 0x48) {
                    rvaDispl1 = readUInt32(0x0FB0) ^ XOR_KEY;
                    rvaDispl2 = readUInt32(0x0FB4) ^ XOR_KEY;
                }
            }
Esempio n. 34
0
 internal void CreateMainType()
 {
     _mainType = new MainType(this);
     AddType(_mainType);
 }
Esempio n. 35
0
 public ActionResult Create(MainType mainType)
 {
     _db.MainTypes.Add(mainType);
     _db.SaveChanges();
     return(RedirectToAction("Index"));
 }
Esempio n. 36
0
 protected override void ScanForObfuscator()
 {
     mainType = new MainType(module);
     mainType.Find();
 }
        private void Change(BuildAssembly assembly)
        {
            var module  = (BuildModule)assembly.Module;
            var strings = new HashList <string>();

            MainType.Create(assembly);

            if (assembly.EncryptIL)
            {
                strings.Add(".");                 // Dot is at index 0
            }
            if (_evaluationPeriodInDays > 0)
            {
                module.MainType.GenerateCheckForExpiredEvaluation(_evaluationPeriodInDays);
            }

            if (assembly.StripObfuscationAttributeExists)
            {
                ObfuscationAttributeStripper.Strip(assembly);
            }

            if (assembly.SuppressILdasm)
            {
                CA.SuppressIldasmAttribute.AddIfNotExists(assembly.CustomAttributes);
            }

            if (assembly.RenameMembers || assembly.DevirtualizeMethods)
            {
                ExplicitMethodCallBuilder.Build(assembly);
            }

            if (CancellationPending)
            {
                return;
            }

            if (_renameAssemblies)
            {
                MemberRenameHelper.BuildRenamedAssemblyResolver(assembly, _renamedAssemblyNames);
            }

            if (assembly.HasWpfResource && (_renameAssemblies || _renameMembers))
            {
                BamlMemberReferenceMapper.Map(assembly, _log);
            }

            if (assembly.HasWpfResource && _renameAssemblies)
            {
                ResourceHelper.RenameWpfResource(assembly);
            }

            if (_renameAssemblies)
            {
                ResourceHelper.RenameSatelliteAssemblies(assembly);
            }

            if (assembly.ObfuscateResources)
            {
                ResourceObfuscator.Obfuscate(assembly);
            }

            if (_obfuscateResources)
            {
                ResourceResolverGenerator.Generate(assembly);
            }

            if (assembly.ObfuscateStrings)
            {
                StringObfuscator.Obfuscate(assembly, strings);
            }

            if (CancellationPending)
            {
                return;
            }

            if (assembly.SealTypes)
            {
                TypeSealer.Seal(assembly);
            }

            if (assembly.DevirtualizeMethods)
            {
                MethodDevirtualizer.Devirtualize(assembly);
            }

            if (CancellationPending)
            {
                return;
            }

            if (_renameMembers)
            {
                ExplicitMethodOverrideBuilder.Build(assembly, _nameGenerator);
            }

            if (_encryptIL)
            {
                ILCryptoMapper.Map(assembly);
            }

            if (assembly.EncryptIL)
            {
                ILCryptoObfuscator.Obfuscate(assembly, strings);
            }

            if (CancellationPending)
            {
                return;
            }

            if (assembly.RemoveUnusedMembers)
            {
                Stripper.Strip(assembly);
            }

            if (assembly.ObfuscateControlFlow)
            {
                ControlFlowObfuscator.Obfuscate(assembly, true);
            }

            if (strings.Count > 0)
            {
                StringLoaderGenerator.Generate(assembly, strings);
            }

            if (CancellationPending)
            {
                return;
            }

            // From this point no more code can be added.

            MainType.Generate(assembly);
            DelegateTypeGenerator.Generate(assembly);
            GeneratedCodeObfuscator.Obfuscate(assembly, _nameGenerator);

            if (CancellationPending)
            {
                return;
            }

            ILCryptoBlobBuilder.MapMemberReferences(assembly);
            MemberReferenceMapper.Map(assembly);
            MemberNameChanger.Change(assembly);

            if (CancellationPending)
            {
                return;
            }

            assembly.Compile();

            Scavenge();
        }
            public MethodInfos(MainType mainType, MyPEImage peImage, PeHeader peHeader, McKey mcKey)
            {
                this.mainType = mainType;
                this.peImage = peImage;
                this.peHeader = peHeader;
                this.mcKey = mcKey;

                decryptHandlersV1 = new Decrypt[] { decrypt1a, decrypt4a, decrypt2a, decrypt3a, decrypt5, decrypt6, decrypt7 };
                decryptHandlersV2 = new Decrypt[] { decrypt3a, decrypt2a, decrypt1a, decrypt4a, decrypt5, decrypt6, decrypt7 };
                decryptHandlersV3 = new Decrypt[] { decrypt1a, decrypt2a, decrypt3a, decrypt4a, decrypt5, decrypt6, decrypt7 };
                decryptHandlersV4 = new Decrypt[] { decrypt2a, decrypt1a, decrypt3a, decrypt4a, decrypt5, decrypt6, decrypt7 };
                decryptHandlersV5a = new Decrypt[] { decrypt4a, decrypt2a, decrypt3a, decrypt1a, decrypt5, decrypt6, decrypt7 };
                decryptHandlersV5b = new Decrypt[] { decrypt4b, decrypt2b, decrypt3b, decrypt1b, decrypt6, decrypt7, decrypt5 };
                decryptHandlersV5c = new Decrypt[] { decrypt4c, decrypt2c, decrypt3c, decrypt1c, decrypt6, decrypt7, decrypt5 };
                decryptHandlersV6a = new Decrypt[] { decrypt4d, decrypt2d, decrypt3d, decrypt1d, decrypt6, decrypt7, decrypt5 };

                structSize = getStructSize(mcKey);

                uint methodInfosRva = peHeader.getRva(0x0FF8, mcKey.readUInt32(0x005A));
                uint encryptedDataRva = peHeader.getRva(0x0FF0, mcKey.readUInt32(0x0046));

                methodInfosOffset = peImage.rvaToOffset(methodInfosRva);
                encryptedDataOffset = peImage.rvaToOffset(encryptedDataRva);
            }
Esempio n. 39
0
 internal MainTypeCallProxyBuilder(BuildModule module)
 {
     _module   = module;
     _mainType = module.MainType;
     _random   = module.RandomGenerator;
 }
Esempio n. 40
0
 public ProxyDelegateFinder(ModuleDefinition module, MainType mainType)
     : base(module)
 {
     this.mainType = mainType;
 }
Esempio n. 41
0
 public TamperDetection(ModuleDefinition module, MainType mainType)
 {
     this.module = module;
     this.mainType = mainType;
 }
Esempio n. 42
0
 public PeHeader(MainType mainType, PeImage peImage)
 {
     uint headerOffset;
     version = getHeaderOffsetAndVersion(peImage, out headerOffset);
     headerData = peImage.offsetReadBytes(headerOffset, 0x1000);
 }
Esempio n. 43
0
 public ActionResult Edit(MainType mainType)
 {
     _db.Entry(mainType).State = EntityState.Modified;
     _db.SaveChanges();
     return(RedirectToAction("Details", new { id = mainType.MainTypeId }));
 }
 internal bool Accept(Type type)
 {
     return(MainType.IsAssignableFrom(type));
 }
		protected override void ScanForObfuscator() {
			mainType = new MainType(module);
			mainType.Find();
		}
Esempio n. 46
0
            public MethodInfos(MainType mainType, PeImage peImage, PeHeader peHeader, McKey mcKey)
            {
                this.mainType = mainType;
                this.peImage = peImage;
                this.peHeader = peHeader;
                this.mcKey = mcKey;

                structSize = getStructSize(mcKey);

                uint methodInfosRva = peHeader.getRva2(0x0FF8, mcKey.readUInt32(0x005A));
                uint encryptedDataRva = peHeader.getRva2(0x0FF0, mcKey.readUInt32(0x0046));

                methodInfosOffset = peImage.rvaToOffset(methodInfosRva);
                encryptedDataOffset = peImage.rvaToOffset(encryptedDataRva);
            }