mirror of
https://github.com/wismna/ModernKeePassLib.git
synced 2025-10-03 23:50:20 -04:00
Update to KeePassLib version 2.45
This commit is contained in:
@@ -22,6 +22,7 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
#if KeePassLibSD
|
||||
@@ -820,6 +821,52 @@ namespace ModernKeePassLib.Utility
|
||||
IDisposable d = (o as IDisposable);
|
||||
if(d != null) d.Dispose();
|
||||
}
|
||||
|
||||
internal static T BytesToStruct<T>(byte[] pb, int iOffset)
|
||||
where T : struct
|
||||
{
|
||||
if(pb == null) throw new ArgumentNullException("pb");
|
||||
if(iOffset < 0) throw new ArgumentOutOfRangeException("iOffset");
|
||||
|
||||
int cb = Marshal.SizeOf(typeof(T));
|
||||
if(cb <= 0) { Debug.Assert(false); return default(T); }
|
||||
|
||||
if(iOffset > (pb.Length - cb)) throw new ArgumentOutOfRangeException("iOffset");
|
||||
|
||||
IntPtr p = Marshal.AllocCoTaskMem(cb);
|
||||
if(p == IntPtr.Zero) throw new OutOfMemoryException();
|
||||
|
||||
object o;
|
||||
try
|
||||
{
|
||||
Marshal.Copy(pb, iOffset, p, cb);
|
||||
o = Marshal.PtrToStructure(p, typeof(T));
|
||||
}
|
||||
finally { Marshal.FreeCoTaskMem(p); }
|
||||
|
||||
return (T)o;
|
||||
}
|
||||
|
||||
internal static byte[] StructToBytes<T>(ref T t)
|
||||
where T : struct
|
||||
{
|
||||
int cb = Marshal.SizeOf(typeof(T));
|
||||
if(cb <= 0) { Debug.Assert(false); return MemUtil.EmptyByteArray; }
|
||||
|
||||
byte[] pb = new byte[cb];
|
||||
|
||||
IntPtr p = Marshal.AllocCoTaskMem(cb);
|
||||
if(p == IntPtr.Zero) throw new OutOfMemoryException();
|
||||
|
||||
try
|
||||
{
|
||||
Marshal.StructureToPtr(t, p, false);
|
||||
Marshal.Copy(p, pb, 0, cb);
|
||||
}
|
||||
finally { Marshal.FreeCoTaskMem(p); }
|
||||
|
||||
return pb;
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class ArrayHelperEx<T> : IEqualityComparer<T[]>, IComparer<T[]>
|
||||
|
@@ -180,6 +180,8 @@ namespace ModernKeePassLib.Utility
|
||||
internal static DialogResult SafeShowMessageBox(string strText, string strTitle,
|
||||
MessageBoxButtons mb, MessageBoxIcon mi, MessageBoxDefaultButton mdb)
|
||||
{
|
||||
// strText += MessageService.NewParagraph + (new StackTrace(true)).ToString();
|
||||
|
||||
#if KeePassLibSD
|
||||
return MessageBox.Show(strText, strTitle, mb, mi, mdb);
|
||||
#else
|
||||
|
@@ -119,10 +119,12 @@ namespace ModernKeePassLib.Utility
|
||||
// 2140:
|
||||
// Explicit control focusing is ignored.
|
||||
// https://sourceforge.net/p/keepass/feature-requests/2140/
|
||||
// 5795:
|
||||
// 5795: [Fixed]
|
||||
// Text in input field is incomplete.
|
||||
// https://bugzilla.xamarin.com/show_bug.cgi?id=5795
|
||||
// https://sourceforge.net/p/keepass/discussion/329220/thread/d23dc88b/
|
||||
// https://github.com/mono/mono/commit/1a79065f8cd9f128e6e527e5d573111f794ce288
|
||||
// https://github.com/mono/mono/pull/5947
|
||||
// 9604:
|
||||
// Trying to resolve a non-existing metadata token crashes Mono.
|
||||
// https://github.com/mono/mono/issues/9604
|
||||
@@ -162,6 +164,10 @@ namespace ModernKeePassLib.Utility
|
||||
// 686017:
|
||||
// Minimum sizes must be enforced.
|
||||
// https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=686017
|
||||
// 688007: [Fixed]
|
||||
// Credentials are required for anonymous web requests.
|
||||
// https://bugzilla.novell.com/show_bug.cgi?id=688007
|
||||
// https://sourceforge.net/p/keepass/bugs/1950/
|
||||
// 801414:
|
||||
// Mono recreates the main window incorrectly.
|
||||
// https://bugs.launchpad.net/ubuntu/+source/keepass2/+bug/801414
|
||||
@@ -192,13 +198,21 @@ namespace ModernKeePassLib.Utility
|
||||
if(g_dForceReq.TryGetValue(uBugID, out bForce)) return bForce;
|
||||
|
||||
ulong v = NativeLib.MonoVersion;
|
||||
if(v != 0)
|
||||
if(v == 0) return true;
|
||||
|
||||
bool b = true;
|
||||
switch(uBugID)
|
||||
{
|
||||
if(uBugID == 10163)
|
||||
return (v >= 0x0002000B00000000UL); // >= 2.11
|
||||
case 5795:
|
||||
b = (v < 0x0005000A00000000UL); break;
|
||||
case 10163:
|
||||
b = (v >= 0x0002000B00000000UL); break;
|
||||
case 688007:
|
||||
b = (v < 0x0006000000000000UL); break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
return true;
|
||||
return b;
|
||||
}
|
||||
|
||||
internal static void SetEnabled(string strIDs, bool bEnabled)
|
||||
|
@@ -320,6 +320,18 @@ namespace ModernKeePassLib.Utility
|
||||
return str;
|
||||
}
|
||||
|
||||
internal static string RtfFilterText(string strText)
|
||||
{
|
||||
if(strText == null) { Debug.Assert(false); return string.Empty; }
|
||||
|
||||
// A U+FFFC character causes the rest of the text to be lost.
|
||||
// With '?', the string length, substring indices and
|
||||
// character visibility remain the same.
|
||||
// More special characters (unproblematic) in rich text boxes:
|
||||
// https://docs.microsoft.com/en-us/windows/win32/api/richedit/ns-richedit-gettextex
|
||||
return strText.Replace('\uFFFC', '?');
|
||||
}
|
||||
|
||||
internal static bool ContainsHighChar(string str)
|
||||
{
|
||||
if(str == null) { Debug.Assert(false); return false; }
|
||||
@@ -975,35 +987,25 @@ namespace ModernKeePassLib.Utility
|
||||
public static string AddAccelerator(string strMenuText,
|
||||
List<char> lAvailKeys)
|
||||
{
|
||||
if(strMenuText == null) { Debug.Assert(false); return null; }
|
||||
if(strMenuText == null) { Debug.Assert(false); return string.Empty; }
|
||||
if(lAvailKeys == null) { Debug.Assert(false); return strMenuText; }
|
||||
|
||||
int xa = -1, xs = 0;
|
||||
for(int i = 0; i < strMenuText.Length; ++i)
|
||||
{
|
||||
char ch = strMenuText[i];
|
||||
char ch = char.ToLowerInvariant(strMenuText[i]);
|
||||
|
||||
#if KeePassLibSD
|
||||
char chUpper = char.ToUpper(ch);
|
||||
#else
|
||||
char chUpper = char.ToUpperInvariant(ch);
|
||||
#endif
|
||||
xa = lAvailKeys.IndexOf(chUpper);
|
||||
if(xa >= 0) { xs = i; break; }
|
||||
|
||||
#if KeePassLibSD
|
||||
char chLower = char.ToLower(ch);
|
||||
#else
|
||||
char chLower = char.ToLowerInvariant(ch);
|
||||
#endif
|
||||
xa = lAvailKeys.IndexOf(chLower);
|
||||
if(xa >= 0) { xs = i; break; }
|
||||
for(int j = 0; j < lAvailKeys.Count; ++j)
|
||||
{
|
||||
if(char.ToLowerInvariant(lAvailKeys[j]) == ch)
|
||||
{
|
||||
lAvailKeys.RemoveAt(j);
|
||||
return strMenuText.Insert(i, @"&");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(xa < 0) return strMenuText;
|
||||
|
||||
lAvailKeys.RemoveAt(xa);
|
||||
return strMenuText.Insert(xs, @"&");
|
||||
return strMenuText;
|
||||
}
|
||||
|
||||
public static string EncodeMenuText(string strText)
|
||||
|
@@ -287,13 +287,13 @@ namespace ModernKeePassLib.Utility
|
||||
if(strUrl.Length == 0) { Debug.Assert(false); return string.Empty; }
|
||||
|
||||
#if !ModernKeePassLib
|
||||
if(!strUrl.StartsWith(Uri.UriSchemeFile + ":", StrUtil.CaseIgnoreCmp))
|
||||
if(!strUrl.StartsWith(Uri.UriSchemeFile + ":", StrUtil.CaseIgnoreCmp))
|
||||
{
|
||||
Debug.Assert(false);
|
||||
return strUrl;
|
||||
}
|
||||
#endif
|
||||
try
|
||||
try
|
||||
{
|
||||
Uri uri = new Uri(strUrl);
|
||||
string str = uri.LocalPath;
|
||||
|
Reference in New Issue
Block a user