当前位置: 首页>>代码示例>>C#>>正文


C# Spr.SprContext类代码示例

本文整理汇总了C#中KeePass.Util.Spr.SprContext的典型用法代码示例。如果您正苦于以下问题:C# SprContext类的具体用法?C# SprContext怎么用?C# SprContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SprContext类属于KeePass.Util.Spr命名空间,在下文中一共展示了SprContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ReplacePickPw

		// Legacy, for backward compatibility only; see PickChars
		private static string ReplacePickPw(string strText, SprContext ctx,
			uint uRecursionLevel)
		{
			if(ctx.Entry == null) { Debug.Assert(false); return strText; }

			string str = strText;

			while(true)
			{
				const string strStart = @"{PICKPASSWORDCHARS";

				int iStart = str.IndexOf(strStart, StrUtil.CaseIgnoreCmp);
				if(iStart < 0) break;

				int iEnd = str.IndexOf('}', iStart);
				if(iEnd < 0) break;

				string strPlaceholder = str.Substring(iStart, iEnd - iStart + 1);

				string strParam = str.Substring(iStart + strStart.Length,
					iEnd - (iStart + strStart.Length));
				string[] vParams = strParam.Split(new char[] { ':' });

				uint uCharCount = 0;
				if(vParams.Length >= 2) uint.TryParse(vParams[1], out uCharCount);

				str = ReplacePickPwPlaceholder(str, strPlaceholder, uCharCount,
					ctx, uRecursionLevel);
			}

			return str;
		}
开发者ID:riking,项目名称:go-keepass2,代码行数:33,代码来源:SprEngine.PickChars.cs

示例2: ReplacePickPwPlaceholder

		private static string ReplacePickPwPlaceholder(string str,
			string strPlaceholder, uint uCharCount, SprContext ctx,
			uint uRecursionLevel)
		{
			if(str.IndexOf(strPlaceholder, StrUtil.CaseIgnoreCmp) < 0) return str;

			ProtectedString ps = ctx.Entry.Strings.Get(PwDefs.PasswordField);
			if(ps != null)
			{
				string strPassword = ps.ReadString();

				string strPick = SprEngine.CompileInternal(strPassword,
					ctx.WithoutContentTransformations(), uRecursionLevel + 1);

				if(!string.IsNullOrEmpty(strPick))
				{
					ProtectedString psPick = new ProtectedString(false, strPick);
					string strPicked = (CharPickerForm.ShowAndRestore(psPick,
						true, true, uCharCount, null) ?? string.Empty);

					str = StrUtil.ReplaceCaseInsensitive(str, strPlaceholder,
						SprEngine.TransformContent(strPicked, ctx));
				}
			}

			return StrUtil.ReplaceCaseInsensitive(str, strPlaceholder, string.Empty);
		}
开发者ID:riking,项目名称:go-keepass2,代码行数:27,代码来源:SprEngine.PickChars.cs

示例3: Compile

		public static string Compile(string strText, bool bIsAutoTypeSequence,
			PwEntry pwEntry, PwDatabase pwDatabase, bool bEscapeForAutoType,
			bool bEscapeQuotesForCommandLine)
		{
			SprContext ctx = new SprContext(pwEntry, pwDatabase, SprCompileFlags.All,
				bEscapeForAutoType, bEscapeQuotesForCommandLine);
			return Compile(strText, ctx);
		}
开发者ID:dbremner,项目名称:keepass2,代码行数:8,代码来源:SprEngine.cs

示例4: Compile

        public static string Compile(string strText, SprContext ctx)
        {
            if(strText == null) { Debug.Assert(false); return string.Empty; }
            if(strText.Length == 0) return string.Empty;

            SprEngine.InitializeStatic();

            if(ctx == null) ctx = new SprContext();
            ctx.RefsCache.Clear();

            string str = SprEngine.CompileInternal(strText, ctx, 0);

            // if(bEscapeForAutoType && !bIsAutoTypeSequence)
            //	str = SprEncoding.MakeAutoTypeSequence(str);

            return str;
        }
开发者ID:amiryal,项目名称:keepass2,代码行数:17,代码来源:SprEngine.cs

示例5: FillEntryStrings

		private static string FillEntryStrings(string str, SprContext ctx,
			uint uRecursionLevel)
		{
			List<string> vKeys = ctx.Entry.Strings.GetKeys();

			// Ensure that all standard field names are in the list
			// (this is required in order to replace the standard placeholders
			// even if the corresponding standard field isn't present in
			// the entry)
			List<string> vStdNames = PwDefs.GetStandardFields();
			foreach(string strStdField in vStdNames)
			{
				if(!vKeys.Contains(strStdField)) vKeys.Add(strStdField);
			}

			// Do not directly enumerate the strings in ctx.Entry.Strings,
			// because strings might change during the Spr compilation
			foreach(string strField in vKeys)
			{
				string strKey = (PwDefs.IsStandardField(strField) ?
					(@"{" + strField + @"}") :
					(@"{" + PwDefs.AutoTypeStringPrefix + strField + @"}"));

				if(!ctx.ForcePlainTextPasswords && strKey.Equals(@"{" +
					PwDefs.PasswordField + @"}", StrUtil.CaseIgnoreCmp) &&
					Program.Config.MainWindow.IsColumnHidden(AceColumnType.Password))
				{
					str = SprEngine.FillIfExists(str, strKey, new ProtectedString(
						false, PwDefs.HiddenPassword), ctx, uRecursionLevel);
					continue;
				}

				// Use GetSafe because the field doesn't necessarily exist
				// (might be a standard field that has been added above)
				str = SprEngine.FillIfExists(str, strKey, ctx.Entry.Strings.GetSafe(
					strField), ctx, uRecursionLevel);
			}

			return str;
		}
开发者ID:dbremner,项目名称:keepass2,代码行数:40,代码来源:SprEngine.cs

示例6: GetEntryListSprContext

		internal static SprContext GetEntryListSprContext(PwEntry pe,
			PwDatabase pd)
		{
			SprContext ctx = new SprContext(pe, pd, SprCompileFlags.Deref);
			ctx.ForcePlainTextPasswords = false;
			return ctx;
		}
开发者ID:riking,项目名称:go-keepass2,代码行数:7,代码来源:MainForm_Functions.cs

示例7: TransformContent

		public static string TransformContent(string strContent, SprContext ctx)
		{
			if(strContent == null) { Debug.Assert(false); return string.Empty; }

			string str = strContent;

			if(ctx != null)
			{
				if(ctx.EncodeQuotesForCommandLine)
					str = SprEncoding.MakeCommandQuotes(str);

				if(ctx.EncodeAsAutoTypeSequence)
					str = SprEncoding.MakeAutoTypeSequence(str);
			}

			return str;
		}
开发者ID:dbremner,项目名称:keepass2,代码行数:17,代码来源:SprEngine.cs

示例8: DerefFn

		internal static string DerefFn(string str, PwEntry pe)
		{
			if(!MightDeref(str)) return str;

			SprContext ctx = new SprContext(pe,
				Program.MainForm.DocumentManager.SafeFindContainerOf(pe),
				SprCompileFlags.Deref);
			// ctx.ForcePlainTextPasswords = false;

			return Compile(str, ctx);
		}
开发者ID:dbremner,项目名称:keepass2,代码行数:11,代码来源:SprEngine.cs

示例9: PerformTextTransforms

		private static string PerformTextTransforms(string strText, SprContext ctx,
			uint uRecursionLevel)
		{
			string str = strText;
			int iStart;
			List<string> lParams;

			while(ParseAndRemovePlhWithParams(ref str, ctx, uRecursionLevel,
				@"{T-REPLACE-RX:", out iStart, out lParams, true))
			{
				if(lParams.Count < 2) continue;
				if(lParams.Count == 2) lParams.Add(string.Empty);

				try
				{
					string strNew = Regex.Replace(lParams[0], lParams[1], lParams[2]);
					strNew = TransformContent(strNew, ctx);
					str = str.Insert(iStart, strNew);
				}
				catch(Exception) { }
			}

			while(ParseAndRemovePlhWithParams(ref str, ctx, uRecursionLevel,
				@"{T-CONV:", out iStart, out lParams, true))
			{
				if(lParams.Count < 2) continue;

				try
				{
					string strNew = lParams[0];
					string strCmd = lParams[1].ToLower();

					if((strCmd == "u") || (strCmd == "upper"))
						strNew = strNew.ToUpper();
					else if((strCmd == "l") || (strCmd == "lower"))
						strNew = strNew.ToLower();
					else if(strCmd == "base64")
					{
						byte[] pbUtf8 = StrUtil.Utf8.GetBytes(strNew);
						strNew = Convert.ToBase64String(pbUtf8);
					}
					else if(strCmd == "hex")
					{
						byte[] pbUtf8 = StrUtil.Utf8.GetBytes(strNew);
						strNew = MemUtil.ByteArrayToHexString(pbUtf8);
					}
					else if(strCmd == "uri")
						strNew = Uri.EscapeDataString(strNew);
					else if(strCmd == "uri-dec")
						strNew = Uri.UnescapeDataString(strNew);

					strNew = TransformContent(strNew, ctx);
					str = str.Insert(iStart, strNew);
				}
				catch(Exception) { Debug.Assert(false); }
			}

			return str;
		}
开发者ID:dbremner,项目名称:keepass2,代码行数:59,代码来源:SprEngine.cs

示例10: FillRefPlaceholders

		private static string FillRefPlaceholders(string strSeq, SprContext ctx,
			uint uRecursionLevel)
		{
			if(ctx.Database == null) return strSeq;

			string str = strSeq;

			int nOffset = 0;
			for(int iLoop = 0; iLoop < 20; ++iLoop)
			{
				str = SprEngine.FillRefsUsingCache(str, ctx);

				int nStart = str.IndexOf(StrRefStart, nOffset, SprEngine.ScMethod);
				if(nStart < 0) break;
				int nEnd = str.IndexOf(StrRefEnd, nStart + 1, SprEngine.ScMethod);
				if(nEnd <= nStart) break;

				string strFullRef = str.Substring(nStart, nEnd - nStart + 1);
				char chScan, chWanted;
				PwEntry peFound = FindRefTarget(strFullRef, ctx, out chScan, out chWanted);

				if(peFound != null)
				{
					string strInsData;
					if(chWanted == 'T')
						strInsData = peFound.Strings.ReadSafe(PwDefs.TitleField);
					else if(chWanted == 'U')
						strInsData = peFound.Strings.ReadSafe(PwDefs.UserNameField);
					else if(chWanted == 'A')
						strInsData = peFound.Strings.ReadSafe(PwDefs.UrlField);
					else if(chWanted == 'P')
						strInsData = peFound.Strings.ReadSafe(PwDefs.PasswordField);
					else if(chWanted == 'N')
						strInsData = peFound.Strings.ReadSafe(PwDefs.NotesField);
					else if(chWanted == 'I')
						strInsData = peFound.Uuid.ToHexString();
					else { nOffset = nStart + 1; continue; }

					if((chWanted == 'P') && !ctx.ForcePlainTextPasswords &&
						Program.Config.MainWindow.IsColumnHidden(AceColumnType.Password))
						strInsData = PwDefs.HiddenPassword;

					SprContext sprSub = ctx.WithoutContentTransformations();
					sprSub.Entry = peFound;

					string strInnerContent = SprEngine.CompileInternal(strInsData,
						sprSub, uRecursionLevel + 1);
					strInnerContent = SprEngine.TransformContent(strInnerContent, ctx);

					// str = str.Substring(0, nStart) + strInnerContent + str.Substring(nEnd + 1);
					SprEngine.AddRefToCache(strFullRef, strInnerContent, ctx);
					str = SprEngine.FillRefsUsingCache(str, ctx);
				}
				else { nOffset = nStart + 1; continue; }
			}

			return str;
		}
开发者ID:dbremner,项目名称:keepass2,代码行数:58,代码来源:SprEngine.cs

示例11: FillRefsUsingCache

		private static string FillRefsUsingCache(string strText, SprContext ctx)
		{
			string str = strText;

			foreach(KeyValuePair<string, string> kvp in ctx.RefsCache)
			{
				// str = str.Replace(kvp.Key, kvp.Value);
				str = StrUtil.ReplaceCaseInsensitive(str, kvp.Key, kvp.Value);
			}

			return str;
		}
开发者ID:dbremner,项目名称:keepass2,代码行数:12,代码来源:SprEngine.cs

示例12: GeneratePassword

        private static string GeneratePassword(string strProfile, SprContext ctx)
        {
            PwProfile prf = Program.Config.PasswordGenerator.AutoGeneratedPasswordsProfile;
            if(!string.IsNullOrEmpty(strProfile))
            {
                if(strProfile == @"~")
                    prf = PwProfile.DeriveFromPassword(ctx.Entry.Strings.GetSafe(
                        PwDefs.PasswordField));
                else
                {
                    List<PwProfile> lPrf = PwGeneratorUtil.GetAllProfiles(false);
                    foreach(PwProfile p in lPrf)
                    {
                        if(strProfile.Equals(p.Name, StrUtil.CaseIgnoreCmp))
                        {
                            prf = p;
                            break;
                        }
                    }
                }
            }

            ProtectedString ps;
            PwgError e = PwGenerator.Generate(out ps, prf, null,
                Program.PwGeneratorPool);
            if((e != PwgError.Success) || (ps == null)) return string.Empty;

            string strGen = ps.ReadString();
            strGen = SprEngine.TransformContent(strGen, ctx);
            return strGen;
        }
开发者ID:rdealexb,项目名称:keepass,代码行数:31,代码来源:EntryUtil.cs

示例13: ReplaceHmacOtpPlaceholder

        private static string ReplaceHmacOtpPlaceholder(string strText,
            SprContext ctx)
        {
            PwEntry pe = ctx.Entry;
            PwDatabase pd = ctx.Database;
            if((pe == null) || (pd == null)) return strText;

            string str = strText;

            const string strHmacOtpPlh = @"{HMACOTP}";
            if(str.IndexOf(strHmacOtpPlh, StrUtil.CaseIgnoreCmp) >= 0)
            {
                const string strKeyFieldUtf8 = "HmacOtp-Secret";
                const string strKeyFieldHex = "HmacOtp-Secret-Hex";
                const string strKeyFieldBase32 = "HmacOtp-Secret-Base32";
                const string strKeyFieldBase64 = "HmacOtp-Secret-Base64";
                const string strCounterField = "HmacOtp-Counter";

                byte[] pbSecret = null;
                try
                {
                    string strKey = pe.Strings.ReadSafe(strKeyFieldUtf8);
                    if(strKey.Length > 0)
                        pbSecret = StrUtil.Utf8.GetBytes(strKey);

                    if(pbSecret == null)
                    {
                        strKey = pe.Strings.ReadSafe(strKeyFieldHex);
                        if(strKey.Length > 0)
                            pbSecret = MemUtil.HexStringToByteArray(strKey);
                    }

                    if(pbSecret == null)
                    {
                        strKey = pe.Strings.ReadSafe(strKeyFieldBase32);
                        if(strKey.Length > 0)
                            pbSecret = MemUtil.ParseBase32(strKey);
                    }

                    if(pbSecret == null)
                    {
                        strKey = pe.Strings.ReadSafe(strKeyFieldBase64);
                        if(strKey.Length > 0)
                            pbSecret = Convert.FromBase64String(strKey);
                    }
                }
                catch(Exception) { Debug.Assert(false); }
                if(pbSecret == null) pbSecret = new byte[0];

                string strCounter = pe.Strings.ReadSafe(strCounterField);
                ulong uCounter;
                ulong.TryParse(strCounter, out uCounter);

                string strValue = HmacOtp.Generate(pbSecret, uCounter, 6,
                    false, -1);

                pe.Strings.Set(strCounterField, new ProtectedString(false,
                    (uCounter + 1).ToString()));
                pd.Modified = true;

                str = StrUtil.ReplaceCaseInsensitive(str, strHmacOtpPlh, strValue);
            }

            return str;
        }
开发者ID:rdealexb,项目名称:keepass,代码行数:65,代码来源:EntryUtil.cs

示例14: FillPlaceholders

 public static string FillPlaceholders(string strText, SprContext ctx)
 {
     return FillPlaceholders(strText, ctx, 0);
 }
开发者ID:rdealexb,项目名称:keepass,代码行数:4,代码来源:EntryUtil.cs

示例15: FillEntryStringsSpecial

        private static string FillEntryStringsSpecial(string str, SprContext ctx,
            uint uRecursionLevel)
        {
            if((str.IndexOf(UrlSpecialRmvScm, SprEngine.ScMethod) >= 0) ||
                (str.IndexOf(UrlSpecialScm, SprEngine.ScMethod) >= 0) ||
                (str.IndexOf(UrlSpecialHost, SprEngine.ScMethod) >= 0) ||
                (str.IndexOf(UrlSpecialPort, SprEngine.ScMethod) >= 0) ||
                (str.IndexOf(UrlSpecialPath, SprEngine.ScMethod) >= 0) ||
                (str.IndexOf(UrlSpecialQuery, SprEngine.ScMethod) >= 0))
            {
                string strUrl = SprEngine.FillIfExists(@"{URL}", @"{URL}",
                    ctx.Entry.Strings.GetSafe(PwDefs.UrlField), ctx, uRecursionLevel);

                str = StrUtil.ReplaceCaseInsensitive(str, UrlSpecialRmvScm,
                    UrlUtil.RemoveScheme(strUrl));

                try
                {
                    Uri uri = new Uri(strUrl);

                    str = StrUtil.ReplaceCaseInsensitive(str, UrlSpecialScm,
                        uri.Scheme);
                    str = StrUtil.ReplaceCaseInsensitive(str, UrlSpecialHost,
                        uri.Host);
                    str = StrUtil.ReplaceCaseInsensitive(str, UrlSpecialPort,
                        uri.Port.ToString());
                    str = StrUtil.ReplaceCaseInsensitive(str, UrlSpecialPath,
                        uri.AbsolutePath);
                    str = StrUtil.ReplaceCaseInsensitive(str, UrlSpecialQuery,
                        uri.Query);
                }
                catch(Exception) { } // Invalid URI
            }

            return str;
        }
开发者ID:ashwingj,项目名称:keepass2,代码行数:36,代码来源:SprEngine.cs


注:本文中的KeePass.Util.Spr.SprContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。