mirror of
https://github.com/winfsp/winfsp.git
synced 2025-04-22 08:23:05 -05:00
src: dotnet: check dll version during assembly load
This commit is contained in:
parent
5d8384a508
commit
197ce7c30a
@ -175,6 +175,8 @@ FSP_API NTSTATUS FspVersion(PUINT32 PVersion)
|
||||
* Two threads competing to read the version will read
|
||||
* the same value from the Version resource.
|
||||
*/
|
||||
*PVersion = 0;
|
||||
|
||||
extern HINSTANCE DllInstance;
|
||||
WCHAR ModuleFileName[MAX_PATH];
|
||||
PVOID VersionInfo;
|
||||
|
@ -18,6 +18,7 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.Security.AccessControl;
|
||||
@ -850,6 +851,17 @@ namespace Fsp.Interop
|
||||
FspWin32FromNtStatus = GetEntryPoint<Proto.FspWin32FromNtStatus>(Module);
|
||||
FspDebugLogSetHandle = GetEntryPoint<Proto.FspDebugLogSetHandle>(Module);
|
||||
}
|
||||
private static void CheckVersion()
|
||||
{
|
||||
FileVersionInfo Info;
|
||||
UInt32 Version = 0, VersionMajor, VersionMinor;
|
||||
Info = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location);
|
||||
FspVersion(out Version); VersionMajor = Version >> 16; VersionMinor = Version & 0xFFFF;
|
||||
if (Info.FileMajorPart != VersionMajor || Info.FileMinorPart > VersionMinor)
|
||||
throw new TypeLoadException(String.Format(
|
||||
"incorrect dll version (need {0}.{1}, have {2}.{3})",
|
||||
Info.FileMajorPart, Info.FileMinorPart, VersionMajor, VersionMinor));
|
||||
}
|
||||
static Api()
|
||||
{
|
||||
#if false //DEBUG
|
||||
@ -857,6 +869,7 @@ namespace Fsp.Interop
|
||||
Debugger.Break();
|
||||
#endif
|
||||
LoadProto(LoadDll());
|
||||
CheckVersion();
|
||||
}
|
||||
|
||||
[DllImport("kernel32.dll", CallingConvention = CallingConvention.StdCall, SetLastError = true)]
|
||||
|
Loading…
x
Reference in New Issue
Block a user