Пример #1
0
        public static string Save(ConnectionProfileInfo info, bool rememberPassword)
        {
            ConnectionInfo connectionInfo = ObjectHelper.CloneObject <ConnectionInfo>(info.ConnectionInfo);

            info.Database = connectionInfo.Database;

            if (!rememberPassword)
            {
                connectionInfo.Password = "";
            }

            string encrptedPassword = "";

            if (rememberPassword && !string.IsNullOrEmpty(connectionInfo.Password))
            {
                encrptedPassword = AesHelper.Encrypt(connectionInfo.Password);
            }

            string profileName = info.Name;

            if (string.IsNullOrEmpty(profileName))
            {
                profileName = info.ConnectionDescription;
            }

            var accountProfiles = AccountProfileManager.GetProfiles(info.DatabaseType);

            AccountProfileInfo accountProfile = accountProfiles.FirstOrDefault(item => item.Server == connectionInfo.Server &&
                                                                               item.Port == connectionInfo.Port &&
                                                                               item.UserId == connectionInfo.UserId &&
                                                                               item.IntegratedSecurity == connectionInfo.IntegratedSecurity);

            bool changed = false;

            if (accountProfile != null)
            {
                if (!accountProfile.IntegratedSecurity && accountProfile.Password != encrptedPassword)
                {
                    changed = true;
                    accountProfile.Password = connectionInfo.Password;
                }
            }
            else
            {
                changed        = true;
                accountProfile = new AccountProfileInfo()
                {
                    DatabaseType = info.DatabaseType
                };
                ObjectHelper.CopyProperties(connectionInfo, accountProfile);
            }

            if (changed)
            {
                AccountProfileManager.Save(accountProfile, rememberPassword);
            }

            List <ConnectionProfileInfo> profiles = new List <ConnectionProfileInfo>();

            if (File.Exists(ProfilePath))
            {
                profiles = (List <ConnectionProfileInfo>)JsonConvert.DeserializeObject(File.ReadAllText(ProfilePath), typeof(List <ConnectionProfileInfo>));
            }

            ConnectionProfileInfo oldProfile = profiles.FirstOrDefault(item => item.Name == info.Name && item.DatabaseType == info.DatabaseType);

            if (oldProfile == null)
            {
                info.AccountProfileId = accountProfile.Id;
                profiles.Add(info);
            }
            else
            {
                ObjectHelper.CopyProperties(info, oldProfile);
            }

            File.WriteAllText(ProfilePath, JsonConvert.SerializeObject(profiles, Formatting.Indented));

            return(profileName);
        }
Пример #2
0
        /// <summary>
        /// Step #4
        /// 
        /// Read, decode, and process the code section.
        /// </summary>
        /// <returns></returns>
        private bool Step4()
        {
            // Do nothing if we are not encrypted..
            if ((this.StubHeader.Flags & (uint)DrmFlags.NoEncryption) == (uint)DrmFlags.NoEncryption)
                return true;

            // Obtain the main code section that is encrypted..
            var mainSection = this.File.GetOwnerSection(this.StubHeader.TextSectionVirtualAddress);
            if (mainSection.PointerToRawData == 0 || mainSection.SizeOfRawData == 0)
                return false;

            // Save the code section for later use..
            this.CodeSection = mainSection;

            try
            {
                // Obtain the .text section data..
                var textSectionData = new byte[mainSection.SizeOfRawData + this.StubHeader.TextSectionStolenData.Length];
                Array.Copy(this.StubHeader.TextSectionStolenData, 0, textSectionData, 0, this.StubHeader.TextSectionStolenData.Length);
                Array.Copy(this.File.FileData, this.File.GetFileOffsetFromRva(mainSection.VirtualAddress), textSectionData, this.StubHeader.TextSectionStolenData.Length, mainSection.SizeOfRawData);

                // Create the AES decryption class..
                var aes = new AesHelper(this.StubHeader.AES_Key, this.StubHeader.AES_IV, CipherMode.ECB, PaddingMode.PKCS7);
                aes.RebuildIv(this.StubHeader.AES_IV);
                var data = aes.Decrypt(textSectionData, CipherMode.CBC, PaddingMode.None);
                if (data == null)
                    return false;

                // Set the override section data..
                this.CodeSectionData = data;

                return true;
            }
            catch
            {
                return false;
            }
        }
Пример #3
0
        /// <summary>
        /// Step #5
        /// 
        /// Read, decode, and process the main code section.
        /// </summary>
        /// <returns></returns>
        private bool Step5()
        {
            byte[] codeSectionData;

            // Obtain the main code section (typically .text)..
            var mainSection = this.File.GetOwnerSection(this.File.GetRvaFromVa(BitConverter.ToUInt32(this.PayloadData.Skip(this.SteamDrmpOffsets[3]).Take(4).ToArray(), 0)));
            if (mainSection.PointerToRawData == 0 || mainSection.SizeOfRawData == 0)
                return false;

            // Save the code section for later use..
            this.CodeSection = mainSection;

            // Determine if we are using encryption on the section..
            var flags = BitConverter.ToUInt32(this.PayloadData.Skip(this.SteamDrmpOffsets[0]).Take(4).ToArray(), 0);
            if ((flags & (uint)DrmFlags.NoEncryption) == (uint)DrmFlags.NoEncryption)
            {
                // No encryption was used, just read the original data..
                codeSectionData = new byte[mainSection.SizeOfRawData];
                Array.Copy(this.File.FileData, this.File.GetFileOffsetFromRva(mainSection.VirtualAddress), codeSectionData, 0, mainSection.SizeOfRawData);
            }
            else
            {
                // Encryption was used, obtain the encryption information..
                var aesKey = this.PayloadData.Skip(this.SteamDrmpOffsets[5]).Take(32).ToArray();
                var aesIv = this.PayloadData.Skip(this.SteamDrmpOffsets[6]).Take(16).ToArray();
                var codeStolen = this.PayloadData.Skip(this.SteamDrmpOffsets[7]).Take(16).ToArray();

                // Restore the stolen data then read the rest of the section data..
                codeSectionData = new byte[mainSection.SizeOfRawData + codeStolen.Length];
                Array.Copy(codeStolen, 0, codeSectionData, 0, codeStolen.Length);
                Array.Copy(this.File.FileData, this.File.GetFileOffsetFromRva(mainSection.VirtualAddress), codeSectionData, codeStolen.Length, mainSection.SizeOfRawData);

                // Decrypt the code section..
                var aes = new AesHelper(aesKey, aesIv);
                aes.RebuildIv(aesIv);
                codeSectionData = aes.Decrypt(codeSectionData, CipherMode.CBC, PaddingMode.None);
            }

            // Store the section data..
            this.CodeSectionData = codeSectionData;

            return true;
        }