KeePassLib bumped to 2.37, compilation ok.

WIP tests
This commit is contained in:
bg45
2017-10-21 13:25:54 -04:00
committed by BONNEVILLE Geoffroy
parent d5b7845242
commit c82d6d001d
15 changed files with 414 additions and 91 deletions

View File

@@ -50,6 +50,24 @@ namespace ModernKeePassLib.Native
set { m_bAllowNative = value; }
}
private static int? g_oiPointerSize = null;
/// <summary>
/// Size of a native pointer (in bytes).
/// </summary>
public static int PointerSize
{
get
{
if(!g_oiPointerSize.HasValue)
#if KeePassUAP
g_oiPointerSize = Marshal.SizeOf<IntPtr>();
#else
g_oiPointerSize = Marshal.SizeOf(typeof(IntPtr));
#endif
return g_oiPointerSize.Value;
}
}
private static ulong? m_ouMonoVersion = null;
public static ulong MonoVersion
{
@@ -130,13 +148,13 @@ namespace ModernKeePassLib.Native
{
if(m_platID.HasValue) return m_platID.Value;
#if KeePassRT
m_platID = PlatformID.Win32NT;
#if KeePassUAP
m_platID = EnvironmentExt.OSVersion.Platform;
#else
m_platID = Environment.OSVersion.Platform;
#endif
#if (!KeePassLibSD && !KeePassRT)
#if (!KeePassLibSD && !KeePassUAP)
// Mono returns PlatformID.Unix on Mac OS X, workaround this
if(m_platID.Value == PlatformID.Unix)
{
@@ -149,7 +167,55 @@ namespace ModernKeePassLib.Native
return m_platID.Value;
}
#if (!KeePassLibSD && !KeePassRT)
private static DesktopType? m_tDesktop = null;
public static DesktopType GetDesktopType()
{
if(!m_tDesktop.HasValue)
{
DesktopType t = DesktopType.None;
if(!IsUnix()) t = DesktopType.Windows;
else
{
try
{
string strXdg = (Environment.GetEnvironmentVariable(
"XDG_CURRENT_DESKTOP") ?? string.Empty).Trim();
string strGdm = (Environment.GetEnvironmentVariable(
"GDMSESSION") ?? string.Empty).Trim();
StringComparison sc = StrUtil.CaseIgnoreCmp;
if(strXdg.Equals("Unity", sc))
t = DesktopType.Unity;
else if(strXdg.Equals("LXDE", sc))
t = DesktopType.Lxde;
else if(strXdg.Equals("XFCE", sc))
t = DesktopType.Xfce;
else if(strXdg.Equals("MATE", sc))
t = DesktopType.Mate;
else if(strXdg.Equals("X-Cinnamon", sc))
t = DesktopType.Cinnamon;
else if(strXdg.Equals("Pantheon", sc)) // Elementary OS
t = DesktopType.Pantheon;
else if(strXdg.Equals("KDE", sc) || // Mint 16
strGdm.Equals("kde-plasma", sc)) // Ubuntu 12.04
t = DesktopType.Kde;
else if(strXdg.Equals("GNOME", sc))
{
if(strGdm.Equals("cinnamon", sc)) // Mint 13
t = DesktopType.Cinnamon;
else t = DesktopType.Gnome;
}
}
catch(Exception) { Debug.Assert(false); }
}
m_tDesktop = t;
}
return m_tDesktop.Value;
}
#if (!KeePassLibSD && !KeePassUAP)
public static string RunConsoleApp(string strAppPath, string strParams)
{
return RunConsoleApp(strAppPath, strParams, null);
@@ -192,8 +258,6 @@ namespace ModernKeePassLib.Native
if(strStdInput != null)
{
// Workaround for Mono Process StdIn BOM bug;
// https://sourceforge.net/p/keepass/bugs/1219/
EnsureNoBom(p.StandardInput);
p.StandardInput.Write(strStdInput);
@@ -217,7 +281,11 @@ namespace ModernKeePassLib.Native
return strOutput;
}
catch(Exception) { Debug.Assert(false); }
#if DEBUG
catch(Exception ex) { Debug.Assert(ex is ThreadAbortException); }
#else
catch(Exception) { }
#endif
return null;
};
@@ -258,7 +326,7 @@ namespace ModernKeePassLib.Native
private static void EnsureNoBom(StreamWriter sw)
{
if(sw == null) { Debug.Assert(false); return; }
if(!NativeLib.IsUnix()) return;
if(!MonoWorkarounds.IsRequired(1219)) return;
try
{
@@ -267,9 +335,24 @@ namespace ModernKeePassLib.Native
byte[] pbBom = enc.GetPreamble();
if((pbBom == null) || (pbBom.Length == 0)) return;
FieldInfo fi = typeof(StreamWriter).GetField("preamble_done",
// For Mono >= 4.0 (using Microsoft's reference source)
try
{
FieldInfo fi = typeof(StreamWriter).GetField("haveWrittenPreamble",
BindingFlags.Instance | BindingFlags.NonPublic);
if(fi != null)
{
fi.SetValue(sw, true);
return;
}
}
catch(Exception) { Debug.Assert(false); }
// For Mono < 4.0
FieldInfo fiPD = typeof(StreamWriter).GetField("preamble_done",
BindingFlags.Instance | BindingFlags.NonPublic);
if(fi != null) fi.SetValue(sw, true);
if(fiPD != null) fiPD.SetValue(sw, true);
else { Debug.Assert(false); }
}
catch(Exception) { Debug.Assert(false); }
}
@@ -285,7 +368,10 @@ namespace ModernKeePassLib.Native
public static bool TransformKey256(byte[] pBuf256, byte[] pKey256,
ulong uRounds)
{
if(m_bAllowNative == false) return false;
#if KeePassUAP
return false;
#else
if(!m_bAllowNative) return false;
KeyValuePair<IntPtr, IntPtr> kvp = PrepareArrays256(pBuf256, pKey256);
bool bResult = false;
@@ -298,26 +384,31 @@ namespace ModernKeePassLib.Native
if(bResult) GetBuffers256(kvp, pBuf256, pKey256);
NativeLib.FreeArrays(kvp);
FreeArrays(kvp);
return bResult;
#endif
}
/// <summary>
/// Benchmark key transformation.
/// </summary>
/// <param name="uTimeMs">Number of seconds to perform the benchmark.</param>
/// <param name="uTimeMs">Number of milliseconds to perform the benchmark.</param>
/// <param name="puRounds">Number of transformations done.</param>
/// <returns>Returns <c>true</c>, if the benchmark was successful.</returns>
public static bool TransformKeyBenchmark256(uint uTimeMs, out ulong puRounds)
{
puRounds = 0;
if(m_bAllowNative == false) return false;
#if KeePassUAP
return false;
#else
if(!m_bAllowNative) return false;
try { puRounds = NativeMethods.TransformKeyBenchmark(uTimeMs); }
catch(Exception) { return false; }
return true;
#endif
}
private static KeyValuePair<IntPtr, IntPtr> PrepareArrays256(byte[] pBuf256,