Update to KeePassLib version 2.45

This commit is contained in:
Geoffroy BONNEVILLE
2020-05-12 12:46:25 +02:00
parent 107e009807
commit 2e1cc97738
21 changed files with 166 additions and 65 deletions

View File

@@ -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[]>